Skip to content

Instantly share code, notes, and snippets.

View DC3's full-sized avatar

Dee Cheung DC3

View GitHub Profile
@DC3
DC3 / watchify.coffee
Created July 15, 2015 04:40
watchify-task
fs = require 'fs'
path = require 'path'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
stream = require 'vinyl-to-stream'
watchify = require 'watchify'
browserify = require 'browserify'
defaultOptions =
@DC3
DC3 / bling.js
Last active March 14, 2019 02:06
/* bling.js */
window.$ = document.querySelectorAll.bind(document)
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn)
}
NodeList.prototype.__proto__ = Array.prototype
@DC3
DC3 / build.sh
Created June 15, 2015 10:49
browserify-build-sample
#!/usr/bin/env sh
# 监听
#watchify -t coffeeify --extension='.coffee' -dv \
#-e ./public/assets/coffee/components/uploadModal.coffee \
#-o ./public/dist/scripts/u.js
# 监听 + 分离
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
@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))
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 / README.md
Last active August 29, 2015 14:17
React Two-Way Binding Example

React Two-Way Binding Helpers Sample

docs

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
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"
@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()