Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Castellucci ryancdotorg

View GitHub Profile
@ryancdotorg
ryancdotorg / rand.c
Created Aug 23, 2021
A simple command line random number generator that can compile on x86_64 without libc
View rand.c
// gcc -Os -DNO_LIBC -fno-builtin -static -nostdlib -fomit-frame-pointer rand.c -o rand
// gcc -O3 rand.c -o rand
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/random.h>
#include <inttypes.h>
View c_str.py
# escape a `str`, `bytes`, `bytearray` or `Iterable[int]` value as a C string
def c_str(s):
out = '' # see https://w.wiki/34HP
trigraph = {33, 39, 40, 41, 45, 47, 60, 61, 62}
escape = {8: 98, 9: 116, 10: 110, 13: 114, 34: 34, 39: 39, 92: 92}
if isinstance(s, bytearray): s = bytes(s)
if isinstance(s, bytes):
try: s = s.decode()
except: pass
if isinstance(s, str): s = map(ord, s)
@ryancdotorg
ryancdotorg / default.conf
Created Feb 7, 2021
An opinionated nginx default server configuration block
View default.conf
# An opinionated nginx default server configuration block
# Author: Ryan Castellucci https://rya.nc/ @ryancdotorg
# Revision: 2021-02-07
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
# Send ACME (LetsEncrypt) requests to a special directory
@ryancdotorg
ryancdotorg / setImmediate.js
Created Jan 3, 2021
A setImmediate polyfill optimized for size.
View setImmediate.js
(function(global, name, mc, counter, slice){
if (!(name in global)) {
if (mc = mc in global && new global[mc]) {
mc.port1.onmessage = function(evt) {
slice[evt = evt.data]();
delete slice[evt];
};
global[name] = function(cb) {
var args = slice.call(arguments, 1);
@ryancdotorg
ryancdotorg / Makefile
Created Nov 12, 2020
A Makefile for bundling javascript
View Makefile
all: javascript
javascript: bundle_js min_js
bundle_js: $(patsubst %/,%.bundle.js,$(foreach js,$(sort $(dir $(wildcard src/js/*/*.js))),$(subst src/,static/,$(js))))
min_js: $(patsubst %.js,%.min.js,$(foreach js,$(wildcard src/js/*.js),$(subst src/,static/,$(js))))
static/js/%.min.js: src/js/%.js
terser $< --safari10 --ecma 5 -c passes=2 -m --mangle-props regex=/^_/ -o $@
@ryancdotorg
ryancdotorg / fnode.js
Last active Jan 11, 2021
A nodejs REPL that'll autoload code
View fnode.js
#!/usr/bin/env node
// save somewhere in $PATH as fnode, remember to chmod +x
const vm = require('vm');
const fs = require('fs');
const tty = require('tty');
const path = require('path');
const repl = require('repl');
@ryancdotorg
ryancdotorg / sw.js
Last active Oct 14, 2020
Self-extracting Service Worker Cache PoC code. The resulting file *MUST* be served with content-type: application/javascript; charset=x-user-defined
View sw.js
var ArchiveReader = function(ab) {
if (!(this instanceof ArchiveReader)) {
throw new Error('ArchiveReader must be instantiated with `new`!');
}
this.ab = ab;
this.dv = new DataView(ab);
this.offset = 0;
this.td = typeof TextDecoder === 'function' ? new TextDecoder() : null;
}
@ryancdotorg
ryancdotorg / nd-json-tar.py
Created Jun 27, 2020
Python script that constructs tar archives from newline delimited JSON input.
View nd-json-tar.py
#!/usr/bin/env python3
import os, sys
import json
import tarfile
# apply attributes
def modify(attrib, stat, info):
if 'mtime' in attrib:
info.mtime = attrib['mtime']
View tasker-randomize-ad-id.xml
<TaskerData sr="" dvi="1" tv="5.9.2">
<Profile sr="prof22" ve="2">
<cdate>1568555561584</cdate>
<edate>1569679198184</edate>
<id>22</id>
<mid0>21</mid0>
<nme>Rotate Ad ID</nme>
<Time sr="con0">
<fh>0</fh>
<fm>0</fm>