Skip to content

Instantly share code, notes, and snippets.

View atdt's full-sized avatar
💭
I may be slow to respond.

Ori Livneh atdt

💭
I may be slow to respond.
  • Google
  • New York City
View GitHub Profile
@atdt
atdt / cluster_ssh.py
Last active August 29, 2015 13:56
Python distributed shell with OpenSSH
# -*- coding: utf-8 -*-
"""
Copyright 2014 Ori Livneh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@atdt
atdt / getId.js
Last active August 29, 2015 13:56
getId
function getId() {
var id = null;
try {
id = localStorage.getItem( 'popupsId' );
if ( id === null ) {
id = mw.user.generateRandomSessionId();
localStorage.setItem( 'popupsId', id );
}
} catch (e) {}
return id;
@atdt
atdt / statsd.py
Created February 18, 2014 12:25
trivial statsd client
import socket
class Stats:
"""A simple StatsD metric client.
See <https://github.com/etsy/statsd/wiki/Protocol> for details.
"""
def __init__(self, host, port):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.address = (host, port)
@atdt
atdt / geotests.sh
Last active August 29, 2015 13:56
Unit tests for bits.wikimedia.org/geoiplookup
#/usr/bin/env bash
# Unit tests for /geoiplookup
# Usage: geotests HOSTNAME
url="${1:-localhost}/geoiplookup" fails=0
pass() { echo "$(tput bold; tput setaf 2)PASSED:$(tput sgr0) $*"; }
fail() { echo "$(tput bold; tput setaf 1)FAILED:$(tput sgr0) $*"; fails=$(($fails+1)); }
assert() { curl -s -H "Host: bits.wikimedia.org" \
${3:+-H "X-Forwarded-For: ${3}"} ${url} | grep -q "${2}" && pass $1 || fail $1; }
@atdt
atdt / djbtest.py
Created March 4, 2014 20:25
benchmark of py_djb_hash
import itertools
words = itertools.cycle(line.strip() for line in open('/usr/share/dict/words', 'rt'))
def py_djb_hash(s):
'''Return the value of DJB's hash function for the given 8-bit string.'''
h = 5381
for c in s:
h = (((h << 5) + h) ^ ord(c)) & 0xffffffff
@atdt
atdt / I42c00b546.js
Created March 8, 2014 07:08
Proposed interface for I42c00b546
var checkUsername = ( function () {
var api = new mw.Api(),
req = null,
checked = {};
return function ( username ) {
if ( !checked.hasOwnProperty( username ) ) {
checked[ username ] = $.Deferred();
if ( req ) {
@atdt
atdt / serialization_sniffing_test.php
Created March 18, 2014 22:30
Verify that MemcachedPeclBagOStuff can read igbinary-serialized values even when its serializer is set to PHP.
<?php
function rawGet( $key ) {
$socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_connect( $socket, '127.0.0.1', 11211 );
socket_write($socket, "get $key\r\n" );
$value = trim( socket_read( $socket, 4096 ) );
socket_close( $socket );
return $value;
};
@atdt
atdt / hhvm.conf
Created March 21, 2014 23:41
Upstart job configuration for HHVM; save as /etc/init/hhvm.conf
description "HipHop Virtual Machine for PHP"
setuid www-data
setgid www-data
exec /usr/bin/hhvm --config /etc/hhvm/server.hdf --mode server -vServer.Type=fastcgi -vServer.Port=9000
respawn
@atdt
atdt / fix_timeouts.patch
Last active August 29, 2015 13:58
Backport of e291667 for v0.2.0
From cfec08d7ead003480481c9736e04e868214ea8f9 Mon Sep 17 00:00:00 2001
From: Ori Livneh <ori@wikimedia.org>
Date: Tue, 8 Apr 2014 16:11:22 -0700
Subject: [PATCH] Backport of e291667 for v0.2.0
---
phantomjs/main.js | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/phantomjs/main.js b/phantomjs/main.js
import json
import collections
records = [json.loads(line) for line in open('deprecated-js.json')]
def iter_modules():
for record in records:
for module in record.get('modules', ()):
yield module