Skip to content

Instantly share code, notes, and snippets.

View fipar's full-sized avatar

Fernando Ipar fipar

View GitHub Profile
@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)
;; show matching parenthesis
(show-paren-mode 1)
;; evil mode always on so I can keep using the vim shortcuts I know
(require 'evil)
(evil-mode 1)
(add-to-list 'load-path "/Users/fernandoipar/.emacs.d/")
;; logito, pcache, tabulated list, gh-ghist, required by gist
(require 'logito)
-- build binary with:
-- ghc --make -o hello maintest.hs
module Main where
main = putStrLn "Hello, world"
@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 / find_orphans.js
Created June 10, 2015 16:19
Find orphaned documents in mongodb (for pre 2.6 where cleanupOrphaned does not exist).
var database = "sample";
var collection = "tests";
var connections = [];
config = db.getMongo().getDB("config");
config.shards.find().forEach(
function (shard,_a,_i) {
connections.push(new Mongo(shard["host"]));
}