Skip to content

Instantly share code, notes, and snippets.

Avatar

Ted Blackman belisarius222

View GitHub Profile
@belisarius222
belisarius222 / ddp_log.js
Created Jan 10, 2013
patch client-side Meteor functions to print out the DDP messages. Add this somewhere in your client-side JS before Meteor.startup() and it should print out the DDP messages. Please let me know if there are some that are missing! I'm not sure I caught all of the handler functions.
View ddp_log.js
var monkeyPatches = {
'_livedata_data': 'DATA',
'_livedata_error': 'ERROR',
'_livedata_nosub': 'NOSUB',
'_livedata_connected': 'CONNECTED',
'_livedata_result': 'RESULT',
};
_.each(_.keys(monkeyPatches),function(funcName){
var modifiedFunctionName = funcName+'_original';
var extension = {};
@belisarius222
belisarius222 / Meteor local mirror
Last active Mar 26, 2018 — forked from anonymous/Meteor local mirror
Added `changed` callback and factored out shared --> local conversion.
View Meteor local mirror
//common to client and server
SharedCollection = new Meteor.Collection('shared');
//client from here on out
LocalMirror = new Meteor.Collection(null);
var convertSharedToLocal = function(sharedDoc) {
var localDoc = LocalCollection._deepcopy(sharedDoc); // undocumented API, might change
@belisarius222
belisarius222 / loadTiming.js
Created Mar 30, 2013
Log start time, end time, and duration for requests using phantomjs. Also print out the average request durations. You should probably modify it a bit to make sure it exits under whatever conditions make the most sense for you. Run like: phantomjs loadTiming.js http://www.google.com
View loadTiming.js
var page = require('webpage').create(),
system = require('system'),
startTime, address, requestStartTimes, requestDurations;
if (system.args.length === 1) {
console.log('Usage: netlog.js <some URL>');
phantom.exit(1);
}
address = system.args[1];
@belisarius222
belisarius222 / location.js
Last active Dec 17, 2015
a super-bare-bones implementation of a reactive window.location (include this somewhere on the client in a Meteor app)
View location.js
var Location = {};
this.Location = Location;
Location.dep = new Deps.Dependency;
Location.state = window.history.state;
window.onpopstate = function(event){
Location.state = event.state;
// note that popstate gets fired on initial page load in Webkit,
@belisarius222
belisarius222 / get-from-bucket.py
Last active Dec 21, 2015
little script to download files sequentially from an S3 bucket. This will download all the mongo binaries into the same directory as the script.
View get-from-bucket.py
import requests
filenames = [
'doxygenConfig',
'firstExample',
'secondExample',
'SConstruct',
'mongod',
'mongo',
'mongodump',
@belisarius222
belisarius222 / long_to_bytes.py
Last active Aug 29, 2015
python3 implementation of long_to_bytes from pysrp package
View long_to_bytes.py
def long_to_bytes(n):
l = []
x = 0
off = 0
while x != n:
b = (n >> off) & 0xFF
l.append( b )
x = x | (b << off)
off += 8
l.reverse()
@belisarius222
belisarius222 / gray.py
Last active Jul 16, 2021
Gray codes in python
View gray.py
def gray(n):
if n == 1:
return ["0", "1"]
originals = gray(n - 1)
prefixedOriginals = ["0" + d for d in originals]
reflected = list(reversed(originals))
prefixedReflected = ["1" + d for d in reflected]
return prefixedOriginals + prefixedReflected
@belisarius222
belisarius222 / handgrenade.py
Last active Apr 15, 2016
Custom Python Exceptions
View handgrenade.py
class HandGrenadeError: pass
class WrongNumberError(HandGrenadeError): pass
class HolyHandGrenade:
def reference(self):
return "Armaments, chapter two, verses nine through twenty-one."
def lob(self, number):
if number != 3:
View Tiling.py
import cv2
def downsample(im):
return im[::2, ::2, :]
def smoothIm(im, kernelSize=5):
return cv2.GaussianBlur(im, (kernelSize, kernelSize), 0)
@belisarius222
belisarius222 / hoon.kak
Created Sep 2, 2017
hoon syntax highlighting for kakoune
View hoon.kak
# Detection
#
hook global BufCreate .*[.](hoon) %{
set buffer filetype hoon
}
# Highlighters & Completion
#