Skip to content

Instantly share code, notes, and snippets.

@ekho
ekho / gat.js
Created June 6, 2012 04:06
Track outgoing links with google analytics
(function(){
function addEventListener(element, event, listener) {
if (typeof listener != 'function')
return;
if (event == 'ready' && element == document){
if (/(loaded|complete)/.test(document.readyState)) {
listener();
return;
}
@ekho
ekho / syntax_highliting_for_blogger.js
Last active December 10, 2015 08:08
Syntax highlighting in Blogger
(function() {
var baseUrl = 'http://alexgorbatchev.com/pub/sh/current';
var theme = 'Default';
var bloggerMode = true;
function addScript (uri) {
var e = document.createElement('script'); e.type = 'text/javascript';
e.src = baseUrl + uri;
document.getElementsByTagName('script')[0].parentNode.appendChild(e);
}
@ekho
ekho / gist:5454679
Last active December 16, 2015 15:19
compare leveldb-daemon (https://github.com/mambaru/leveldb-daemon), memcached & redis through phpredis (https://github.com/nicolasff/phpredis) leveldb-daemon: ~34,6s memcached: ~6.5s redis: ~5.1s
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__));
include_once 'JsonRpc.php';
$config = include 'config.php';
$connect = new JsonRpc_Connection($config['host'], $config['port']);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
@ekho
ekho / ThreadManager.php
Created May 16, 2013 08:20
ThreadManager
<?php
declare(ticks = 1);
/**
* ThreadManager
*/
class ThreadManager extends CApplicationComponent
{
const E_WORKER = 255;
protected static $isChildWorker = false;
@ekho
ekho / intersected_classes.php
Last active December 19, 2015 04:08
Shows duplicated classes in two folders
<?php
if ($argc != 3) {
echo 'Usage:', PHP_EOL, "\tphp ", basename($argv[0]), ' <source directory 1> <source directory 2>', PHP_EOL;
exit(1);
}
function token_get_namespaces($tokens)
{
$tokens = array_map(
function ($token) {
@ekho
ekho / pg_random_int_array.sql
Last active February 9, 2024 13:47
Postgresql function for generating random integer array
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim));
end
$BODY$ LANGUAGE plpgsql;
-- usage example
select random_int_array(15, 6, 40);
-- return example
@ekho
ekho / pgAgent daemon
Last active July 2, 2024 17:14
pgAgent daemon
http://www.ekho.name/2012/03/pgagent-debianubuntu.html
@ekho
ekho / callbak_with_context.js
Created September 20, 2013 12:08
javascript callback with specified context
function hitch(func, context){
return function(){
return func.apply(context, arguments);
};
};
// example will out to browser console object myOwnContext after clicking on specified element
$('...').click(
var myOwnContext = {prop: 1};
hitch(function(){ console.dir(this); }, myOwnContext);
# Usage:
# 1. Drop this file into lib/capistrano/submodule_strategy.rb
# 2. Add the following to your Capfile:
# require './lib/capistrano/submodule_strategy'
# 3. Add the following to your config/deploy.rb
# set :git_strategy, SubmoduleStrategy
require 'capistrano/git'
module SubmoduleStrategy
<?php
/**
* CIDR.php
*
* Utility Functions for IPv4 ip addresses.
* Supports PHP 5.3+ (32 & 64 bit)
* @author Jonavon Wilcox <[email protected]>
* @revision Carlos Guimarães <[email protected]>
* @version Wed Mar 12 13:00:00 EDT 2014
*/