Skip to content

Instantly share code, notes, and snippets.

View erikkaplun's full-sized avatar

Erik Kaplun erikkaplun

  • UXO
  • Tallinn, Estonia
View GitHub Profile
@erikkaplun
erikkaplun / demo.cpp
Created March 19, 2012 18:01
smartpointer (C++)
#include <iostream>
#include <vector>
#include <cassert>
#include <string>
using std::vector;
using std::cout;
using std::endl;
using std::string;
@erikkaplun
erikkaplun / demo.cpp
Created March 19, 2012 18:03
smartpointer (C)
#include <stdio.h>
#include <assert.h>
#define DEBUG
#include "smartasspointer.h"
struct spaceship_t { /* extends */ smartass_t _;
const char* name;
};
#!/usr/bin/python
# coding: utf-8
import socket
import time
s = socket.socket()
#host = '195.50.209.244'
host = '127.0.0.1'
#port = 80
@erikkaplun
erikkaplun / restartable.py
Created July 31, 2012 11:12
transparent object restarts
class Restartable(object):
@classmethod
def __new__(cls, *args, **kwargs):
ret = super(Restartable, cls).__new__(*args, **kwargs)
ret.__initargs__ = (args[1:], kwargs)
return ret
# this is something like a clone with __getinitargs__ but let's not call
# it a clone because it's semantically different--i.e. explicitly discards
# any state other than the initial one.
@erikkaplun
erikkaplun / main.py
Created August 1, 2012 09:58
import with SyntaxError
print "importing problematic_module through other_module:"
try:
import other_module
except Exception as e:
print "...got", e
print "importing problematic_module directly:"
try:
import problematic_module
except Exception as e:
@erikkaplun
erikkaplun / traceback.py
Created December 9, 2012 23:29
Traceback parser and merger
class Traceback(object):
@classmethod
def parse(cls, tb_str):
tb_lines = tb_str.strip().split('\n')
firstline = tb_lines.pop(0)
step_lines = []
while True:
if tb_lines[0].startswith(' '):
step_lines.append(tb_lines.pop(0))
# ... snip
class Cell(_BaseCell): # TODO: inherit from Greenlet?
uri = None
hub = None
impl = None
proc = None
stash = None
stopped = False
trait Extractor[T, U] { def unapply(x: T): Option[U] }
object Extractor {
def apply[T, U](f: PartialFunction[T, U]) = new Extractor[T, U] {
def unapply(x: T) = f.lift(x)
}
}
val EmployedAt = Extractor[Person, Company] {
case Person(_, _, Some(Position(_, Some(c)))) => c
}
$ rm -f *.class; fsc -shutdown
[Compile server exited]
$ time scala test.scala
real 0m5.779s <--------
user 0m0.375s
sys 0m0.069s
--------------------------
~/code/scala/testtask$ fsc # käivitab fsc daemoni
#####################
# git
#####################
alias g=git
alias s='g status'
alias gs='g status'
alias a='g add'
alias ga='g add'
alias gap='ga -p'
alias gf='g fetch'