Skip to content

Instantly share code, notes, and snippets.

View diezguerra's full-sized avatar

Saúl diezguerra

View GitHub Profile
# Snippet setting git branch and git dirty helper
# Commit at the end kept from original snippet, I added the rev-parse stuff and the proper redirection.
set fish_git_dirty_color red
set fish_git_clean_color brown
function parse_git_dirty
if test (git status 2> /dev/null ^&1 | tail -n1) != "nothing to commit (working directory clean)"
echo (set_color $fish_git_dirty_color)
else
@diezguerra
diezguerra / keybase.md
Created February 5, 2016 01:57
keybase.md

Keybase proof

I hereby claim:

  • I am diezguerra on github.
  • I am saul (https://keybase.io/saul) on keybase.
  • I have a public key whose fingerprint is 41CC 20BC 641C 0215 84F8 5736 2F7D 9259 08E9 7490

To claim this, I am signing this object:

In = lambda: map(int, raw_input().split())
integer_no, unique_no = In()
a = In()
uniques = [In().pop() for _ in range(unique_no)]
aux = [0] * integer_no
seen = set()
for idx in xrange(integer_no - 1, -1, -1):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import dateutil.parser
import pytz
date_string = '2013-10-14T12:47:12.776270'
date_object = pytz.timezone('America/Los_Angeles').localize(dateutil.parser.parse(date_string))
print date_object.isoformat()
import requests
import json
r = requests.get('https://graph.facebook.com/search?q=&type=adcountry&limit=500')
countries = {country['name']: country['country_code'] for country in r.json()['data']}
assert countries['Spain'] == 'ES'
assert len(countries) == 216
@diezguerra
diezguerra / noleaks.py
Last active December 17, 2015 07:19
Closure saving and GC example. # needs memory_profiler module! $ python -m memory_profiler noleaks.py
#!/usr/bin/env python2.7
import gc
def iterjam():
import functools as ft
def iterjam2():
@diezguerra
diezguerra / dict_optimization.py
Created May 2, 2013 06:08
Dict initialization optimization
"""
Result:
Using original function 1000 loops, best of 3: 200 us per loop
Using itertools.chain 10000 loops, best of 3: 130 us per loop
Using joined sets 10000 loops, best of 3: 142 us per loop
Using double the tags and modulo 1000 loops, best of 3: 184 us per loop
"""
@diezguerra
diezguerra / slice_upsert.py
Last active December 15, 2015 18:29
Python Slice Upsert
a_range = range(12)
a_range[-2:] = range(10,20)
assert a_range == range(20)
a_range[10:11] = range(10)[::-1]
a_range[20:] = []
assert a_range == range(10) + range(10)[::-1]
keywords = "apple, pear, banana, lemon and orange"
keywords = keywords.split(', ')
@diezguerra
diezguerra / filterdict.py
Last active December 14, 2015 00:39
How to filter dicts in python, the right way.
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <rawcell>
# How to filter Python dictionaries, the right way.
#
# Expected output:
# Original list lookup => 100 loops, best of 3: 9.82 ms per loop
# Dict trick lookup => 1000 loops, best of 3: 315 us per loop