Skip to content

Instantly share code, notes, and snippets.

View rcmachado's full-sized avatar

Rodrigo Machado rcmachado

View GitHub Profile
@rcmachado
rcmachado / shutdown-test.conf
Created November 8, 2012 20:12
Upstart: execute task on shutd own (but before the kill signal)
description "Upstart task: execute this script on shutdown or reboot"
task
# this will execute this script before the upstart send the KILL signals
start on starting rc RUNLEVEL=[06]
exec mktemp --tmpdir=/home/ubuntu test.XXXXXX
@rcmachado
rcmachado / git-commits-per-author
Created January 25, 2013 19:22
Custom git commands
git ls-files -z |
xargs -0 -n1 -E'\n' -J {} git blame --date short -wCMcp '{}' |
perl -pe 's/^.*?\((.*?) +\d{4}-\d{2}-\d{2} +\d+\).*/\1/' |
sort |
uniq -c |
sort -rn
@rcmachado
rcmachado / logger.js
Created February 5, 2013 18:08
Javascript "class" (Logger) to use in MongoDB scripts. This class prints the messages (respecting log level specified on constructor).
/**
* Logger class to print messages according to specified level.
*
* Usage:
* var log = new Logger(Logger.INFO);
* log.info("Show message");
*/
function Logger(level) {
this.level = level || Logger.DEBUG;
@rcmachado
rcmachado / update-git.sh
Created March 28, 2013 14:56
How to install most recent git using homebrew
# install brew if not installed
which brew > /dev/null || ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# update brew package list
brew update
# install git from brew
[[ -x /usr/local/bin/git ]] || brew install git
# if git is installed, upgrade it
@rcmachado
rcmachado / error_reporting.php
Last active July 8, 2017 03:00
Script to verify PHP error_reporting settings. Adapted from http://us3.php.net/manual/en/errorfunc.constants.php#109430
<?php
$errorLevel = error_reporting();
print "Current error_reporting level: $errorLevel <br>\n";
print "E_ALL value: " . E_ALL . " <br>\n";
for ($i = 0; $i < 15; $i++) {
$errVal = $errLevel & pow(2, $i);
print FriendlyErrorType($errVal) . " ($errVal) <br>\n";
}
@rcmachado
rcmachado / remove_hover_rule.js
Created November 4, 2013 14:21
Remove CSS :hover rules for touch devices to avoid iOS double-tap behavior. Copied and adapted from http://retrogamecrunch.com/tmp/hover (just a fix for sheet.cssRules)
// disable :hover on touch devices
// based on https://gist.github.com/4404503
// via https://twitter.com/javan/status/284873379062890496
// + https://twitter.com/pennig/status/285790598642946048
// re http://retrogamecrunch.com/tmp/hover
// NOTE: we should use .no-touch class on CSS
// instead of relying on this JS code
function removeHoverCSSRule() {
if ('createTouch' in document) {
try {
<?php
use \OAuth\Common\Token\TokenInterface;
use \OAuth\Common\Storage\Exception\TokenNotFoundException;
use \OAuth\Common\Storage\Exception\AuthorizationStateNotFoundException;
use \OAuth\Common\Storage\TokenStorageInterface;
use \sfStorage;
class Symfony1Storage implements TokenStorageInterface
{
@rcmachado
rcmachado / copy-db.sh
Last active April 3, 2021 01:54
Script to copy all tables from one database to another.
#!/bin/bash
#
# Script to copy all tables from one database to another.
#
# Requires:
# * MySQL 5.6
# * Percona xtrabackup tools (http://www.percona.com/software/percona-xtrabackup)
#
# Known caveats:
# * Will copy structure of all tables from one database to another, but only InnoDB
@rcmachado
rcmachado / install.sh
Last active August 29, 2015 14:06
Install my boxen
#!/bin/sh
# Install & configure boxen
SKIP_ENCRYPTION="--no-fde"
BOXEN_REPOSITORY="https://github.com/rcmachado/my-boxen"
sudo mkdir -p /opt/boxen
sudo chown ${USER}:staff /opt/boxen
git clone ${BOXEN_REPOSITORY} /opt/boxen/repo
cd /opt/boxen/repo
@rcmachado
rcmachado / Makefile
Last active February 7, 2024 06:04
Add a help target to a Makefile that will allow all targets to be self documenting
.SILENT:
.PHONY: help
# Based on https://gist.github.com/prwhite/8168133#comment-1313022
## This help screen
help:
printf "Available targets\n\n"
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \