Skip to content

Instantly share code, notes, and snippets.

View lanqy's full-sized avatar
🎯
Focusing

Lan Qingyong lanqy

🎯
Focusing
  • Shenzhen,China
View GitHub Profile
@lanqy
lanqy / randomMobileNum.js
Created March 28, 2013 03:06
随机生成20w号码
var mobiles = [];
for (var i = 0; i < 200000; i++) {
mobiles[i] = (13000000000 + Math.floor(Math.random() * 1000000000)).toString();
}
其他单位 秒
1 分 60 秒
1 小时 3600 秒
1 天 86400 秒
1 周 604800 秒
1 月 (30.44 天) 2629743 秒
1 年 (365.24 天) 31556926 秒
@lanqy
lanqy / gist:5625051
Created May 22, 2013 03:27
special characters
var speicalChar = /[^\w\s]/gi; // special characters
if(speicalChar.test(str)){
// do something
}
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
@lanqy
lanqy / gist:5982869
Created July 12, 2013 08:42
判断浏览器及版本
// form http://stackoverflow.com/questions/5916900/detect-version-of-browser
navigator.userBrowser = (function(){
var N= navigator.appName, ua= navigator.userAgent, tem;
var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?'];
return M;
})();
@lanqy
lanqy / gist:6067881
Created July 24, 2013 03:31
Lazy Function Definition Pattern
//Lazy Function Definition Pattern
// form http://michaux.ca/articles/lazy-function-definition-pattern
var getScrollY = function () {
if (typeof window.pageYOffset == 'number') {
getScrollY = function () {
return window.pageYOffset;
};
} else if ((typeof document.compatMode == 'string') && (document.compatMode.indexOf('CSS') >= 0) && (document.documentElement) && (typeof document.documentElement.scrollTop == 'number')) {
getScrollY = function () {
// from http://qiita.com/Oakbow/items/3374175d76d82792134d
(function () {
if (!("indexOf" in Array.prototype)) {
Array.prototype.indexOf = function (find, i) {
var n;
if (i === undefined) i = 0;
if (i < 0) i += this.length;
if (i < 0) i = 0;
n = this.length;
@lanqy
lanqy / api.js
Created October 19, 2013 05:06 — forked from fwielstra/api.js
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end