Skip to content

Instantly share code, notes, and snippets.

View jorben's full-sized avatar
:fishsticks:

脚本哥 jorben

:fishsticks:
View GitHub Profile
@jorben
jorben / password_level.js
Created April 9, 2014 06:43
分三级区分密码强度
/**
* 密码强度等级验证
*/
function valid_strong_password (password) {
if (password.length < 6 || parseInt(password) == password || /^[a-zA-Z]+$/.test(password) || /^[^a-zA-Z0-9]+$/.test(password)) {
return 0;
}
if (/^.{6,7}$/.test(password) || !/[0-9]/.exec(password) || !/[a-z]/.exec(password) || !/[A-Z]/.exec(password)) {
return 1;
@jorben
jorben / FPOperation.js
Created April 11, 2014 05:24
javascript 浮点数操作出各种问题,比如0.1+0.2结果不等于0.3。而toFixed方法似乎也不是严格遵循四舍六入五留双,比如0.295.toFixed(2)的结果不是0.30
/**
* FPOperation: 浮点数操作
* 优点:自动计算原数据精确位数
* @param {Number} x
* @param {Number} y
* @param {String} operator
**/
function FPOperation(x, y , operator) {
if (!operator) {
return ;
@jorben
jorben / sem_wait.c
Last active August 29, 2015 14:00
信号量实现的互斥锁,示例中有且只有一个进程能获得锁,并设置SEM_UNDO在进程异常时自动释放锁,避免因为进程异常而死锁。
// 创建/打开 只允许一个进程进行P操作的信号量,并等待它
static bool s_wait_sem()
{
const key_t SEM_KEY = 0xA001FFFF;
int semid = semget(SEM_KEY, 1, IPC_CREAT|IPC_EXCL|0666);
if (semid >= 0)
{
// 计算机重启后,首次启动进程
@jorben
jorben / auto_increase.js
Last active August 6, 2018 01:20
闭包实现 自增计数
var auto_increase = function(){
var id=0;
return function(){return ++id;}
}();
// 1
auto_increase();
// 2
auto_increase();
// ...
@jorben
jorben / some_shit.js
Created July 15, 2014 08:23
JAVASCRIPT的一些坑
// 坑一、js的基本类型有那些?
number string boolean object null undefined
typeof null //===>"object"
//这只能说是最初的JavaScript实现的bug,而现在标准就是这样规范的.
//V8曾经修正并实现过typeof null=== "null",但最终证明不可行.http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null
// 坑二、NaN isNaN
isNaN('a') //===>true
isNaN('09') //===>false
@jorben
jorben / comm.h
Last active December 3, 2015 09:59
c++常用小工具方法集
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
@jorben
jorben / select_server.c
Last active November 12, 2015 10:37
tcp select模型服务端示例
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
@jorben
jorben / git_toturial
Created November 27, 2015 02:15 — forked from guweigang/git_toturial
git命令大全
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "xxx@xxx.com" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://git@192.168.53.168/VT.git # clone远程仓库
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>