Skip to content

Instantly share code, notes, and snippets.

@joedavis
joedavis / http.zig
Created July 10, 2022 16:31
Barebones HTTP implementation in Zig
const std = @import("std");
pub const Headers = std.StringHashMap([]const u8);
pub const StatusCode = enum(u32) {
@"continue" = 100,
switching_protocols = 101,
processing = 102,
early_hints = 103,
Index: sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.26
diff -u -p -r1.26 sysupgrade.sh
--- sysupgrade.sh 14 Oct 2019 06:58:53 -0000 1.26
+++ sysupgrade.sh 15 Oct 2019 19:30:14 -0000
@@ -25,7 +25,7 @@ umask 0022
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
#!/usr/bin/env python3
"""
Animation of the Schrodinger equation for a particle in a 1D box
-∂²/∂x² ψ(x,t) = i ∂/∂t ψ(x,t) (natural units)
for a non-eigenstate initial state ψ, with boundary conditions
ψ(0,t) = ψ(1,t) = 0.
#![feature(macro_rules)]
#![feature(globs)]
use std::fmt::*;
macro_rules! bitfield(
{ $name:ident: $repr:ty,
$(($getter:ident, $setter:ident): $width:expr),+ } => (
#[packed]
#[deriving(Show)]
struct $name($repr);
#![feature(macro_rules)]
use std::collections::HashMap;
macro_rules! map(
{ $T:ident $($args:tt)* } => {
{
let mut m = $T::new();
map_insert! { m $($args)* }
}
@joedavis
joedavis / singleton.hh
Created January 1, 2014 13:26
Singleton with statically allocated storage, useful for embedded systems, operating system kernels and driver development.
// Singleton with statically allocated storage, useful for embedded systems,
// operating system kernels and driver development.
/*
* Written in 2014 by Joe Davis <[email protected]>
*
* To the extent possible under law, the author(s) have dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
@joedavis
joedavis / let-example.c
Created December 27, 2010 17:03
"Let" special form, in C
/* Example usage of "let" */
#include "let.h"
int
main (int argc, char *argv[])
{
let ((x, 42),
(y, 3.14159))
{
@joedavis
joedavis / foreach.h
Created October 18, 2010 16:41
Foreach loop in C
/* Foreach loop in GNU C, released in the public domain by Joe Davis.
* Credit would be nice ;)
*/
#ifndef FOREACH_H_
#define FOREACH_H_
#include <stdbool.h>
#include <string.h>