Skip to content

Instantly share code, notes, and snippets.

@depp
depp / Makefile
Created Jun 25, 2021
Injection Demo
View Makefile
all: inject.dylib main
inject.dylib: inject.c
cc -dynamiclib $^ -o $@
main: main.c
cc $^ -o $@
View readme.md

Sampling Uniformly in a Sphere

  • Method 1: rejection sampling: sample uniformly in a cube, then reject points outside the unit sphere.

  • Method 2: polar sampling: use polar coordinates to directly generate points uniformly in the sphere

There are two implementations here. One in JavaScript, one in C. Which method is faster is different depending on the language!

Results (JavaScript)

@depp
depp / rsrc2macbinary.py
Created Mar 18, 2021
Convert resource fork files to MacBinary files
View rsrc2macbinary.py
"""rsrc2macbinary.py - convert resource fork to MacBinary file"""
import datetime
import os
import struct
import sys
import zlib
def die(*msg):
print('Error:', *msg, file=sys.stderr)
raise SystemExit(1)
@depp
depp / ctl.py
Created Nov 10, 2020
Nintendo 64 CTL Dumper
View ctl.py
"""Dump a Nintendo 64 .ctl file to text.
Usage: python3 ctl.py <file.ctl>
"""
import argparse
import struct
import sys
SPACE = ' ' * 80
def pr(indent, *msg):
View match.rs
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Error::Transient(ref e) => Some(e),
Error::Fatal(ref e) => Some(e),
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
&Error::Transient(ref e) => Some(e),
@depp
depp / heightmap_smooth.py
Last active Sep 17, 2019
How to Create a Smooth Heightmap
View heightmap_smooth.py
# https://www.reddit.com/r/proceduralgeneration/comments/d5gde4/heightmap_with_strict_neighbour_cell_constraints/
import numpy as np
import scipy.ndimage as ndimage
def generate(w, h, d):
return np.random.randint(0, d, (w, h))
def smooth(arr):
for z in range(np.min(arr), np.max(arr) + 1):
# Set of all tiles at height Z.
@depp
depp / find_merge_conflicts.py
Created Apr 23, 2019
Find Git merge conflicts
View find_merge_conflicts.py
# https://stackoverflow.com/questions/55817243/does-git-keep-a-record-of-past-merge-conflicts
import subprocess
import sys
def list_merges():
proc = subprocess.run(
['git', 'rev-list', '--parents', '--min-parents=2', '--all'],
stdout=subprocess.PIPE,
check=True,
encoding='ASCII',
@depp
depp / hello32.asm
Created Apr 9, 2019
32-bit Hello World for DOS with DOS/32A
View hello32.asm
;; 32-bit Hello World
;; This creates a Linear Executable which can be run with DOS/32A.
;; See: http://dos32a.narechk.net/index_en.html
;;
;; To compile,
;; nasm -o hello32.exe -f bin hello32.asm
;; To run,
;; dos32a hello32
;; Screenshot: https://imgur.com/EiaU2py
bits 32
@depp
depp / scrape.py
Created Feb 26, 2019
Scraping with Python
View scrape.py
# https://stackoverflow.com/questions/54876010
from bs4 import BeautifulSoup
import json
import requests
import sys
from urllib.parse import urljoin
def get_list(uri):
"""Scan the manga list for links to manga."""
response = requests.get(uri)
@depp
depp / pipe.py
Created Aug 9, 2018
Simple command piping in Python
View pipe.py
# https://stackoverflow.com/questions/51756938/how-to-make-a-generic-method-in-python-to-execute-multiple-piped-shell-commands
import shlex
import subprocess
def run_pipe(cmds):
pipe = subprocess.DEVNULL
procs = []
for cmd in cmds:
proc = subprocess.Popen(cmd, stdin=pipe, stdout=subprocess.PIPE)
procs.append(proc)