Compare commits

...

4 Commits

Author SHA1 Message Date
Tom
605606ca4c Small fix for atom feed 2025-06-11 10:42:23 +02:00
Tom
45f07eb92a Add tiny webservers 2025-06-11 10:42:04 +02:00
Tom
bd44164320 Make a funny first letter 2025-06-11 10:40:38 +02:00
Tom
1440873b46 Move birthday 2025-06-11 10:40:22 +02:00
21 changed files with 178 additions and 1060 deletions

2
.gitignore vendored
View File

@ -15,5 +15,5 @@ package-lock.json
*.pdf *.pdf
*.fbx *.fbx
*.secret *.secret
*.ipynb # *.ipynb
/scripts/dead-link-checker /scripts/dead-link-checker

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,14 +0,0 @@
<!DOCTYPE html><html lang="en"><head>
<script src="p5.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<script src="sketch.js"></script>
</head>
<body>
<div id="sketch-holder">
<!-- Our sketch will go here! -->
</div>
</body></html>

View File

@ -1,103 +0,0 @@
let w = 200;
let stepsize = 1;
let Nwalkers = 300;
let fr = 30;
let beta = 0.1; //beta = 0 chooses infinite temperature, beta = inf forces the walkers to go only towards the gradient
let betaslider;
let radio;
let cw = 500;
let canvas, src, pg;
let walkerpos = []
let transparent;
function proposal(pos) {}
let img;
let distfield;
function preload() {
img = loadImage('birthday.png');
distfield = loadImage('distfield.png');
}
let dist, showdist, showtarget, showpaths, showwalkers;
let step;
let newpos;
function setup() {
console.log('canvas has size: ', cw, cw);
canvas = createCanvas(cw, cw);
canvas.parent('sketch-holder');
//pixelDensity(1);
//let d = pixelDensity();
frameRate(fr);
betaslider = createSlider(0, 1, 0.5, 0.0001);
//betaslider.position(10, 10);
betaslider.style('width', '80px');
showdist = createCheckbox('Show distance function', false);
showtarget = createCheckbox('Show target image', false);
showpaths = createCheckbox('Show paths', true);
showwalkers = createCheckbox('Show walkers', true);
overlay = createGraphics(windowWidth, windowHeight);
overlay.pixelDensity(1);
overlay.background(color(0,0,0,0));
dist = function(pos) {
return distfield.get(pos.x, pos.y)[0];
}
colorMode(HSL);
walkers = [];
for(let i = 0; i < Nwalkers; i += 1) {
append(walkerpos, createVector(random(width), random(height)));
}
step = createVector(0,0);
}
let b;
function draw() {
background(255);
if(showdist.checked()) image(distfield, 0, 0); //the min distance to the nearest non white pixel in the target image
if(showtarget.checked()) image(img, 0, 0); //the target image
if(showpaths.checked()) {
//tint(255, 5e6 / frameCount / Nwalkers);
image(overlay, 0, 0);
}
//text(dist(createVector(mouseX, mouseY)), width/2, height/2);
//text(overlay.get(mouseX, mouseY), width/2, height/2);
beta = betaslider.value();
beta = beta / (1 - beta);
overlay.loadPixels();
for(let i = 0; i < Nwalkers; i += 1) {
//let debug = Math.sqrt((mouseX - walkerpos[i].x)**2 + (mouseY - walkerpos[i].y)**2) < 10;
step.x = 2*stepsize*(random() - 0.5);
step.y = 2*stepsize*(random() - 0.5);
newpos = p5.Vector.add(walkerpos[i], step);
let df = dist(newpos) - dist(walkerpos[i]);
if(df > 0 | exp(beta * df) > random(1.0)) {
walkerpos[i].add(step);
}
if(showwalkers.checked()) circle(walkerpos[i].x, walkerpos[i].y, 3);
// loop over
index = 4 * (int(walkerpos[i].y) * overlay.width + int(walkerpos[i].x));
b = overlay.pixels[index+3] + 5
overlay.pixels[index+3] = b;
}
overlay.updatePixels();
}

View File

@ -1,13 +0,0 @@
html, body {
margin: 0;
padding: 0;
}
#sketch-holder {
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
width: 500px;
}

View File

