Skip to content

Instantly share code, notes, and snippets.

@joshsmith
joshsmith / simplegeo_zips.py
Created November 15, 2011 01:30
Finding zip codes within the radius of a given address using SimpleGeo
from math import pi,sqrt,sin,cos,asin,atan2
from simplegeo import Client
import json
def get_nearby_zips(address, radius, client):
'''
Given an address and radius (and the SimpleGeo client), returns
a comma-separated list of zip codes within that radius.
'''
context = client.context.get_context_by_address(address)
@joshsmith
joshsmith / email.js
Created November 16, 2011 19:32
jQuery email validation and Kissmetrics
function isEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
$("#validate-form").submit(function (event, dontCheck) {
$email = $('#email');
$form = $('#validate-form');
var email = $email.val();
@joshsmith
joshsmith / simplegeo_zips.js
Created November 18, 2011 22:45
Finding zip codes within the radius of a given address using SimpleGeo (with JS!)
$(document).ready(function() {
simplegeo_key = 'TOKEN';
var places_client = new simplegeo.Places12Client(simplegeo_key);
var context_client = new simplegeo.ContextClient(simplegeo_key);
var zips = {
zips: ''
};
@joshsmith
joshsmith / eventemitter.js
Created November 21, 2011 20:30
Hands-On Node Event Emitter Exercise 1
var EventEmitter = require('events').EventEmitter;
var util = require('util');
// Here is the Ticker constructor
var Ticker = function() { // This is a pseudo-class }
util.inherits(Ticker, EventEmitter);
// Emit tick on the tick event
Ticker.prototype.tick = function() {
@joshsmith
joshsmith / facebook-client.jst
Created November 30, 2011 01:53
Facebook Client for Node.js
/**
* Facebook Client for Node.js
* @author Josh Smith
*/
var qs = require('querystring'),
request = require('request'),
conf = require('../config/conf');
var Facebook = exports.Facebook = function(userId, accessToken) {
everyauth.facebook
.entryPath('/auth/facebook')
.scope('email, user_likes, user_location, offline_access, publish_stream, publish_checkins, publish_actions')
.appId(app.settings.fbAppId)
.appSecret(app.settings.fbAppSecret)
.findOrCreateUser(function(session, accessToken, accessTokExtra, fbUserMetadata) {
User.findOne().where('facebook.id', fbUserMetadata.id).run(function(err, user) {
console.log(user);
if(user) {
// Update
@joshsmith
joshsmith / gist:1420915
Created December 2, 2011 00:17
jitsu error logs
data: 2011-12-02T00:15:12.772Z: throw e; // process.nextTick error, or 'error' event on first tick
data: 2011-12-02T00:15:12.772Z: ^
data: 2011-12-02T00:15:12.772Z: Error: ECONNREFUSED, Connection refused
data: 2011-12-02T00:15:12.772Z: at Socket._onConnect (net.js:601:18)
data: 2011-12-02T00:15:12.772Z: at IOWatcher.onWritable [as callback] (net.js:186:12)
data: 2011-12-02T00:15:12.765Z: Warning: connection.session() MemoryStore is not
data: 2011-12-02T00:15:12.765Z: designed for a production environment, as it will leak
data: 2011-12-02T00:15:12.765Z: memory, and obviously only work within a single process.
data: 2011-12-02T00:15:12.392Z: carapace has wrapped: /usr/local/src/joshsmith/wadsup/wadsup/app.js
data: 2011-12-02T02:09:16.333Z: events.js:47
data: 2011-12-02T02:09:16.333Z: throw new Error("Uncaught, unspecified 'error' event.");
data: 2011-12-02T02:09:16.333Z: ^
data: 2011-12-02T02:09:16.333Z: Error: Uncaught, unspecified 'error' event.
data: 2011-12-02T02:09:16.333Z: at [object Object].emit (events.js:47:15)
data: 2011-12-02T02:09:16.333Z: at [object Object].<anonymous> (/usr/local/src/joshsmith/wadsup/wadsup/node_modules/pg/lib/client.js:10...
data: 2011-12-02T02:09:16.333Z: at [object Object].emit (events.js:64:17)
data: 2011-12-02T02:09:16.333Z: at Socket.<anonymous> (/usr/local/src/joshsmith/wadsup/wadsup/node_modules/pg/lib/connection.js:47:12)
data: 2011-12-02T02:09:16.333Z: at Socket.emit (events.js:64:17)
data: 2011-12-02T02:09:16.333Z: at Socket._onReadable (net.js:678:14)
/**
* Module dependencies.
*/
var express = require('express');
// Create the server
app = express.createServer();
var pg = require('pg');
client = new pg.Client(app.settings.db);
client.on('error', function(error) {
console.log(error);
});