Skip to content

Instantly share code, notes, and snippets.

View samuraisam's full-sized avatar

Samuel Sutch samuraisam

View GitHub Profile
grammar PB::Grammar {
token TOP { ^ <.ws> <proto> <.ws> $ <.ws> }
token proto { [<message> | <package> | <import> | <option> | <enum> | <extend> | <service> | ';']* }
# comments and whitespace
token nl { \xA | "\r" \xA | "\r" | "\f" }
regex comment { '//' [.]*? <.nl> $ }
token ws { <!ww> [ \s | <.comment> ]* }
# import
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@0xced
0xced / NSData+CommonDigest.h
Created May 23, 2011 09:00
NSData+CommonDigest: The most elegant NSData category for cryptographic hash functions
/*
Licensed under the MIT License
Copyright (c) 2011 Cédric Luthi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@samuraisam
samuraisam / NSString+Truncation.h
Created December 15, 2010 23:05
Simple, reliable word truncation whether HTML exists in the text or not.
@interface NSString (WordTruncation)
- (NSString *)substringOfHTMLToWordIndex:(NSUInteger)to appendOnTruncate:(NSString *)append softLimit:(int)leSoftLimit;
- (NSString *)substringToWordIndex:(NSUInteger)to;
@end
@patrys
patrys / abstract.py
Created September 17, 2010 11:59
Parametrized apps for Django
class AbstractMixin(object):
_classcache = {}
@classmethod
def contribute(cls):
return {}
@classmethod
def construct(cls, *args, **kwargs):
attrs = cls.contribute(*args, **kwargs)
"""
My dependency injection framework for Python. Using a context manager it allows
you to rewrite globals (such as imports, top-level classes and functions, whatever
you want) in a module and have them replaced at the end of the with block. This is
usually enough. `proxy` is just a dict-wrapping type class which will create a
type with "class variables" for every key you give it.
Usage:
from di import *
@davepeck
davepeck / FlickDynamics.h
Created April 24, 2009 00:26
Objective-C code that mimics the flick-to-scroll behavior found in iPhone scrolling views. This code is independent of coordinate system, animation rate, and the specific UI context you're working with -- perfect especially for getting good scrolling beha
//
// FlickDynamics.h
// (c) 2009 Dave Peck <davepeck [at] davepeck [dot] org>
// http://davepeck.org/
//
// This code is released under the BSD license. If you use my code in your product,
// please put my name somewhere in the credits and let me know about it!
//
// This code mimics the scroll/flick dynamics of the iPhone UIScrollView.
// What's cool about this code is that it is entirely independent of any iPhone