Skip to content

Instantly share code, notes, and snippets.

View DC3's full-sized avatar

Dee Cheung DC3

View GitHub Profile
'wkjkjd fsk fsdjk\nbbb sss fasdf'.replace(/(bbb|sss)(\s)?/g, function(match, p1, p2){
var min = 1, max = p1.length - 1,
pos = Math.floor(Math.random() * (max - min + 1)) + min; //randint
return p1.substr(0, pos) + 'a' + p1.substr(pos, p1.length - 1) + p2;
});
# http://www.1758.com/hlmy/yanse2.htm
$ ->
timeEl = $('.time')
boxEl = $('#box')
interval = null
eachTime = 1 # ms
replaceRE = /[^\d]+/g
getColor = (str) ->
operations =
'*': (a, b) -> a*b
'+': (a, b) -> a+b
evaluate = (arr) ->
calc = (operation, refArr) ->
hasOperation = (index = arr.indexOf(operation)) isnt -1
return refArr unless hasOperation
pos = index - 1
@DC3
DC3 / gist:67544c90035f466866a1
Last active August 29, 2015 14:11
promise 示例
# 兼容 jQuery Deferred 与 ES6 Promise 的写法的 Promise Wrapper
# https://gist.github.com/DC3/d2c37399eae2f7f08d16
do ->
hasPromise = (window.Promise and window.Promise.all)
hasjQuery = (($ = window.jQuery) and window.jQuery.fn.jquery)
return if hasPromise or not hasjQuery
Promise = (func) ->
$.Deferred(({resolve, reject}) ->
func.call null, resolve, reject
).promise()
function base64image() {
if [ -z "$1" ]
then
echo "give me a filename"
fi
filename=$(basename "$1")
extension="${filename##*.}"
out="$filename.base64"
str=$(base64 --wrap=0 "$1")
echo "data:image/$extension;base64,$str" | cat > "$out"
do (win = window, doc = window.document, className = 'wrap-placeholder', selector = '[placeholder]') ->
# support placeholder
return if doc.createElement('input').placeholder isnt undefined
modern = doc.addEventListener
setStyles = (node, styles) ->
console.log 'debug', JSON.stringify styles
for name, val of styles
console.log 'debug', [name, val]
node.style[name] = val
@DC3
DC3 / README.md
Last active August 29, 2015 14:17
React Two-Way Binding Example

React Two-Way Binding Helpers Sample

docs

do ->
hasPromise = (window.Promise and window.Promise.all)
hasjQuery = (($ = window.jQuery) and window.jQuery.fn.jquery)
return if hasPromise or not hasjQuery
Promise = (func) ->
$.Deferred(({resolve, reject}) ->
func.call null, resolve, reject
).promise()
Promise.all = (arr) -> new Promise (resolve, reject) ->
if Object::toString.call(arr) isnt '[object Array]'
@DC3
DC3 / md2cf.sh
Last active March 14, 2019 02:07 — forked from teppeis/md2cf.sh
#!/bin/sh
# Convert Markdown to Confluence
#
# Supported syntax
# * heading (1-6)
# * blockquote (only single line ".bq")
# * code block fence (```)
# * inline code (`foo`)
# * link ([name](url))
JSONP = do (win = window, doc = document) ->
head = doc.getElementsByTagName('head')[0]
createScript = (url) ->
node = doc.createElement('script')
node.onload = -> head.removeChild node
node.onerror = ->
head.removeChild node
throw new Error 'JSONP load script error'
node.src = url