Skip to content

Instantly share code, notes, and snippets.

@igroff
igroff / sqlite_queue.py
Created February 5, 2016 21:16
Queue like data structure backed by sqlite
import os
import apsw
import pdb
class SqliteQueue(object):
_create = 'CREATE TABLE IF NOT EXISTS queue (id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT)'
_append = 'INSERT INTO queue (item) VALUES (?)'
_pop_get = 'SELECT id, item FROM queue ORDER BY id LIMIT 1'
_pop_del = 'DELETE FROM queue WHERE id = ?'
@igroff
igroff / delimitedListOfStringsToTree.coffee
Last active August 29, 2015 14:11
Turns a list of consistently delimited strings into something treeish
listOfDelimitedStringsToTree = (lines, delimiter) ->
stringTreeToObjectTree = (root) ->
childNodes = []
for name, value of root
# path is just metadata for this whole process
# so we skip it
if name isnt "path"
node =
name: name
children: stringTreeToObjectTree(value)
/* Takes a list ofdelimited strings, where the delimiter is intended to imply
* a hierarchy ( somewhat like a file system path ) and turns it into
* a tree-like structure consisting of nodes looking something like
* { name: "", children: [] }
* The tree starts at the root node, which is ( no foolin' ) called
* root. So the top (root) node is:
* { name: "root", children: [xxx] }
*/
function listOfDelimitedStringsToTree(lines, delimiter){
function stringTreeToObjectTree(root){
/* The idea here is that we take something that's formatted like a query string, and
return a dictionary (object) it represents
*/
function qsLikeToObj(qsLike){
var obj = {};
qsLike.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { obj[$1] = $3; }
);
return obj;
@igroff
igroff / stats.r
Last active August 29, 2015 14:03
Rscript to calculate 'stats' from a list of numbers on stdin
#! /usr/bin/env Rscript
a <- scan(file("stdin"), c(0), quiet=TRUE);
cat(length(a), sd(a), min(a), max(a), mean(a), median(a), "\n");
@igroff
igroff / getTimezoneOffsetHoursAndMinutes.js
Last active September 4, 2015 15:39
getTimezoneOffsetHoursAndMinutes -- Really, is this not already somewhere?
// name is still bad, have yet to figure what would be more correct
// sign change differences make re-using the TimezoneOffset verbage
// confusing
Date.prototype.getTimezoneOffsetHoursAndMinutes = function(){
// offset in minutes
var tzo = this.getTimezoneOffset();
// determine 'direction' from GMT we are
// if offset is positive, we're 'in the past'
var behindGMT = tzo > 0;
// work in positive