Skip to content

Instantly share code, notes, and snippets.

View fipar's full-sized avatar

Fernando Ipar fipar

View GitHub Profile
#!/bin/bash
sysbench \
--test=/usr/share/doc/sysbench/tests/db/insert.lua \
--mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user=sysbench \
--mysql-password=sysbench \
--mysql-db=sysbench \
--mysql-table-engine=innodb \
--oltp-test-mode=complex \
@fipar
fipar / fac.sh
Last active November 25, 2015 13:08
fac()
{
[ $1 -eq 0 ] && echo 1 && return
seq $1 |tr '\n' '*'|sed 's/*$//g' | bc
}
@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)
@fipar
fipar / gist:6498750
Created September 9, 2013 17:20
Create many databases and tables for innodb_file_per_table crash recovery slowness test
for i in $(seq 40000); do mysql -e "create database test_$i"; for j in $(seq 250); do mysql test_$i -e "create table test_$j (id int not null auto_increment primary key) engine=innodb; insert into test_$j values (null),(null),(null);"; done; done
@fipar
fipar / mysqlslap_employees_order_by
Last active December 30, 2015 01:49
Testing query scalability with concurrency
# Requires : employees dataset (https://dev.mysql.com/doc/employee/en/)
# Then just create table employees_idx_on_hire_date like employees; alter table employees_idx_on_hire_date add key (hire_date);
# Pick one of these:
cat<<EOF>query.txt
select * from employees.employees_idx_on_hire_date order by hire_date desc limit 10
EOF
cat<<EOF>query.txt
;; show matching parenthesis
(show-paren-mode 1)
;; evil mode always on so I can keep using the vim shortcuts I know
(evil-mode 1)
(add-to-list 'load-path "/Users/fernandoipar/.emacs.d/")
;; logito, pcache, tabulated list, gh-ghist, required by gist
(require 'logito)
(require 'pcache)