Skip to content

Instantly share code, notes, and snippets.

View cantremember's full-sized avatar
✏️
Under Construction

Dan Foley cantremember

✏️
Under Construction
View GitHub Profile
@cantremember
cantremember / catchAndThrow.rb
Last active May 10, 2021 23:01
Ruby's Kernel#catch and #throw
def catchAndThrow(flow)
i = 0
if (flow == :return) then
return i
end
catch do |label|
# TODO: something useful
i += 1
throw label if (flow == :throw)
@cantremember
cantremember / matchURI.test.mjs
Created May 10, 2021 20:41
matchURI Test Suite
import assert from 'assert';
import { matchURI } from './matchURI.mjs';
assert.deepStrictEqual(matchURI('UNPARSEABLE'), {
uri: 'UNPARSEABLE',
id: undefined,
reason: 'error',
});
assert.deepStrictEqual(matchURI('https://stealth.mil/resource/SECRET'), {
uri: 'https://stealth.mil/resource/SECRET',
@cantremember
cantremember / matchURI.mjs
Last active May 10, 2021 20:59
matchURI, using a labeled block
import { URL } from 'url';
const DOMAINS = new Set([ 'example.com', 'alternate.net' ]);
const SEGMENTS = new Set([ 'query', 'search' ]);
export function matchURI(uri) {
let id = undefined;
let url;
try {
@cantremember
cantremember / client-binary-mode.js
Created April 30, 2017 22:13
Socket.io Client messaging using Binary Mode
/**
* Socket.io => Client => Listener
*/
function onSocketMessage: (channel_id, array_buffer) =>
// ArrayBuffer => String
// http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
json = String.fromCharCode.apply(null, new Uint8Array(array_buffer));
try {
@cantremember
cantremember / server-binary-mode.js
Last active April 30, 2017 22:13
Socket.io Server messaging using Binary Mode
/**
* Redis => Server => Socket.io
*/
function onRedisMessage(channel, message) {
var json;
try {
json = JSON.parse(message);
}
catch (err) {
@cantremember
cantremember / nginx-ws-tls-termination.conf
Created April 30, 2017 20:21
Nginx as a TLS Termination proxy for WebSockets
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream server_cluster {
# sticky connections are critical for non-WebSocket Socket.io
# http://socket.io/docs/using-multiple-nodes/
ip_hash;
@cantremember
cantremember / allow-perf.sh
Last active April 30, 2017 19:12
`perf` will complain about "WARNING: Kernel *blah blah*"
#!/bin/bash
#
# https://gist.github.com/trevnorris/9616784
sudo sysctl kernel.kptr_restrict=0
sudo sysctl kernel.perf_event_paranoid=0
sudo sysctl kernel.perf_event_mlock_kb=65536
@cantremember
cantremember / install-debug-symbols.sh
Last active April 2, 2022 13:28
Installing debug symbols for the Linux Kernel
#!/bin/bash
#
# https://askubuntu.com/questions/197016/how-to-install-a-package-that-contains-ubuntu-kernel-debug-symbols
# https://wiki.ubuntu.com/DebuggingProgramCrash#Debug_Symbol_Packages
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01
sudo apt-get update
@cantremember
cantremember / install-perf.sh
Last active April 30, 2017 19:03
perf + brendangregg/FlameGraph
#!/bin/bash
#
# https://perf.wiki.kernel.org/index.php/Main_Page
# https://perf.wiki.kernel.org/index.php/Tutorial#Sampling_with_perf_record
# https://perf.wiki.kernel.org/index.php/Tutorial#Sample_analysis_with_perf_report
sudo apt-get install -y linux-tools-`uname -r`
sudo apt-get install -y linux-tools-common
sudo apt-get install -y linux-cloud-tools-`uname -r`
sudo apt-get install -y linux-cloud-tools-common
@cantremember
cantremember / redis.conf
Created April 30, 2017 18:49
Redis; lots of connections, low tolerance for under-run
daemonize yes
logfile "/var/log/redis/redis-server.log"
save ""
dir /tmp
# lots of connections
maxclients 10000
# low tolerance for under-run
# otherwise, redis-server gets a memory leak