Skip to content

Instantly share code, notes, and snippets.

@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 / 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){
(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 / 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>');
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 / 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 timeit
t = timeit.Timer(stmt="""\
def test(pwd, n_iter):
for i in range(n_iter):
pwd = hashlib.sha1(pwd).hexdigest()
test('hello', 50000)
""", setup='import hashlib')
print t.timeit(100) / 100
@csytan
csytan / gomtv-live.html
Created December 10, 2010 11:14
downloads the live stream for viewing on vlc
<html>
<body>
<a href="javascript:
(function() {
  var el=document.createElement('div'),
      b=document.getElementsByTagName('body')[0],
      otherlib=false,
      msg='';
class Votable(BaseModel):
points = db.IntegerProperty(default=1)
score = db.FloatProperty()
up_votes = db.StringListProperty() # contains user key_names
down_votes = db.StringListProperty() # contains user key_names
def update_score(self):
"""Adapted from reddit's algorithm
http://code.reddit.com/browser/r2/r2/lib/db/sorts.py?rev=4778b17e939e119417cc5ec25b82c4e9a65621b2
"""
@csytan
csytan / blobstore_tornado.py
Created November 12, 2010 02:42
blobstore tornado uploadhandler config
### app.yaml ###
- url: /upload
script: main.py
login: admin
### views.py ###
class BlobstoreUpload(BaseHandler):
def post(self):
key = self.get_argument('key')