Skip to content

Instantly share code, notes, and snippets.

@gotomypc
gotomypc / Bus.coffee
Created October 28, 2012 08:08 — forked from mrjjwright/Bus.coffee
Bus.js
# Bus 0.1(alpha)
# (c) 2010 John Wright, QuickLeft Inc.
# Bus may be freely distributed under the MIT license.
# For all details and documentation:
# http://github.com/mrjjwright/Bus
#
#
#
# Bus would not be possible without Jeremy Ashkenas who wrote CoffeeScript, the language
@gotomypc
gotomypc / BackboneSyncJSON.js
Created October 28, 2012 08:09 — forked from mrjjwright/BackboneSyncJSON.js
plugin for Backbone that send the models as application/json encoded bodies
methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read': 'GET'
};
getUrl = function(object) {
if (!(object && object.url)) {
throw new Error("A 'url' property or function must be specified");
} else {
@gotomypc
gotomypc / remove_null_guids.coffee
Created October 28, 2012 08:09 — forked from mrjjwright/remove_null_guids.coffee
An example of a data migration in NoSQLite
require "nosqlite"
require "Math.uuid"
convert_callback: (row) ->
if not row.guid?
row.guid: Math.uuidFast();
return row;
db_file: "my_db.sqlite"
@gotomypc
gotomypc / restler_javascript.js
Created October 28, 2012 08:10 — forked from mrjjwright/restler_javascript.js
Coffeescript Node.js example
require.paths.unshift("/Users/johnw/js/node_modules")
require("./underscore")
sys: require("sys")
rest: require("restler")
rest.get('http://github.com/api/v2/json/repos/show/mrjjwright').addListener('complete',
((data) ->
repositories: JSON.parse(data).repositories
for repository in repositories
@gotomypc
gotomypc / gist:3968033
Created October 28, 2012 08:11 — forked from mrjjwright/gist:3240020
Extract largest image thumbnail from url using node and cheerio
cheerio = require('cheerio')
Shred = require('shred')
shred = new Shred()
http = require('http')
URL = require('url')
server = http.createServer (request, response) ->
url = URL.parse(request.url, true)
urlToDiscover = url.query['url']
startDiscovery urlToDiscover, (theImageURL) ->
@gotomypc
gotomypc / parser_bench.js
Created October 28, 2012 08:11 — forked from tagomoris/parser_bench.js
node.js html parser (jquery style) benchmark
var fs = require('fs'),
async = require('async');
var try_series = function(func_name, func, data, times, cb){
var start = new Date();
var tries = new Array(times);
for(var i = 0 ; i < times ; i++) {
tries[i] = function(callback){func(data, callback);};
}
async.series(tries, function(err,result){
@gotomypc
gotomypc / README.md
Created October 28, 2012 08:12 — forked from Filirom1/README.md
Scrapping Wikipedia example

An example of fast scrapper

A scrapper based on nodejs, written in coffeescript and using cheerio and request packages

This is an equivalent of the pjscrape exemple but really faster:

@gotomypc
gotomypc / index.js
Created October 28, 2012 08:12 — forked from max-mapper/index.js
display all pngs from a url in a terminal
var cheerio = require('cheerio')
var request = require('request')
var pictureTube = require('picture-tube')
var url = require('url')
var async = require('async')
var site = process.argv[2]
console.log('fetching', site)
request(site, function(e,r,b) {
@gotomypc
gotomypc / api.js
Created October 28, 2012 08:53 — forked from ww24/api.js
HIT講義情報API
var http = require('http'),
https = require('https'),
Iconv = require('iconv').Iconv,
iconv = new Iconv('EUC-JP', 'UTF-8//TRANSLIT//IGNORE'),
cheerio = require('cheerio'),
request = require('request');
var site = 'http://www.hit.ac.jp/gakusei/chgschool/',
port = 8880;
@gotomypc
gotomypc / registrar.js
Created October 28, 2012 14:59 — forked from ideiudicibus/registrar.js
A simple SIP registrar that uses Node.js and Redis
var sip = require('sip');
var sys = require('sys');
var redis = require('redis');
//Trim leading and trailing whitespace from string values.
function trim(str) {
return str.replace(/^\s+|\s+$/g, '');
}
sip.start({},function(request) {