This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.1758.com/hlmy/yanse2.htm | |
$ -> | |
timeEl = $('.time') | |
boxEl = $('#box') | |
interval = null | |
eachTime = 1 # ms | |
replaceRE = /[^\d]+/g | |
getColor = (str) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 兼容 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer