Skip to content

Instantly share code, notes, and snippets.

@mwilliamson
mwilliamson / frontend.js
Last active February 8, 2021 14:50
WebSocket server
function handleConnect(url: string) {
setState({type: "connecting"});
const socket = new WebSocket(url);
let nextMessageIndex = 0;
socket.onmessage = function (event) {
const message = JSON.parse(event.data);
if (message.index !== nextMessageIndex) {
setState({type: "sync-error"});
@mwilliamson
mwilliamson / gist:2cdf38bee1fa68f0800e
Created April 30, 2014 17:36
py-bt output from spur.py issue #14
(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/packet.py, 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
mwilliamson / gist:7378638
Last active December 27, 2015 19:39
Encode and de-code run-length encoding in Prolog with a single predicate.
encode([], []).
encode(XS, [E|ES]) :-
reverse(XS, XSReversed),
append(XRightReversed, XLeft, XSReversed),
XLeft \= [],
expand(XLeft, E),
reverse(XRightReversed, XRight),
encode(XRight, ES).
@mwilliamson
mwilliamson / gist:7378428
Last active April 5, 2022 09:58
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.
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>'