Skip to content

Instantly share code, notes, and snippets.

"""
A listagent is a factory to conveniently instanstiating sliceagents.
A sliceagent can access and mutate an original list "live": it never
creates any copy of the original and only refers to it via "address
translation" -- normalizing its indices by the size of the original list on
every operation.
>>> x = [22, 7, 2, -5, 8, 4]
>>> listagent(x)[1:].sort()
#!/usr/bin/env python
import getpass
import os
import sys
## Application specific
SDK_DIR = '/usr/local/google_appengine'
APP_DIR = '/home/username/src/app'
APPID = 'something-awesome'
#!/usr/bin/env python2.6
"""
Usage: python ./rsa_tuples [-s] n
Generate `n` RSA tuples using 200-digit primes.
Requires:
ent.py <http://modular.fas.harvard.edu/ent/ent_py>
stream.py <http//github.com/aht/stream.py>
import "container/ring"
// Use a goroutine to receive values from `out` and store them
// in an auto-expanding buffer, so that sending to `out` never blocks.
// Return a channel which serves as a sending proxy to to `out`.
func sendproxy(out chan<- int) chan<- int {
in := make(chan int, 100)
go func() {
n := 1000 // the allocated length of the circular queue
first := ring.New(n)
package main
import (
"rand"
"time"
"flag"
"fmt"
)
func getCoord(rg *rand.Rand) float64 {
@aht
aht / LICENSE.txt
Created August 4, 2011 15:28 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@aht
aht / gist:1251197
Created September 29, 2011 16:39 — forked from trrichard/gist:1226966
Bookmarklet to uncripple Kindle Cloud Reader
javascript:(function(){
var importJs=function(jsUrl){
var s=document.createElement("script");
s.setAttribute("src",jsUrl);
document.body.appendChild(s);
};
importJs("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js");
})();
$('iframe').contents().find('iframe').each(function() {
this.contentWindow.onclick = null;
@aht
aht / collection size and indexes
Created January 17, 2013 10:34
$centerSphere query hangs mongodb
> db['similar_items.tanhxdiv5ratings_cosinesimilarities.6'].count()
27745186
> db['similar_items.tanhxdiv5ratings_cosinesimilarities.6'].getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "osapi_int.similar_items.tanhxdiv5ratings_cosinesimilarities.6",
"""
Automated installation of ejabberd with a postgresql backend inspired by this
article: http://www.planeterlang.org/en/planet/article/How_to_install_ejabberd_2.0.0_with_PostgreSQL_support/
"""
from fabric.api import run, sudo
EJABBERD_VERSION = '2.0.5'
EJABBERD_SOURCE_HOME = '~/dev/xmpp/oss'
POSTGRES_PSQL_PASSWORD = 'user'
@aht
aht / gist:5097702
Created March 6, 2013 08:45
ansible postgres playbook with PostGIS on Ubuntu, setting up postgis_template and creating databases from this postgis_template
# Based on https://github.com/ansible/ansible/blob/devel/examples/playbooks/postgresql.yml
---
- hosts: postgres.vm
sudo: yes
tasks:
- name: ensure latest postgres & postgis packages are latest
action: apt pkg=$item update_cache=yes state=latest
with_items: