Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
grantmichaels / node-elasticsearch-service
Created May 13, 2012 18:06 — forked from jaysoo/node-elasticsearch-service
elasticsearch service using node.js
var http = require('http'),
url = require('url'),
_ = require('underscore'),
elastical = require('elastical');
var client = new elastical.Client();
if (process.argv.length < 3) {
console.log('Port number is required');
return;
@grantmichaels
grantmichaels / app.js
Created May 13, 2012 18:05
NodeJS HTTP Chat Application
var express = require("express");
var sys = require("sys");
var io = require("socket.io");
var ChatServer = {};
ChatServer.members = {};
ChatServer.publish = function(client, data) {
if (client in ChatServer.members)
@grantmichaels
grantmichaels / install_node.sh
Created May 13, 2012 18:04 — forked from mashihua/install_node.sh
Install node.js on Ubuntu
#!/bin/bash
NODE_VERSION=0.4.12
NODE_FILE=node-v$NODE_VERSION
MY_USER=mashihua
REDIS_VERSION=2.0.3
apt-get update
apt-get install -y build-essential git-core nginx libssl-dev pkg-config
wget http://nodejs.org/dist/$NODE_FILE.tar.gz
@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 / install_node.sh
Created May 13, 2012 18:03 — forked from carlosvillu/install_node.sh
Configure NodeJs + NPM + NGINX
#!/bin/bash
NODE_VERSION=0.4.10
NPM_VERSION=1.0.22
sudo apt-get update
sudo apt-get install -y build-essential git-core nginx libssl-dev pkg-config curl
# Install node
mkdir -p $HOME/local/node
git clone git://github.com/joyent/node.git
@grantmichaels
grantmichaels / gist:2689528
Created May 13, 2012 18:03 — forked from diegodfsd/gist:1098712
NodeJs consumindo Twitter API
var http = require('http');
var host = "search.twitter.com",
requestUrl = '/search.json?q=nodejs',
twitter = http.createClient(80, host),
request = twitter.request('GET', requestUrl,
{ "host" : host, "User-Agent" : "Nodejs HTTP Client" });
request.on('response', function(response){
var body = '';
response.setEncoding("utf8");
@grantmichaels
grantmichaels / makro_scraper.js
Created May 13, 2012 18:01 — forked from pierot/makro_scraper.js
Makro NodeJS scraping
var request = require('request'), http = require('http'), $ = require('jquery'), querystring = require('querystring');
http.createServer(function (req, res) {
var q = querystring.parse(req.url);
var locations = {'deurne': 0, 'machelen': 1, 'alleur': 2, 'eke': 3, 'sint-pieters-leeuw': 4};
request({uri: 'http://www.makro.be/Content/assortiment/benzinestation/benzineprijzen/1/index.jsp?stat=' + locations[q.l]}, function (error, response, body) {
res.writeHead(200, {'Content-Type': 'text/xml'});
var fuel_types = ['diesel', 'eurosuper', 'superplus'];
@grantmichaels
grantmichaels / webserver.js
Created May 13, 2012 18:00 — forked from hectorcorrea/webserver.js
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");
@grantmichaels
grantmichaels / gist:2689519
Created May 13, 2012 18:00 — forked from nilcolor/gist:812487
Node.js pristine server template
var http = require('http'),
url = require('url'),
qs = require('querystring');
var paths = {
'__default__': function (req, res) {
console.log('noop');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
},
@grantmichaels
grantmichaels / app.js
Created May 13, 2012 17:58 — forked from betobaz/app.js
node.js Upload file formidable
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, stylus = require('stylus')
, util = require('util')
//, form = require('connect-form')