Skip to content

Instantly share code, notes, and snippets.

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

会有猫的 gonejack

💭
I may be slow to respond.
View GitHub Profile
@gonejack
gonejack / appendQuery.js
Created March 14, 2016 02:26
append query parameters to URL
function (url, name, value) {
if (url) {
var parser = document.createElement('a');
parser.url = url;
return url + [(parser.search ? '&' : '?'), name, '=', value].join('');
}
else {
return '';
}
@gonejack
gonejack / ObjectCompareFunc.js
Last active February 25, 2016 08:30
recursive compare
function recursiveCompare(a, b) {
if (!(a instanceof Object) && !(b instanceof Object)) {
return a === b;
}
else if (a instanceof Array && b instanceof Array) {
for (var i = 0, l = a.length; i < l; i++) {
if (recursiveCompare(a[i], b[i]) === false) {
return false;
}
<?php
/**
* Created by PhpStorm.
* User: Youi
* Date: 2015-12-05
* Time: 02:47
*/
// buffer all upcoming output
ob_start();
<?php
/**
* Convert bytes to human readable format
*
* @param integer bytes Size in bytes to convert
* @return string
*/
function bytesToSize($bytes, $precision = 2)
{
@gonejack
gonejack / trim_for_chinese.php
Last active November 14, 2015 13:54
trim function for Chinese space characters
<?php
$s = preg_replace('^(([ \r\n\t])*( )*)*', '', $s);
$s = preg_replace('(([ \r\n\t])*( )*)*$', '', $s);
@gonejack
gonejack / blocked.txt
Last active November 14, 2015 01:58
COW blocked.txt
google.com
youtube.com
google.com.hk
googleusercontent.com
googleapis.com
googlesyndication.com
google-analytics.com
googlevideo.com
gstatic.com
ggpht.com
//task killer
taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]
@gonejack
gonejack / get_redirect_location.php
Last active October 31, 2015 14:22
PHP get URL redirect location
<?php
function get_redirect_url($url) {
stream_context_set_default(array(
'http' => array(
#'method' => 'HEAD',
'request_fulluri' => true,
'proxy' => 'tcp://127.0.0.1:1080'
)
));
x+'' //convert to string
+x //convert to number
!!x //convert to boolean
//generate short random string
Math.random().toString(36).slice(-5)
//generate random ports
((Math.random() + 1) / 2 * 65535).toString().slice(0, 5)
undefined
null
0
-0
NaN
''(empty string)