Skip to content

Instantly share code, notes, and snippets.

@yulanggong
yulanggong / less2stylus.coffee
Created March 15, 2012 02:17 — forked from lancejpollard/less2stylus.coffee
Convert LESS to Stylus for Twitter Bootstrap
# Quick hack of regular expressions to convert twitter bootstrap from LESS to Stylus
less2stylus = (string) ->
string = string
.replace(/^(\ *)(.+)\ +\{\ *\n?\ */mg, "$1$2\n$1 ") # remove opening brackets
.replace(/^(\ *)([^\ \n]+)\ +\{\ *\n?\ */mg, "$1$2\n$1 ") # remove opening brackets
.replace(/\ *\{\ *\n*/g, "\n") # remove opening brackets again (some random cases I'm too lazy to think through)
.replace(/\ *\}\ *\n*/g, "\n") # remove closing brackets
.replace(/\;\ *?$/gm, "") # remove semicolons
.replace(/@(\w+):(\ *)\ /g, (_, $1, $2) -> # replace @variable: with $variable =
"$#{$1}#{$2} = "
@yulanggong
yulanggong / lessc_watch.js
Created March 15, 2012 02:36
Less compiler with --watch and --smartpath support
/*
* Less compiler with --watch and --smartpath support
*
* Based on lessc of less 1.3.0
*
* Added options:
*
* -w, --watch Watch files (include @import files) for changes and re-compile
*
* -m, --smartpath output css file like this:
@yulanggong
yulanggong / gist:2224161
Created March 28, 2012 06:15 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@yulanggong
yulanggong / critique.md
Created April 5, 2012 03:53 — forked from Raynos/critique.md
jQuery library critique

jQuery

Related: [Why you don't need jQuery as an abstraction][2]

$ itself is a god object. Everything goes on it. The standard plugin / extension architecture that is recommended is to just bolt more methods on $ itself!

Surely this is bad. An example would be how we have both $.load which is overloaded to do completely different things. If they were on two separate sensibly named objects $Container.load and $EventTarget.load. Personally I would deprecate the latter in favour of .on('load'

The animation should be it's own little modular thing, not bolted onto $. Ajax should be it's own little modular thing, not bolted onto $

@yulanggong
yulanggong / dark.theme
Created May 21, 2012 15:06
Dark Theme for Windows XP
[Theme]
DisplayName=@themeui.dll,-2016
; My Computer
[CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\DefaultIcon]
DefaultValue=%WinDir%explorer.exe,0
; My Documents
[CLSID\{450D8FBA-AD25-11D0-98A8-0800361B1103}\DefaultIcon]
DefaultValue=%WinDir%SYSTEM32\mydocs.dll,0
@yulanggong
yulanggong / cnNum2ArabNum.js
Created August 7, 2012 01:05
中文数字转阿拉伯数字
var cnNum2ArabNum = function(cn){
var arab, parts, cnChars = '零一二三四五六七八九'
if (!cn) {
return 0
}
if (cn.indexOf('亿') !== -1){
parts = cn.split('亿')
return cnNum2ArabNum(parts[0]) * 1e8 + cnNum2ArabNum(parts[1])
@yulanggong
yulanggong / webtools.js
Created August 28, 2012 05:05
Some Web development tools for Notepad++ (NppScripting)
/**
* Some Web development tools for Notepad++ (NppScripting)
* Based on jsbeautifier.js and service of reducisaurus.appspot.com.
*/
var format = Editor.addMenu("Webtools");
format.addItem({
text:"JSBeautify\tCtrl+Shift+F",
cmd:function(){do_js_beautify();}
});
@yulanggong
yulanggong / deepRecursionCallback.js
Created September 28, 2012 07:23
deepRecursionCallback
var stackSize = 0;
function foo(a, stackSize){
stackSize ++;
bar();
if (!a.length) return;
if (stackSize > 1000) {
@yulanggong
yulanggong / jsStyle.js
Created September 29, 2012 03:28
jsStyle
//缩进两个空格
var a = 1
, b = 2
, c = 3
, d = {
e: 4
, f: 5
, g: 6
}
, h = [
@yulanggong
yulanggong / buttonImageChangeDirection.jsx
Created October 31, 2012 01:52
多态按钮图片的横纵向转换
/**
* 多态按钮图片的横纵向转换
* 在 Photoshop CS6 下测试过
* 2012-10-30
* @param {Array} map 转换前后的按钮位置映射关系,下面有例子
* @param {String} flag 方向标志, v2h 纵转横, h2v 横转纵
* @param {Document} [doc] 默认为当前文档
*/
function changeDirection(map, flag, doc){