Skip to content

Instantly share code, notes, and snippets.

@matomesc
matomesc / redis.markdown
Created Jan 12, 2012 — forked from bdotdub/redis.markdown
Running redis using upstart on Ubuntu
View redis.markdown

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

@matomesc
matomesc / vending.js
Created Feb 9, 2012
Vending machine DFA transitions
View vending.js
// usage: node vending.js > transitions
var coins = [5, 10, 25, 100];
var _sum = 125;
var validTransitions = [];
coins.forEach(function (c) { check(0, c); })
function check(sum, coin, transitions) {
transitions = transitions || [];
var newSum = sum + coin;
@matomesc
matomesc / ipc.js
Created Mar 3, 2012
why does child memory keep growing?
View ipc.js
var cp = require('child_process');
if (!process.send) {
// master
var child = cp.fork('./test.js');
child.on('message', function (msg) {
process.stdout.write(msg);
});
} else {
// child
View mongodb_inserts.js
var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, { auto_reconnect: false });
var db = new mongodb.Db('tester', server, { native_parser: true });
var insertCount = 0;
db.open(ready);
function ready(err, db) {
process.nextTick(function () {
db.collection('statuses', function (err, coll) {
View tree_traversal.js
// depth first in-order
function traverse(node) {
console.log(node.value);
node.children.forEach(function (child) {
traverse(child);
});
}
View .gitconfig
[user]
name = Mihai Tomescu
email = matomesc@gmail.com
[core]
excludesfile = ~/.gitignore
[alias]
st = status
ci = commit
@matomesc
matomesc / buckets.py
Created Aug 8, 2013
Buckets items by timestamp and counts the items in each bucket
View buckets.py
class Buckets(object):
"""
Buckets items by timestamp and counts the items in each bucket.
"""
def __init__(self, since, interval=300):
"""
:param since: Starting timestamp in seconds.
:type since: int
:param interval: The bucket size in seconds.
@matomesc
matomesc / twit_errors.js
Created Aug 8, 2013
Twit doesn't return instances of Error when errors occur
View twit_errors.js
var Twit = require('twit');
var t = new Twit({
consumer_key: 'a',
consumer_secret: 'b',
access_token: 'c',
access_token_secret: 'd'
});
t.get('user/timeline', function (err, result) {
@matomesc
matomesc / gossip_stream.js
Last active Dec 20, 2015
Gossip MessageStream usage
View gossip_stream.js
var stream = hub.sendAll('check-temp');
stream.on('error', function (err) {
// called when there are errors - ex: missing ack / reply timeout
console.log(err);
});
stream.on('ack', function (ackMsg) {
// not sure how useful this is
});
@matomesc
matomesc / reqparser.py
Created Nov 13, 2013
flask-restful NestedRequestParser
View reqparser.py
from flask import request
from flask.ext.restful.reqparse import Argument, RequestParser
class NestedArgument(Argument):
def __init__(self, name, **kwargs):
pieces = name.split('.')
self.full_name = name