Skip to content

Instantly share code, notes, and snippets.

赖小赖 laispace

Block or report user

Report or block laispace

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@laispace
laispace / fetchLocalJSON.m
Last active Apr 1, 2016
fetch local json file and parse it to a dictionary
View fetchLocalJSON.m
- (NSDictionary *)fetchLocalJSON:(NSString *) pathForResource {
NSDictionary *dictionary;
// read JSON file
NSString *fileName = [[NSBundle mainBundle] pathForResource:pathForResource ofType:@"json"];
if (fileName) {
NSLog(@"file exist: %@", fileName);
// get file data
NSData *fileData = [[NSData alloc] initWithContentsOfFile:fileName];
@laispace
laispace / after.js
Created Feb 2, 2016
invoke a callback after all operations
View after.js
function after (count, callback) {
return function () {
while(--count === 0) {
console.log(arguments);
callback.call(this, arguments);
}
}
}
// define some operations
@laispace
laispace / count-string-length.js
Created Nov 11, 2015
计算字符串长度, 中文算两个
View count-string-length.js
function countStringLength (string) {
var len = string.length;
var count = 0;
for (var i = 0; i < len; i ++) {
var num = string.charCodeAt(i);
if (num == 94 || num > 127) {
count += 2;
} else {
count += 1;
}
@laispace
laispace / count-alloy-posts-per-month.py
Last active Oct 22, 2015
统计 alloyteam.com 每月博文阅读数量
View count-alloy-posts-per-month.py
__author__ = 'alloyteam.com'
# -*- coding: UTF-8 -*-
import urllib.request
import re
class Spider:
def __init__ (self, pageStartNum, pageEndNum, year, monthStart, monthEnd, sortOutput) :
@laispace
laispace / randomArray.js
Created Aug 31, 2015
打乱数组顺序
View randomArray.js
function randomArray (array) {
if (array.length === 1) {
return array;
} else {
var len = array.length;
var index = ~~(Math.random() * len);
var item = array.splice(index, 1);
return item.concat(randomArray(array));
}
@laispace
laispace / openWindowByUrl.js
Created Jul 28, 2015
打开一个新页面
View openWindowByUrl.js
/**
* 打开一个新的页面
* @param {String} url
*/
openWindowByUrl: function(url) {
var a = document.createElement('a');
a.href = '';
a.setAttribute("target", '_blank');
var evt = document.createEvent("HTMLEvents");
evt.initEvent("click");
@laispace
laispace / isEnglish.js
Created Jul 28, 2015
判断字符是否为英文
View isEnglish.js
/**
* 判断置顶字符是否为英文
* @method isEnglish
* @param {String} s
* @return {Boolean}
*/
isEnglish: function(s) {
var code = ('' + s).charCodeAt(0);
if (code >= 0x0041 && code <= 0x005A || code >= 0x0061 && code <= 0x007A) {
return true;
@laispace
laispace / isChinese.js
Created Jul 28, 2015
判断字符是否为中文
View isChinese.js
/**
* 判断置顶字符是否为中文
* @method isChinese
* @param {String} s
* @return {Boolean}
*/
isChinese: function(s) {
//4E00 - 9FA5
var code = ('' + s).charCodeAt(0);
if (code >= 0x4E00 && code <= 0x9FA5) {
@laispace
laispace / pattern-decorator.js
Created Feb 8, 2015
设计模式-装饰者模式
View pattern-decorator.js
// pattern-decorator.js
// ===== 1. let instance has new functions =====
function Person (name, age) {
this.name = name;
this.age = age;
}
Person.prototype.say = function (something) {
console.log(this.name, 'says: ', something);
@laispace
laispace / pattern-factory.js
Last active Aug 29, 2015
设计模式-工厂模式
View pattern-factory.js
// ===== 1.pattern-factory.js=====
// Car factory
function Car (options) {
this.type = options.type || 'car';
this.owner = options.owner || null;
this.price = options.price || null;
}
// Trunk factory
You can’t perform that action at this time.