Skip to content

Instantly share code, notes, and snippets.

layoutElement.addEventListener("touchstart", handleStart, false);
layoutElement.addEventListener("touchmove", handleMove, false);
layoutElement.addEventListener("touchend", handleEnd, false);
function handleStart(event) {
event.preventDefault();
var touches = event.changedTouches;
for (var i=0; i<touches.length; i++) {
Header.onDragStart({
@whunter
whunter / inheritance.js
Last active August 29, 2015 14:01
prototypical inheritance
var Animal = {
walk: function() {
console.log('walk');
},
talk: function() {
console.log('talk');
}
};
function Dog() {
this.talk = function() {
@whunter
whunter / create_nested_dirs.rb
Created May 23, 2014 17:32
Create nested directories in RoR public folder
require 'fileutils'
FileUtils::mkdir_p Rails.root + 'public/foo/bar'
@whunter
whunter / lightspuzzler.py
Last active August 29, 2015 14:15
Figure out which lights would remain on given the scenario described by Click and Clack here: http://www.cartalk.com/content/hall-20000-lights?question
#!/usr/bin/python
import sys
# @author Lee Hunter
# @email wleehunter@gmail.com
# @prerequisites: python version 2.5 or higher (I think)
# @usage: python lightspuzzler.py <number_of_lights>
# @example: python lightspuzzler.py 20000 (This would give the results from the actual question. It will also take forever)
# short, messy script to calculate which lights would remain on given the scenario described by Click and Clack.
@whunter
whunter / quicksort.py
Created July 28, 2015 16:02
Python implementation of quicksort using an example list with lots of explanation in the output.
#!/usr/bin/python
# Based on example here: http://www.algolist.net/Algorithms/Sorting/Quicksort
def partition(numList, left, right, side):
i = left
j = right
tmp = None
pivot = numList[(left+right) / 2]
print "Beginning " + side + " partition"
@whunter
whunter / redis_check.rb
Created October 7, 2015 16:56
check redis status
Timeout.timeout(0.5) { TCPSocket.open("localhost", 6379) { } }
@whunter
whunter / text_rotate.js
Last active February 22, 2016 14:11
Create a div containing your specified text and rotate about the axis you specify at the speed you specify using absolutely zero css.
/**
@param String - text to rotate
@param Number - time to complete one rotation (in milliseconds)
@param String - axis to rotate about
Usage:
text_rotate("My text to rotate", 1000, "x");
*/
function text_rotate(text,time,axis){
var d=l="";
@whunter
whunter / sublime_user.json
Created December 15, 2015 14:38
sublime user settings
{
"detect_indentation": false,
"draw_white_space": "all",
"font_size": 15.0,
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"translate_tabs_to_spaces": true
@whunter
whunter / fb_login.js
Created January 2, 2016 16:28
Script for handling Facebook app login/logout. Uses jQuery because I'm lazy. You could call the other stuff that you need to do at the end of onFbLogin().
var FacebookLogin= {
APPID: null,
connected: false,
accessToken: null,
loginResponse: null,
signedRequest: null,
userID: null,
$loginLink: null,
$logoutLink: null,
@whunter
whunter / adb_rotation.sh
Created February 9, 2016 18:13
android device display rotation via adb
# disable auto rotation
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
# force landscape
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
# back to portrait
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
# upside down