Skip to content

Instantly share code, notes, and snippets.

@stuntgoat
stuntgoat / R_notes.R
Last active December 26, 2015 11:09
Notes on R
#### write a dataframe as a csv
write.table(df, file="<filename>", row.names=F, sep=",", quote=F)
#### select dataframe rows by column value
df[df$state=="<colname>",]
#### select columns
# by column index
want_cols <- c(7, 8, 12)
trimmed_df <- df[,want_cols]
@stuntgoat
stuntgoat / go.bash
Last active December 20, 2015 13:49
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
eval `ssh-agent -s`
ssh-add $HOME/.ssh/github # for disco-files repo
ssh-add $HOME/.ssh/nn_trainer_key # for nn_trainer repo
from Queue import PriorityQueue
def backtrack(node, parent_map):
"""
Accepts a search node and a map from nodes to nodes representing the parent node
Returns a list of nodes that correspond to a path starting at start node and ending at given node
"""
parent = parent_map[node]
path = [node, parent] # assumes parent is not None
while True:
class Search(object):
def __init__(self, state, *args, **kwargs):
self.state = state
self.cost_func = None
def actions(self):
"""
Returns a set of actions.
@stuntgoat
stuntgoat / websocket_demo2.py
Created May 16, 2012 01:36
websocket demo to send multiple messages in Brubeck
import sys
import logging
import os
from brubeck.request_handling import Brubeck, WebMessageHandler
from brubeck.connections import Mongrel2Connection
from ws4py.framing import Frame, \
OPCODE_CONTINUATION, OPCODE_TEXT, \
OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG
@stuntgoat
stuntgoat / tests.txt
Created May 13, 2012 05:44
zlib and Redis tests with Python
setup_compress = """
for i in xrange(10000):
r.hset(str(i), str(i), zlib.compress(10 * "my name is mud", 1))"""
setup_normal = """
for i in xrange(10000):
r.hset(str(i), str(i), 10 * "my name is mud")"""
@stuntgoat
stuntgoat / osc-recv.ck
Created April 21, 2012 20:55
OSC receive dot ChucK
// (launch with OSC_send.ck)
// the patch
// create our OSC receiver
OscRecv recv;
// use port 6449
6449 => recv.port;
// start listening (launch thread)
recv.listen();
@stuntgoat
stuntgoat / mongrel2.error.log
Created April 3, 2012 20:06
mongrel2 timeout
Tue, 03 Apr 2012 20:04:50 GMT [WARN] (src/register.c:336: errno: Resource temporarily unavailable) Killed 1 connections according to min_ping: 120, min_write_rate: 300, min_read_rate: 300
Tue, 03 Apr 2012 20:04:50 GMT [WARN] (src/mongrel2.c:205: errno: Resource temporarily unavailable) Timeout task killed 1 tasks, waiting 10 seconds for more.
@stuntgoat
stuntgoat / ws.py
Created April 3, 2012 19:52
websocket handling for Brubeck
# I am using http://isr.nu/ws/WebSocketTest.htm to help debug my websocket connection
# and I send websocket requests to ws://127.0.0.1:6767/websockets
######## IMPORTANT:
######## Add the websocket method to the MessageHandler class
## inside brubeck.request_handling- add 'websocket' method:
# HTTP_METHODS = ['get', 'post', 'put', 'delete',
# 'head', 'options', 'trace', 'connect', 'websocket']
@stuntgoat
stuntgoat / encoder.py
Created December 13, 2011 06:42
Added pretty printing in HTML for json.encoder.py in Python 2.7.1
"""Implementation of JSONEncoder
Added pretty printing to html, wherein indents are "&nbsp;" and newlines are "<br>".
# added html keyword arg; default is html=False
json.dumps(obj[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, html[, separators[, encoding[, default[, **kw]]]]]]]]]]])
Serialize obj to a JSON formatted str.
If html is True and indent is not None the encoder indents are printed as "&nbsp;" and newlines are "<br>"
"""
import re