Skip to content

Instantly share code, notes, and snippets.

@dotmanila
dotmanila / Vagrantfiles.txt
Created September 20, 2017 17:58
Random Vagrantfiles for quick tests.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
@dotmanila
dotmanila / ZFS_and_ext4_Configuration.txt
Last active December 27, 2022 04:56
ZFS and ext4 Configuration
# Create ext4 RAID
sudo mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 \
--name=mysql /dev/sdb /dev/sdc /dev/sdd /dev/sde
sudo mkdir /mysql-ext4
sudo mkfs.ext4 /dev/md0
sudo mount -o rw,relatime /dev/md0 /mysql-ext4
sudo mkdir /mysql-ext4/msb
sudo chown revin.revin /mysql-ext4/msb
@dotmanila
dotmanila / dump-per-table-recovery.sh
Created October 10, 2016 00:09
Dump data from a crashing MySQL server with corrupt pages.
#!/bin/bash
pid_file_path=/var/lib/mysql/mysqld.pid
for d in $(cat dbs-list.txt); do
#if ! grep $d important-dbs.txt; then continue; fi
mysql $d -BNe 'show tables' > /tmp/tables.txt
for t in $(cat /tmp/tables.txt); do
while true; do
test -s "$pid_file_path" && break
@dotmanila
dotmanila / DataSource.java
Created February 25, 2016 05:52
Java source code, using connection pool with c3p0
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class DataSource {
private static DataSource datasource;
@dotmanila
dotmanila / C3P0DataSourceExample.java
Created February 25, 2016 05:51
Sample Java Source Code utilizing connection pools fom DataSource.java.
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Instant;
public class C3P0DataSourceExample {
@dotmanila
dotmanila / callgrind-with-mysql.txt
Last active November 29, 2015 06:34
MySQL Thread Running "SELECT SLEEP(10)" via callgrind
# Ran with valgrind --tool=callgrind mysqld ...
# mysql -e 'select sleep(10)'
# callgrind_control -b
Frame: Backtrace for Thread 24
[ 0] pthread_cond_timedwait@@GLIBC_2.3.2 (1 x)
[ 1] Interruptible_wait::wait(st_mysql_cond*, st_mysql_mutex*) (1 x)
[ 2] Item_func_sleep::val_int() (1 x)
[ 3] Item::send(Protocol*, String*) (2 x)
[ 4] Protocol::send_result_set_row(List<Item>*) (2 x)
@dotmanila
dotmanila / php-xdebug.sh
Created November 29, 2015 06:04
Running XDebug Function Trace from Command Line
#!/bin/bash
php -d xdebug.collect_params=4 -d xdebug.collect_return=1 \
-d xdebug.collect_includes=1 -d xdebug.auto_trace=1 pareto.t.php
@dotmanila
dotmanila / pareto_in.php
Created November 29, 2015 06:00
Pareto Distribution Simulator in PHP
<?php
$pareto_power = log(0.7) / log(1.0-0.7);
function sb_rand_pareto($a, $b) {
global $pareto_power;
return $a + ($b - $a + 1) * pow((double)(rand() % 4294967295) / 4294967295, $pareto_power);
}
for($i=0; $i<=1000; $i++) {
@dotmanila
dotmanila / mysql-partition-manager.sh
Created October 22, 2015 22:48
Manage partitions on a table partition with RANGE on datetime column
#!/bin/bash
MYCMD="mysql"
MAX_OLD=3
MIN_NEW=3
SCHEMA=sphinx
TABLE=search_query_log
LOGFILE=/tmp/search_query_log_partitions.log
DISKPATH=/sphinx/search_query_log_archive
ERRTO="[email protected]"
@dotmanila
dotmanila / python-check-binlogs.py
Created August 29, 2015 02:44
Check create timestamp of binary logs
#!/usr/bin/python
import os, time
from struct import unpack
from datetime import datetime
d = '/home/mysql/backup_data/backup_str/binlogs'
x = 180
oldest = int(time.time())-(90*24*60*60)