Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar

Tit Petric titpetric

View GitHub Profile
<?php
/****
* This script presents an "algorithmic" way of doing a cohort analysis
* on your eCommerce customer database.
*
* This can be useful if you want to automate a lifetime value calculation
* based on some data available from a CSV file, database or API.
*
* The specifics of how your eCommerce system stores this information is
* abstracted out to a couple of objects with methods such as
@keyurdg
keyurdg / mysql_query_multiplexer.go
Created March 18, 2013 19:01
Read output from pt-query-digest and multiplex queries to MySQL over multiple threads.
package main
import (
"bufio"
"bytes"
_ "github.com/Go-SQL-Driver/MySQL"
"database/sql"
"flag"
"fmt"
"io"
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D);
@tomnomnom
tomnomnom / trait-deps.php
Created December 30, 2012 14:00
An experiment: using traits for dependency injection
<?php
// An experiment: using traits for dependency injection
// A trait provides a way to inject a Logger and a way to use it
trait aLogger {
protected $logger = null;
public function setLogger(Logger $logger){
$this->logger = $logger;
}
public function log($msg){
@extraordinaire
extraordinaire / reconnecting_pdo.php
Last active June 27, 2023 11:12
Reconnectable PDO
<?php
class ReconnectingPDO
{
protected $dsn, $username, $password, $pdo, $driver_options;
public function __construct($dsn, $username = "", $password = "", $driver_options = array())
{
$this->dsn = $dsn;
$this->username = $username;
$this->password = $password;
@morphizer
morphizer / process_slow_logs.py
Created October 17, 2012 03:32
Scripts to send mysql slow query logs to anemometer for analysis
#!/usr/bin/env python
# Processes the files in the incoming directory for query analysis in anemometer
# Supply the db user/pass/host
import glob, os, shutil, sys
from subprocess import Popen
db_user = "anemometer"
db_pass = "password"
@mardix
mardix / php-cs-fixer-pre-commit.php
Created September 4, 2012 17:06
A pre-commit hook to make PHP code PSR-2 compliant, check for syntax error
#!/usr/bin/php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP error (lint), and make sure the code
* is PSR compliant.
*
* Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
*
@liutaihua
liutaihua / nginx-SLA
Created April 28, 2012 09:52
nginx log collector for opentsdb
#!/usr/bin/env python
# -*-mode: python; coding: iso-8859-1 -*-
#
# Copyright (c) Liu taihua <defage@gmail.com>
"""
Usage:
[-h|--help] [-t interval=60] [-c cluster=Nanhui] [-H prefer=hostname|IP] [-v|--verbose True|False]
Example:
@perusio
perusio / gist:2154235
Created March 21, 2012 23:47
High performance tuning of Nginx
## From a post on the ML, apropos this:
## http://lowlatencyweb.wordpress.com/2012/03/20/500000-requestssec-modern-http-servers-are-fast.
## For sysctl.conf
net.ipv4.tcp_slow_start_after_idle = 0
echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle
echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse
@dspezia
dspezia / Makefile
Created February 23, 2012 15:50
Example of pipelining with hiredis
OBJ = genload.o
BINS = genload
CC=g++
OPTIMIZATION?=-O3
CFLAGS?=$(OPTIMIZATION) $(ARCH) $(PROF) -I ../hiredis
CCLINK?=-pthread
LDFLAGS?=-L../hiredis -lhiredis -lm
OBJ = example.o