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 / 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.
#!/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 / 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;
};
@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 / Fact.java
Created March 8, 2012 13:31
Cython factorial bench
public class Fact {
static private int factorial(int n) {
int ret = 1;
for (int j = n; j > 0; j -= 1) {
ret *= j;
}
return ret;
}
static private void bench() {
@erikkaplun
erikkaplun / selfdocumenting.py
Created January 30, 2012 14:31
@selfdocumenting decorator
import inspect
def selfdocumenting(f):
f.__doc__ = inspect.getsource(f)
return f
# well written method
@selfdocumenting
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Selver</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="reset.css" type="text/css" media="screen, print, projection" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen, print, projection" />
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
<link href="jquery.loadmask.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.loadmask.min.js"></script>
@erikkaplun
erikkaplun / index.html
Created April 21, 2011 12:20
Ideelabor pildirakendus
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>img</title>
<link rel="stylesheet" href="css/supersized.css" type="text/css" media="screen" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>img</title>
<link rel="stylesheet" href="css/supersized.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="js/supersized.3.1.3.min.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Täheaabits</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>