Skip to content

Instantly share code, notes, and snippets.

@weishuaiwang
weishuaiwang / get_uri_params.php
Created October 29, 2012 02:36
Get uri params
function get_uri_params( $default = 'page', $uri = array() )
{
$uri = empty($uri) ? $_GET : $uri;
if (is_array($default)) {
foreach ($default as $value) {
unset( $uri[$value] );
}
} else {
unset( $uri[$default] );
}
@weishuaiwang
weishuaiwang / pagination_helper.php
Created October 29, 2012 02:41
PHP Pagination
<?php
/*
$params['total_rows'] = 100;
$params['page'] = isset($_GET['page']) ? $_GET['page'] : 1;
$params['type'] = get_uri_params();
$params['per_page'] = 10;
echo pagination( $params );
*/
function pagination( $params )
@weishuaiwang
weishuaiwang / jQuery-plugin-template.js
Created November 26, 2012 09:52
jQuery plugin template
// Shawn Khameneh
// ExtraordinaryThoughts.com
(function($) {
var privateFunction = function() {
// 执行代码
}
var methods = {
init: function(options) {
@weishuaiwang
weishuaiwang / Number.prototype.js
Created November 28, 2012 01:49
Number.prototype
//addition
Number.prototype.add = function(arg){
var r1,r2,m;
try{r1=this.toString().split(".")[1].length}catch(e){r1=0}
try{r2=arg.toString().split(".")[1].length}catch(e){r2=0}
m=Math.pow(10,Math.max(r1,r2))
return (this*m+arg*m)/m
}
//substruction
@weishuaiwang
weishuaiwang / php-multi-thread.php
Created December 3, 2012 01:06
PHP multi-thread
<?php
/**
* @title: PHP多线程类(Thread)
* @version: 1.0
* @author: phper.org.cn < web@phper.org.cn >
* @published: 2010-11-2
*
* PHP多线程应用示例:
* require_once 'thread.class.php';
* $thread = new thread();
@weishuaiwang
weishuaiwang / php-secure-password.php
Created December 3, 2012 02:37
Generate random passwords that are highly secure
<?php
/**
* Generate random passwords that are highly secure
*
* @return string
* @param $level 1:easy 2:Normal 3:Hard
* @author
**/
function generatePassword($length = 6, $level = 2){
list($usec, $sec) = explode(' ', microtime());
@weishuaiwang
weishuaiwang / base64-utf8-utf16.js
Created December 6, 2012 04:03
Convert utf8 to utf16 and reverse
var base64 = {};
(function(exports) {
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
function base64encode(str) {
var out, i, len;
var c1, c2, c3;
len = str.length;
i = 0;
@weishuaiwang
weishuaiwang / QR-php.php
Created December 7, 2012 06:17
Generate QR using PHP
class qrcode {
private $data;
//creating text qr code
public function text($text){
$this->data = $text;
}
//creating code with link mtadata
public function link($url){
@weishuaiwang
weishuaiwang / MysqlDb.php
Created December 10, 2012 06:11
PHP Mysql Database Class
<?php
class MysqlDB {
protected $_mysql;
protected $_where = array();
protected $_query;
protected $_paramTypeList;
protected $_crudType = null;
@weishuaiwang
weishuaiwang / Number.js
Created December 10, 2012 06:13
Number.prototype add + sub + mul + div
//addition
Number.prototype.add = function(arg){
var r1,r2,m;
try{r1=this.toString().split(".")[1].length}catch(e){r1=0}
try{r2=arg.toString().split(".")[1].length}catch(e){r2=0}
m=Math.pow(10,Math.max(r1,r2))
return (this*m+arg*m)/m
}
//substruction