Skip to content

Instantly share code, notes, and snippets.

@gotomypc
gotomypc / server.js
Created October 28, 2012 04:05 — forked from daithiw44/server.js
Twitter GET users/profile_image/:screen_name, Nodejs get latest user profile_image output as a base64 encoded data URI, avoid the 302 redirect of the call with request module.
/*
* Access the profile image (Twitter GET users/profile_image/:screen_name) for a user with the indicated screen_name.
* Currently this resource does not return JSON (or XML), but instead returns a 302 redirect to the actual image resource.
* Use requests request.head with option followRedirect set to false to get the image file name from the json in the header response.
* Using the image file URL get the profile image and convert to base64 encoding to use as in this example as data URI (which could be saved to a DB/storage etc for later use etc).
* example call : http://127.0.0.1:4444/?screen_name=daithi44
*/
var http = require('http'),
request = require('request'),
@gotomypc
gotomypc / server.js
Created October 28, 2012 04:08 — forked from daithiw44/server.js
GET users/profile_image/:screen_name, Nodejs get latest user profile_image and avoid the 302 redirect with request.
/*
* Access the profile image in various sizes for the user with the indicated screen_name.
* Currently this resource does not return JSON (or XML), but instead returns a 302 redirect to the actual image resource.
* Use requests request.head with option followRedirect set to false to get the image file name from the json in the header response.
* example : http://127.0.0.1:4400/?screen_name=daithi44
*/
var http = require('http')
, request = require('request')
, url = require('url');
@gotomypc
gotomypc / gist:3967472
Created October 28, 2012 04:12 — forked from daithiw44/gist:3032376
Nodejs Anagram Website Scraper with express and Domains, update to previous example gist: 1335009
// Updated example to utilize 'basic' Domains with express.
// Website Scraper that scrapes off a site (without permission I may add)
// had seen some screen scraping examples using jQuery this example is jQuery-less.
var express = require('express'),
request = require('request'),
jsdom = require('jsdom'),
builder = require('xmlbuilder').create(),
sys = require('util'),
createDomain = require('domain').create,
app = express.createServer();
@gotomypc
gotomypc / gist:3967534
Created October 28, 2012 04:37 — forked from yuanchuan/gist:3232510
download pages with nodejs
var fs = require('fs')
, http = require('http')
, path = require('path')
, cheerio = require('cheerio');
var archive = 'http://apod.nasa.gov/apod/archivepix.html'
, base = path.dirname(archive) + '/'
, target = 'archive/english/';
@gotomypc
gotomypc / testPaginegialleCinema.js
Created October 28, 2012 04:53 — forked from ideiudicibus/testPaginegialleCinema.js
paginegialle.it cinema web scraping
var request = require('request'),
cheerio = require('cheerio'),
url= 'http://www.paginegialle.it/cinema-programmazione/Roma%20(RM)',
ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2';
var parsePage = function(error, response, body) {
if (error || response.statusCode != 200) {
console.log(error);
}
@gotomypc
gotomypc / Beanutils.java
Created October 28, 2012 05:05 — forked from ideiudicibus/Beanutils.java
Merge two java beans useful when discovering differences
class Beanutils{
//merge two bean by discovering differences
private <M> void merge(M target, M destination) throws Exception {
BeanInfo beanInfo = Introspector.getBeanInfo(target.getClass());
// Iterate over all the attributes
for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
// Only copy writable attributes
if (descriptor.getWriteMethod() != null) {
@gotomypc
gotomypc / gist:3967732
Created October 28, 2012 05:30 — 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 / expose_secure_db.coffee
Created October 28, 2012 08:06 — forked from mrjjwright/expose_secure_db.coffee
Expose Secure DB over node
# Start up the http server
console.log("Starting on port #{options.port}")
server.listen(options.port)
# Start up dnode and expose our remote secure API to the user. This API has built-in token based security so we will be ok if the
# web-socket is over https
remote =
db: dbSecure
dnode(remote).listen(server)
@gotomypc
gotomypc / secure_db.coffee
Created October 28, 2012 08:07 — forked from mrjjwright/secure_db.coffee
A Secure MongoDB like API
# Now create a secure API to this
# library that requires authentication
# Users can only access these collections
collectionWhiteList = ["records", "sources", "searchers"]
# These collections don't need any authentication at all for
findWithNoAuthentication = ["sources"]
secureTemplate = (user, collectionName, cb, doneCB) ->
if not user? or not user.accessToken?
@gotomypc
gotomypc / backbone_http_mapping.js
Created October 28, 2012 08:07 — forked from mrjjwright/backbone_http_mapping.js
Default Backbone HTTP Verb Mapping
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};