Skip to content

Instantly share code, notes, and snippets.

View thanos's full-sized avatar

thanos vassilakis thanos

View GitHub Profile
@thanos
thanos / erang_view-couch_util
Created March 13, 2012 19:39
An erlang view using couch:util
fun({Doc}) ->
Bucket = couch_util:get_value(<<"bucket">>, Doc, null),
Emit(Bucket, null)
end.
@thanos
thanos / couchdb-ec2-install.sh
Created April 4, 2012 15:38 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@thanos
thanos / secondsToDate.erl
Created April 5, 2012 19:31
Convert seconds to a date in erlang
msToDate(Milliseconds) ->
BaseDate = calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}}),
Seconds = BaseDate + (Milliseconds div 1000),
{ Date,_Time} = calendar:gregorian_seconds_to_datetime(Seconds),
Date.
@thanos
thanos / kombu_example.py
Created June 14, 2012 23:15
A simple example of a kombu fanout exchange using python generators and coroutines
from kombu import Exchange
from kombu import Queue
from kombu import BrokerConnection
class ProduceConsume(object):
def __init__(self, exchange_name, **options):
exchange = Exchange(exchange_name, type='fanout', durable=False)
queue_name = options.get('queue', exchange_name+'_queue')
self.queue = Queue(queue_name ,exchange)
@thanos
thanos / couchdb-ec2-install.sh
Created July 2, 2012 16:32 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@thanos
thanos / python_property.py
Created July 2, 2012 19:17
creates a python property
def aproperty():
doc = "The aproperty property."
def fget(self):
return self._aproperty
def fset(self, value):
self._aproperty = value
def fdel(self):
del self._aproperty
return locals()
aproperty = property(**aproperty())
@thanos
thanos / c-sed.py
Created July 9, 2012 19:12
a kind of simple sed for config files
#!/bin/env python
import sys
from ConfigParser import SafeConfigParser, NoOptionError
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-s", "--set", dest="set", action='append', help="use to add or change an option, eg --set=processor,autostart,true\nwill add autostart=true to the [processor] section")
parser.add_option("-g", "--get", dest="get", help="use to get an option, eg --get=processor,autostart\ncould return true, the default return falue is an empty string:''")
(options, args) = parser.parse_args()
@thanos
thanos / django_template_filters.py
Created July 11, 2012 15:55
Django quantity format template tag/filter
@register.filter(name='quantityformat')
def quantityformat(bytes):
"""
Formats the value like a 'human-readable' file size (i.e. 13K, 4.1M,
102, etc).
"""
try:
bytes = float(bytes)
except (TypeError,ValueError,UnicodeDecodeError):
return ungettext("%(size)d", "%(size)d", 0) % {'size': 0}
@thanos
thanos / url_fetch.py
Created July 12, 2012 17:06
A quick version of urlopen but nearly always works
import httplib2
def url_fetch(url, user=None, password=None, method="GET", body=None, headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
"""
A quick version of urlopen but nealry always works
"""
h = httplib2.Http(".cache")
if user:
h.add_credentials(user,password)
@thanos
thanos / format_mount.sh
Created July 30, 2012 20:55
formates and mounts a drive for ubuntu linux -= I use this all the time in EC2 to add ESB
sudo mkfs -t ext4 /dev/$1
sudo mount -t ext4 /dev/$1 $2