Skip to content

Instantly share code, notes, and snippets.

View benbuckman's full-sized avatar

Ben Buckman benbuckman

View GitHub Profile
<?php
/**
* Implementation of hook_drush_command().
*/
function MODULE_drush_command() {
$items = array();
$items['resync-content-taxonomy'] = array(
'description' => "Re-sync content_taxonomy from term_node",
);
return $items;
<?php
// force download of CSV
// simulate file handle w/ php://output, direct to output (from http://www.php.net/manual/en/function.fputcsv.php#72428)
// (could alternately write to memory handle & read from stream, this seems more direct)
// headers from http://us3.php.net/manual/en/function.readfile.php
header('Content-Description: File Transfer');
header('Content-Type: application/csv');
header("Content-Disposition: attachment; filename=FILENAME.csv");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@benbuckman
benbuckman / drupal-syslog-parser.js
Created November 29, 2011 17:56
node.js script to parse Drupal logs in linux syslog (and find distinct 404'd URLs)
// drupal log parser w/ node.js
// takes a filtered syslog file
// run as node `drupal-syslog-parser.js LOGPATH`
// [install dependencies (lazy,underscore) first with `npm install ___`]
var lazy = require('lazy')
, fs = require('fs')
, path = require('path')
, _ = require('underscore');
@benbuckman
benbuckman / seq-test.js
Created December 11, 2011 05:15
Understanding node-seq (control flow library for node.js)
### OUTPUT ###
vars at end: { firstVar: 'A', secondVar: 'B', thirdVar: 'C' }
in A
vars: {}
in B
vars: {}
timer done in A
in C
vars: {}
@benbuckman
benbuckman / intercept-stdout.js
Created May 20, 2012 15:42 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
var _ = require('underscore'),
util = require('util');
// intercept stdout, passes thru callback
// also pass console.error thru stdout so it goes to callback too
// (stdout.write and stderr.write are both refs to the same stream.write function)
// returns an unhook() function, call when done intercepting
module.exports = function interceptStdout(callback) {
var old_stdout_write = process.stdout.write,
old_console_error = console.error;
@benbuckman
benbuckman / pig-latin.js
Created July 20, 2012 13:45
Pig Latin Interpreter in javascript/node.js
/*
Pig Latin interpreter
by Ben Buckman, July 20 2012
Rules:
- All words beginning with a consonant have their first letter moved to the end of word followed by 'ay'.
Example: Hello -> Ellohay
- All words beginning with a vowel have their first letter moved to the end moved to the word followed by 'hay'.
Example: Another -> Notherahay
@benbuckman
benbuckman / elevators.js
Created July 20, 2012 13:48
Elevator dispatch algorithm in javascript
/*
Elevator algorithm
by Ben Buckman, for a job interview process 7/18/12
*/
// == INSTRUCTIONS ==
// Iterate through the elevators list and return the elevator that is:
// closest, AND
// moving in the right direction (or idle),
// - [ben] this could mean 2 things:
@benbuckman
benbuckman / magicdictionary.coffee
Created November 30, 2012 21:07
Magic Dictionary algo
dict = ['hello', 'kitty', 'farm']
isWordInDict = (word)->
(dict.indexOf(word) > -1)
findAllWords = (str)->
words = []
for startInd in [0..(str.length - 1)]
for endInd in [(startInd + 1)..str.length]
@benbuckman
benbuckman / test-refs.js
Created December 4, 2012 18:13
Testing JS references
// is it possible to hold a reference to a wrapper's object,
// such that the reference automatically updates when the object updates?
// (rather than staying with the original object)?
var assert = require('assert');
function Wrapper(){
this.client = null;
};
@benbuckman
benbuckman / test-getters.js
Created December 5, 2012 22:43
JS getter example
function Client(){
this.subClient = new SubClient();
};
function SubClient(){
this.numConnections = 0;
this.status = 'OK';
};
// getting error,
// TypeError: Invalid property. A property cannot both have accessors and be writable or have a value, #<Object>