Skip to content

Instantly share code, notes, and snippets.

View saranrapjs's full-sized avatar

Jeff Sisson saranrapjs

View GitHub Profile
@jgadelange
jgadelange / gist:808ebcb95cdfc469e7fb
Created September 20, 2014 14:02
Django/Stripe: parse timestamp and estimate prorate
from django.utils import timezone
def parse_timestamp(ts):
if ts is not None:
dt = datetime.datetime.fromtimestamp(ts)
dt = dt.replace(tzinfo=timezone.utc)
return dt
@tcr
tcr / code.js
Created October 23, 2011 07:22
How can you make the Github API accept Unicode characters in JSON?
function JSON_stringify(s, emit_unicode)
{
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/[\u007f-\uffff]/g,
function(c) {
return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
}
);
}
@constantology
constantology / __proto__.js
Last active October 14, 2015 01:28
An explanation of `__proto__` using an example and a `__proto__` "polyfill" for MSIE 9 & 10.
function Collection() {
this.push.apply( this, arguments );
}
Collection.prototype = [];
Collection.prototype.push = function( item ) { // we need to wrap this.push in a function or we'll get a recursion error from
if ( arguments.length > 1 ) { // the arguments.length always being > 1 since the Array index is passed to the iterator
this.slice.call( arguments ).map( function( val ) { this.push( val ); }, this );
return this.length;
@fitnr
fitnr / apportion.py
Last active August 4, 2016 16:33
Apportionment algorithm for the US House of Representatives
# Uses method of least proportions to apportion House members among states.
# http://en.wikipedia.org/wiki/United_States_congressional_apportionment#The_Method_of_Equal_Proportions
# use like this:
# python apportion.py --built-in 2010
# python apportion.py --file file.csv --key <column name>
# python apportion.py --file file.csv --key <column name> --reps 444
# python apportion.py --file file.csv --key <column name> --distsize 500000
from __future__ import division, print_function
import sys
import csv
@djinn
djinn / syllable.go
Created May 29, 2014 10:00
Syllable calculation done in golang
package main
import (
"log"
"strings"
)
func isVowel(chr_ rune) bool {
chr := string(chr_)
if (strings.EqualFold(chr, "a") || strings.EqualFold(chr, "e") ||
@tomtaylor
tomtaylor / names.txt
Last active April 28, 2017 16:16
English village names generated by Tensorflow
Allers Bottom
Culack
Swrarby
Fenwall St Eastake
Anbarth
St Ninhope
Thawkanham Water Green
Mige Lane
Up Maling
Firley Dinch
@j0uni
j0uni / gist:5168414
Created March 15, 2013 08:47
808 #16 camera configuration file + instructions
Date time=[2013/03/15-10:43:16];date time setting,format yyyy/mm/dd hh:mm:ss,
Movie resolution=[0];Movie resolution setting,0:720p 30fps,1:wvga 30fps,2:vga 30fps,
Movie cycle time=[1];movie cycle time,0:5 minutes,1:20 minutes,2:40 minutes,3: 70 minutes,
movie Loop Recording=[0];set loop recording on or off,0:off,1:on,
Movie stamp=[0];set date / time stamp on or off,0:off,1:on,
Movie sound=[2];set movie sound,0:mute,1:level 1,2:level 2,3:level 3,
LED=[0];set LED flicker when recording,0:off,1:on,
Movie quality=[1];set movie quality,set movie data rate,0:10 Mbps,1:7 Mbps,
Power off=[1];set system auto power off time when system pending,0:off,1:30 seconds,2:1 minutes,3:2 minutes,
Movie Flip=[0];set movie rotate,0:off,1:on,
20:10 dat-gitter-bot> (scriptjs) @mafintosh can you contrast hyperlog vs hypercore for their log capabilities, you dropped hypercore at some point. Is hypercore by itself as useful for an append only log use case?
20:10 <•mafintosh> @scriptjs right
20:10 <•mafintosh> so hyperlog is a DAG structure (a merkle dag even)
20:10 <•mafintosh> where data you insert can point to other data you insert
20:10 <•mafintosh> which is really great if you have multiple peers collaborating on the same data structure
20:11 <•mafintosh> a hyperlog is also always fully replicated since that makes the replication protocol pretty trivial
20:11 <•mafintosh> (i really need to write some white paper on that at some point)
20:11 <•mafintosh> hypercore is just simple single-writer append-only logs
20:11 <•mafintosh> so abstraction-wise hyperlog > hypercore
20:12 <•mafintosh> we could even make hyperlog run on top of hypercore which i really wanna do
@asciimike
asciimike / app.yaml
Created September 11, 2018 18:56
Testing Google Cloud IAP (https://cloud.google.com/iap) with GAE 2nd Generation Runtimes
runtime: nodejs8
@okdistribute
okdistribute / index.js
Last active January 28, 2019 08:29
dat with webrtc
var webrtc = require('webrtc-swarm')
var signalhub = require('signalhub')
var hyperdrive = require('hyperdrive')
var memdb = require('memdb')
var pump = require('pump')
var DEFAULT_SIGNALHUBS = 'https://signalhub.mafintosh.com'
var drive = hyperdrive(memdb())