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 / gist:04c9490212ec04fdf99f
Created October 21, 2015 12:07
Fix: Cairo for el Capitan
xcode-select --install
var keys = [37, 38, 39, 40]
var prevent = (e) => {
if ( e.type != 'keydown' || keys.indexOf(e.keyCode) != -1 ) {
e.preventDefault()
return false
}
}
var disableScroll = (node) => {
node = node || window
node.onwheel = node.ontouchmove = document.onkeydown = prevent
@davidhellsing
davidhellsing / gist:01ecaecd4245441a81280310f7e847bc
Last active December 15, 2017 13:11
Haystack needle recursive
findKey = (haystack, needle) => {
let found = false
const iterate = (obj) => (
Object.keys(obj).forEach((key) => {
if (found === false) {
if (key === needle) {
found = key
} else if (obj[key] && typeof obj[key] === 'object') {
iterate(obj[key])
}
@davidhellsing
davidhellsing / gist:6fbd8b82d14cec8482e9d9b427aae62c
Created January 17, 2018 00:20
simple vanillaJS smooth scroll
<html>
<head>
<style>
#content{height: 8000px; width: 800px; margin: 0 auto; background: yellow;position: relative;}
</style>
</head>
<body>
<div id="content">
Lorem<br>
Lorem<br>