Skip to content

Instantly share code, notes, and snippets.

@jfrazee
jfrazee / twitter_filter.js
Created January 10, 2012 23:22
Twitter Streaming API with Node.js Request module
var request = require('request');
function filter(options, callback){
var params = {
uri: "https://stream.twitter.com/1/statuses/filter.json",
}
if (typeof options['oauth'] !== 'undefined'){
params.oauth = options.oauth;
delete options.oauth;
}
@andreif
andreif / chat.rb
Created December 30, 2011 18:00 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@mislav
mislav / stupid-json.rb
Created December 21, 2011 12:31
Stupid simple JSON parser & generator
# encoding: utf-8
#
## Stupid small pure Ruby JSON parser & generator.
#
# Copyright © 2013 Mislav Marohnić
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the “Software”), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
@alejandro
alejandro / app.js
Created December 16, 2011 23: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')
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@Geraint
Geraint / client.html
Created December 6, 2011 15:12
Responsive Images with node.js
<!doctype html>
<html>
<head>
<script>
var uri = 'http://localhost:1337/?width=' + window.innerWidth;
document.write('<script src="' + uri + '"><\/script>');
</script>
@joseprando
joseprando / httpsocketio.js
Created December 5, 2011 12:53
NodeJS HttpServer com Socket.io
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
app.listen(8000);
function handler (req, res) {
req.setEncoding('utf-8');
fs.readFile(__dirname + '/index.html', 'utf8',
function (err, data) {
@peterc
peterc / dnsd.rb
Created December 2, 2011 23:47
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@cpatni
cpatni / app.rb
Created November 21, 2011 22:39
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@blake8086
blake8086 / twitter.js
Created November 17, 2011 23:13
Simple node.js server to stream Twitter 'Spritzer' level stream to client browser
global.server = require('http').createServer(function(request, response) {
global.twitterFeed = require('https').get({
auth: 'username:password',
host: 'stream.twitter.com',
path: '/1/statuses/sample.json',
}, function(res) {
res.setEncoding('utf8');
response.writeHead(200, 'text/plain');
res.on('data', function(chunk) {
response.write(chunk);