Skip to content

Instantly share code, notes, and snippets.

Félix López flopezluis

Block or report user

Report or block flopezluis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View benchmark
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)
View timeit.py
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 Dec 15, 2015
example to open tabs at start
View vimrc
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 Dec 14, 2015
Small example the how I'm using pytest
View conftest,py
@pytest.fixture()
def foo_client(monkeypatch):
def authenticate():
pass
monkeypatch.setattr(FooClient, "authenticate", authenticate)
return FooClient("token", "secret")
View example.py
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
View UnexpectedFrameError
import logging
import sys
import os
import settings
import pika
import re
from threading import Timer
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
@flopezluis
flopezluis / example.py
Created Oct 31, 2012
Batching with Pika
View example.py
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 / record.py
Created Oct 6, 2012
an old script I created to record Vaughan Radio
View record.py
import sys
import time as timer
import urllib
from datetime import datetime, time
import signal
name = ''
def record():
url_stream = urllib.urlopen("http://vaughanradio.streaming-pro.com:8012/;stream.nsv")
f = open("%s_%s.mp3" %(name, datetime.now().strftime("%y-%m-%d")),"wb");
print ('Recording...')
@flopezluis
flopezluis / gist:3255861
Created Aug 4, 2012
Bookmark to delete all the queues in a vhost. RabbitMQ
View gist:3255861
//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 delete_queues = function(name) {
$.ajax({
url:'api/queues/' +vhost+ '/' + name,
type: 'DELETE',
success:function(data) {
View rabbit_exchange_type_throttling.erl
%%
%%
%% This plugin is based on rabbitmq-recent-history-exchange
%% from Alvaro Videla https://github.com/videlalvaro/rabbitmq-recent-history-exchange
%%
%% This is plugin has been developed by ShuttleCloud.
%%
%% This exchange gives you the possibility to set throttling to any
%% exchange. This exchange receives a message and after a time it's delivered
%% to the final exchange. It works as an intermediary
You can’t perform that action at this time.