Skip to content

Instantly share code, notes, and snippets.

@boundsj
boundsj / node-on-ec2-port-80.txt
Created October 26, 2011 05:06 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80
THE PROBLEM:
Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)
THE TEMPTINGLY EASY BUT TOTALLY WRONG SOLUTION:
Alter the port the script talks to from 8000 to 80:
}).listen(80);
@boundsj
boundsj / .profile
Created March 13, 2012 04:28
My .profile
################################################################
# jesse's .profile
################################################################
# set path so that the bin folder that brew uses comes before
# the /usr/bin
PATH=/usr/local/bin:$PATH
@boundsj
boundsj / create_template_postgis.sh
Created March 13, 2012 14:24
Create the postgis template on a mac that had postgis installed from brew
# path taken from brew install notes
POSTGIS_SQL_PATH=/usr/local/share/postgis
# Creating the template spatial database.
createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
# Allows non-superusers the ability to create from this template
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
@boundsj
boundsj / findnear.py
Created April 30, 2012 22:48
Find and count all the things nearby a place
import math
import pymongo
from pymongo import Connection
earth_radius_in_miles = 3959.0
radians_to_degrees = 180.0 / math.pi
radius = (0.0189393939 / earth_radius_in_miles) * radians_to_degrees # 100 foot radius
bbox_earth_radius = 3959.0 # miles
bbox_dist_from_center = 0.1 # miles
@boundsj
boundsj / cosine_sim_examples.py
Created June 24, 2012 20:27
Cosine Similarity Examples
# -*- coding: utf-8 -*-
from math import sqrt
def vector_length(vector):
"""
Compute length (aka magnitude, Euclidiean norm) of vector.
This gives the ordinary distance from the origin to the point x,
a consequence of the Pythagorean theorem.
@boundsj
boundsj / test.js
Created July 20, 2012 19:31
Node global, module, export exercise
var user1 = require('./user.js'),
user2 = require('./user.js'),
assert = require('assert');
// initialize the value in user1
user1.name("test");
// set it to another value in user2
user2.name("ohai");
// user1's value has been changed
assert.equal(user1.name(), "ohai", "oops");
@boundsj
boundsj / findnear.py
Created July 26, 2012 00:54
Find all the things with a bounding box and no mongo geo.
import math
import pymongo
from pymongo import Connection
# constants to
bbox_earth_radius = 3959.0 # miles
bbox_dist_from_center = 0.1 # miles
def sum_by_distinct_type(dist_type, distinct_key, args):
nearby_requests = db.windygrid.find({"$and": [{"where.latitude": {"$gte": args["ll_y"]}}, \
@boundsj
boundsj / test.js
Created July 26, 2012 18:58
How to run a jasmine test in a backbone boilerplate app
define([
// Application.
"app",
// Modules
"app/modules/todo"
],
function(app, Todo) {
console.log("test ran");
@boundsj
boundsj / counting.py
Created July 31, 2012 20:08
Python 102
###
# how many times have you done something like this?
###
# check if dict has key
# if so then increment value
# if not then add key and init value to 1
def increment(d, v):
if v in d:
@boundsj
boundsj / gist:6168910
Created August 6, 2013 21:34
center div
.container {
position: relative;
}
.centered {
position: absolute;
height: 10px;
width: 10px;
top: 50%;