Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Buckman benbuckman

View GitHub Profile
View Drupal - Re-Sync Content Taxonomy.php
<?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;
View php: output to downloaded csv.php
<?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 Nov 29, 2011
node.js script to parse Drupal logs in linux syslog (and find distinct 404'd URLs)
View drupal-syslog-parser.js
// 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 Dec 11, 2011
Understanding node-seq (control flow library for node.js)
View seq-test.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 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
View intercept-stdout.js
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 Jul 20, 2012
Pig Latin Interpreter in javascript/node.js
View pig-latin.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 Jul 20, 2012
Elevator dispatch algorithm in javascript
View elevators.js
/*
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:
View magicdictionary.coffee
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 Dec 4, 2012
Testing JS references
View test-refs.js
// 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;
};
View test-getters.js
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>