Skip to content

Instantly share code, notes, and snippets.

View grantmichaels's full-sized avatar

grantmichaels grantmichaels

View GitHub Profile
@grantmichaels
grantmichaels / Reduce, Kaffeine, NodeJS and Redis
Created May 13, 2012 20:53 — forked from jedisct1/Reduce, Kaffeine, NodeJS and Redis
Tiny recommendation engine using Map/Reduce, Kaffeine, NodeJS and Redis
sys = require "sys";
http = require "http";
url = require "url";
connect = require "connect";
redis = require "redis";
hashRing = require "hash_ring";
Sharding = {
servers = { "127.0.0.1 10000 6378": 1 };
ring = new hashRing.HashRing servers;
require 'rubygems'
require 'sinatra'
get '/' do
"hello world"
end
@grantmichaels
grantmichaels / app.js
Created May 13, 2012 20:50 — forked from ag4ve/app.js
Simple blog with node.js, express and mongodb
var express = require('express'),
app = express.createServer(),
Post = require('./models/post');
app.configure(function () {
app.use(express.methodOverride());
app.use(express.bodyDecoder());
app.use(express.staticProvider(__dirname + '/public'));
app.use(express.compiler({src: __dirname + '/public', enable: ['sass']}));
app.use(express.logger());
@grantmichaels
grantmichaels / twitter_streaming.js
Created May 13, 2012 19:01 — forked from ryanmcgrath/twitter_streaming.js
Access the Twitter Streaming API with ease (Node.js).
var util = require('util'),
http = require('http'),
events = require('events');
var Twitter = function(opts) {
this.username = opts.username;
this.password = opts.password;
this.track = opts.track;
this.data = '';
};
@grantmichaels
grantmichaels / pdf2png.js
Created May 13, 2012 19:03
PDF to PNG with Node.js and GhostScript
var exec = require('child_process').exec;
var fs = require('fs');
var util = require('util');
var http = require('http');
var url = require('url');
var PDFDocument = require('pdfkit'); // http://pdfkit.org/
http.createServer(function (req, res) {
@grantmichaels
grantmichaels / NodeSqlite.js
Created May 13, 2012 18:03 — forked from TravelingTechGuy/NodeSqlite.js
Using SQLite from Node.js
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('guy.sqlite'); //':memory:'
db.serialize(function() {
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='lorem'", function(error, row) {
if (row !== undefined) {
console.log("table exists. cleaning existing records");
db.run("DELETE FROM lorem", function(error) {
if (error)
console.log(error);
@grantmichaels
grantmichaels / Publish a message
Created May 13, 2012 19:07 — forked from nivertech/Publish a message
Server-side Events with Node.js and Redis
linus@Newton:~$ redis-cli
redis 127.0.0.1:6379> publish /updates.foo "hello there!"
(integer) 1
redis 127.0.0.1:6379>
@grantmichaels
grantmichaels / beacon.js
Created May 13, 2012 18:54 — forked from ruturajv/beacon.js
node.js web beacon (web bug) serving
http = require('http');
url = require('url');
http.createServer(function(req, res){
var requestURL = url.parse(req.url, true)['pathname'];
if (requestURL == '/log.gif') {
var imgHex = '47494638396101000100800000dbdfef00000021f90401000000002c00000000010001000002024401003b';
var imgBinary = new Buffer(imgHex, 'hex');
res.writeHead(200, {'Content-Type': 'image/gif' });
twitter.json
@grantmichaels
grantmichaels / app.js
Created May 13, 2012 20:49 — forked from nulltask/app.js
Node.js network balanced cluster with Socket.IO
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, cluster = require('cluster');
var app = module.exports = express.createServer()
, io = require('./socket')(app);