Skip to content

Instantly share code, notes, and snippets.

mwilliamson / frontend.js
Last active Feb 8, 2021
WebSocket server
View frontend.js
function handleConnect(url: string) {
setState({type: "connecting"});
const socket = new WebSocket(url);
let nextMessageIndex = 0;
socket.onmessage = function (event) {
const message = JSON.parse(;
if (message.index !== nextMessageIndex) {
setState({type: "sync-error"});
mwilliamson / gist:2cdf38bee1fa68f0800e
Created Apr 30, 2014
py-bt output from issue #14
View gist:2cdf38bee1fa68f0800e
(gdb) t a a py-bt
Thread 5 (Thread 0x7f4f592d4700 (LWP 7760)):
Thread 4 (Thread 0x7f4f57964700 (LWP 30772)):
#6 Frame 0x7f4f50002190, for file /usr/local/lib/python2.7/dist-packages/paramiko/, line 208, in read_all (self=<Packetizer(_Packetizer__remainder='', _Packetizer__block_size_in=16, _Packetizer__compress_engine_out=None, _Packetizer__sent_packets=4, _Packetizer__mac_engine_in=<module at remote 0x7f4f61b4f408>, _Packetizer__sequence_number_out=7L, _Packetizer__received_packets_overflow=0, _Packetizer__closed=False, _Packetizer__sequence_number_in=9L, _Packetizer__logger=<Logger(name='paramiko.transport', parent=<RootLogger(name='root', parent=None, handlers=[], level=30, disabled=0, propagate=1, filters=[]) at remote 0x7f4f6245e6d0>, handlers=[], level=0, disabled=0, manager=<Manager(emittedNoHandlerWarning=0, disable=0, root=<...>, loggerDict={'test': <Logger(name='test', parent=<...>, handlers=[<FileHandler(stream=<file at remote 0x7f4f5b695540>, encoding=None, lock=<_RLock(_Verbose__verbos
mwilliamson / gist:7378638
Last active Dec 27, 2015
Encode and de-code run-length encoding in Prolog with a single predicate.
View gist:7378638
encode([], []).
encode(XS, [E|ES]) :-
reverse(XS, XSReversed),
append(XRightReversed, XLeft, XSReversed),
XLeft \= [],
expand(XLeft, E),
reverse(XRightReversed, XRight),
encode(XRight, ES).
mwilliamson / gist:7378428
Last active Dec 27, 2015
Different ways of implementing run-length encoding in Prolog. Only encode3 seems to work both ways (encoding and decoding) with large inputs, but has the disadvantage that inefficient encodings are listed first.
View gist:7378428
encode([], []).
encode([X|XT], [[Count, X] | RestEncoded]) :-
consume([X|XT], X, Count, Rest),
encode(Rest, RestEncoded).
consume([], _, 0, []).
consume([X|XT], X, Count, Rest) :-
consume(XT, X, SubCount, Rest),
succ(SubCount, Count).
import time
from boto.ec2.connection import EC2Connection
from boto import ec2
import spur.ssh
import spur
key = '<your key here>'
secret = '<your secret here>'
instanceId = '<your instance id>'