Skip to content

Instantly share code, notes, and snippets.

/**
* 把 2014-02-02 15:30:20 转换为 Date 对象,
* iOS Safari 仅支持 1995-12-17T03:24:00 格式,故对更常用的无 T 的需额外处理
*
* @param {String} dateString - 待转换的时间字符串,格式形如 2014-02-02 15:30:20
*
* @return {Date} - 转换后的 Date 对象
*/
function parseDate(dateString) {
var arr = dateString.split(/[- :]/);
{
decodeSpecialUnicode: function(str) {
var ptn = /\\u([0-f]{4})/ig;
return str.replace(ptn, function(match, group) {
return String.fromCharCode(parseInt(group, 16));
});
},
encodeSpecialUnicode: function(str) {
@liunian
liunian / introrx.md
Last active August 29, 2015 14:20 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

/**
* find all markdown files in given directory, (here just current directory)
* and then fetch their title to generate index markdown file
*
* use -v to show verbose detail
* use -o to specify output file, default to ./index.md
* use -d to specify scanner directory, such as -d the_directory, default to ./
*/
var fs = require('fs'),
path = require('path')
@liunian
liunian / gist:9757295
Last active April 26, 2024 03:30
References
{
'Safari Developer Library': 'https://developer.apple.com/library/safari/navigation/index.html',
'Safari HTML Reference': 'https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html',
'Safari Web Content Guide': 'https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html'
}
@liunian
liunian / gist:9338301
Last active April 26, 2024 03:30
Human Readable File Size with PHP
<?php
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
echo human_filesize(filesize('example.zip'));
@liunian
liunian / isContain
Last active April 26, 2024 03:30
mouseenter / mouseleave
function bindMouseLeave(obj, fn) {
if (obj.attachEvent) {
obj.attachEvent('onmouseleave', function() {
fn.call(obj, window.event);
});
} else {
obj.addEventListener('mouseout', function(e) {
var rt = e.relatedTarget;
if (rt !== obj && !isContain(obj, rt)) {
fn.call(obj, e);
var supports = (function() {
var div = document.createElement('div'),
vendors = 'Khtml Ms O Moz Webkit'.split(' '),
len = vendors.length;
return function(prop) {
if ( prop in div.style ) return true;
prop = prop.replace(/^[a-z]/, function(val) {
return val.toUpperCase();
@liunian
liunian / gist:7133112
Created October 24, 2013 08:08
A to Z in 10x10
/*
10 x 10
A-Z ( 65 -> 90)
output something like this
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* J I * * * * * * *