Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
grantmichaels / node-redis-data-pubsub.js
Created May 13, 2012 18:36 — forked from stash/node-redis-data-pubsub.js
Streaming data pubsub - node.js + redis
var redis = require('redis');
var pubcli = redis.createClient(6380, '127.0.0.1');
var subcli = redis.createClient(6380, '127.0.0.1');
var datacli = redis.createClient(6380, '127.0.0.1', {return_buffers:true});
var have = 0;
datacli.lrange('data.theresource', 0, -1, function(err,chunks) {
console.log("initial data!",chunks);
@grantmichaels
grantmichaels / node-jqtemplate-sample.js
Created May 13, 2012 18:35 — forked from hakobera/node-jqtemplate-sample.js
Using jQuery Template in node.js
var jsdom = require('jsdom');
jsdom.env({
html: "<html><body></body></html>",
scripts: [
'http://code.jquery.com/jquery-1.6.2.min.js',
'http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
@grantmichaels
grantmichaels / gist:2689641
Created May 13, 2012 18:31 — forked from chrismatthieu/gist:945280
Tropo Node.JS Transcription Example
/**
* Showing with the Express framwork http://expressjs.com/
* Express must be installed for this sample to work
*/
var tropoapi = require('tropo-webapi');
var express = require('express');
var app = express.createServer();
var sys = require('sys');
@grantmichaels
grantmichaels / top3stories.js
Created May 13, 2012 18:30 — forked from DTrejo/top3stories.js
Gets top three articles from frontpage and newpage of Hacker News. Blog post on scraping: http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga
// Scraping Made Easy with jQuery and SelectorGadget
// (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//
@grantmichaels
grantmichaels / server.coffee
Created May 13, 2012 18:28 — forked from patrickdanger/server.coffee
Basic FileServer in node.js
http = require 'http'
url = require 'url'
fs = require 'fs'
path = require 'path'
server = http.createServer (req, resp) ->
uri = url.parse req.url, yes
query = uri.queryString
filepath = path.normalize uri.pathname
@grantmichaels
grantmichaels / transparent-gif.js
Created May 13, 2012 18:28 — forked from sspencer/transparent-gif.js
Serve a transparent GIF from NodeJS
// Two ways to serve transparent GIF
var buf = new Buffer([
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
0x02, 0x44, 0x01, 0x00, 0x3b]);
res.send(buf, { 'Content-Type': 'image/gif' }, 200);
@grantmichaels
grantmichaels / app.js
Created May 13, 2012 18:15 — forked from ryanflorence/app.js
Node.JS + Socket.IO + 10 minutes = Chat
/**
* Module dependencies.
*/
var express = require('express')
, io = require('socket.io');
var app = module.exports = express.createServer();
// Configuration
@grantmichaels
grantmichaels / static_server.js
Created May 13, 2012 18:10 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
var Request = require("request");
// USER: API 用戶名稱
// PWD: API 密碼
// SIGNATURE: 簽名
/* METHOD: SetExpressCheckout
RETURNURL:當於PayPal 網站完成明細確認後,瀏覽器將帶顧客返回至此網址。
CANCELURL:當顧客選擇終止付款時,瀏覽器將帶顧客返回至此網址。
@grantmichaels
grantmichaels / deploy.sh
Created May 13, 2012 18:06 — forked from matthewhudson/deploy.sh
Deploy Node.js to Heroku
# Create the app on the Cedar stack:
heroku create --stack cedar
# Creating sharp-rain-871... done, stack is cedar
# http://sharp-rain-871.herokuapp.com/ | [email protected]:sharp-rain-871.git
# Git remote heroku added
# Rename the application.
heroku rename newname
git push heroku master