Skip to content

Instantly share code, notes, and snippets.

View belisarius222's full-sized avatar

Ted Blackman belisarius222

View GitHub Profile
@belisarius222
belisarius222 / ddp_log.js
Created January 10, 2013 07:24
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.
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 March 26, 2018 15:02 — forked from anonymous/Meteor local mirror
Added `changed` callback and factored out shared --> local conversion.
//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 March 30, 2013 19:24
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
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 December 17, 2015 04:58
a super-bare-bones implementation of a reactive window.location (include this somewhere on the client in a Meteor app)
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 December 21, 2015 06:09
little script to download files sequentially from an S3 bucket. This will download all the mongo binaries into the same directory as the script.
import requests
filenames = [
'doxygenConfig',
'firstExample',
'secondExample',
'SConstruct',
'mongod',
'mongo',
'mongodump',
@belisarius222
belisarius222 / long_to_bytes.py
Last active August 29, 2015 13:57
python3 implementation of long_to_bytes from pysrp package
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 July 16, 2021 05:27
Gray codes in python
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 April 15, 2016 05:18
Custom Python Exceptions
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:
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 September 2, 2017 08:36
hoon syntax highlighting for kakoune
# Detection
#
hook global BufCreate .*[.](hoon) %{
set buffer filetype hoon
}
# Highlighters & Completion
#