Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
davidhellsing / gist:9484466
Last active August 29, 2015 13:57
click:fast - a fast click event alternative that triggers the handler much faster on touch devices (and also prevents click events on swipe/scroll).
$.event.special['click:fast'] = {
propagate: true,
add: function(handleObj) {
var getCoords = function(e) {
if ( e.touches && e.touches.length ) {
var touch = e.touches[0];
return {
x: touch.pageX,
y: touch.pageY
@davidhellsing
davidhellsing / gist:b7deb968e450f1d87d46
Created May 6, 2014 05:03
Deploy dist directory to gh-pages
#!/bin/bash
git add .
git commit -am 'master deploy'
git checkout gh-pages
git checkout master -- dist
rsync -a -v dist/ ./
rm -rf dist
git add .
git commit -am 'page deploy'
git push
// example:
// var stateHandler = State(node, function(state) { this.className = state.active ? 'active' : '' })
// stateHandler.set({ active: true })
var states = {}
function State(elem, render) {
if ( states.hasOwnProperty(elem) )
return states[elem]
if ( !(this instanceof State) ) {
var instance = new State(elem, render)
@davidhellsing
davidhellsing / gist:f2c4842e3fea551a32ce
Last active August 29, 2015 14:07
Fix Brew for OSX Yosemite
vi /usr/local/Library/brew.rb

Change line 1 from:

#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

to:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0

Save and exit

@davidhellsing
davidhellsing / gist:e6eea9c6659ca9c23e7a
Created October 24, 2014 09:31
Postgres fix for yosemite

sudo mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/

@davidhellsing
davidhellsing / gist:b8a24b537750de4064cc
Created November 24, 2014 13:22
Fix: X11 for Yosemite

sudo ln -s /opt/X11 /usr/X11

@davidhellsing
davidhellsing / entity.js
Created September 12, 2011 19:51
Simple bookmarklet to convert selected text to HTML entities
function n(f) {
return f.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
a = document.activeElement;
v = a.value;
s = a.selectionStart;
e = a.selectionEnd;
a.value = v.substr(0,s) + n(v.substr(s,e)) + v.substr(e,v.length);
/*
@davidhellsing
davidhellsing / support.letterspacing.js
Created January 10, 2012 13:51
Test if browser supports fractional values of letter spacing
/* Test if the browser supports decimal letterspacing for fine kerning (f.ex 0.5px)
* At the moment (january 2012), at least webkit (chrome & safari) does not render decimal pixels correctly
* https://bugs.webkit.org/show_bug.cgi?id=20606
* Using this method, you can at least provide an alternative kerning for those browsers
*/
var letterspacing = (function(d) {
var test = d.createElement('div'),
ret = true;
test.style.letterSpacing = '.5px';
@davidhellsing
davidhellsing / prime.js
Created February 20, 2012 19:16
Prime number tester
// Test if a number is Prime using a simple regex.
// Demo: http://jsfiddle.net/rJhpq/
function prime(n) {
return !/^1?$|^(11+?)\1+$/.test((function(n){s='';while(n--)s+='1';return s;}(n)));
}
@davidhellsing
davidhellsing / gist:04c9490212ec04fdf99f
Created October 21, 2015 12:07
Fix: Cairo for el Capitan
xcode-select --install