Skip to content

Instantly share code, notes, and snippets.

View fernandoflorez's full-sized avatar
🍺

Fernando Flórez fernandoflorez

🍺
View GitHub Profile
@fernandoflorez
fernandoflorez / s.py
Created June 26, 2020 15:40
Shortest version of baby shark song (python)
s=lambda c=0,l=0:['Mommy','Daddy','Grandma','Grandpa'][c]+' shark'+(', '+' '.join(['doo']*6) if l<3 else '!')+'\n'+('' if c>3 else s(c,l+1) if l<3 else s(c+1,0) if c<3 else '')
brew install cloc
cd /to/project/folder
cloc .
$ hackon <project_name>
# supports autocompletion:
$ hackon <TAB><TAB>
function _hackon() {
local opts cur prev
opts=`ls -l $HOME/projects/ | egrep '^d' | awk '{print $9}'`
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
function hackon() {
import pyrax
if __name__ == '__main__':
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials('username', 'api_key')
cf = pyrax.cloudfiles
container = cf.get_container('container_name')
objects = container.get_objects(full_listing=True)
import pyrax
if __name__ == '__main__':
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials('username', 'api_key')
cf = pyrax.cloudfiles
container = cf.get_container('container_name')
container.delete_all_objects()
from gevent import monkey
from gevent.pool import Pool
from gevent import Timeout
monkey.patch_all()
import pyrax
if __name__ == '__main__':
pool = Pool(100)
pyrax.set_setting('identity_type', 'rackspace')
#!/usr/bin/env python
# original url: https://github.com/funciton/nagios-plugins
import urllib2
try:
import json
except ImportError:
import simplejson as json # NOQA
UNKNOWN = -1
@fernandoflorez
fernandoflorez / gist:5199604
Created March 19, 2013 20:06
jinja2 RedisBytecodeCache
class RedisBytecodeCache(BytecodeCache):
def __init__(self, conn):
self._conn = conn
def load_bytecode(self, bucket):
code = self._conn.get(bucket.key)
if code is not None:
return bucket.bytecode_from_string(code)
Color_Off="\[\033[0m\]" # text reset
IBlack="\[\033[0;90m\]" # black
IRed="\[\033[0;91m\]" # red
IGreen="\[\033[0;92m\]" # green
IYellow="\[\033[0;93m\]" # yellow
# time vars
Time12h="\T"
PathShort="\w"