Skip to content

Instantly share code, notes, and snippets.

@redbluish
redbluish / webcommon.js
Created April 2, 2014 03:03
异步顺序加载JS脚本
var WebCommon = (function (func) {
return func(WebCommon || {}, $);
}).call(this, function (wc, $, undefined) {
var
// 获取指定param的查询字符串值
query = function (param) {
var match = RegExp('[?&]' + param + '=([^&]*)').exec(location.href.split('#')[0]);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
},
@redbluish
redbluish / jquery-map-pitfall.js
Created April 2, 2014 03:01
jQuery.map的坑
_.map(['foo', 'bar'], function (item, index) {
return [index, item];
});
['foo', 'bar'].map(function (item, index) {
return [index, item];
});
$(['foo', 'bar']).map(function (index, item) {
return [index, item];
@redbluish
redbluish / Log-.md
Created March 7, 2014 17:30 — forked from bgrins/Log-.md

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@redbluish
redbluish / closure_caveat.js
Created December 9, 2013 12:46
closure_caveat.js
// closure caveat
// case 1
;(function (window, $, undefined) {
var $target;
function howdy() {
var x = 'foo';
if (!$target) {
@redbluish
redbluish / curry.js
Created December 6, 2013 16:12
curry.js
;(function (window, undefined) {
var _slice = [].slice;
function curry(fn) {
var arity = fn.length;
return (function given(argsSoFar) {
return function () {
var updatedArgsSoFar = argsSoFar.concat(_slice.call(arguments, 0));
@redbluish
redbluish / variadic.js
Created December 1, 2013 17:09
variadic.js
;(function (window, undefined) {
var _slice = Array.prototype.slice;
function variadic(fn) {
var numParams = fn.length, // 形参个数
numNamedArgs = numParams - 1;
return numParams < 1 ? fn : function () {
var
@redbluish
redbluish / df.js
Created November 27, 2013 08:59
dynamic generate methods.
;(function (window, undefined) {
// [es5-shim.min.js](http://tinyurl.com/omk7rjt)
'use strict';
'11||111||2||2||3||4||2||3||3||4||5||5||3||4||5||6||5||6||4||4||4||4||4||4||4||4||4||5||6||6'
.split('||')
.reduce(function (result, item, index) {
index % 6 === 0 ? result.push([item]) : result[result.length - 1].push(item);
return result;
}, [])
@redbluish
redbluish / schedule.js
Created November 17, 2013 02:04
schedule.js
var schedule = (function (self) {
var paused = false, // 标记状态
queue = []; // 队列
// 入队
self.join = function (fn, params) {
params = params || {};
var args = [].concat(params.args);
queue.push(function (_) {