Skip to content

Instantly share code, notes, and snippets.

View welefen's full-sized avatar

welefen

View GitHub Profile

结果

isNumericByRegExp x 1,316,572 ops/sec ±1.16% (87 runs sampled)
isNumeric x 525,836 ops/sec ±1.34% (85 runs sampled)
Fastest is  isNumericByRegExp

测试代码

#!/bin/sh
#Here's a little one liner that'll do the trick (for passwordless auth) after you've done the ssh-keygen -d:
#how to use: /skey forum@zjm-forum-test10.zjm
if [ $# -lt 1 ]; then
echo "usage: $0 <username@host>"
echo " i.e.: $0 welefen@www.welefen.com"
echo
@welefen
welefen / gist:447dffb497fb4260e67b
Created October 20, 2014 10:48
Node.js里转码
var iconvLite = require('iconv-lite');
global.convertEncoding = function(str, encoding){
encoding = encoding || 'utf8';
if (encoding === 'utf8') {
return iconvLite.decode(new Buffer(str, 'binary'), 'gb2312');
}else{
return iconvLite.encode(str, 'gb2312').toString('binary');
}
};
@welefen
welefen / gist:4ce5a1edf89bbcf9cf54
Last active April 20, 2018 04:37
js实现php里的rawurlencode和urlencode
function rawurlencode(str) {
str = (str+'').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}
@welefen
welefen / gist:9889394
Created March 31, 2014 10:22
thinkjs里的继承
/**
* 动态创建一个类
* 提供了继承、扩展、调用父级别方法等方法
* @return {[type]} [description]
*/
global.Class = function (prop) {
var cls = function () {
function T(args) {
if(typeof this.init === 'function'){
@welefen
welefen / gist:9889357
Created March 31, 2014 10:18
delegates
/**
* 基于配置的事件代理
* @param {[type]} configs [description]
* @return {[type]} [description]
*/
$.fn.delegates = function(configs) {
el = $(this[0]);
for (var name in configs) {
var value = configs[name];
if (typeof value == 'function') {
@welefen
welefen / gist:8516854
Created January 20, 2014 08:39
判断是否是数字的正则
var numberReg = /^((\d*\.?\d*(?:e[+-]?\d*(?:\d?\.?|\.?\d?)\d*)?)|(0[0-7]+)|(0x[0-9a-f]+))$/i
@welefen
welefen / gist:8514282
Created January 20, 2014 03:08
获取2个日期之间的月份列表
<?php
$fromYear = 2013;
$fromMonth = 10;
$endYear = 2015;
$endMonth = 5;
$months = ($endYear - $fromYear) * 12 + $endMonth - $fromMonth;
for($i=-1;$i<$months;$i++){
@welefen
welefen / gist:7746175
Last active January 6, 2020 08:53
php判断文件编码和检测文件是否有UTF-8头信息
<?php
/**
* 获取内容的编码
* @param string $str
*/
function get_encoding($str = "") {
$encodings = array (
'ASCII',
'UTF-8',
@welefen
welefen / gist:6932225
Last active December 25, 2015 06:29
建立css选择器的压缩字典
function getDict(length, prefix){
length = length || 1;
prefix = prefix || "";
var chars = "abcdefghijklmnopqrstuvwxyz".split("");
var result = [];
chars.forEach(function(char){
result.push(prefix + char);
if(length>1){
result.push.apply(result, getDict(length - 1, char));
}