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
%%
%%
%% 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
@flopezluis
flopezluis / DuplicatedChannels.java
Created June 21, 2012 07:44
Check whether you have repeated channels in the spring integration context.
import org.xml.sax.SAXException;
@Component("duplicatedChannels")
public class DuplicatedChannels {
private final Log logger = LogFactory.getLog(this.getClass());
@Autowired
private ApplicationContext appContext;
@flopezluis
flopezluis / gist:2375487
Created April 13, 2012 09:53
truncate + suffix
var truncate = function(msg, len, suffix) {
var truncated = msg.substring(0, len);
if (msg.length > len) {
truncated += suffix;
}
return truncated;
}
@flopezluis
flopezluis / gist:2375225
Created April 13, 2012 08:59
require for fabric in ubuntu system
def require(package):
with settings(hide('stdout'), warn_only=True):
out = run('dpkg -s %s' %package)
if not out.succeeded:
print "The package is not installed. Installing \n"
sudo("apt-get install %s" %package)
else:
print "The package is installed.\n"
@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 / 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
@flopezluis
flopezluis / DictAsMember.py
Created December 2, 2011 15:55
Simple but useful
class DictAsMember(dict):
def __getattr__(self, name):
"""
From : http://docs.python.org/reference/datamodel.html#object.__getattr__
Called when an attribute lookup has not found the attribute in the usual places
(i.e. it is not an instance attribute nor is it found in the class tree for self).
name is the attribute name
http://stackoverflow.com/questions/8709975/overwrite-in-python
"""
value = self[name]
@flopezluis
flopezluis / gist:1270433
Created October 7, 2011 14:52
Yahtzee categories
from itertools import imap, groupby
def get_duplicates(sec):
return [x for x in sec if sec.count(x) > 1]
class SumEquals(object):
"""
Ones, Twos, Threes, Fours, Fives, Sixes:
"""
@flopezluis
flopezluis / gist:1267749
Created October 6, 2011 15:47
Testing heapq
from heapq import heappush, heappop
def heapsort(iterable, priorities={}):
"""
Sorted the secuence according to the priorities
the biggest number is the less prioritary
>>> priorities ={'Como': 1}
>>> sec = ['camino', 'Como', 'test']
>>> heapsort(sec, priorities)
@flopezluis
flopezluis / gist:1197416
Created September 6, 2011 12:30
filter to return the get paremeters
from django import template
register = template.Library()
@register.filter
def get_parameters(request):
"""
Returns the list of get paremeter
"""
parameters = "?"