Skip to content

Instantly share code, notes, and snippets.

View routevegetable's full-sized avatar

Lee Marshall routevegetable

  • West Oakland, CA
View GitHub Profile
@routevegetable
routevegetable / source_list.py
Created June 3, 2020 18:36
Extract source file list from GDB
source_list = open("$SOURCE_LIST_FILE", "w")
lines = gdb.execute('info sources', to_string=True).split('\n')
for line in lines:
line = line.strip()
if not line.startswith('/'):
continue
parts = line.split(',')
for part in parts:
source_list.write(part.strip() + '\n')
source_list.close()
get_win_path() {
P=${PWD/\/usr\/lib/\/windows\/system32}
P=${P/\/usr\/bin/\/program files}
P=${P/$HOME/\/Documents and Settings\/$USER}
P=$(echo ${P//\//\\} | tr '[:lower:]' '[:upper:]')
echo "C:$P"
}
export PS1="\$(get_win_path)>"
@routevegetable
routevegetable / asyncratelimiter.js
Last active April 10, 2020 15:53
No idea if this works
function AsyncRateLimiter() {
/* Operation is in progress */
this.doingThing = false;
/* Next operation to do after this one */
this.nextFn = false;
}
AsyncRateLimiter.prototype.submit = function(fn) {
@routevegetable
routevegetable / led-balls.c
Created March 23, 2020 05:39
ws2811 mood lighting
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <stdbool.h>
#include <time.h>
@routevegetable
routevegetable / wrapper.h
Last active July 27, 2020 15:52
Macros to help you wrap things
#define DEF_WRAPPER(ret,name,...) typedef ret (*wrapped_##name##_t)(__VA_ARGS__); \
static wrapped_##name##_t wrapped_##name = NULL; \
ret name(__VA_ARGS__)
#define CALL_INNER(name, ...) (wrapped_##name ? wrapped_##name : (wrapped_##name = ((wrapped_##name##_t)dlsym(RTLD_NEXT,#name))))(__VA_ARGS__)
// Example:
//
//DEF_WRAPPER(ssize_t,send,int socket, const void *buffer, size_t length, int flags)
@routevegetable
routevegetable / fake_dns.sh
Last active November 21, 2019 22:10
Shell script to run a program with a fake DNS
#!/bin/bash
# Usage:
# fake_dns 12.23.45.67 fakedomain.com <program> [args...]
set -e
IP=$1
HOST=$2
shift 2
@routevegetable
routevegetable / eyes.c
Created November 5, 2019 20:13
Hacked together program for neopixel-based spooky eyes halloween display
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
@routevegetable
routevegetable / lut-automaton.c
Created October 23, 2019 15:30
Faster, LUT-based elementary cellular automaton
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <memory.h>
uint8_t get_bits(uint8_t *in_base, size_t start_bit, size_t n_bits)
{
size_t split = start_bit % 8;
uint8_t *base = &in_base[start_bit/8];
@routevegetable
routevegetable / automaton.c
Created September 28, 2019 03:39
Elementary Cellular Automaton implementation
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
void step(char *state, size_t len, char rule)
{
/* Buffer large enough to hold all bits */
char state_copy[len];
// void print_hex(unsigned char num);
.data
buff:
.ascii "0x00\n"
.global print_hex
.text
print_hex:
mov %rdi,%rax