Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Morris mikemorris

View GitHub Profile
@mikemorris
mikemorris / keysearch.json
Created Feb 16, 2012
KeySearch (Safari extension) Keywords
View keysearch.json
[
{
"enabled": true,
"keyword": "w",
"name": "Wikipedia",
"url": "http://en.wikipedia.org/w/index.php?search=@@@",
"shortcut": ""
},
{
"keyword": "default",
View symfony.sh
#!/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 Mar 23, 2012
Build PHP 5.4.0 from source with i18n support for MacOS X 10.7 Lion
View gist:2166324
# 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
PHP Script to scrape records from corp.dcra.dc.gov
View gist:2569571
<?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
PHP script to scrape links from HTML files
View gist:2654086
<?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];
View Canvas Pixel Map
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;
}
View gist:3419951
{
"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 Sep 28, 2012 — forked from burin/each_with_index.coffee
each_with_index handlebars helper, adds an {{index}} prop accessible from within the block
View each_with_index.js
// <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 Dec 12, 2012
jitsu deploy error
View gist:4269698
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 Apr 11, 2013
return length of piped JSON array
View length.js
#!/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);