Skip to content

Instantly share code, notes, and snippets.

View GerBawn's full-sized avatar

GerBawn GerBawn

  • shenzhen, guangzhou
View GitHub Profile
@GerBawn
GerBawn / captcha.php
Created March 30, 2015 11:47
create an captcha
<?php
session_start();
function createCaptcha(){
$image = imagecreatetruecolor(100, 30);
$bgColor = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bgColor);
$captcha = '';
for($i = 0; $i < 4; $i++){
$fontSize = 6;
$fontColor = imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155));
@GerBawn
GerBawn / ImageWaterMark.class.php
Created March 31, 2015 16:10
An class to create watermark or make thumb
<?php
/**
* Created by PhpStorm.
* User: Ger
* Date: 2015/3/31
* Time: 20:54
*/
class ImageWaterMark {
@GerBawn
GerBawn / MyMail
Last active August 29, 2015 14:25
使用socket与smtp服务器进行通信,进而发送邮件
<?php
/**
*使用socket与smtp服务器通信,进而发送邮件
* @author GerBawn <[email protected]>
* @version 1.0
* @Last Modified 2015/07/18
*/
class MyMail{
/**
@GerBawn
GerBawn / arrow_bubble.css
Created August 1, 2015 02:20
A speech bubble with arrow
.bubble{
position: relative;
background-color: #292929;
width: 200px;
height: 150px;
/*line-height: 150px;*/
color: white;
display: table;
text-align: center;
border-radius: 10px;
@GerBawn
GerBawn / transformHtml.php
Created August 11, 2015 07:32
转换HTML,防止XSS攻击
<?php
function transformHTML($string, $length = null) {
// Helps prevent XSS attacks
// 去除多余空白.
$string = trim($string);
// 同意转为utf8编码
$string = utf8_decode($string);
$string = htmlentities($string, ENT_NOQUOTES);
$string = str_replace("#", "&#35;", $string);
@GerBawn
GerBawn / makeSelectQueriesToLoad.sql
Created August 11, 2015 09:48
产生select语句用于数据预热
SELECT DISTINCT
CONCAT('SELECT ',ndxcollist,' FROM ',db,'.',tb,
' ORDER BY ',ndxcollist,';') SelectQueryToLoadCache
FROM
(
SELECT
engine,table_schema db,table_name tb,
index_name,GROUP_CONCAT(column_name ORDER BY seq_in_index) ndxcollist
FROM
(
@GerBawn
GerBawn / reset.css
Created August 12, 2015 03:01
重置所有样式
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@GerBawn
GerBawn / downloadFile.php
Created August 13, 2015 01:35
download something from Internet
<?php
function downloadFile($url, $saveName){
set_time_limit(0);
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
@GerBawn
GerBawn / download.php
Created August 20, 2015 03:36
php提供文件下载
<?php
$file = "/tmp/dummy.tar.gz";
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-Length: ". filesize($file));
readfile($file);
?>
@GerBawn
GerBawn / mcrypt.php
Created September 23, 2015 01:32
des加密
<?php
/**
* Created by PhpStorm.
* User: tew
* Date: 2015/9/23
* Time: 9:32
*/
class mcrypt{
public static $key = '7fdc4b8e';
public static function encode($text){