Skip to content

Instantly share code, notes, and snippets.

Dan Foley cantremember

Block or report user

Report or block cantremember

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cantremember
cantremember / client-binary-mode.js
Created Apr 30, 2017
Socket.io Client messaging using Binary Mode
View client-binary-mode.js
/**
* 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 Apr 30, 2017
Socket.io Server messaging using Binary Mode
View server-binary-mode.js
/**
* 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 Apr 30, 2017
Nginx as a TLS Termination proxy for WebSockets
View nginx-ws-tls-termination.conf
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 Apr 30, 2017
`perf` will complain about "WARNING: Kernel *blah blah*"
View allow-perf.sh
#!/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 Apr 30, 2017
Installing debug symbols for the Linux Kernel
View install-debug-symbols.sh
#!/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 Apr 30, 2017
perf + brendangregg/FlameGraph
View install-perf.sh
#!/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 Apr 30, 2017
Redis; lots of connections, low tolerance for under-run
View redis.conf
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
@cantremember
cantremember / Vagrantfile
Last active Apr 30, 2017
baseline Vagrant file for Node.js perf testing
View Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu-i386-14.10"
# Node.js server port, per `config.app.port`
config.vm.network "forwarded_port", guest: 3201, host: 3201
# # for remote inspection using `webkit-devtools-agent` or some equivalent
# config.vm.network "forwarded_port", guest: 3999, host: 3999
config.ssh.forward_agent = true
@cantremember
cantremember / monkey_patch_with_proxy.js
Last active Dec 19, 2018
using a Proxy to monkey-patch a method
View monkey_patch_with_proxy.js
class Foo {
method() {
return 'foo';
}
}
class Wrapper {
constructor(wrapped) {
this.latch = 2; // arbitrary condition; "proxy it this many times"
return new Proxy(wrapped, this);
@cantremember
cantremember / es6_protected_to_es5.js
Created Mar 2, 2016
exposing @Protected methods in an ES6 module to ES5
View es6_protected_to_es5.js
/*
consumer.js
`node consumer.js`
*/
import Lib from './lib';
const { method: libMethod } = Lib; // <= 2-step destructure
console.log(Lib.method());
console.log(libMethod());
You can’t perform that action at this time.