Skip to content

Instantly share code, notes, and snippets.

View fipar's full-sized avatar

Fernando Ipar fipar

View GitHub Profile
@fipar
fipar / jruby-clojure-stm.rb
Created March 14, 2014 00:25
thread safe attribute accessors using clojure Atoms
require "java"
class Class
def atom_attr_accessor(*args)
self.class_eval("
require 'clojure.jar'
java_import 'clojure.lang.LockingTransaction'
java_import 'clojure.lang.Atom'
")
@fipar
fipar / split_processlist
Created April 3, 2014 14:30
split pt-stalk processlist capture into individual files per timestamp, including only the query text and not 'NULL' queries. meant to then feed pt-query-digest --type rawlog
cnt=-1
f = nil
File.open(ARGV[0]).each_line do |line|
if line.match "^TS"
f.close unless f.nil?
f = File.open(line.gsub(" ","_"), 'w')
else
f.write(line.gsub(" Info: ","")) if line.match " Info: " and not line.match " Info: NULL"
end
end
@fipar
fipar / gist:3bf5b48685e89e7199f3
Created October 31, 2014 17:06
sample joomla queries
EXPLAIN SELECT a.title, a.description AS text, '' AS created, '2' AS browsernav, a.id AS catid, CASE WHEN CHAR_LENGTH(a.alias) != 0 THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END as slug FROM j_categories AS a WHERE (a.title LIKE '%super%' OR a.description LIKE '%super%') AND a.published IN (1,2) AND a.extension = 'com_content'AND a.access IN (1,1,2,3,6) GROUP BY a.id, a.title, a.description, a.alias ORDER BY a.title DESC LIMIT 0, 50;
EXPLAIN SELECT a.name AS title, '' AS created, a.con_position, a.misc, CASE WHEN CHAR_LENGTH(a.alias) != 0 THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END as slug, CASE WHEN CHAR_LENGTH(c.alias) != 0 THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as catslug, CONCAT_WS(',', a.name, a.con_position, a.misc) AS text,CONCAT_WS(' / ', 'Contacts', c.title) AS section,'2' AS browsernav FROM j_contact_details AS a INNER JOIN j_categories AS c ON c.id = a.catid WHERE (a.name LIKE '%super%' OR a.misc LIKE '%super%' OR a.con_position LIKE '%super%' OR a.address LIKE '%super%' OR a.s
@fipar
fipar / worker_pool_example.sh
Created November 20, 2014 13:20
worker pool in bash
#!/bin/bash
THREADS=3
worker()
{
echo "thread $1 starting"
sleep 3
rm -f /tmp/lock.$1
echo "thread $1 finished"
@fipar
fipar / gist:570d4dbad37c51ad523c
Created June 27, 2015 21:54
simple-todo meteor app using tokumx, on mac.

These are instructions on getting the simple-todo test app from the meteor tutorial (link below) running on a Mac and using TokuMX instead of MongoDB. It was written in response to this request: https://www.percona.com/blog/2015/05/08/mongodb-percona-tokumxse-experimental-build-rc5-available/#comment-10864682

Prerequsites:

@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 / 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]), "", "", "", "", ""