Skip to content

Instantly share code, notes, and snippets.

@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
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@fdmanana
fdmanana / gist:1343454
Created November 6, 2011 20:47
Erlang/OTP gen_server simplified API, basics

Client side API

Start a gen_server programmatically

gen_server:start(ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

gen_server:start(ServerName, ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

@Pet3ris
Pet3ris / fsm.clj
Created January 25, 2012 13:27
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |
@rossnelson
rossnelson / postgres-queries.rst
Created April 28, 2012 18:04 — forked from madelfio/postgres-queries.rst
Useful Postgres Admin Queries

Useful Postgres Admin Queries

  • pg_stat_activity (currently executing queries):

    select * from pg_stat_activity where current_query not like '<%';
    
  • pg_user (all database users):

    select * from pg_user;
    
@hugoduncan
hugoduncan / gist:2839891
Created May 31, 2012 00:41
OAuth with friend and oauthentic
(ns myapp.authenticate.oauth
"OAuth authentication"
(:require
[cheshire.core :as json]
[clj-http.client :as http]
[clojure.string :as string]
[clojure.tools.logging :as logging])
(:use
[oauthentic.core :only [build-authorization-url fetch-token]]
[ring.util.response :only [redirect]]
@sax
sax / gist:3113693
Created July 14, 2012 22:24
set up basic zone in SmartOS within VirtualBox
## Set up SmartOS in VirtualBox
# http://www.perkin.org.uk/posts/automated-virtualbox-smartos-installs.html
# set up global zone with Joyent datasets
if [[ ! -e /var/db/imgadm/sources.list || `grep -v "https://datasets.joyent.com/datasets" /var/db/imgadm/sources.list` ]]; then
echo "https://datasets.joyent.com/datasets" >> /var/db/imgadm/sources.list
fi
imgadm update
@megakorre
megakorre / rust-poly.md
Created August 8, 2012 21:47
blog: rust pollymorpism

EDIT! full code can be found here gist

So I played around with rust a bit now. And I thought I might share some random stuff.

So say you wanted to represent a expression tree with plus and minus nodes and a node for values. One way to do this would be to use rust's enum's.

In rust enums are like haskell's union types so you can specify the different values to be constructors carrying data.

@banker
banker / set_benchmark.rb
Created August 30, 2012 16:32
Which of these is the fastest?
x = 10000.times.to_a
a,b,c = x.dup, x.dup, x.dup
Benchmark.measure { 1000.times { out = []; out += a; out += b; out +=c; out.uniq! } }
Benchmark.measure { 1000.times { out = Set.new; out += a; out += b; out +=c; } }
Benchmark.measure { 1000.times { out = {}; a.each {|e| out[e] ||= 1}; b.each {|e| out[e] ||= 1}; c.each {|e| out[e] ||= 1}; } }
@ryankearney
ryankearney / ComcastInject.html
Last active June 10, 2023 14:40
This is the code Comcast is injecting into its users web traffic.
<script language="JavaScript" type="text/javascript">
// Comcast Cable Communications, LLC Proprietary. Copyright 2012.
// Intended use is to display browser notifications for critical and time sensitive alerts.
var SYS_URL='/e8f6b078-0f35-11de-85c5-efc5ef23aa1f/aupm/notify.do';
// var image_url='http://servicealerts.comcast.net:8080/images/mt';
var image_url='http://xfinity.comcast.net/constantguard/BotAssistance/notice/images';
var headertext1='<strong>Comcast Courtesy Notice</strong>';
var textline1='You have reached 90% of your <b>monthly data usage allowance</b>.';
var textline2='Please sign in for more information and to remove this alert.';
var acknowledgebutton='<a href=\"#\" onClick="document.location.href=\''+SYS_URL+'?dispatch=redirect&redirectName=login&paramName=bmUid\'" title="Sign in to acknowledge" style="color: #FFFFFF;"><img alt="Sign in to acknowledge" src="'+image_url+'/mt_signin.png"/></a>';