Instantly share code, notes, and snippets.

View byte.c
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 0;
int g = 0;
unsigned char ch;
if (argc > 1) {
View trees.py
import random
class TreeNode(object):
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def __hash__(self):
View group.m
#import <Foundation/Foundation.h>
#include <grp.h>
#include <string.h>
#include <sys/stat.h>
@interface FileOwnerManager : NSObject
- (BOOL)isWheelPresent:(NSString *)path;
@end
@implementation FileOwnerManager
View Blood.hs
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs, getProgName)
data BloodPressureCategory = Normal
| Prehypertension
| Hypertension1
| Hypertension2
| HypertensiveCrisis
View Zodiac.hs
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs)
offset = (flip mod) 12
animal 4 = "Rat"
animal 5 = "Ox"
animal 6 = "Tiger"
animal 7 = "Rabbit"
animal 8 = "Dragon"
View evil_decorator.py
import sys
from functools import wraps
from types import FunctionType
def is_python3():
return sys.version_info >= (3, 0)
def more_vars(**extras):
View scope.py
# This totally works, even though `i` isn't passed into the
# lambda, nor is it defined prior to the lambda declaration.
calculate_efp = lambda v: v - i
[calculate_efp(v) for i, v in enumerate([10,100,1000])]
View mongo-groupby-date.js
db.samples.aggregate([ {$match: {user: 28804}}, {$group: {_id: {year: {$year: "$timestamp"}, month: {$month: "$timestamp"}, day: {$dayOfMonth: "$timestamp"}}, reputation: {$max: "$reputation"}}}])
View conv.py
actual = [['0:00.762', '0:01.435'], ['2:01.374', '2:07.423'], ['3:01.412', '3:07.314']]
expected = [['0.762', '1.435'], ['121.374', '127.423'], ['181.412', '187.314']]
def convert(s):
mins, secs = s.split(':')
mins = int(mins)
secs = float(secs)
secs = 60 * mins + secs
return secs
View nilclass.m
#import <Foundation/Foundation.h>
int main (int argc, char const *argv[])
{
@autoreleasepool {
id obj = [[nil alloc] init];
NSLog(@"%@ (%p)", obj, obj);
[obj release];
}