Skip to content

Instantly share code, notes, and snippets.

@gotomypc
gotomypc / index.coffee
Created October 28, 2012 15:58 — forked from lancejpollard/index.coffee
Scrape Periodic Table of Elements from Wikipedia in Node.js
# http://www.webelements.com/aluminium/
# http://environmentalchemistry.com/yogi/periodic/Al.html
# http://www.chemicool.com/elements/aluminum.html
parseWikipediaTableOfElements = ->
urls = []
$("#mw-content-text table tr td[title] a").each ->
urls.push($(this).attr('href'))
urls
@gotomypc
gotomypc / image2base64.js
Created October 31, 2012 00:21 — forked from jfsiii/image2base64.js
Convert a remote image to Base64-encoded string
// Uses [request](https://github.com/mikeal/request)
// /?url=http://nodejs.org/logo.png
// /?uri=http://nodejs.org/logo.png
// /?url=http://nodejs.org/logo.png&cb=cbName
// /?url=http://nodejs.org/logo.png&callback=cbName
var fs = require('fs');
var url = require('url');
var http = require('http');
var request = require('request');
@gotomypc
gotomypc / http-agent.js
Created November 3, 2012 15:01 — forked from indexzero/http-agent.js
Code samples from the "jsdom and jquery" article on the Nodejitsu blog
var httpAgent = require('http-agent'),
util = require('util');
var agent = httpAgent.create('www.google.com', ['finance', 'news', 'images']);
agent.addListener('next', function (err, agent) {
console.log('Body of the current page: ' + agent.body);
console.log('Response we saw for this page: ' + util.inspect(agent.response));
// Go to the next page in the sequence
@gotomypc
gotomypc / load-generator.js
Created November 4, 2012 14:14 — forked from tkrueger/load-generator.js
generate and measure CPU load with node.js
#!/usr/bin/env node
require(__dirname+"/processor-usage.js").startWatching();
var shouldRun = true;
var desiredLoadFactor = .5;
function blockCpuFor(ms) {
var now = new Date().getTime();
var result = 0
@gotomypc
gotomypc / curl.sh
Created November 4, 2012 14:20 — forked from pyykkis/curl.sh
Node.js httpServer middleware as it should be
curl localhost:3000
@gotomypc
gotomypc / example.js
Created November 4, 2012 14:20 — forked from ggreer/example.js
Node.js weirdness with child processes and signals
var blah = setTimeout(function () {
console.log('example dying');
}, 30000);
var blah2 = setTimeout(function () {
console.log('example debugging');
process.stdout.write('example debugging');
// debugger;
}, 5000);
@gotomypc
gotomypc / Websocket-speed-test.js
Created November 4, 2012 14:20 — forked from NHQ/Websocket-speed-test.js
Test how fast your browser handles websockets with Node.js.
var server = require( 'http' ).createServer();
// our html template
var script = function( f ) {
// get just the content of this script
var s = /^[^\{]+\{\n?([\s\S]+)\}/.exec( f )[1];
return [
'<!DOCTYPE html><html>',
'<head>',
'<script type="text/javascript">',s,'</script>',
@gotomypc
gotomypc / tail_recursed_loop.js
Created November 4, 2012 14:21
Tail Recursion in Node.js
start_date = Date.now()
old_date = start_date
seconds_running = 120
console.log('Starting Program at: ' + Date())
loop_flag = true
loop()
function loop() {
@gotomypc
gotomypc / __request
Created November 5, 2012 09:39 — forked from natos/__request
Multiple Requests with Request (Node.js)
var request = require('request')
/**
* Handle multiple requests at once
* @param urls [array]
* @param callback [function]
* @requires request module for node ( https://github.com/mikeal/request )
*/
var __request = function (urls, callback) {
@gotomypc
gotomypc / gist:4016809
Created November 5, 2012 11:37
enumerate property in Object&Class from JavaScript
function TestProp () {
var p1 = 'abc';
var priFunc = function() {
console.log('Im private function');
}
this.privilegeFunc = function () {
console.log('Im priviledge function');
}
this.pubProp = "Public property";
}