Skip to content

Instantly share code, notes, and snippets.

View jk2K's full-sized avatar
💭
I may be slow to respond.

Meng Ye jk2K

💭
I may be slow to respond.
View GitHub Profile
@jk2K
jk2K / gist:9636804
Last active August 29, 2015 13:57
测试文件夹是否可写
function dir_writeable($dir) {
$writeable = 0;
if(!is_dir($dir)) {
@mkdir($dir, 0777);
}
if(is_dir($dir)) {
if($fp = @fopen("$dir/test.txt", 'w')) {
@fclose($fp);
@unlink("$dir/test.txt");
$writeable = 1;
@jk2K
jk2K / gist:9636889
Created March 19, 2014 07:16
验证邮箱是否正确
function isemail($email) {
return strlen($email) > 6 && strlen($email) <= 32 && preg_match("/^([A-Za-z0-9\-_.+]+)@([A-Za-z0-9\-]+[.][A-Za-z0-9\-.]+)$/", $email);
}
@jk2K
jk2K / gist:9636901
Created March 19, 2014 07:18
格式化文件大小
function size_format( $bytes, $decimals = 0 ) {
$quant = array(
// ========================= Origin ====
'TB' => 1099511627776, // pow( 1024, 4)
'GB' => 1073741824, // pow( 1024, 3)
'MB' => 1048576, // pow( 1024, 2)
'kB' => 1024, // pow( 1024, 1)
'B ' => 1, // pow( 1024, 0)
);
foreach ( $quant as $unit => $mag )
@jk2K
jk2K / auto_post_to_github.bat
Last active August 29, 2015 14:01
windows批处理:自动发布代码到github automatically post to github
::方便调试set cur_path = %cd%
e:
cd e:\www\CGBT2
git checkout gh-pages
php e:\www\newcgbt_release\v2.0\tools\db_dict_generator.php
move C:\Users\Lee\Desktop\db_dict.html e:\www\CGBT2
git add db_dict.html
git commit -am "generate database dict, %date:~0, 10%"
git push origin gh-pages
git checkout master
@jk2K
jk2K / import_to_fengche.py
Created May 20, 2014 10:40
自动将txt文本里的内容发布到fengche代办中
# coding=utf-8
from urllib import request
from urllib import parse
from http import cookiejar
username = 'your_username'
password = 'your_password'
login_url = 'https://fengcheco.com/auth/identity/callback'
project_id = 'your_project_id'
iteration_id = 'your_iteration_id'
@jk2K
jk2K / bulk_recount_usercredit.php
Created May 27, 2014 07:33
批量重新计算discuz用户积分
<?php
require './source/class/class_core.php';
$discuz = & discuz_core::instance();
$discuz->init();
$credit = & credit::instance();
$sql = 'select uid from ' . DB::table('common_member');
$users = DB::fetch_all($sql);
//重新计算用户积分
@jk2K
jk2K / chunzhen_ip.php
Created May 28, 2014 05:48
PHP利用纯真IP数据库获取地址信息,代码转载自:PHP爱好者 [http://www.joyphper.net/]
<?php
/**
* IP 地理位置查询类
*
* @author joyphper
* @version 1.0
* @copyright 2010 joyphper.net
*/
@jk2K
jk2K / netpayclient.php
Last active August 29, 2015 14:12
chinapay向上兼容php5.5
<?php
define("DES_KEY", "SCUBEPGW");
define("HASH_PAD", "0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff003021300906052b0e03021a05000414");
bcscale(0);
$private_key = array();
if (!function_exists('hex2bin'))
{
function hex2bin($hexdata)
{
$bindata = '';
@jk2K
jk2K / github_post_recieve.php
Created September 21, 2015 08:31 — forked from cowboy/github_post_recieve.php
GitHub PHP webhook to auto-pull on repo push
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ( $_POST['payload'] ) {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull 2>& 1' );
echo 'success';
}
@jk2K
jk2K / DividerItemDecoration.java
Created November 10, 2015 08:53
android RecyclerView ItemDecoration class
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**