Skip to content

Instantly share code, notes, and snippets.

View fipar's full-sized avatar

Fernando Ipar fipar

View GitHub Profile
@fipar
fipar / service
Created November 24, 2011 17:42
As I miss service from RH when using ports.
#!/bin/bash
#rh-like service primitive wrapper for launchctl
usage()
{
echo "usage: service <name> <start|stop>">&2
}
[ $# -ne 2 ] && {
usage
@fipar
fipar / log_innodb_locks
Created September 11, 2012 17:59
view+event to log innodb lock blocks
CREATE VIEW percona.innodb_lock_blocks AS
SELECT ilw.requesting_trx_id AS requesting_trx_id,
ilw.blocking_trx_id AS blocking_trx_id,
itrxr.trx_started AS requesting_trx_started,
itrxb.trx_started AS blocking_trx_started,
itrxr.trx_mysql_thread_id AS requesting_mysql_thread_id,
itrxb.trx_mysql_thread_id AS blocking_mysql_thread_id,
itrxr.trx_query AS requesting_query,
itrxb.trx_query AS blocking_query,
itrxr.trx_started AS requesting_trx_started,
@fipar
fipar / multi-fifo
Created October 24, 2012 21:32
stream data to multiple pipes
#!/bin/bash
# as introduced here: http://fernandoipar.com/2011/03/10/piping-data-to-multiple-processes/
usage()
{
cat <&2
usage : multi-fifo target0 [target1 [target2 [...]]]
Where each targetN is a program you want to send the input multi-fifo receives
@fipar
fipar / panic-recover.go
Created November 28, 2012 21:45
Basic example of panic / recover use in golang
package main
import (
"fmt"
"time"
)
func mainLoop() {
fmt.Println("starting main loop, this will die after dividing by 0")
i := 0
@fipar
fipar / ParseDSN
Created December 12, 2012 20:18 — forked from anonymous/ParseDSN
// returns the individual fields for a dsn, or an error
func ParseDSN(input string) (error error, host string, port string, user string, password string, database string) {
args := strings.Split(string(input), ",")
if len(args) < 1 {
return errors.New("Seems like " + string(input) + " is not a valid dsn"), "", "", "", "", ""
}
for i := 0; i < len(args); i++ {
tmp := strings.Split(args[i], "=")
if len(tmp) < 2 {
return errors.New("I can't parse " + args[i]), "", "", "", "", ""
@fipar
fipar / jruby-clojure-stm
Created March 20, 2013 16:50
Minimal example of raw Clojure's STM use from JRuby
require "java"
require "clojure.jar"
java_import "clojure.lang.LockingTransaction"
java_import "clojure.lang.Ref"
counter = Ref.new(0)
puts "Initial value : #{counter.deref}"
@fipar
fipar / bash-random-salt
Created March 21, 2013 18:22
Generate a random salt from bash
#!/bin/bash
[ $# -eq 0 ] && {
echo "usage: salt <length>">&2
exit
}
strings </dev/urandom | while read line; do
echo $line | tr '\n\t ' $RANDOM:0:1 >> /tmp/.salt.$$
salt=$(cat /tmp/.salt.$$)
[ ${#salt} -ge $1 ] && salt=${salt:0:$1} && echo $salt && break
@fipar
fipar / gist:5537440
Created May 8, 2013 01:02
full mysql backup with xbackup.sh wrapper
root@lucid64:~/mootools# ./xbackup.sh full
Backup type: full
Backup job started: Tue May 7 18:01:40 PDT 2013
Running full backup /backup//bkps/2013-05-07_18_01_40
Checking disk space ... (data: 29516) (disk: 75403716)
Xtrabackup started: Tue May 7 18:01:40 PDT 2013
Backing up with: /usr/bin/innobackupex --no-timestamp /backup//bkps/2013-05-07_18_01_40
@fipar
fipar / gist:5537447
Last active December 17, 2015 02:39
xbackup.sh usage
root@lucid64:~/mootools# ./xbackup.sh
usage: xbackup.sh <type> [ts] [incremental-basedir]
Where
<type> is full or incr
[ts] is a timestamp to mark the backup with. defaults to $(date +%Y-%m-%d_%H_%M_%S)
[incremental-basedir] if <type> is incr, this will be passed to --incremental-basedir
@fipar
fipar / timetracker.sh
Last active December 21, 2015 02:48
Basic script to help me track time spent on tasks.
#!/bin/bash
#very simple script to track time spent on tasks
#assumes:
# - you are single threaded, so no concurrent tasks
# - if you punch in to a task while you are punched into another one, you're punched out from the latter
# - you only care about accuracy down to minute intervals
# - you have a running mysql instance in localhost
# - you're not replicating this anywhere, you don't expect this to grow a lot, since the schema is stupid and has no keys other than PK, etc. This is only meant to help you track your daily work hours, you should be permanently saving those somewhere else.
# - you just want to track time. you don't really care about performance for this little helper script (i.e. it runs the CLI several times in a row instead of keeping an open connection)