Skip to content

Instantly share code, notes, and snippets.

Avatar

Ted Blackman belisarius222

View GitHub Profile
@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 / 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 / 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 / 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
#
View up-forward-toward-%ford-0.md

up 1: forward %ford, toward 0k

up: 1
authors: [~rovnys-ricfer(ted@tlon.io), ~pittyp-datfun(anton@tlon.io)]

overview

%ford is urbit's build system. It's one of the seven kernel modules (vanes)

@belisarius222
belisarius222 / meetup.hoon
Last active Sep 23, 2017
some examples of compiling hoon to nock
View meetup.hoon
::
:::: it's a trap!
::
!=
=/ a 3
|.
?: =(a 5)
a
$(a +(a))
::
@belisarius222
belisarius222 / .vimrc
Created Nov 15, 2017
.vimrc_11_15_2017
View .vimrc
set nocompatible
set encoding=utf-8
let mapleader = " "
" Vundle stuff
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'