Skip to content

Instantly share code, notes, and snippets.

View xarg's full-sized avatar

Alex Plugaru xarg

View GitHub Profile
@xarg
xarg / shapping-https.sh
Created February 11, 2013 09:51
Limiting traffic with tc
#!/bin/bash
#
# tc uses the following units when passed as a parameter.
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: Kilobits per second
# mbit: Megabits per second
# bps: Bytes per second
# Amounts of data can be specified in:
# kb or k: Kilobytes
@xarg
xarg / fabric_lexer.py
Created July 10, 2012 20:12
Fabric Pygments Lexer
from pygments.lexer import RegexLexer, bygroups
from pygments.token import Text, Name, Generic, Whitespace, Operator
class FabLexer(RegexLexer):
name = 'FAB'
aliases = ['fab', 'fabric']
filenames = ['*.txt', '*.log']
tokens = {
'root': [
@xarg
xarg / apples_oranges_adapter.py
Created November 24, 2011 13:39
Apples and Oranges with an zope component adapter
from zope.component import getGlobalSiteManager, adapts
from zope.interface import Interface, implements
class IApple(Interface):
"""I'm an apple"""
class Apple:
implements(IApple) # we need this so we can adapt this class
worm = "~~~"
@xarg
xarg / speach_utility.py
Created November 24, 2011 12:11
Speach utility
from zope.component import getGlobalSiteManager
from zope.interface import Interface, implements
#It's is common practice to prefix interfaces with a big "i".
class ISpeach(Interface):
def say(text):
"""Say something"""
class Hello: # Our utility
#I promise that I implement ISpeach interface.
@xarg
xarg / apple_wrapper.py
Created November 23, 2011 14:55
Apples and Oranges with a wrapper
class Apple:
worm = "~~~"
class Orange:
def slices(self):
return [1, 2, 3]
def get_slices(basket):
"""For each item in the basket get it's slices"""
slices = []
@xarg
xarg / apples_oranges.py
Created November 23, 2011 14:34
Apples and Oranges
class Apple:
worm = "~~~"
class Orange:
def slices(self):
return [1, 2, 3]
def get_slices(basket):
"""For each item in the basket get it's slices"""
slices = []
@xarg
xarg / memcache-stats.py
Created October 4, 2011 15:15
Memcache monitoring script
#!/usr/bin/python
import os
import memcache
import time
from pprint import pprint
client = memcache.Client(["127.0.0.1:11211"])
while True:
os.system('clear')
@xarg
xarg / gist:1259106
Created October 3, 2011 13:29
A golang templating language example spec
Assertions:
- I'm not stupid
- I don't want to be limited by some idiotic `people that write templates are stupid` rule.
- I don't want to learn yet another template language.
- I want to use golang expressions if, for..
- I want all the power of indexing, getting attributes and performing operations that golang offers.
- I want to type less stuff and do more.
- I want to include other templates in my template. (jinja?)
- I want to extend templates.
@xarg
xarg / gist:1167533
Created August 24, 2011 08:00
git config
[user]
name = Alexandru Plugaru
email = alexandru.plugaru@gmail.com
[color]
ui = auto
[diff]
guitool = diffuse
[alias]
ci = commit --verbose
cam = commit -a --amend
@xarg
xarg / parser2.py
Created July 29, 2011 12:46
parsing osm data
#!/usr/bin/env python
import os
from lxml import etree
from multiprocessing import Process, Queue
import simplejson as json
import cPickle
import math
###############
# #