Skip to content

Instantly share code, notes, and snippets.

View flengyel's full-sized avatar
🎯
Focusing

F Lengyel flengyel

🎯
Focusing
  • The City University of New York
  • New York
  • 14:26 (UTC -04:00)
View GitHub Profile
var BuildTemplate = ' \
<h2 class="small-caps">build</h2> \
';
var BuildV = BaseV.extend({
className: 'btn-group-vertical',
initialize: function(o){
this.__player = o.player;
@flengyel
flengyel / approximatenormal.js
Created December 4, 2013 01:43
Approximation to normal distribution by summing three uniformly distributed random numbers, normalized to [-1,1].
function rnd_snd() {
return (Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1);
}
function rnd(mean, stdev) {
return Math.round(rnd_snd()*stdev+mean);
}
@flengyel
flengyel / hngen.py
Created November 29, 2013 04:01 — forked from grantslatton/hngen.py
import urllib2
import re
import sys
from collections import defaultdict
from random import random
"""
PLEASE DO NOT RUN THIS QUOTED CODE FOR THE SAKE OF daemonology's SERVER, IT IS
NOT MY SERVER AND I FEEL BAD FOR ABUSING IT. JUST GET THE RESULTS OF THE
CRAWL HERE: http://pastebin.com/raw.php?i=nqpsnTtW AND SAVE THEM TO "archive.txt"
@flengyel
flengyel / new_gist_file.py
Created November 22, 2013 17:03
Sum of 10 natural numbers is 2011, sum of their reciprocals is one. Uses fractions module for exact rational arithmetic, and map-reduce.
#!/usr/bin/env python
from fractions import Fraction
def verify(a):
return sum(a)== 2011 and sum(map ((lambda n: Fraction(1,n)), a)) == Fraction(1,1)
if __name__=='__main__':
x = [ [704, 4, 4, 4, 8, 704, 352, 176, 44, 11], [864, 3, 6, 8, 8, 8, 16, 18, 864, 216],
[912, 3, 4, 4, 19, 24, 912, 57, 38, 38], [920, 10, 5, 10, 23, 23, 920, 92, 4, 4],
[1080, 4, 4, 6, 9, 12, 12, 20, 432, 432], [1188, 3, 4, 6, 9, 9, 297, 297, 99, 99],
@flengyel
flengyel / merge.py
Created November 14, 2013 03:15
Merge sort in python
def __merge(a, lo, hi):
"""__merge(a,lo,hi) merge sorts array a from
index lo to index hi, where 0<=lo <= hi < len(a)."""
if lo < hi:
m = (lo+hi)/2
__merge(a,lo,m)
__merge(a,m+1,hi)
b = a[lo:m+1]
c = a[m+1:hi+1]
i = j = 0;
@flengyel
flengyel / heapsort.py
Created November 14, 2013 03:14
Heap sort, lifted from Active State
def HeapSort(A):
def heapify(A):
start = (len(A) - 2) / 2
while start >= 0:
siftDown(A, start, len(A) - 1)
start -= 1
def siftDown(A, start, end):
root = start
while root * 2 + 1 <= end:
@flengyel
flengyel / python_resources.md
Created November 14, 2013 03:11 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@flengyel
flengyel / crash.css
Created August 26, 2013 17:22
Basic about page technique for cartographic sites using backbone and Mustache, lifted and abstracted from nyc.crashmapper.com.
body {
margin: 0px;
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-weight: 200;
}
a {
text-decoration: none;
color: blue;
}
@flengyel
flengyel / rgis.conf
Created August 26, 2013 16:25
Ubuntu upstart script for Africa Rapid Indicator Mapping System backend
# rgis.py job file
# install to /etc/init/rgis.conf
description "Backend service for A-RIMS"
author "Florian Lengyel <florian.lengyel@gmail.com>"
env WORKDIR=/Users/ecr/florian/Dropbox/Programming/REST
start on (filesystem and started autofs and started apache2)
stop on runlevel [016]
@flengyel
flengyel / onrender.html
Created August 7, 2013 16:16
Worked examples derived from Chapter 2 of Building Backbone Plugins.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta lang="en">
<title>Backbone BaseView with corrections</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="backbone.js"></script>
</HEAD>
<BODY>