Skip to content

Instantly share code, notes, and snippets.

@csytan
csytan / locale.py
Created December 16, 2010 07:45
db backed locale replacement for tornado on appengine
# -*- coding: utf-8 -*-
import urllib
import re
import decimal
import uuid
import datetime
from google.appengine.ext import db
try:
import json
import random
def name_generator():
adjectives = ['narly', 'arrogant', 'fickle', 'eager', 'modest', 'greasy', 'tart', 'swift', 'quaint', 'unslightly', 'fancy', 'brave', 'delightful', 'jolly', 'shy', 'itchy', 'obedient', 'voiceless', 'raspy', 'silly', 'powerful', 'tender', 'clumsy', 'juicy', 'bitter', 'damp', 'fluffy', 'substantial', 'sticky', 'ancient', 'foolish']
nouns = ['carrot', 'barley', 'banana', 'garlic', 'pickle', 'mouse', 'baboon', 'herring', 'tramp', 'panda', 'owl', 'parsnip', 'whale', 'lettuce', 'yam', 'mammoth', 'rock', 'mushroom', 'elephant', 'panther', 'phoenix', 'onion', 'cloth', 'chair', 'lemonade', 'tyvek', 'underpants', 'willow', 'girdle', 'clover', 'society', 'beaver', 'tart', 'wolf', 'leather', 'pantyhose', 'socks']
return random.choice(adjectives) + random.choice(nouns)
@csytan
csytan / lazy_video_loading.js
Created April 19, 2011 07:31
Lazy loads videos as you scroll. Place the iframe src in a "data-embed" attribute. Use with jQuery.
$(document).ready(function(){
var vid_links = $('a.video');
function showVideos(){
if (!vid_links.length) return;
var window_bottom = $(window).scrollTop() + $(window).height() + 500;
vid_links.each(function(){
var link = $(this);
if (link.offset().top < window_bottom){
link.replaceWith(
'<iframe src="' + link.attr('data-embed') + '" class="video" frameborder="0"></iframe>');
(function($){ // Module pattern, means vars defined here will not leak outside
// Global vars. Some people use CAPS for them -- it's your personal preference
var MAP = null;
var INFOWINDOW = null;
...
function setLocation() {
@csytan
csytan / reddit.js
Created March 12, 2013 01:43
Reddit JS comment loading
function findRedditComments(query){
var url = 'http://www.reddit.com/search.json?syntax=plain&sort=top'+
'&q=' + query + '&jsonp=?';
$.getJSON(url, function(data){
var articles = data.data.children;
articles.sort(function(a, b){
return b.data.num_comments - a.data.num_comments;
});
var article = articles[0];
if (article && article.data.num_comments){
@csytan
csytan / fims_proposal.md
Last active January 3, 2016 14:49
FIMS proposal. Feedback welcome.

With the possibility of a new NIMS project, FIMS (Future Information Management System), we have the opportunity to create something better by learning from the issues that have affected us in the past with NIMS.

Overview

Objective: To create an online facility inventory for Ethiopia

Goals:

  • Software Maintainability: "do one thing and do it well"
  • Offline & mobile data collection
@csytan
csytan / service.conf
Last active August 29, 2015 13:59
Tornado Upstart example
# Ubuntu upstart file at /etc/init/<service>.conf
# More info: http://upstart.ubuntu.com/cookbook/
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
setuid <username>
@csytan
csytan / async_thread.py
Created April 18, 2014 21:19
Tornado async handler with threading
import time
# For python 2.7 use:
# pip install futures
import concurrent.futures
import tornado.ioloop
import tornado.web
import tornado.gen
@csytan
csytan / sequencer.html
Created July 11, 2014 15:32
sequencer.html
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0;
}
.node {
cursor: pointer;
fill: red;
@csytan
csytan / crawl.py
Created October 14, 2014 17:27
Nigeria polling booths crawler
import csv
import json
import os
import time
import urllib
def load(**kwargs):
url = 'http://booths.nigeriaelections.org/getStuff.php'