Skip to content

Instantly share code, notes, and snippets.

View hfknight's full-sized avatar

fei.io hfknight

View GitHub Profile
@hfknight
hfknight / gist:8c616abe8650cc1d0d38
Created November 19, 2014 18:18
Prevent iOs from zooming onfocus
/* setting the font-size to 16px. (or better, by using the browser’s default font-size). */
input[type='text'],
input[type='number'],
textarea {
font-size: 16px;
}
@hfknight
hfknight / gist:4b04cb0c70a6a62e7b10
Created September 15, 2014 04:20
leetcode - permutation sequence
public String getPermutation(int n, int k) {
if (n <= 0 || k <= 0)
return "";
// can't use array because we need remove item each time
// create the number array
int mod = 1;
ArrayList<Integer> nl = new ArrayList<Integer>();
for (int i = 1; i <= n; i++) {
nl.add(i);
mod *= i; // calculate n!
@hfknight
hfknight / gist:777f4b00bc045837e02f
Last active August 29, 2015 14:06
leetcode - gas station
public int canCompleteCircuit(int[] gas, int[] cost) {
int[] remain = new int[gas.length];
for (int i = 0; i < remain.length; i++) {
int j = i;
boolean canComp = true;
int capt = 0;
do {
capt += gas[j] - cost[j];
@hfknight
hfknight / gist:decfc1e5934b350b8389
Last active August 29, 2015 14:01
Apache HTTP Server: password authentication
1. htpasswd -c /usr/local/apache/passwd/passwords <username1>
htpasswd /usr/local/apache/passwd/passwords <username12>
2. httpd.conf, add the following inside <Directory ....> section
AuthType Basic
AuthName "<Authentication Realm>"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
#Require user <username>
@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; }
@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: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: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: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:7311069
Last active December 27, 2015 10:28
中文网页字体设置
font-family: … "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
/* 中文字体之前的「…」代表西文字体 */