Skip to content

Instantly share code, notes, and snippets.

View trevordixon's full-sized avatar

Trevor Dixon trevordixon

View GitHub Profile
@trevordixon
trevordixon / convert.js
Created May 15, 2015 17:54
Convert LilyBin MongoDB dump to new DB
var Promise = require('bluebird');
const scores = require('./lib/db');
var LineByLineReader = require('line-by-line'),
lr = new LineByLineReader('scores.json');
lr.on('line', function(line) {
var data = JSON.parse(line);
var id = data['_id'];
console.log(id, data.revisions.length);
@trevordixon
trevordixon / hello.go
Created October 8, 2014 06:32
Simple Go OSXFuse write test
// Hellofs implements a simple "hello world" file system.
package main
import (
"flag"
"fmt"
"log"
"os"
"bazil.org/fuse"
@trevordixon
trevordixon / ArraySet.js
Last active August 29, 2015 14:02
Very simple javascript array-backed set
function ArraySet() {
this._items = [];
}
ArraySet.prototype.add = function add(item) {
if (this._items.indexOf(item) > -1) {
return false;
}
this._items.push(item);
return true;
@trevordixon
trevordixon / parseCSV.js
Created May 25, 2014 03:07
Very Simple Javascript CSV Parser
function parseCSV(str) {
var arr = [];
var quote = false;
for (var row = col = c = 0; c < str.length; c++) {
var cc = str[c], nc = str[c+1];
arr[row] = arr[row] || [];
arr[row][col] = arr[row][col] || '';
if (cc == '"' && quote && nc == '"') { arr[row][col] += cc; ++c; continue; }
if (cc == '"') { quote = !quote; continue; }
@trevordixon
trevordixon / test.js
Created May 7, 2014 05:18
Test speed of repeated require() calls
var iters = 100000;
// Many require calls
var start = process.hrtime();
for (var i = 0; i < iters; i++) {
require('fs');
}
console.log('Many require calls: ' + process.hrtime(start)[1]/1000000 + ' milliseconds');
// Many noop function calls
@trevordixon
trevordixon / pq.cs
Created April 10, 2014 16:51
C# Priority Queue
using System;
using System.Collections.Generic;
// From http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx
public class PriorityQueue<T> where T : IComparable<T> {
private List<T> data;
public PriorityQueue() {
this.data = new List<T>();
}
ruleset foursquare_checkins {
meta {
name "Foursquare Checkins"
description <<
Foursquare Checkins
>>
author ""
logging off
use module a169x701 alias CloudRain
use module a41x186 alias SquareTag
@trevordixon
trevordixon / simplex.cs
Last active February 10, 2024 22:54
Simplex maximization algorithm in C#
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace Simplex {
class Simplex {
private double[] c;
private double[,] A;
private double[] b;
private HashSet<int> N = new HashSet<int>();
ruleset twilio {
meta {
use module b505206x2 alias LocationData
}
rule nearby {
select when location new_current
pre {
checkin = LocationData:get_location_data("fs_checkin");
[{"title":"Masterminds of Programming","subtitle":"Conversations with the Creators of Major Programming Languages","authors":["Federico Biancuzzi","Shane Warden"],"publisher":"\"O'Reilly Media, Inc.\"","publishedDate":"2009","description":"Provides interviews with the creators of a variety of programming languages, covering the processes that led to specific decisions, their goals, and how their experiences have made an impact on computer programming.","industryIdentifiers":[{"type":"ISBN_13","identifier":"9780596515171"},{"type":"ISBN_10","identifier":"0596515170"}],"pageCount":480,"printType":"BOOK","categories":["Computers"],"averageRating":3.5,"ratingsCount":22,"contentVersion":"preview-1.0.0","imageLinks":{"smallThumbnail":"http://bks3.books.google.com/books?id=uECbAgAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api","thumbnail":"http://bks3.books.google.com/books?id=uECbAgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"},"language":"en","previewLink":"http://books.google.