Skip to content

Instantly share code, notes, and snippets.

View flopezluis's full-sized avatar

Félix López flopezluis

  • Salamanca - Spain
View GitHub Profile
@flopezluis
flopezluis / example.py
Created October 31, 2012 18:13
Batching with Pika
import logging
import pika
from threading import Timer
BATCH_SIZE = 100
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
@flopezluis
flopezluis / gist:1880114
Created February 22, 2012 00:17
get the last element of a generator (python)
#modification of http://stackoverflow.com/questions/5983265/pythonic-way-of-determining-if-the-current-element-is-the-first-or-last-element
def annotate_last_item(gen):
prev_val = gen.next()
for val in gen:
yield False, prev_val
prev_val = val
yield True, prev_val

#Effective Communication


Prepare the conversation.

  • Why are we having this conversation?
    Your time is valuable, other people's time is valuable. If you need to use this time, the least you can do is to prepare it. Things such as "what do you want to achieve?", "What info you need to give?", and all following...
  • What do you expect from the meeting?
    How many times do you go to a meeting without thinking what's the outcome you want from it?
  • Try to understand the audience.:
  • How can I get to my audience better?.
@flopezluis
flopezluis / gist:2172067
Created March 23, 2012 15:53
Bookmark to purge all the queues in a vhost. RabbitMQ
//add this to your bookmarks. The default vhost in RabbitMq is "/",
// so you should have as virtualhost %2F, but due to chrome escape it, i used %252f
//i assume you're in the management site (http://www.rabbitmq.com/management.html)
javascript:
vhost="%252f";
var purge = function(name) {
$.ajax({
url:'api/queues/' + vhost + "/" + name + '/contents/',
type: 'DELETE',
success:function(data) {
@flopezluis
flopezluis / ordered_hm.js
Created June 3, 2011 07:22
Ordered Hash Map
/*
* Simple hash map using javascript objects and an ordered array.
* Repeated elements are not allowed.
*
* @param sort_method By default is ASC order, but you can specified whatever you want.
*
* The public methods are:
* -set
* -get
* -del
from time import clock as now
def catastrophic(n):
pat = re.compile('([a|b]+)+c')
text = "%s" %('a' * n)
pat.search(text)
def test(f, *args, **kargs):
start = now()
f(*args, **kargs)
import timeit
def catastrophic(n):
pat = re.compile('([a|b]+)+c')
text = "%s" %('a' * n)
pat.search(text)
from functools import partial
for i in range(100):
cata = partial(catastrophic, i)
print "The function lasted: %f" %timeit.timeit(cata, number=1)
@flopezluis
flopezluis / vimrc
Last active December 15, 2015 12:59
example to open tabs at start
let i_{1} = "~/Dev/project/x.py"
let i_{2} = "~/Dev/project/x2.py"
let i_{3} = "~/Dev/project/x3.py"
let j = 1
while j<=3
execute "tabnew " i_{j}
let j=j+1
endwhile
@flopezluis
flopezluis / conftest,py
Last active December 14, 2015 23:08
Small example the how I'm using pytest
@pytest.fixture()
def foo_client(monkeypatch):
def authenticate():
pass
monkeypatch.setattr(FooClient, "authenticate", authenticate)
return FooClient("token", "secret")
import logging
import pika
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
class ExampleConsumer(object):
"""This is an example consumer that will handle unexpected interactions