Skip to content

Instantly share code, notes, and snippets.

View hernantz's full-sized avatar
🏠
Working from home

hernantz

🏠
Working from home
View GitHub Profile
@hernantz
hernantz / test_union_find.py
Created August 19, 2012 22:20
These files are the python implementation of the union find algoritm and it's unit tests.
#!/usr/bin/env python
import unittest
from union_find import UnionFind
class TestUnionFind(unittest.TestCase):
def test_init(self):
u = UnionFind(5)
self.assertEquals([0, 1, 2, 3, 4], u.id)
@hernantz
hernantz / common_fabfile.py
Last active July 14, 2017 06:00
Fabfile with common fabric tasks, featuring virtualenvwrapper, nginx, supervisord, git deployment and some other goodies.
from fabric.api import task, local, sudo, run, prefix, env, cd
from fabric.contrib.files import exists, first
from contextlib import contextmanager, nested
def once(s):
"""Command_prefixes is a list of prefixes"""
if s not in env.command_prefixes:
return s
return 'true'
@hernantz
hernantz / grooveshark_api.py
Last active August 29, 2015 14:07
Grooveshark Python API
#!/usr/bin/env python
import httplib
import StringIO
import hashlib
import uuid
import random
import string
import sys
import os
import subprocess
@hernantz
hernantz / tictactoe.py
Last active August 29, 2015 14:14
Simple tic tac toe game
# -*- coding: utf-8 -*-
GRID = {
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
@hernantz
hernantz / post-checkout-hook
Created April 22, 2015 16:32
Delete pyc files git hook
$ cat ~/path/to/.git/hooks/post-checkout
#!/bin/bash
echo "Cleaning pyc"
find . -iname '*.pyc' -delete
@hernantz
hernantz / recursive.hs
Created April 28, 2015 01:25
Some homework on learning haskell
-- repeat
rep :: Int -> x -> [x]
rep 0 x = []
rep n x = [x] ++ rep (n-1) x
-- get value at
at :: [x] -> Int -> x
at (x:xs) 0 = x
at (x:xs) n = at (xs) (n-1)
@hernantz
hernantz / a.py
Created July 29, 2015 01:20
The golden rule for where to mock.patch()
class SomeClass:
def some_method(self):
some_function()
def some_function():
pass
@hernantz
hernantz / play.sh
Created April 8, 2016 23:04
play any song from youtube
# play <some song name>
function play {
youtube-dl --default-search=ytsearch: \
--youtube-skip-dash-manifest \
--output="${TMPDIR:-/tmp/}%(title)-s%(id)s.%(ext)s" \
--restrict-filenames \
--format="bestaudio[ext!=webm]" \
--exec=mplayer -vvv "$*"
}
@hernantz
hernantz / httpie_post_json.sh
Last active April 16, 2016 01:57
HTTPie POST JSON
# Example of how to query elasticsearch with httpie
echo '{"query": {"match": {"name": "beer"}}}' | http POST :9200/my_index/my_doctype/_search/
from collections import deque
def sol(inp):
strd = sorted(inp)
enum = enumerate(strd)
for idx, item in enum:
# ASEGURARSE QUE ESTO SEA UN TRIO SIEMPRE
next_3 = idx + 3