Skip to content

Instantly share code, notes, and snippets.

View andurilan's full-sized avatar

operator.malcolm andurilan

View GitHub Profile
@northox
northox / slapshot.sh
Created April 23, 2017 00:54
Download and validate OpenBSD snapshot then install /bsd.rd
#!/bin/sh
path=snapshots
url=ftp://openbsd.cs.toronto.edu/pub/OpenBSD/
rel=`uname -r`
major=`echo $rel | sed 's/\..*//'`
minor=`echo $rel | sed 's/.*\.//'`
mkdir -p $path
cd $path
@nicowilliams
nicowilliams / fork-is-evil-vfork-is-good-afork-would-be-better.md
Last active November 5, 2023 12:14
fork() is evil; vfork() is goodness; afork() would be better; clone() is stupid

I recently happened upon a very interesting implementation of popen() (different API, same idea) called popen-noshell using clone(2), and so I opened an issue requesting use of vfork(2) or posix_spawn() for portability. It turns out that on Linux there's an important advantage to using clone(2). I think I should capture the things I wrote there in a better place. A gist, a blog, whatever.

This is not a paper. I assume reader familiarity with fork() in particular and Unix in general, though, of course, I link to relevant wiki pages, so if the unfamiliar reader is willing to go down the rabbit hole, they should be able to come ou

@leommoore
leommoore / btoa-atob.js
Last active November 19, 2017 08:00
btoa & atob
function btoa(str) {
if ((typeof str) !== 'string') {
str = JSON.stringify(str);
}
var buffer;
if (str instanceof Buffer) {
buffer = str;
@SplittyDev
SplittyDev / a_readme.md
Last active September 21, 2021 19:37
x86 bare metal protected mode itoa implementation

Freestanding x86 itoa implementation

For use in OS development.
Designed to be assembled with NASM, porting it over to other assemblers should be easy.

License

You are free to use, modify, distribute and sell this code.
A small message referring to this gist would be nice, though not required.

Important

This implementation uses a custom calling convention.

@MightyPork
MightyPork / usb_hid_keys.h
Last active May 1, 2024 05:11
USB HID Keyboard scan codes
/**
* USB HID Keyboard scan codes as per USB spec 1.11
* plus some additional codes
*
* Created by MightyPork, 2016
* Public domain
*
* Adapted from:
* https://source.android.com/devices/input/keyboard-devices.html
*/
@zrsmith92
zrsmith92 / external.rs
Created March 2, 2015 18:41
Rust printf interface
use libc::{c_char, c_int};
extern {
#[allow(dead_code)]
pub fn puts(str: *const c_char) -> c_int;
#[allow(dead_code)]
pub fn printf(format: *const c_char, ...) -> c_int;
}
@fcaylus
fcaylus / .colors
Created June 1, 2014 08:17
Colors defines in shell.
#
# Colored defines
#
RCol='\e[0m' # Text Reset
# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m';
Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m';
Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m';
@BertrandBordage
BertrandBordage / cat.asm
Created April 16, 2014 19:04
Command-line read file in X86_64 intel assembly for Linux
; À compiler avec nasm -felf64 cat.asm && ld cat.o -o cat
%define SYS_EXIT 60
%define SYS_READ 0
%define SYS_WRITE 1
%define SYS_OPEN 2
%define SYS_CLOSE 3
%define STDOUT 1
%define BUFFER_SIZE 2048
@jboner
jboner / latency.txt
Last active May 6, 2024 07:06
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@tonious
tonious / hash.c
Last active February 17, 2023 02:25
A quick hashtable implementation in c.
/* Read this comment first: https://gist.github.com/tonious/1377667#gistcomment-2277101
* 2017-12-05
*
* -- T.
*/
#define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */
#include <stdlib.h>
#include <stdio.h>