Skip to content

Instantly share code, notes, and snippets.

View proger's full-sized avatar
🎯
Focusing

Volodymyr Kyrylov proger

🎯
Focusing
View GitHub Profile
@proger
proger / gist:960583
Created May 7, 2011 15:30
path processing
# [string] -> [[path component]]
components = lambda lines: map(lambda s: s.split('/')[1:], map(lambda s: s.strip(), lines))
# [component] -> {c1: {c2: {c3: ...}}}
rawtree = lambda x: reduce(lambda l,k: {k:l if type(l) is dict else {l:{}}}, x[::-1], {})
# [{c1: {c2: a}, {c1: {c3: a}] -> {c1: {c2: a c3: a}}
reducefn = lambda t,e: (lambda key=e.keys()[0]: (lambda oval=t.get(key): \
dict( \
filter(lambda i: i[0] != key, t.items()) + [ \
#include <sys/types.h>
#include <sys/sendfile.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
@proger
proger / gist:1053153
Created June 29, 2011 04:31
waking up
sky ~ 0 % at 06:30
mpc play
commands will be executed using /usr/local/bin/zsh
job 1309318200.c at Wed Jun 29 06:30:00 2011
sky ~ 0 % mpc stop
volume: 99% repeat: on random: on single: off consume: off
sky ~ 0 % atq
no files in queue.
sky ~ 0 % at 06:45
mpc play
/*
* Disables hfs+ journal
* origin: http://dmunsie.wordpress.com/code/hacks/
*
* compiles on linux
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//
// VKBlockSelector.h
//
#include <objc/runtime.h>
#import <Foundation/Foundation.h>
/*
* note: each file has its own!
*/
import os, sys, socket, time
socket.setdefaulttimeout(10)
r,w = socket.socketpair()
def child():
try:
print r.recv(10)
except socket.timeout:
@proger
proger / gist:1145238
Created August 14, 2011 19:58
strace
socketpair(PF_FILE, SOCK_STREAM, 0, [3, 5]) = 0
fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
fcntl(5, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK) = 0
clone(Process 11378 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f09b91b59d0) = 11378
[pid 11377] select(0, NULL, NULL, NULL, {1, 0} <unfinished ...>
[pid 11378] poll([{fd=3, events=POLLIN}], 1, 10000 <unfinished ...>
[pid 11377] <... select resumed> ) = ? ERESTARTNOHAND (To be restarted)
import sys
import pdb
import socket
class Rdb(pdb.Pdb):
def __init__(self, port=4444):
self.old_stdout = sys.stdout
self.old_stdin = sys.stdin
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#!/usr/bin/env macruby
framework 'Cocoa'
framework 'CoreData'
def path(p) NSURL.fileURLWithPath p end
def moc_init(mompath, sqlitedbpath)
mom = NSManagedObjectModel.alloc.initWithContentsOfURL mompath
oictl% cat /usr/bin/nroff
#!/bin/sh
echo $* >&2
arg=$(eval echo \$$#)
[ $arg = "-" ] && exec /opt/local/bin/mandoc < /dev/stdin || exec /opt/local/bin/mandoc $arg