Skip to content

Instantly share code, notes, and snippets.

View hfknight's full-sized avatar

fei.io hfknight

View GitHub Profile
@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: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: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: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 / css-layout-debugger
Last active August 29, 2015 14:14
visualizing your CSS layouts
[].forEach.call($$("*"),function(a){
a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})
// from https://gist.github.com/addyosmani/fd3999ea7fce242756b1
/* using svg as a background-image */
.my-element {
background-image: url(image.svg);
}
.no-svg .my-element {
background-image: url(image.png);
}
.my-element {
background-image: url(fallback.png);
@hfknight
hfknight / gist:ec9b37ac6093c40b25a3
Created March 23, 2015 14:49
Flex Box CSS for All Browers
.flex-container {
height: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-direction: normal;
-moz-box-direction: normal;
@hfknight
hfknight / gist:1ae7e6ea671012fef9cc
Created June 2, 2015 19:41
EnableTouch(Active) State Support on iOS Safari
window.onload = function() {
if(/iP(hone|ad)/.test(window.navigator.userAgent)) {
document.body.addEventListener('touchstart', function() {}, false);
}
};
/* or add ontouchstart="" in element attributes */
@hfknight
hfknight / gist:3968493158935eb60894
Created July 20, 2015 15:08
SVG edge cut off in Firefox
add attribute overflow="visible" to <svg>
/* aslo add to sprint file if using that */
run curl -L https://www.npmjs.com/install.sh | sh