Skip to content

Instantly share code, notes, and snippets.

View pjhades's full-sized avatar
🚮

pjhades

🚮
View GitHub Profile
@pjhades
pjhades / Makefile
Last active August 29, 2019 13:17
f
all: libbaz.so libbar.so foo
# libbaz depends on libm
libbaz.so: libbaz.h libbaz.c
gcc -o $@ -shared -fPIC -lm $^
# libbar depends on libbaz
libbar.so: libbar.h libbar.c
gcc -o $@ -L. -Wl,-rpath=. -lbaz -shared -fPIC $^
@pjhades
pjhades / pretty.py
Created October 16, 2018 02:00
pretty ugly
#!/usr/bin/env python3
def word(w):
def f(tokens):
return tokens[1:] if len(tokens) > 0 and tokens[0] == w else False
return f
def zero_or_more(parser):
def f(tokens):
if len(tokens) == 0:
@pjhades
pjhades / interrupt.sh
Created August 16, 2018 15:00
Distribute NIC interrupts evenly among the first X cores
#!/bin/bash
mask() {
local bytes=$((($2+3)/4))
local remaining=$((bytes%8))
local groups=$((bytes/8))
local s=$(printf "%0${bytes}x" $((1<<$1)))
local rc=${s::$remaining}
s=${s:$remaining}
while [ -n "$s" ]; do
se std::{mem, ptr};
fn swap_ptr(p1: &mut *mut Vec<i32>, p2: &mut *mut Vec<i32>) {
let mut p3: *mut Vec<i32> = ptr::null_mut();
p3 = *p1;
*p1 = *p2;
*p2 = p3;
}
fn main() {
struct S;
impl S {
fn foo(&self) { println!("S::foo"); }
fn bar(&self) { println!("S::bar"); }
}
fn foo() { println!("foo"); }
fn bar() { println!("bar"); }
use std::boxed::Box;
#[derive(Debug, PartialEq)]
enum N {
V(Vec<Box<N>>),
S(Box<N>),
C(i32),
}
macro_rules! t {
@pjhades
pjhades / ebpf.c
Created December 14, 2016 16:20
eBPF program to distribute incoming traffic among multiple cores in a round-robin way
int load_bpf(int mod)
{
int map_fd;
map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(int),
sizeof(uint64_t), 1);
if (map_fd < 0) {
log_error("creating BPF map failed");
return map_fd;
}
@pjhades
pjhades / moveapp2sdcard
Last active May 13, 2016 02:30
Move apps to SD card storage and create symbolic links at original positions pointing to the new paths. HAVE NOT TRIED, USE WITH CARE.
#!/usr/bin/env bash
name=$(basename $0)
usage="link files/directories to destination.\n\
usage: $name [-i|-p] <src> <abs dst dir>\n\
-i\task before overwriting\n\
-p\tpreview operations before executing\n"
confirm=''
@pjhades
pjhades / align.c
Created January 8, 2015 16:44
Memory alignment cases.
#include <stdio.h>
struct P1 { int i; char c; long j; char d; };
struct P2 { long j; char c; char d; int i; };
struct P3 { short w[3]; char c[3]; };
struct P4 { short w[3]; char *c[3]; };
struct P5 { struct P1 a[2]; struct P2 *p; };
int main()
{
@pjhades
pjhades / nerv.bashrc
Created November 16, 2012 11:13
NERV's .bashrc :)
echo -e "\e[1;31m __ _._.,._.__\e[0m"
echo -e "\e[1;31m .o8888888888888888P'\e[0m"
echo -e "\e[1;31m .d88888888888888888K\e[0m"
echo -e "\e[1;31m ,8 888888888888888888888boo._\e[0m"
echo -e "\e[1;31m :88b 888888888888888888888888888b.\e[0m"
echo -e "\e[1;31m \`Y8b 88888888888888888888888888888b.\e[0m"
echo -e "\e[1;31m \`Yb. d8888888888888888888888888888888b\e[0m"
echo -e "\e[1;31m \`Yb.___.88888888888888888888888888888888888b\e[0m"
echo -e "\e[1;31m \`Y888888888888888888888888888888CG88888P\"'\e[0m"
echo -e "\e[1;31m \`88888888888888888888888888888MM88P\"'\e[0m"