Skip to content

Instantly share code, notes, and snippets.

View tjstebbing's full-sized avatar
🐝
.go .py .js .vim

Timothy Stebbing tjstebbing

🐝
.go .py .js .vim
View GitHub Profile
#!/usr/bin/node
/* butterfly state machine */
var Egg = function(species) {
this.species = species;
console.log("An egg");
this.hatch = function() {
@tjstebbing
tjstebbing / gist:2766573
Created May 22, 2012 04:30
services concept for node servers
var Service = require('services');
var express = require('express');
var log = require('clog');
var mongodb = require('mongodb');
var amqp = require('amqp');
logService = function(settings, services, cb) {
if(settings.debug) {
log.configure({'log level' : 5});
@tjstebbing
tjstebbing / gist:3311463
Created August 10, 2012 05:50
Test post for blogthingy

This is a test blog post

It uses markdown!

var so = { "this" : "is" }, a = "test";
  • One
@tjstebbing
tjstebbing / gist:3375583
Created August 17, 2012 03:05
Another test post for Alicorn, this time with categories

This is a test with categories :)

Alicorn is a pure client-side blog engine which uses the gists of a user as the source for blog entries and comments. This has the benefit that it can be deployed anywhere that static file hosting is available, and is entirely source-controlled and unhackable.

@tjstebbing
tjstebbing / gist:3507987
Created August 29, 2012 07:29
simple img browser ui with bootstrap
<div class='row-fluid'>
<div class='span6'>
<div class='row-fluid'>
<div>
<form class="navbar-search pull-left">
<input type="text" class="search-query" placeholder="Search" style="background-color: white; border-color: #ccc;">
</form>
</div>
</div>
@tjstebbing
tjstebbing / gist:4083252
Created November 16, 2012 01:59
live styles
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script>
function CSS($scope) {
$scope.css = "body {\n background-color: #000;\n}";
}
angular.module('stylatron', []).directive('ngStyleContents',
function() {
@tjstebbing
tjstebbing / argument_tutorial.py
Created March 13, 2013 01:24
A basic tutorial on arguments in python :)
line = '\n'+80*'*'+'\n' #formatting helper
# A quick overview of argument handling in python
# ************************************************************************
# In python, functions have arguments which are both positional and keyword
# arguments, that is you can call a function using implicit positions to assign
# values to an argument, or you can call them with specific arguments.
# Arguments can also have defaults in the function definition, as with the
// Mongo DB queue helper.
var oneMinute = 60 * 1000; // in js milliseconds.
var lockTime = 30 * oneMinute;
var safeOpts = { safe: true, w: 1, journal: true };
/* processQueuedItems(collection, filter, taskFunc, log, callback)
*
* collection: a mongodb Collection object
import csv, StringIO, random, sys
from datetime import date, timedelta as td
try:
count = int(sys.argv[1])
except:
count = 10
def dates(d1, d2):
return [str(d1 + td(days=x)) for x in range((d2-d1).days + 1)]
function groupData(data, nGroups) {
var out = [];
data.sort(function(a, b) { return a > b; })
var hop = data[data.length-1] / nGroups;
for(var i=0; i<data.length; i++) {
var index = Math.ceil(data[i] / hop);
if(!out[index]) out[index] = [];
out[index].push(data[i]);
}