View fetchLocalJSON.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
View after.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function after (count, callback) { | |
return function () { | |
while(--count === 0) { | |
console.log(arguments); | |
callback.call(this, arguments); | |
} | |
} | |
} | |
// define some operations |
View count-string-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
View count-alloy-posts-per-month.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'alloyteam.com' | |
# -*- coding: UTF-8 -*- | |
import urllib.request | |
import re | |
class Spider: | |
def __init__ (self, pageStartNum, pageEndNum, year, monthStart, monthEnd, sortOutput) : |
View randomArray.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
View openWindowByUrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 打开一个新的页面 | |
* @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"); |
View isEnglish.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断置顶字符是否为英文 | |
* @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; |
View isChinese.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断置顶字符是否为中文 | |
* @method isChinese | |
* @param {String} s | |
* @return {Boolean} | |
*/ | |
isChinese: function(s) { | |
//4E00 - 9FA5 | |
var code = ('' + s).charCodeAt(0); | |
if (code >= 0x4E00 && code <= 0x9FA5) { |
View pattern-decorator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
View pattern-factory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ===== 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 |
NewerOlder