Skip to content

Instantly share code, notes, and snippets.

View yuuichi-fujioka's full-sized avatar

yuuichi fujioka yuuichi-fujioka

View GitHub Profile
@yuuichi-fujioka
yuuichi-fujioka / find submodules.py
Created January 31, 2014 01:11
Find and load submodules.
import pkgutil
def load_submodules(mod):
for (importer, name, ispkg) in pkgutil.iter_modules(path=mod.__path__,
prefix=mod.__name__ + '.'):
if not ispkg:
yield importer.find_module(name).load_module(name)
@yuuichi-fujioka
yuuichi-fujioka / config
Created January 31, 2014 01:14
Disable host key verification on ssh
Host 192.168.56.*
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
@yuuichi-fujioka
yuuichi-fujioka / backdoor_example.py
Created February 5, 2014 00:41
Eventlet Backdoor
import time
import eventlet
from eventlet import backdoor
def main():
eventlet.monkey_patch()
eventlet.spawn(backdoor.backdoor_server, eventlet.listen(('localhost', 3000)))
@yuuichi-fujioka
yuuichi-fujioka / print_example.py
Created February 5, 2014 01:10
print function in < 3.0
from __future__ import print_function
print('foo', 'bar')
# output is "foo bar"
@yuuichi-fujioka
yuuichi-fujioka / memcache_reader.py
Created February 10, 2014 07:18
Example for using memcached
import memcache
c = memcache.Client(['127.0.0.1:11211'])
print c.get('name')
# "Taro" will be printed
@yuuichi-fujioka
yuuichi-fujioka / pecan_rest_api.py
Created February 10, 2014 07:18
REST API with pecan
import eventlet
from eventlet import wsgi
import pecan
from pecan import rest
class V1Controller(rest.RestController):
@pecan.expose()
def get(self, id):
@yuuichi-fujioka
yuuichi-fujioka / ceilometer v2 query example.sh
Created February 19, 2014 02:17
Example of ceilometer v2 api query (not complex)
curl -X GET -H 'X-Auth-Token: <Token>' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'User-Agent: python-ceilometerclient' 'http://ceilometer-host:8777/v2/samples?q.field=meter&q.op=eq&q.value=switch.flow&q.field=metadata.flow.id&q.type=int&q.op=eq&q.value=0'
@yuuichi-fujioka
yuuichi-fujioka / conf.py
Created February 20, 2014 07:09
Example of load python based config file
v = {
'foo': 'bar'
}
@yuuichi-fujioka
yuuichi-fujioka / prop.py
Created February 25, 2014 06:42
property example
class Foo():
def __init__(self):
self.meta = {}
@property
def name(self):
return self.meta.get('name', None)
@name.setter
@yuuichi-fujioka
yuuichi-fujioka / with_example.py
Created February 25, 2014 06:49
with example
class Foo():
def __enter__(self):
print 'begin transaction'
return self
def __exit__(self, type, value, traceback):
if value:
print 'An error has occured in this transaction'
else: