Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Castellucci ryancdotorg

View GitHub Profile
@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>
@ryancdotorg
ryancdotorg / web-crypto-scrypt.js
Last active Apr 6, 2020
An async JavaScript Scrypt implementation using Web Cryptography APIs for PBKDF2.
View web-crypto-scrypt.js
// Based on https://github.com/ricmoo/scrypt-js
"use strict";
(function(root) {
const MAX_VALUE = 0x7fffffff;
// Returns a Promise that resolves to an ArrayBuffer.
async function PBKDF2_HMAC_SHA256(password, salt, iterations, dkLen) {
return crypto.subtle.importKey('raw', password, {name: 'PBKDF2'}, false, ["deriveBits"]).then(
@ryancdotorg
ryancdotorg / setgw.sh
Created Mar 14, 2020
Sets up routing when you don't have an on-subnet IP configured.
View setgw.sh
#!/bin/sh
IFACE="$1"
SRCIP="$2"
DSTIP="$3"
MAC=`/usr/sbin/arping -r -C1 -w10 -i "$IFACE" -S "$SRCIP" "$DSTIP"`
if [ $? -eq 0 ]
then
/sbin/ip neigh replace "$DSTIP" lladdr "$MAC" dev "$IFACE" nud permanent || exit $?
/sbin/ip route replace default via "$DSTIP" dev "$IFACE" || exit $?
else