Skip to content

Instantly share code, notes, and snippets.

View matomesc's full-sized avatar

Mihai Tomescu matomesc

View GitHub Profile
@matomesc
matomesc / vending.js
Created February 9, 2012 19:16
Vending machine DFA transitions
// 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 / reqparser.py
Created November 13, 2013 04:34
flask-restful NestedRequestParser
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
@matomesc
matomesc / gossip_stream.js
Last active December 20, 2015 22:49
Gossip MessageStream usage
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 / twit_errors.js
Created August 8, 2013 23:17
Twit doesn't return instances of Error when errors occur
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 / buckets.py
Created August 8, 2013 19:45
Buckets items by timestamp and counts the items in each bucket
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 / .gitconfig
Created January 17, 2013 02:21
My .gitconfig
[user]
name = Mihai Tomescu
email = matomesc@gmail.com
[core]
excludesfile = ~/.gitignore
[alias]
st = status
ci = commit
@matomesc
matomesc / tree_traversal.js
Created March 18, 2012 01:20
tree traversals
// depth first in-order
function traverse(node) {
console.log(node.value);
node.children.forEach(function (child) {
traverse(child);
});
}
@matomesc
matomesc / mongodb_inserts.js
Created March 5, 2012 05:06
mongodb inserts
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) {
@matomesc
matomesc / ipc.js
Created March 3, 2012 20:20
why does child memory keep growing?
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
@matomesc
matomesc / redis.markdown
Created January 12, 2012 00:58 — forked from bdotdub/redis.markdown
Running redis using upstart on Ubuntu

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: