Skip to content

Instantly share code, notes, and snippets.

# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@teepark
teepark / btree.py
Created September 9, 2010 22:45
a pure-python B tree and B+ tree implementation
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@aisipos
aisipos / jsonp-in-flask.py
Created July 20, 2011 01:20 — forked from farazdagi/jsonp-in-flask.py
JSONP in Flask
import json
from functools import wraps
from flask import redirect, request, current_app
def support_jsonp(f):
"""Wraps JSONified output for JSONP"""
@wraps(f)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
@nrk
nrk / redis_hash_copy.php
Created November 8, 2011 10:50
Use Redis scripting to copy an hash to a new key.
<?php
require 'autoload.php';
$redis = new Predis\Client('tcp://127.0.0.1', 'dev');
// *** NOTE *** Lua's unpack() has a limit on the size of the table imposed by
// the number of Lua stack slots that a C function can use. This value is defined
// by LUAI_MAXCSTACK in luaconf.h and for Redis is set to 8000, which translates
// to an hash of 4000 elements since HGETALL returns a list that interleaves field
@saetia
saetia / gist:1623487
Last active July 16, 2024 05:56
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@jdp
jdp / LICENSE
Last active April 15, 2022 15:42
A* pathfinding over any arbitrary graph structure, with example Cartesian grid implementation
Copyright (C) 2012 Justin Poliey <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT
# fabric extension to enable handling expected prompts
#
# Read more at http://ilogue.com/jasper/blog/fexpect--dealing-with-prompts-in-fabric-with-pexpect/
#
# This file Copyright (c) Jasper van den Bosch, ilogue, [email protected]
# Pexpect Copyright (c) 2012 Noah Spurrier ,see: http://www.noah.org/wiki/pexpect#License
from fabric.state import env
import fabric.api
@drewkerrigan
drewkerrigan / gist:4218222
Created December 5, 2012 18:31
php multi-get mapred
require("riak-php-client/riak.php");
$client = new RiakClient('127.0.0.1', 8098);
$mr = new RiakMapReduce($client);
$keys = array("TFrWAVz8RRVEEqCH3nS27O4InLB","FEwZgNI4VTJSIZxSas0QpOCCXjn","EkSkmblyIAT5VL7xYpScP2GP71G");
foreach ($keys as $key) {
$mr->add("local_ns~users", $key);
}
$mr->map("Riak.mapValues");
@georgepsarakis
georgepsarakis / split.sql
Created March 3, 2013 21:02
Split (explode) function for MySQL. Simple version requires 3 arguments, S (the delimited string), DELIM (delimiter) and S_INDEX the index of the instance of substring between delimiters. The LTSPLIT, RTSPLIT & TSPLIT wrappers perform trimming on the returned substring, on leading, trailing & both characters respectively.
DROP FUNCTION IF EXISTS SPLIT;
DROP FUNCTION IF EXISTS _SPLIT;
DROP FUNCTION IF EXISTS RTSPLIT;
DROP FUNCTION IF EXISTS LTSPLIT;
DELIMITER //
-- Simple Split (no trim)
CREATE FUNCTION SPLIT(S CHAR(255), DELIM VARCHAR(30), S_INDEX TINYINT UNSIGNED) RETURNS VARCHAR(255)
BEGIN
RETURN _SPLIT(S, DELIM, S_INDEX, '', 0);