Skip to content

Instantly share code, notes, and snippets.

@jcrubino
jcrubino / sapd_parse.py
Created July 7, 2012 13:00
SAPD Neighborhood Watch Db
# SAPD Neighborhood Watch Db
# Parses San Antonio Police Neighborhood Calls pdfs into json for dbs
#
#
# Dev Env: Ubuntu 12.04
# Licensed under the GNU General Public License: http://www.gnu.org/licenses/gpl.html
# Requires xpdf utils available at the command line (not a python library (yet))
# pymongo & Mongodb
# pdfs from http://www.sanantonio.gov/neighborhoodpolicecalls/policecalls.aspx
#
@jcrubino
jcrubino / ring_buffer
Last active August 29, 2015 14:14 — forked from mtambos/ring_buffer
import numpy as np
class RingBuffer(np.ndarray):
'A multidimensional ring buffer.'
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
return obj
// http://is.gd/gWewbP
extern mod extra;
use extra::treemap::TreeMap;
use extra::json::ToJson;
use extra::serialize::Decodable;
use json = extra::json;
// structs are required for decoding a JSON object into a Rust object
#[deriving(Decodable)]
@jcrubino
jcrubino / battleship.py
Last active August 29, 2015 14:11
Battleship NG in Python
"""
TODO:
move fit function to GameBoard
assert all ships on playing board
game board keeps record of players ships
players call to game board and get proper access to game state and own board.
create frp board
ship observes its own location for hits
posts damage or detroyed signal to location on the board
create temporary sequence predictor_seq;
CREATE temporary TABLE linear_systems_test_data( id INTEGER NOT NULL, lhs DOUBLE PRECISION[], rhs DOUBLE PRECISION);
insert into linear_systems_test_data values (nextval('predictor_seq'), '{352137.0,84.7067061967771,-150.185137392799,122.050417659229,-74.0884874537119,99.7911494563722,-3.7907455558484,181224.690513009,106938.029173016,69336.1362009346,18335.0,12.7007088793537,-250.440511627437,-62.5561474971013,-292.703374755409,-167.012940969203,-78.511449979818,9451.24681999999,5585.85191537643,3628.50938401}'::float[], 88920344.0 );
insert into linear_systems_test_data values (nextval('predictor_seq'), '{84.7067061967771,176105.544243727,61.0252088296143,-73.1971959184637,7.54222162981446,-48.6063990056131,-37.7170700467655,-11006.0678697046,-11871.4874441653,-10787.6157862104,12.7007088793537,9313.85168737771,-31.2780737485506,-85.9645308238089,-89.8568249242787,-78.6462830692247,10.8622991388217,-566.613529886409,-617.49619500345,-565.289335368564}'::float[]
@jcrubino
jcrubino / gist:6007affdea9f871f481c
Created December 4, 2014 20:10
Gogs Http Client
import requests
from lxml import html # would prefer not to parse html but currently this is the only option
# set these to whatever your gogs account is
username = "username"
password = "password"
cookie_filename = "gogs.cookies"
gogs_url = "your_gogs_url"
gogs_port = "3000"
@jcrubino
jcrubino / gist:70a38ae46b034ae8f056
Last active August 29, 2015 14:10
Command Pattern Continued
/*
Command Pattern Continued
Adapted from https://en.wikipedia.org/wiki/Command_pattern#JavaScript
& http://www.onjava.com/pub/a/onjava/2006/04/05/ajax-mutual-exclusion.html
Application: Wallace Variation for Lamports Bakery Algorithm for implementing mutex in javascript
*/
@jcrubino
jcrubino / gist:5bd10e19fe7b661ad51c
Last active August 29, 2015 14:10
Generic Command Pattern Javascript
/* Generic Command Pattern in Javascript */
/* Adapted from https://en.wikipedia.org/wiki/Command_pattern#JavaScript */
/* Application: Wallace Variation for Lamports Bakery Algorithm for implementing mutex in javascript */
/* The Invoker function */
var Invoke = function(){
var _commands = [];
this.storeAndExecute = function(command){
_commands.push(command);
command.execute();
@jcrubino
jcrubino / gist:880a73ce75b5e341acd7
Created November 27, 2014 12:36
Start of OkCoin Websocket Api
package main
import "fmt"
type OkCoin struct {
futures map[string]map[string]map[string]string
spot map[string]map[string]map[string]string
}
func OkCoinApi() OkCoin {
from pylab import *
from scipy.ndimage import measurements
import numpy as np
import matplotlib.pyplot as plt
import time
import sys
import signal
def signal_handler(signal, frame):
sys.exit(0)