Skip to content

Instantly share code, notes, and snippets.

View briangonzalez's full-sized avatar
🏠
🚚

Brian Gonzalez briangonzalez

🏠
🚚
View GitHub Profile
@briangonzalez
briangonzalez / mousewheel.js
Last active October 2, 2015 04:28
Bulletproof mouse-wheel event handling
if ( event.hasOwnProperty('type') && event.type == 'DOMMouseScroll' ){
// Zoom from mousewheel (Firefox)
}
else if ( event.type == 'mousewheel' && event.originalEvent.hasOwnProperty('wheelDeltaY') ) {
// ... (Chrome)
}
else if ( event.type == 'mousewheel' && event.originalEvent.hasOwnProperty('wheelDelta') ) {
// ... (Opera)
direction = ( event.originalEvent.wheelDelta > 0 ) ? 'up' : 'down'
}
@briangonzalez
briangonzalez / gist:2217607
Created March 27, 2012 16:16
Useful Applescript Snippets
-- new tab with a url in chrome
tell application "Google Chrome"
set myTab to make new tab at end of tabs of window 1
set URL of myTab to "http://google.com"
end tell
@briangonzalez
briangonzalez / gist:2377090
Created April 13, 2012 14:03
Sublime Packages
@briangonzalez
briangonzalez / ocr.markdown
Created April 20, 2012 03:49 — forked from henrik/ocr.markdown
OCR on OS X with tesseract

Install ImageMagick for image conversion:

brew install imagemagick

Install tesseract for OCR:

brew install tesseract --all-languages

Or install without --all-languages and install them manually as needed.

@briangonzalez
briangonzalez / underscore_conditionals.js
Created April 23, 2012 16:55 — forked from brianarn/underscore_conditionals.js
Conditionals with underscore.js
// A means of using underscore.js to do templates with conditionals
// Inside of underscore's template, it returns a function that uses
// 'with' on a variable named obj, and you can touch into that using
// inline JS and <% %> wrappers
// A template with conditional display of last names:
var good = _.template("Hello: <%= name %> <% if (obj.lastname) { %> <%= lastname %> <% } %>");
// A template that tries to do that, but fails:
var bad = _.template("Hello: <%= name %> <% if (lastname) { %> <%= lastname %> <% } %>");
@briangonzalez
briangonzalez / gist:2493742
Created April 25, 2012 21:41
Javascript tricks
// ensure user wants to navigate away, or unbind it...
window.onbeforeunload = function() { return "You sure?" };
window.onbeforeunload = null;
@briangonzalez
briangonzalez / gist:3242283
Created August 2, 2012 23:57
Running Applescript from Cocoa
NSString *someScript = [[NSBundle mainBundle] pathForResource:@"some_script" ofType:@"osascript"];
NSString *contents = [NSString stringWithContentsOfFile:someScript encoding:NSUTF8StringEncoding error:nil];
NSAppleScript *script =[[NSAppleScript alloc] initWithSource:contents];
[script executeAndReturnError:nil];
@briangonzalez
briangonzalez / README.md
Created October 21, 2012 04:25
img2boxshadow - a ruby script to convert images to CSS [http://codepen.io/briangonzalez/details/AvrGI#pen-details-tab]

img2boxshadow.rb

a ruby script to convert images to CSS (box-shadows)

Installation

gem install rmagick    # you'll need ImageMagick & Ruby first
gem install colormath
gem install micro-optparse

Combinator Recipes for Working With Objects in JavaScript, Part I

(This post is Part I of [II][Part II]. The recipes in this post are excerpted the book JavaScript Allongé.)

combinators

The word "combinator" has a precise technical meaning in mathematics:

"A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments."--[Wikipedia][combinators]

#!/bin/sh
VERSION=0.11.2
PLATFORM=darwin
ARCH=x64
PREFIX="$HOME/node-v$VERSION-$PLATFORM-$ARCH"
mkdir -p "$PREFIX" && \
curl http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz \
| tar xzvf - --strip-components=1 -C "$PREFIX"