Skip to content

Instantly share code, notes, and snippets.

@damnit
damnit / multipull.sh
Last active August 29, 2015 14:04
multipull dirname
#!/bin/bash
FOLDERS=`find "$1" -maxdepth 1 -type d ! -path "$1" | sed "s|^"$1"/||"`
for i in $FOLDERS; do
printf "\e[34m$1/$i\e[0m\n"
cd "./$1/$i"
git pull
cd ../..
done
@damnit
damnit / list_join.py
Created July 30, 2014 13:51
the functional approach of ".".join
def list_join(sep, items):
""" method wrapper for str.join alternative.
>>> foo = ['foo', 'bar', 'baz']
>>> sep = ","
>>> sep.join(foo)
'foo,bar,baz'
>>> list_join(',', foo)
'foo,bar,baz'
"""
return reduce(lambda x, y: '%s%s%s' % (x, sep, y), items)
@damnit
damnit / unikot.py
Last active August 29, 2015 14:05
this module gives a shit about encoding
# -*- coding: utf-8 -*-
""" This module gives a shit about encoding. """
from __future__ import print_function
import sys
if __name__ == '__main__':
print('---------------------------')
print('| Unicode Analysis Script |')
print('---------------------------')
# -*- coding: utf-8 -*-
from __future__ import print_function
import hashlib
class City(object):
""" This is the Foo object
"""
def __init__(self, name, population):
self._name = name
@damnit
damnit / hello_flask.py
Created August 22, 2014 07:41
browse your home folder :)
from flask import Flask
import os
import threading
app = Flask(__name__)
@app.route('/')
def root():
folder_contents = ""
for node in os.listdir(os.environ.get('HOME')):
@damnit
damnit / test_trac.py
Created August 26, 2014 07:49
test trac components with pytest
""" This module shows how to create Components. """
from trac.core import Component
import pytest
@pytest.fixture
def component_manager():
from trac.core import ComponentManager
return ComponentManager()
@damnit
damnit / trac_observer_pattern.py
Created August 26, 2014 08:45
this is about how trac works
from __future__ import print_function
from trac.core import Component, ComponentManager, Interface, ExtensionPoint, implements
class IMessageObserver(Interface):
def message_received(message):
""" called when message is received. """
class MessageSender(Component):
""" component that sends messages. """
@damnit
damnit / tracsessionmail.py
Created September 25, 2014 07:59
Get mail address from trac session
from trac.web.session import Session
ses = Session(self.env, req)
email = ses.get('email')
@damnit
damnit / funcnuf.py
Created September 29, 2014 15:18
Functional fun with python
""" functional fun module. """
from __future__ import print_function
import inspect
from functools import partial
__author__ = 'damnit <https://github.com/damnit/>'
class FuncDummy(object):
@damnit
damnit / foocmd.py
Created October 17, 2014 14:57
python cmd framework usage
""" foo cli - use this with python 3.x """
import cmd
class FooShell(cmd.Cmd):
""" mite shell command class. """
def __init__(self):
super(FooShell, self).__init__()
self.intro = 'Using foo from CLI. Type help or ? to list commands.\n'