Skip to content

Instantly share code, notes, and snippets.

@vitalbh
vitalbh / busca em tuplas de tuplas
Created January 13, 2012 11:14
busca de um valor em tuplas de tupla com python usando zip
>>> x = ((1,),(2,),(3,))
>>> list(zip(*x)[0])
[1, 2, 3]
>>> 1 in list(zip(*x)[0])
True
>>>
by @cicerocomp
>>> s = ((1,), (2,), (3,))
@vitalbh
vitalbh / sort object
Created January 17, 2012 00:10
Ordenando uma lista de objetos por um atributo do objeto
list = list(lista1) + list(lista2)
list.sort(key=lambda x: x.atributo) #funcao anonima
@vitalbh
vitalbh / ordenação alfabeto definido
Created January 27, 2012 16:47
python sorting - organizando uma lista em uma ordem alfabética pré-definida
alfabeto = "zyxwvutsrqpomnlkjihgfedcba"
s = ['asdf', 'werwer', 'asgfd','wesasd','yasdfas','zsadf']
print sorted(s, key=lambda w: [alfabeto.index(i) for i in w])
@vitalbh
vitalbh / gist:3420392
Created August 21, 2012 23:22 — forked from douglasmiranda/gist:2555156
Solução para instalar lxml no ubuntu com sucesso =] ( erro em pip install lxml )
#Se o erro for algo parecido com isto:
#building 'lxml.etree' extension
#gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w
#In file included from src/lxml/lxml.etree.c:239:0:
#src/lxml/etree_defs.h:9:31: erro fatal: libxml/xmlversion.h: Arquivo ou diretório não encontrado
#compilação terminada.
#error: command 'gcc' failed with exit status 1
#basta instalar libxml2-dev e libxslt-dev
@vitalbh
vitalbh / Vagrantfile
Last active December 22, 2015 10:59
bootstrap vagrant
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 80, host: 8081
config.vm.provision :shell, :path => "provision/shell/bootstrap.sh"
# TODO: fix this hack that ensures 'apt-get update' runs before mysql
# is provisioned with puppet
config.vm.provision :shell, :inline => "apt-get update --fix-missing"
@vitalbh
vitalbh / mkdir_recursive.sh
Created September 9, 2013 19:14
Cria arvore de pastas com 4 níveis( 0 - 9 - a - f )
mkdir -p {{0..9},{a..f}}/{{0..9},{a..f}}/{{0..9},{a..f}}/{{0..9},{a..f}}

Contract Killer 3

Revised date: 07/11/2012

Between us [company name] and you [customer name]

Summary:

We’ll always do our best to fulfil your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

@vitalbh
vitalbh / fonts
Last active February 8, 2016 14:24
Fonts - mime types, gzip and font-face crossdomain bug on firefox
/etc/nginx/mime.types
remove eot (defaults to application/octet-stream).
font/ttf ttf;
font/opentype otf;
application/font-woff woff;
application/vnd.ms-fontobject eot;
# Send a metric to statsd from bash
#
# Useful for:
# deploy scripts (http://codeascraft.etsy.com/2010/12/08/track-every-release/)
# init scripts
# sending metrics via crontab one-liners
# sprinkling in existing bash scripts.
#
# netcat options:
# -w timeout If a connection and stdin are idle for more than timeout seconds, then the connection is silently closed.
@vitalbh
vitalbh / gist:9489144
Created March 11, 2014 16:15
Filtrando resultados no gdata para mobile (controles de acesso conhecidos)
//http://gdata.youtube.com/feeds/mobile/videos/?category=Music&alt=json-in-script&callback=?&orderby=relevance&start-index=" + inicio + "&max-results=" + num_resultados + "&q=
//Gdata para mobile
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var embed = true;
for (a in entry.yt$accessControl) {
if (entry.yt$accessControl[a].action == 'embed' && entry.yt$accessControl[a].permission == 'denied')
embed = false;
}