Skip to content

Instantly share code, notes, and snippets.

View shelwinnn's full-sized avatar
😄

Shelwin Wei shelwinnn

😄
View GitHub Profile
<?php
/**
* 加密 hash,生成发送给用户的 hash 字符串
*
* @param array $hash_data
* @param string $hash_key
* @return string
*/
function encode_hash($hash_data, $hash_key = false)
@shelwinnn
shelwinnn / mysql_if_case_when.sql
Last active August 29, 2015 14:01
mysql sql use if,case when
SELECT
Article_Detail_ID,
CASE find_in_set(aa.Alert_Source, 'O,A')
WHEN find_in_set(aa.Alert_Source, 'O,A') > 1 THEN
aa.Subject_ID
WHEN find_in_set(aa.Alert_Source, 'O,A') > 2 THEN
99
ELSE
0
END AS Subject_ID,
@shelwinnn
shelwinnn / mysql_function_exec_sql.sql
Created May 29, 2014 09:48
mysql 中函数或存储过程中动态执行sql
CREATE DEFINER=`root`@`%` FUNCTION `fn_sms_get_content`(`Article_Detail_ID_In` int,`Subject_ID_In` int, `Template_Type_In` CHAR(1)) RETURNS longtext CHARSET utf8
BEGIN
DECLARE Content_Out LONGTEXT DEFAULT '';
DECLARE Where_Condition VARCHAR(1000);
DECLARE Sql_Str VARCHAR(3000);
SET Where_Condition = CONCAT(CONCAT(' AND Article_Detail_ID=', Article_Detail_ID_In), CONCAT(" AND Template_Type=", Template_Type_In));
IF Subject_ID_In !=0 THEN
Where_Condition = CONCAT(Where_Condition, CONCAT(' AND Subject_ID=', Subject_ID_In));
ELSE
@shelwinnn
shelwinnn / imouto.hosts
Created June 11, 2014 01:36
imouto.hosts
#+BEGIN
#+UPDATE_TIME 2014-06-05 17:00:00
#+MESSAGE
#######################################################################
#
# imouto.host
#
# #Ver : 1.68.0371 Myuseru foaran
# #Update Time : 2014.06.05;17:00
# #Fix & Bug : 请参阅imouto.host.Readme.txt
@shelwinnn
shelwinnn / php_md5.php
Last active August 29, 2015 14:02
php md5
<?php
$str = mb_convert_encoding($str, 'utf-16LE', 'utf8');
echo md5($str);
@shelwinnn
shelwinnn / md5_file.py
Created June 19, 2014 02:10
md5 for file
#-*- coding: UTF-8 -*-
import sys
import hashlib
def md5_file(filepath, raw_output=False, block_size=2*20):
md5 = hashlib.md5()
f = open(filepath, 'rb')
while True
content = f.read(block_size)
if not content:
@shelwinnn
shelwinnn / urlparam.js
Last active August 29, 2015 14:03
url params
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results ? results[1] : false;
}
@shelwinnn
shelwinnn / get_all_methods
Last active August 29, 2015 14:04
get all methods from a class
<?php
function getAllMethods($className){
$class = new ReflectionClass($className);
$methods = $class->getMethods();
foreach($methods as $k=>$method){
//method type
if($method->isAbstract()){
$methods[$k]->type = 'abstract';
}else if($method->isFinal()){
// expires方法的参数是以秒为单位的,其他的方法跟localStorage的相同
// 方法有:getItem/setItem/removeItem/clear/expires
// 30秒后过期
storage.setItem("test","hello world").expires(30);
storage.setItem("test","hello world");
storage.expires(30);
// clear全部由storage创建的localStorage
@shelwinnn
shelwinnn / gist:b3a13eefbf4a3bfb4308
Last active August 29, 2015 14:26 — forked from romainneutron/gist:5340930
Download large files using Guzzle
<?php
use Guzzle\Http\Client;
require __DIR__ . '/vendor/autoload.php';
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download');
$handle = fopen($tmpFile, 'w');
$client = new Client('', array(
Client::CURL_OPTIONS => array(