@ -148,6 +148,19 @@ main {
} }
} }
// p.lead:first-child::first-letter, .blog-namespace > p.lead:first-child::first-letter
div.e-content > p:first-of-type:first-child::first-letter {
float: left;
color: var(--theme-highlight-color);
font-size: 75px;
line-height: 60px;
padding-top: 4px;
padding-right: 15px;
padding-left: 3px;
font-family: Baskerville,Georgia,"URW Bookman","Noto Serif","URW Palladio L","Times New Roman",Times,serif;
// font-family: "Space Grotesk";
}
// All code both inline and block // All code both inline and block
code { code {
font-family: var(--mono-font); font-family: var(--mono-font);

View File

@ -4,6 +4,7 @@ layout: none
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator> <generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator>
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" hreflang="en" /> <link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" hreflang="en" />
<updated>{{site.time | date_to_xmlschema }}</updated> <updated>{{site.time | date_to_xmlschema }}</updated>
<id>{{ page.url | absolute_url | xml_escape }}</id> <id>{{ page.url | absolute_url | xml_escape }}</id>

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -0,0 +1,3 @@
target/
Cargo.lock
.vscode/

View File

@ -0,0 +1,10 @@
[package]
name = "tiny_webserver"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = "0.8.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.140"
tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] }

View File

@ -0,0 +1,34 @@
// use axum::{
// routing::{get,post},
// Router,
// };
// use serde_json::Result;
// use serde::{Deserialize, Serialize};
// #[derive(Serialize, Deserialize, Copy)]
// struct State {
// value: bool
// }
// static STATE: bool = false;
// async fn get_state() -> State {
// &STATE
// }
// #[tokio::main]
// async fn main() {
// // build our application with a single route
// let app = Router::new()
// .route("/get", get(get_state))
// .route("/set", post(set_state));
// // run our app with hyper, listening globally on port 3000
// let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
// axum::serve(listener, app).await.unwrap();
// }

View File

@ -0,0 +1,62 @@
use std::env;
use std::io;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
fn main() {
// The only shared state of this tiny webserver
let mut hitcount: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
// Bind to address given as argument or a default value.
let address = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
println!("Listening on {}", address);
let listener = TcpListener::bind(address).unwrap();
// Handle new connections in an infinite loop.
std::thread::scope(|scope| {
for stream in listener.incoming() {
let mut stream = stream.unwrap();
let hitcount_clone = Arc::clone(&hitcount);
let _ = scope.spawn(move || {
let re = handle_connection(&mut stream, hitcount_clone);
// Print out any errors
if re.is_err() {
println!("Error: {:?}", re);
}
});
}
})
}
fn handle_connection(stream: &mut TcpStream, hitcount: Arc<AtomicUsize>) -> io::Result<()> {
let mut buf = [0; 512];
stream.read(&mut buf).expect("Failed to read from socket.");
let request = str::from_utf8(&buf).expect("Request is not valid utf8");
println!("Got request: {}", request.split("\r\n").nth(0).unwrap_or(&request));
let (status, content) = if request.starts_with("GET / HTTP/1.1\r\n") {
let current_count = hitcount.fetch_add(1, Ordering::Relaxed) + 1;
("200 OK", format!("{{\"hits\": {}}}\n", current_count))
} else {
("404 NOT FOUND", "404 not found".to_string())
};
let length = content.len();
let response = format!(
"HTTP/1.1 {status}\r\n\
Content-Type: application/json\r\n\
Content-Length: {length}
\r\n\r\n\
{content}"
);
stream.write(response.as_bytes())?;
stream.flush()?;
Ok(())
}

View File

@ -0,0 +1,54 @@
use std::env;
use std::io;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
fn main() {
// The only shared state of this tiny webserver
let mut hitcount: usize = 0;
// Bind to address given as argument or a default value.
let address = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
println!("Listening on {}", address);
let listener = TcpListener::bind(address).unwrap();
// Handle new connections in an infinite loop.
for stream in listener.incoming() {
let mut stream = stream.unwrap();
let re = handle_connection(&mut stream, &mut hitcount);
// Print out any errors
if re.is_err() {
println!("Error: {:?}", re);
}
}
}
fn handle_connection(stream: &mut TcpStream, hitcount: &mut usize) -> io::Result<()> {
let mut buf = [0; 512];
stream.read(&mut buf).expect("Failed to read from socket.");
let request = str::from_utf8(&buf).expect("Request is not valid utf8");
println!("Got request: {}", request.split("\r\n").nth(0).unwrap_or(&request));
let (status, content) = if request.starts_with("GET / HTTP/1.1\r\n") {
*hitcount = (*hitcount).saturating_add(1);
("200 OK", format!("{{\"hits\": {}}}\n", hitcount))
} else {
("404 NOT FOUND", "404 not found".to_string())
};
let length = content.len();
let response = format!(
"HTTP/1.1 {status}\r\n\
Content-Type: application/json\r\n\
Content-Length: {length}
\r\n\r\n\
{content}"
);
stream.write(response.as_bytes())?;
stream.flush()?;
Ok(())
}

View File