Skip to content

Instantly share code, notes, and snippets.

View tmacam's full-sized avatar

Tiago Alves Macambira tmacam

View GitHub Profile
@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 / normalize_string.py
Last active May 30, 2023 08:11
string normalization in python: HTML stripping and HTML entity resolution.
#!/usr/bin/python
# vim:ts=4:sts=4:sw=4:et:wrap:ai:fileencoding=utf-8:
"""A collection of string normalization routines.
You are probably looking for normalize_string, that does an aggressive (but
arguably sound) string normalization process.
"""
@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_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
}
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 / 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'])
@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 / 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 / export-process.rst
Created June 12, 2011 19:13
Short guide on how to export code to Git and tidy up its history

Exporting code to Git and tiding up its history

Author

Tiago Alves Macambira [tmacam burocarata org]

Licence

Creative Commons By-SA

Table of Contents

#ifndef PRODUCER_CONSUMER_QUEUE_HPP_
#define PRODUCER_CONSUMER_QUEUE_HPP_
// Based on code from http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
// Original version by Anthony Williams
// Modifications by Michael Anderson -- https://gist.github.com/482342
#include <boost/thread.hpp>