Skip to content

Instantly share code, notes, and snippets.

View hfknight's full-sized avatar

fei.io hfknight

View GitHub Profile
@hfknight
hfknight / gist:5707408
Created June 4, 2013 16:36
Customize Tomcat Directory Listings
1. in tomcat/conf/server.xml, add the directory to appBase paramter in Host section
<Host name="test.example.com" appBase="/mnt/example" autoDeploy="true" reloadable="true">
2. in the listing directory, add WEB-INF/ folder, add web.xml in WEB-INF w/ the following:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
@hfknight
hfknight / gist:5901593
Created July 1, 2013 14:59
workaround for $.browser.msie and $.browser.version on jQuery 1.9.x, but exclusively for detecting IE.
jQuery.browser={};(function(){jQuery.browser.msie=false;
jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)\./)){
jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();
@hfknight
hfknight / gist:6308261
Last active December 21, 2015 12:49
Prevent Animation jerky in webkit based browsers (Safari and etc.)
Webkit flicks if the element you want to animate is bigger than the screen.
The Fix:
Add these two properties to prevent flickering effects:
-webkit-transform: translateZ(0);
-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;
Reference: http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
@hfknight
hfknight / gist:7216085
Created October 29, 2013 14:50
JS: Close Element by clicking anywhere on page
$('#element-need-show').click(function(e){
e.stopPropagation();
});
$("#link-for-popup").click(function(e) {
e.preventDefault();
e.stopPropagation();
$('#element-need-show').show();
});
$(document).click(function() {
$('#element-need-show').hide();
@hfknight
hfknight / gist:7311069
Last active December 27, 2015 10:28
中文网页字体设置
font-family: … "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
/* 中文字体之前的「…」代表西文字体 */
@hfknight
hfknight / gist:7359574
Created November 7, 2013 18:34
Calculate MySQL DB Size
SELECT table_schema "Data Base Name", SUM( data_length + index_length) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
@hfknight
hfknight / gist:7629280
Created November 24, 2013 16:49
Quick Fix for Wordpress Visual Editor blank / not working
if you open browser development tool's console and find some javascript errors like "switchEditors is undefined" or "jquery is undefined", It appears that the new version of WordPress has some new performance optimisation features that concatenate all JavaScript resources into a single request.
Solution: put the following two lines of codes in wp-config.php:
define('CONCATENATE_SCRIPTS', false);
define('SCRIPT_DEBUG', true);
@hfknight
hfknight / gist:8477707
Created January 17, 2014 17:34
Rsync Files between Amazon EC2 Instances
rsync -rav --progress "ssh -i KEY-PAIR.ppk" /mnt/temp/ root@another-instance-ip-addr:/mnt/temp/
@hfknight
hfknight / gist:9814504
Last active August 29, 2015 13:57
Apache Access Log Unique Request Statistics
cat *.txt |grep "YOUR_FILTER"|grep -vi "EXCLUDE_FILTER"|cut -d\" -f2|awk '{print$2}'|sort|uniq -c|sort -nr > report.log
Example:
cat report.log | grep -vi ".css\|.js\|.woff\|.eot\|.ttf\|.jpg\|.gif\|.png\|.ico" |grep -vi "wp-login.php\|wp-cron.php\|wp-admin\|robots.txt" | cut -d\" -f2|awk '{print$2}'|sort|uniq -c|sort -nr
@hfknight
hfknight / gist:9819528
Created March 27, 2014 21:34
Drop Caps (First Letter CSS Style)
p:first-child:first-letter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }