Skip to content

Instantly share code, notes, and snippets.

View thanos's full-sized avatar

thanos vassilakis thanos

View GitHub Profile
@thanos
thanos / extend_optparser.py
Created July 5, 2011 14:41
Extending python's optparser to handle datetime types
import datetime, copy
from optparse import Option, OptionValueError
def check_datatime(option, opt, value):
try:
return datetime.datetime.strptime(value, option.datetime_format)
except ValueError:
raise OptionValueError(
"option %s: invalid complex value: %r" % (opt, value))
@thanos
thanos / daemon_command.py
Created July 5, 2011 14:44
Simple Daemon Django Command
from extend_optparser import make_option
from django.core.management.base import BaseCommand
class DaemonCommand(BaseCommand):
help = 'Runs a process as a daemon'
VERSION="Please Set!!!!"
option_list = BaseCommand.option_list + (
make_option('--daemon', dest='daemon', action="store_true", default=False),
make_option('--delay', dest='delay', type='int', default=20),
@thanos
thanos / django_model_dynamic_choice.py
Created August 1, 2011 14:53
DJANGO: Dynamically generate choices for a model
class DynamicChoice(object):
"""
Trivial example of creating a dynamic choice
"""
def __iter__(self):
for choice in self.generate():
if hasattr(choice,'__iter__'):
yield (choice[0], choice[1])
else:
@thanos
thanos / erlang_couchdb_map.erl
Created August 4, 2011 15:34
Couchdb: An erlang map function to get a value from a sub record
% Couchdb: An erlang map function to get a value from a sub record
%
% gets and emits a record for each sub record in legs keyed by "value_date"
% For the date see: https://gist.github.com/1125467
%
fun({Doc}) ->
Bump = fun(Doc, Rec, Field) ->
case {proplists:get_value(Field, Rec)} of
{undefined} ->
ok;
@thanos
thanos / gist:1125467
Created August 4, 2011 15:38
CouchDB: An oil SWAP
{
"_id": "encompass-375613-20101026",
"_rev": "1-4990bb59d43e6024a4e246b7c0823201",
"source": "encompass",
"keys": [
"transaction_id",
"legs"
],
"timestamp": "Wed Nov 17 18:12:55 2010",
"trader": "XXX, XXXXX",
@thanos
thanos / qjuery-step.js
Created November 11, 2011 21:05
javascript - runs the function, worker, through a number of steps with a delay between each step. Can be used to cycle through images.
/*
* runs the function, worker, through a number of steps with a delay between each step.
* This example flicks through a bunch of images.
* step(0,10, function(num, stop) {
* $('#mo').attr('src', 'images/'+num+'.jpg');
* }, 600);
*/
function step(ind, stop, worker, delay) {
if (ind < stop) {
@thanos
thanos / binary_to_integer.erl
Created January 5, 2012 15:44
A binary to integer converter
list_to_integer(binary_to_list(<<"-12345">>))
fun({Doc}) ->
case {proplists:get_value(<<"name">>, Doc), proplists:get_value(<<"value">>, Doc)} of
{undefined, _} ->
ok;
{_, undefined} ->
ok;
{Name, Value} ->
Emit(Name, {Doc});
_ ->
ok
@thanos
thanos / doing a remote branch in git
Created March 2, 2012 22:22
doing a remote branch in git
#doing a remote branch in git
git push origin origin:refs/heads/version-001
@thanos
thanos / couchdb_convert_javascript_erlang.erl
Created March 8, 2012 16:25
Couchdb: How to convert javascript into erlang
%%%% use couchdb -i to get to the couch prompt.
couch_util:json_decode(<<"{\"key\":\"value\"}">>).