Skip to content

Instantly share code, notes, and snippets.

View tmacam's full-sized avatar

Tiago Alves Macambira tmacam

View GitHub Profile
@tmacam
tmacam / es_uppercase_bug_curl_session.sh
Created May 15, 2014 14:36
Uppercase token filter not being correcly registerred?
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
# DELETE indexes consecutive tests
curl -XDELETE "$ELASTICSEARCH_ENDPOINT/play"
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
;; joins two consecutives lines like vim's "J"
(defun join-lines ()
(interactive)
(save-excursion
(end-of-line)
(insert-char ? 1)
(delete-char 1)
(while (looking-at "\\s +")
(delete-char 1))))
@tmacam
tmacam / password_check.py
Created March 14, 2012 17:33
Verifies a password's strength by measuring its entropy.
"""Verifies a password's strength by measuring its entropy.
Notice that this form of password strength testing does not distinguish easy to
guess passwords like "1111...." from supposedly good passwords like "%hF6Nz-0".
Some rule/points based passwords tests can and should be used together
with this to asset a password's strengh.
References:
- http://xkcd.com/936/
- http://en.wikipedia.org/wiki/Password_strength
@tmacam
tmacam / backtracer.py
Created November 5, 2012 15:46
Python decarator that sends backtraces via POST to a remote server
#!/usr/bin/env python -u
# vim:ts=4:sts=4:sw=4:et:wrap:ai:fileencoding=utf-8:
"""Decorator to log a function's backtrace to a remote server.
Based on client/backtrace.py
from http://github.com/tmacam/DistributedCrawler.
"""
@tmacam
tmacam / backtrace_collector.py
Created November 5, 2012 18:07
Simple Flask app to collect backtraces.
#!/usr/bin/env python -u
# vim:ts=4:sts=4:sw=4:et:wrap:ai:fileencoding=utf-8:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 "\n(%s)")\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 "\n(%s)")\$ '
fi
unset color_prompt force_color_prompt
@tmacam
tmacam / git_sync_master.sh
Created February 19, 2013 16:45
Syncs your git repo and your local copy with the upstream version.
#!/bin/sh
set -e
press_enter() {
set +x
echo "PRESS [ENTER]";
read ENTER;
set -x
}
@tmacam
tmacam / git_park_branch.sh
Created March 5, 2013 13:24
"park" an old branch
#!/bin/sh
set -e
BRANCH=${1:?"Usage: $0 [BRANCH]"}
if ! ( git branch | grep -q ${BRANCH} ); then
echo "ERROR: Uknown branch '${BRANCH}'" > /dev/stderr
exit 1
@tmacam
tmacam / git_prompt.sh
Created May 24, 2013 13:43
Git prompt in my bashrc
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 "\n(%s)")\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 "\n(%s)")\$ '
fi
@tmacam
tmacam / here.py
Created May 29, 2013 13:40
Handy python function to print the current executing python line number , function name and filename.
from inspect import getframeinfo, getouterframes, currentframe
def HERE():
info = getframeinfo(getouterframes(currentframe())[1][0])
print "\t__HERE: @%s %s:%d" % (info.function, info.filename, info.lineno)