Skip to content

Instantly share code, notes, and snippets.

View atdt's full-sized avatar
💭
in rainbows

Ori Livneh atdt

💭
in rainbows
  • Google
  • New York City
View GitHub Profile
@atdt
atdt / wpt-side-by-side
Created August 18, 2015 01:46
Generate a side-by-side comparison video from two WebPageTest runs.
#!/usr/bin/env bash
#
# wpt-side-by-side
# ~~~~~~~~~~~~~~~~
# Generate a side-by-side comparison video from two WebPageTest runs.
#
# Usage:
# wpt-side-by-side WEBPAGETEST_URL_1 WEBPAGETEST_URL_2
#
# Requirements:
@atdt
atdt / apc_vs_memcached.php
Last active August 29, 2015 14:27
Simple benchmark demonstrating the efficiency of APC compared to memcached. Even if the memcached instance is running on localhost, it is a separate process, and PHP has to talk with it via a socket (usually TCP, sometime UNIX). This requires executing many system calls, like select(), accept(), read(), and write(), each of which crosses the bou…
<?php
$loops = 1000;
$data = array( 'a' => 1, 'b' => 2, 'c' => 3 );
// Memcached
$cache = new Memcached();
$cache->addServer( "127.0.0.1", 11211 );
$start = microtime( true );
import json
import os.path
import subprocess
import urllib
import urllib2
GERRIT_API = 'https://gerrit.wikimedia.org/r'
query_string = urllib.urlencode((
@atdt
atdt / keyclean
Created July 1, 2015 20:43
Temporarily disable MBP's internal keyboard, so I can clean it :)
#!/usr/bin/env bash
KEYBOARD_KEXT="/System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/"
countdown() {
local seconds="$1"
while [ $seconds -gt 0 ]; do
sleep 1 &
echo -n "${seconds}.. "
seconds=$(( $seconds - 1 ))
@atdt
atdt / check-jemalloc-prof
Created June 30, 2015 00:02
Check if libjemalloc was built with `--enable-prof` (and thus has memory profiling capabilities) or not.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Check if libjemalloc was built with `--enable-prof` (and thus has
memory profiling capabilities) or not.
Author: Ori Livneh
No copyright restriction
"""
import ctypes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Print the most recent IPython session to stdout.
"""
import sqlite3
import os
HISTORY_FILE = '~/.ipython/profile_default/history.sqlite'
import random
with open('/etc/dsh/group/mediawiki-installation') as f:
app_servers = [line.strip().split('.')[0] for line in f]
num_servers = len(app_servers)
def get_batch():
random.shuffle(app_servers)
return app_servers[:num_servers // 10]
@atdt
atdt / bench.php
Created June 18, 2015 06:49
SyntaxHighlight_GeSHi benchmark
<?php
// run with: hhvm -vEval.Jit=1 bench.php
require_once __DIR__ . '/maintenance/commandLine.inc';
$loops = 20;
$warmups = 10;
$times = array();
$title = Title::newMainPage();
$parserOptions = new ParserOptions();
$wikitext = file_get_contents( __DIR__ . '/quicksort.mediawiki' );
import requests
r = requests.get('https://meta.wikimedia.org/w/api.php?action=sitematrix&format=json')
wikis = r.json()['sitematrix'].values()
sites = {}
for wiki in wikis:
if not isinstance(wiki, dict) or 'site' not in wiki:
continue
for site in wiki['site']:
if 'dbname' not in site:
DocumentRoot /srv/mediawiki
<Directory /srv/mediawiki>
Require all granted
</Directory>
AllowEncodedSlashes on
RewriteEngine On
ProxyPass /wiki fcgi://127.0.0.1:9000/srv/mediawiki/index.php retry=0