Skip to content

Instantly share code, notes, and snippets.

@mikemorris
mikemorris / keysearch.json
Created February 16, 2012 17:42
KeySearch (Safari extension) Keywords
[
{
"enabled": true,
"keyword": "w",
"name": "Wikipedia",
"url": "http://en.wikipedia.org/w/index.php?search=@@@",
"shortcut": ""
},
{
"keyword": "default",
#!/bin/bash
# Expand globs to null when there are no matches
shopt -s nullglob
# Look for either a '<subdir>/console' or a 'symfony' file
until
file=(*/console symfony); [[ -f "$file" ]] && php "$file" "$@" && exit;
do
[[ "$PWD" == "/" ]] && break;
@mikemorris
mikemorris / gist:2166324
Created March 23, 2012 02:38
Build PHP 5.4.0 from source with i18n support for MacOS X 10.7 Lion
# Download, configure, make and install International Components for Unicode
wget http://download.icu-project.org/files/icu4c/49.1/icu4c-49_1-src.tgz
tar xzvf icu4c-49_1-src.tgz
cd icu/source/
./runConfigureICU MacOSX
make
sudo make install
# Install libjpeg support for GD
brew install jpeg
@mikemorris
mikemorris / gist:2569571
Created May 1, 2012 16:50
PHP Script to scrape records from corp.dcra.dc.gov
<?php
function dcra($username, $password, $search) {
$tmp_fname = tempnam('/tmp', 'COOKIE');
$curl_handle = curl_init ('https://corp.dcra.dc.gov/Account.aspx/LogOn');
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $tmp_fname);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
@mikemorris
mikemorris / gist:2654086
Created May 10, 2012 15:55
PHP script to scrape links from HTML files
<?php
$links = shell_exec('egrep -o -r "<a[^<]+?(\w*)</a>" --include=*.html *');
$output;
foreach(preg_split("/(\r?\n)/", $links) as $line){
$file = explode(':', $line)[0];
preg_match('/(?<=href=")[^"]+?(?=")/', $line, $url_matches);
$url = $url_matches[0];
@mikemorris
mikemorris / Canvas Pixel Map
Created August 13, 2012 15:52
Canvas pixel map technique from Paul Bakaus' Google Talk http://www.youtube.com/watch?v=_RRnyChxijA&feature=related
var clickMap = [];
for (var i = 0; n = imageData.length; i < n; i += 4) {
var row = Math.floor((i/4) / width);
var col = (i/4) - (row * width);
if(!clickMap[row]) clickMap[row] = [];
clickMap[row][col] = imageData[i+3] == 0 ? 0 : 1;
}
{
"name": "node",
"subdomain": "nclud",
"scripts": {
"start": "server.js"
},
"version": "0.1.0-70",
"engines": {
"node": "0.8.x"
},
@mikemorris
mikemorris / each_with_index.js
Created September 28, 2012 17:02 — forked from burin/each_with_index.coffee
each_with_index handlebars helper, adds an {{index}} prop accessible from within the block
// <ul data-length="{{records.length}}">
// {{#each_with_index records}}
// <li class="legend_item{{this.index}}" z-index="{{this.reverse}}"><span></span>{{this.name}}</li>
// {{/each_with_index}}
// </ul>
Handlebars.registerHelper("each_with_index", function(array, options) {
var buffer = "";
for (var i = 0, j = array.length; i < j; i++) {
var item = array[i];
@mikemorris
mikemorris / gist:4269698
Created December 12, 2012 17:17
jitsu deploy error
info: Welcome to Nodejitsu nclud
info: jitsu v0.11.4, node v0.8.15
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in server.js
/usr/local/lib/node_modules/jitsu/node_modules/require-analyzer/node_modules/npm/lib/npm.js:299
if (!conf.hasOwnProperty("prefix")) {
^
TypeError: Object #<error> has no method 'hasOwnProperty'
@mikemorris
mikemorris / length.js
Created April 11, 2013 19:52
return length of piped JSON array
#!/usr/bin/env node
var buffer = '';
process.stdin.on('data', function(data) {
buffer += data;
});
process.stdin.on('end', function() {
console.log(Array.prototype.slice.call(JSON.parse(buffer.toString())).length);