Skip to content

Instantly share code, notes, and snippets.

View cpsubrian's full-sized avatar

Brian Link cpsubrian

  • Dropbox
  • Fremont, CA
View GitHub Profile
@cpsubrian
cpsubrian / app-output.txt
Created November 22, 2011 23:38
nconf with multiple files
$ node app.js
My specific title
green
undefined
@cpsubrian
cpsubrian / Cakefile
Created December 1, 2011 06:56
Cakefile help. Need a better way than console.log.
{exec, spawn} = require 'child_process'
task 'test', 'Run Mocha tests', ->
proc = spawn 'mocha', ['-R', 'spec', '--colors']
proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
proc.stderr.on 'data', (buffer) -> console.error buffer.toString()
proc.on 'exit', (status) ->
process.exit(1) if status != 0
@cpsubrian
cpsubrian / example.html
Created December 13, 2011 18:08
Minimal overhead hover
<a href="javascript: void(0);" onmouseover="(function(elem) { someLibraryFunction(elem); })(this);">Fancy Text</a>
@cpsubrian
cpsubrian / download_image.php
Created February 17, 2012 02:13
Download and save an external image to a Drupal 6 site.
<?php
/**
* Save a remote image. Returns a file object.
*/
function download_image($url) {
// Check if the file extension is valid.
$extensions = 'jpg jpeg png gif';
$parsed = parse_url($url);
$regex = '/\.(' . @ereg_replace(' +', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $parsed['path'], $matches)) {
@cpsubrian
cpsubrian / output.txt
Created February 25, 2012 03:34
Workign on a repl
cpsubrian@blink ~/projects/node/gac (master)
$ cake repl
--------------------------
____ _ ____
/ ___| / \ / ___|
| | _ / _ \| |
| |_| |/ ___ \ |___
\____/_/ \_\____|
GAC REPL - try 'help'
@cpsubrian
cpsubrian / csv.coffee
Created March 3, 2012 03:20
Parsing a csv
numRead = 0
numImported = 0
doneReading = false
csv = require('csv')()
csv.fromPath result.filepath, {columns: true}
finish = () ->
process.stdout.write '\n'
log ""
log "Imported #{numImported} users".green
@cpsubrian
cpsubrian / README.md
Created May 2, 2012 19:47
Tiered config example with nconf

Startup a service that depends on amino

./bin/myservice --conf=/path/to/my/conf

Startup a service using the default conf path

./bin/myservice

@cpsubrian
cpsubrian / router.js
Created May 16, 2012 19:43
Director routing regex issue
var path = /^\/socket\.io.+/;
app.router.get(path, handler);
console.log(app.router.routes);
/* CONSOLE OUTPUT
{ '^': { 'socket\\.io.+': { get: [Function: handler] } } }
*/
@cpsubrian
cpsubrian / out.txt
Created August 2, 2012 19:21
EADDRNOTAVAIL in simple node.js web server (OSX)
$ node http.js
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: connect EADDRNOTAVAIL
at errnoException (net.js:670:11)
at connect (net.js:548:19)
at Socket.connect (net.js:613:5)
at Object.<anonymous> (net.js:77:12)
@cpsubrian
cpsubrian / api.js
Created October 8, 2012 20:28 — forked from carlos8f/api.js
relations api
// relations api
// users
var carlos = 'carlos8f'
, brian = 'cpsubrian'
, sagar = 'astrosag_ngc4414'
// repos
var buffet = 'carlos8f/node-buffet'
, views = 'cpsubrian/node-views'