Skip to content

Instantly share code, notes, and snippets.

class Parser(object):
def __call__(self, s):
self.remains_ = s
self.state_ = 'in_key'
self.key_ = []
self.value_ = []
disbatch = {
'in_key': self.in_key,
'in_value': self.in_value,
# default to optional
Person: !message {
1 : {name: id, type: int32, required: Yes},
2 : {name: name, type: string},
3 : {name: email, type: string},
PhoneType: !enum {
0 : MOBILE,
# .ipython/profile_default/startup/00-start.py
import os
if 'PYTHONSTARTUP' in os.environ:
execfile(os.environ['PYTHONSTARTUP'])
http://stackoverflow.com/questions/15151480/simple-dictionary-in-c
enum class BasePair { A, T, C, G };
BasePair Compliment ( BasePair bp )
{
using BasePair::A;
using BasePair::T;
using BasePair::C;
using BasePair::DG;
@npalko
npalko / gist:3862224
Last active October 11, 2015 12:57
file handles should dispose themselves
typedef std::unique_ptr<std::FILE, int (*)(std::FILE *)> unique_fp;
unique_fp(std::fopen(filename, flags), std::fclose);
unique_ptr<std::FILE, decltype(&std::fclose)> p_file (
std::fopen("easy.binary", "wb"), std::fclose);
from contextlib import contextmanager
@contextmanager
def tag(args):
ccontext = ctx(args)
yield context
context.close()
HOMEBREW_VERSION: 0.9
HEAD: 3525e4b730b03d8c49af07bc0332199124baf919
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: dual-core 64-bit penryn
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
GCC-4.2: build 5666
type_protobuf::Test target;
std::string raw;
google::protobuf::io::StringOutputStream output(&raw);
google::protobuf::io::CodedOutputStream encoder(&output);
encoder.WriteVarint32(target.ByteSize());
target.SerializeToCodedStream(&encoder);
@npalko
npalko / yahoo.py
Created December 29, 2011 02:09
Yahoo IChart
#!/usr/bin/env python
import csv
import datetime
import decimal
import urllib
def get(symbol, start, end, frequency='D'):
controller = 'http://ichart.yahoo.com/table.csv?'
@npalko
npalko / .bash_profile
Created October 16, 2011 23:23
.bash_profile
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi