Skip to content

Instantly share code, notes, and snippets.

View dd1994's full-sized avatar
💭
I may be slow to respond.

JIANG Di dd1994

💭
I may be slow to respond.
View GitHub Profile
@dd1994
dd1994 / swipeFunc.js
Created July 6, 2016 09:58 — forked from localpcguy/swipeFunc.js
Simple Mobile Swipe function to get the swipe direction
var swipeFunc = {
touches : {
"touchstart": {"x":-1, "y":-1},
"touchmove" : {"x":-1, "y":-1},
"touchend" : false,
"direction" : "undetermined"
},
touchHandler: function(event) {
var touch;
if (typeof event !== 'undefined'){
@dd1994
dd1994 / web-servers.md
Created April 8, 2016 06:39 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@dd1994
dd1994 / dabblet.css
Created March 29, 2016 07:54
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #eee;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@dd1994
dd1994 / loop.js
Created December 12, 2015 12:13
cycle reference
'use strict'
let ary = []
let obj1 = {
a: 1,
b: ary
}
ary.push(obj1)
@dd1994
dd1994 / bind.js
Last active December 12, 2015 05:14
implement Function.prototype.bind
'use strict'
let bind = function (fn, obj) {
return function () {
fn.apply(obj, arguments)
}
}
let foo = function () {
@dd1994
dd1994 / fn_stack.js
Created December 11, 2015 05:15
show function call stack
'use strict'
function baz() {
debugger
console.log('baz')
bar()
}
function bar() {
debugger
@dd1994
dd1994 / set_timeout.js
Last active November 28, 2015 14:40
an example of setTimeout and clearTimeout
'use strict'
let timeoutID1 = setTimeout(function(arg1, arg2) {
console.log(arg1)
console.log(arg2)
}, 2000, 'hello1', 'go1')
let timeoutID2 = setTimeout(function(arg1, arg2) {
console.log(arg1)
console.log(arg2)
@dd1994
dd1994 / repl.js
Created November 28, 2015 02:38
node repl example
'use strict'
const repl = require('repl')
let r = repl.start("-> ")
let c = r.context
c.msg = "awesome repl"
@dd1994
dd1994 / ns-cheatsheet.clj
Created November 1, 2015 09:41 — forked from ghoseb/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
@dd1994
dd1994 / gcd.clj
Last active November 3, 2015 08:13
get greatest common divisor(use Clojure)
(defn gcd
[div rem]
(if (= rem 0)
div
(gcd rem (mod div rem))))