Skip to content

Instantly share code, notes, and snippets.

@agonzalezro
agonzalezro / truncate_with_suffix.py
Created April 13, 2012 09:43
Create a "summary" with ellipsis from a big string
def truncate(message, size, suffix='...'):
'''Create message cutted with ellipses.
>>> message = 'hello crazy world'
>>> truncate(message, 1)
''
>>> truncate(message, 9)
'hello...'
>>> truncate(message, 15)
'hello crazy...'
@agonzalezro
agonzalezro / rget.py
Created May 30, 2012 23:48
Do a recursive get over the keys of nested dictionaries
# I always have problems with the names, please help me :)
def rget(dictionary, *args):
'''Recursive `.get()` function.
Do a recursive get over the keys of nested dictionaries.
>>> things = {'a': {'b': {'c': 'd'}}}
>>> rget(things, 'a', 'b', 'c')
'd'
@agonzalezro
agonzalezro / gist:5501051
Last active December 16, 2015 21:39
Run django code from a shell script
python manage.py shell << 'EOF'
...
EOF
@agonzalezro
agonzalezro / How_to_do_this.md
Created May 3, 2013 12:59
A question about how to manage branches for my blog
import os
from unipath import Path
import pdb; pdb.set_trace()
print os.path.join(Path(__file__).ancestor(0), 'xxx')
import unittest
PRICE_KEY = 'price'
OFFER_AFTER_KEY = 'offer_after'
DISCOUNT_KEY = 'discount'
PRODUCT_PRICING_DETAILS = {
'A': {
@agonzalezro
agonzalezro / keybase.md
Created March 11, 2014 23:55
Keybase proof

Keybase proof

I hereby claim:

  • I am agonzalezro on github.
  • I am agonzalezro (https://keybase.io/agonzalezro) on keybase.
  • I have a public key whose fingerprint is D470 D82B 48F3 40AD E84C 964B 8DEF CA59 68C8 4A97

To claim this, I am signing this object:

@agonzalezro
agonzalezro / tail_several_logs.sh
Created March 15, 2014 20:32
Tail several logs with tmux
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "I need the log base name"
exit
fi
SESSION=`echo $1|cut -d. -f1`
tmux new-session -s $SESSION -n $SESSION -d
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "coreos"
config.vm.provider "virtualbox" do |v|
@agonzalezro
agonzalezro / flats_gumtree.py
Last active August 29, 2015 14:04
Scrape few pages on gumtree to find a place that match your criteria
import asyncio
import bs4
import requests
import re
import tqdm
from csv import writer
from datetime import datetime
from urllib import parse
FROM_DATE = datetime(2014, 9, 25)