Skip to content

Instantly share code, notes, and snippets.

View stefanooldeman's full-sized avatar

Stefano Oldeman stefanooldeman

  • bol.com
  • Netherlands, Utrecht
View GitHub Profile
@stefanooldeman
stefanooldeman / ServiceContainer.php
Created April 5, 2011 21:14
Dependency Injection With default configuration demo
<?php
class ServiceContainer implements ArrayAccess {
static protected $instance;
public $parameters = array();
public function __construct(array $parameters = array()) {
$this->parameters = $parameters;
@stefanooldeman
stefanooldeman / vim__xsdp_keys_1.markdown
Created May 11, 2011 10:58
#1 out a series of VIM tips on copy/cut and paste buffers

Action: Copy Earl Grey before pickwick and remove the comma after it.

  • Used Keys:
    1. Press v
    2. Move the cursor to end position
    3. Press d
    4. Move to cursor on the comma
    5. Press x
    6. Move cursor to the p from pickwick
    7. Press P
  • hiccups: With x in step 5 the comma is placed in the buffer.
@stefanooldeman
stefanooldeman / gpush.sh
Created July 15, 2011 11:25
push a branch and open the pull request screen
#!/bin/sh
gpush() {
branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
git push origin $branch
_url='https://github.com'
# add username
username=`git config -l | grep user.name | cut -d"=" -f2`
_url="$_url/$username"
@stefanooldeman
stefanooldeman / .gitconfig
Created August 8, 2011 15:34
My git config (color part)
# colour output for diffs
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
@stefanooldeman
stefanooldeman / ghci_hellman.markdown
Created December 14, 2011 08:44
Diffie-Hellman with real world numbers in Haskell..

Here we start in the terminal with ghci (interactive Haskell interperter / ghc) First we create P a nice prime number, and 3 a prime root and two input secrets (8bit) Then start doing the Diffie-Hellman key exchange

Because the lazy evaluation in Haskell defining a variable p is only calculated when needed. And as shown when defining keyA everything is OK. but when called the calculations take too long and are terminated..

Prelude> let p = 2^56 - 46

Prelude> let v = 3

@stefanooldeman
stefanooldeman / before_epoch.php
Created January 13, 2012 10:50
wip trying to check on negative timestamp support and how to detect it
<?php
//if this php version is greater than 5.1 pass
echo strtotime('1766-06-04') . '<br />';
if (version_compare(PHP_VERSION, '5.1', '>')) {
echo 'we support negative dates';
} else {
echo 'we DON'T support negative dates';
}
@stefanooldeman
stefanooldeman / loggers_bootstrap.py
Last active December 15, 2015 09:39
Working example of python's logging module, configured from python dict. have fun.
import logging
import logging.config
console = {
'class': 'logging.StreamHandler',
'formatter': 'console',
'level': 'NOTSET', # log everything!!
}
logfile = {
package require http
namespace eval twitter {
variable status_url "http://api.twitter.com/1/statuses/user_timeline/"
bind pub -|- "!twitter" twitter::tweet
}
proc twitter::tweet {nick uhost hand chan argv} {
if {[string length $argv] < 1} {
from ConfigParser import ConfigParser
class LoaderConfig(dict):
def __init__(self, config_path, section):
_dyn_kwargs = self.load_config(config_path)
super(LoaderConfig, self).__init__(_dyn_kwargs[section])
self.__dict__ = self
@stefanooldeman
stefanooldeman / my-file.py
Last active August 29, 2015 14:05
generate partitions (manual patch)
days = range(16,30) # the days of the month=
p = "ALTER TABLE set_videoads_valid ADD IF NOT EXISTS PARTITION (year={year:d}, month={month:d}, day={day:d}, hour={hour:d}) LOCATION 'hdfs://spil-hadoop/datain/set/portal/valid/year={year:04d}/month={month:02d}/day={day:02d}/hour={hour:02d}'; "
print "USE datain; "
for x in days:
for h in range(0,24):
print p.format(year=2014, month=7, day=x, hour=h)