Skip to content

Instantly share code, notes, and snippets.

View DTrejo's full-sized avatar

David Trejo DTrejo

View GitHub Profile
// 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 / 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));
@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 / .gitignore
Created April 4, 2011 03:32
How to Readline - an example and the beginnings of the docs
node_modules/
@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 / 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 / npm_install_arbitrary_node_location.sh
Created April 24, 2011 06:44
npm_install_arbitrary_node_location.sh
# install npm on machines with node at arbitrary spot
# node is installed at some arbitrary path
echo '# npm paths' >> ~/.bashrc
echo 'export PATH=~/bin:~/local/share/man:$PATH' >> ~/.bashrc
echo 'export MANPATH=$MANPATH:~/local/share/man' # I think this may not work
. ~/.bashrc
cat <<NPMRC >>$HOME/.npmrc
root = ~/.node_libraries
manroot = ~/local/share/man
binroot = ~/bin
@DTrejo
DTrejo / js2xml.js
Created April 30, 2011 03:09
start of bidi conversion between js<-->xml
var util = require('util')
, fs = require('fs')
, xml2js = require('xml2js-expat')
, querystring = require('querystring')
, _ = require('underscore');
// this is provided by xml2js
function parse(xmlString, cb) {
var parser = new xml2js.Parser();
parser.on('end', function(result) {
@DTrejo
DTrejo / expire.js
Created May 2, 2011 06:08
expiring map, different style
// opts = { timeout: 60 }
function ExpiringMap(opts) {
var self = {}
, map = {}
, activeKeys = {
// key: clearTimeout
}
, noop = function() {};
;
@DTrejo
DTrejo / readline-docs.patch
Created May 19, 2011 02:08
readline-docs.patch
From 932e9ced7dff802bb48843f531259fc2eda5a72d Mon Sep 17 00:00:00 2001
From: David Trejo <[email protected]>
Date: Wed, 18 May 2011 18:39:06 -0700
Subject: [PATCH] readline docs
---
doc/api/readline.md | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 133 insertions(+), 0 deletions(-)
create mode 100644 doc/api/readline.md