Skip to content

Instantly share code, notes, and snippets.

@th507
th507 / fastclick_testcase.html
Created December 13, 2012 17:05
Using FastClick with webkit-overflow-scrolling Element
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<meta name="viewport" content="width=device-width,user-scalable=no">
<meta name="viewport" content="width=320">
<meta name='apple-mobile-web-app-capable' content='yes' />
<!--
@th507
th507 / flattenArray.js
Created March 14, 2013 04:51
recursively flatten array in JavaScript
/*
* @name arrayEqual
* @description check if two arrays are equal
* @param {arr} Array to check
* @param {arr} Array to check
* @return {Boolean} Boolean, returns true if arrays are the same
*/
function arrayEqual(a, b) {
@th507
th507 / agnoster.fish
Last active December 17, 2015 21:18 — forked from hauleth/agnoster.fish
improved user detection for Mac
set SEGMENT_SEPARATOR '⮀'
set SEGMENT_BG
set RSTATUS
# Create segment of prompt
function prompt_segment
set -l bg $argv[1]
set -l fg $argv[2]
[ (count $argv) -gt 2 ]; and set -l content $argv[3..-1]
@th507
th507 / sta
Created May 30, 2013 06:44
Show modified file in a svn/git repository
#!/usr/bin/env bash
svncount=`svn status . -q | grep '^M' | wc -l`
if [ "$svncount" -gt 0 ] ; then
status=`svn status . -q`
else
status=`git status -s`
fi
echo $status | awk '/^M/ {print $2}'
@th507
th507 / make_ruby_dict.rb
Last active December 23, 2015 14:29 — forked from henry0312/make_ruby_dict.rb
making dictionary for vim autocomplete from http://henry.animeo.jp/wp/?p=1764 remove trailing =, ?
#!/usr/bin/env ruby
require 'uri'
if ARGV.size != 1
warn "Invalid argument"
exit
end
methods = []
@th507
th507 / web-inspector-prank.js
Created September 26, 2013 03:07
Web Inspector prank
/*
* run it inside Web Inspector, as long as the tab is not closed,
* victim's pasteboard is sabotaged.
* some some other fun stuff as well :)
*/
(function() {
var hiddenConsole = (console._commandLineAPI || console._inspectorCommandLineAPI || {});
// randomly fill the paste board
var mockPasteboard = function () {
@th507
th507 / factory.js
Last active December 24, 2015 18:19
uncurrying + mixin in JavaScript
// uncurrying and mixin two-in-one
// var a = [1, 2];
// push = factory(Array.prototype.push);
// pushA = factory(Array.prototype.push, a);
// push(a, 3) => a = [1, 2, 3]
// or
// pushA(3) => a = [1, 2, 3]
var call = Function.call;
var slice = Array.prototype.slice;
@th507
th507 / ftcTracker.coffee
Last active December 27, 2015 09:19
logging offline visits across sessions
# logging offline visits across sessions
# for in-house tracking and Google Analytics
# See my blog for more information (Chinese)
# http://ljw.me/2013/07/24/logging-offline-visits.html
#
# Usage:
#
# var tracker = new FTCTracker(beaconURLPrefix)
# tracker.push(url)
#
@th507
th507 / currying-with-generator.js
Last active August 29, 2015 14:23
Currying with generator
function *step(fn) {
var arr = Array(fn.length);
for (var i = 0; i < arr.length; i++) {
arr[i] = (yield);
}
var gen = fn.apply(null, arr);
return gen;
}
let yCombinator = f => (g => (...p) => f(g(g))(...p))(g => (...p) => f(g(g))(...p))
var factory = f => (...a) => a.length - a[0].length > 1 ? f.call.call(...a) : f.bind(null, ...a)
//
// we could add some fancy code to eliminate fn.call & fn.bind
//
// var topsy = (f => f.bind(f))(Function.call)
// var turvy = (f => f.bind(f))(Function.bind)
// var factory = f => (...a) => (a.length - a[0].length > 1 ? topsy : turvy(f, null))(...a)
//