Skip to content

Instantly share code, notes, and snippets.

View DTrejo's full-sized avatar

David Trejo DTrejo

View GitHub Profile
@DTrejo
DTrejo / proxytoflickr.js
Created April 10, 2011 00:26
has a problem
var http = require('http')
, httpProxy = require('http-proxy')
, ns = require('node-static')
, file = new(ns.Server)('./public')
, url = require('url')
, querystring = require('querystring')
;
//
// Create a proxy server with custom application logic
@DTrejo
DTrejo / parse-after-streamify.js
Created April 4, 2011 22:09
seems not to work... Why?
var obj = { "tricky": 'these "tick∫."' };
var str = '';
//
// npm install json-streamify
//
require('json-streamify').streamify(obj, function(data) { str += data; });
console.log('%s', str);
console.log('%s', JSON.stringify(obj));
@DTrejo
DTrejo / .gitignore
Created April 4, 2011 03:32
How to Readline - an example and the beginnings of the docs
node_modules/
@DTrejo
DTrejo / iftag.php
Created March 31, 2011 20:19
show post if tag
<!-- start auto-generated posts -->
<?php while (have_posts()) : if (has_tag('featured')) { the_post(); } ?> <!-- <== BROKEN HERE -->
<div class="content" style="background: url(<?php bloginfo('template_url'); ?>/images/dummy-images/coffee.jpg);">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
<!-- end auto-generated posts -->
@DTrejo
DTrejo / parsing ints
Created March 31, 2011 04:18
that are in base 16
var str = '63737472696b65';
var num16 = parseInt(str, 16);
var str2 = 'f';
console.log(parseInt(str2, 16));
// Routes
app.get('/', userIsAuthenticated, function(req, res){
Doc.find( { loc : { $near : [50.62, -20.32], $maxDistance : 50 } } , function (err, docs) {
res.render('index_authenticated.jade', {
locals: {
title: 'Welcome back to Gociety',
status: 'logged in',
currentUser: req.currentUser,
user: req.currentUser,
@DTrejo
DTrejo / crazyiness.js
Created March 21, 2011 01:40
underscore: keys, values, zip, max => undefined
var _ = require('underscore')._;
var data = {"1":0.000007223714765952328,"2":0.0000039749105916010536,"3":0.0000032965765671970454,"7":0.0000020878318258914622,"8":0.000002736989620496371,"9":0.000003076694134649906,"10":0.0000013715180458375907,"12":0.000001159906569939701,"15":6.457211832654003e-7,"18":6.457211832654003e-7,"19":0.0000026097897823643283,"20":0.0000026097897823643266,"21":9.490144663143008e-7,"23":3.4414810316892216e-7,"24":8.821824616442793e-7,"26":0.0000024947065913923583,"38":0.000004404915773841593,"40":0.0000023785425864586267,"41":0.0000018918312871343038,"42":0.0000014913084470653296,"44":0.0000023665042941778225,"51":9.942056313768864e-7,"57":0.0000010616094029956584,"58":0.0000024056413215874137,"100":4.971028156884432e-7,"230":0.0000015658738694185964,"1998":0.000026218026718821232,"the":0.0007400023061007896,"Honourable":0.00022929140436720472,"Gildas":0.00001957342336773246,"L":0.00001957342336773246,".":0.0006657129490331946,"Molgat":0.00001957342336773246,",":0.0003656978308864
@DTrejo
DTrejo / ws
Created March 20, 2011 17:59
ws test
var fs = require('fs')
, path = './DELETEME.txt'
, stream = fs.createWriteStream(path, { flags: 'w+', encoding: 'utf8' })
, data = { "I":0.18181818181818182,"bought":0.18181818181818182 }
;
function cb(err) {
if (err) console.log(err);
console.log('cool, all done.');
}
function findBeer(words) {
//...code...
getResults(word, function(err, result){
// now you can access things!
console.log(err, result);
});
}
function getResults(word, callback) {
@DTrejo
DTrejo / top3stories.js
Created January 21, 2011 22:41
Gets top three articles from frontpage and newpage of Hacker News. Blog post on scraping: http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga
// Scraping Made Easy with jQuery and SelectorGadget
// (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//