Skip to content

Instantly share code, notes, and snippets.

@blessdyb
blessdyb / php_auth.php
Created July 7, 2014 08:05
Several php authentication security method
function md5_auth() {
$current_time = time();
$hash_str = join("", array(MD5_SALT_KEY, $current_time));
return array(
'current_time' => $current_time,
'token' => base64_encode(md5($hash_str)),
);
}
@blessdyb
blessdyb / CSS-Mixin-Less.less
Created February 20, 2014 05:42
CSS Mixin in LESS
.opacity (@opacity) {
@opacityPercentage: @opacity * 100;
opacity: @opacity;
-ms-filter: ~"progid:DXImageTransform.Microsoft.Alpha(opacity=(@{opacityPercentage}))";
filter: ~"alpha(opacity = (@{opacityPercentage}))";
}
.border-radius(@radius) {
border-radius: @radius;
-moz-border-radius: @radius;
@blessdyb
blessdyb / .jshintrc
Created November 15, 2013 15:24
JSHint Default Configuration
{
"curly": true,
"camelcase": true,
"undef": true,
"unused": true,
"eqeqeq": true,
"freeze": true,
"immed": true,
"indent": 4,
"latedef": true,
@blessdyb
blessdyb / casper-scraper.js
Created November 14, 2013 13:14
Use Casper to scrap web page.
var utils = require('utils');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
}
});
@blessdyb
blessdyb / tree-node-generator.html
Last active December 28, 2015 03:09
Create a Infinite Tree Node with JSON
<!doctype html>
<html>
<head>
<title>Tree Node</title>
</head>
<body>
<script src="javascript/vendor/jquery-1.7.2.min.js"></script>
<script src="javascript/vendor/mustache-0.7.2.js"></script>
<script src="javascript/vendor/underscore-min.js"></script>
<style>
@blessdyb
blessdyb / get-location-search-by-value.js
Last active December 21, 2015 08:49
Get url parameters value by name
//http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
getParameterByName: function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
@blessdyb
blessdyb / fibonacci.js
Created August 3, 2013 06:37
3 methods for get fibonacci list element
#!/usr/bin/env node
/*
use node fibonacci num in terminal to get fibonacci list element
*/
var fibonacci1 = function(n) {
if (n < 1) {
return 0;
} else if (n === 1 || n ===2) {
return 1;
} else if (n > 2) {
@blessdyb
blessdyb / common.css
Last active December 18, 2015 00:29
A common css file including normalize and reset css
@import 'https://github.com/necolas/normalize.css/blob/master/normalize.css'
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
@blessdyb
blessdyb / gist:1305740
Created October 22, 2011 07:22 — forked from Psli/gist:938931
Ruby / Rails Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@blessdyb
blessdyb / encode2gb2312.js
Created October 5, 2011 02:35 — forked from lemonhall/encode2gb2312.js
非常特殊的GB2312/GBK 的URIencode函数
function encodeToGb2312(str){
var strOut="";
for(var i = 0; i < str.length; i++){
var c = str.charAt(i);
var code = str.charCodeAt(i);
if(c==" ") strOut +="+";
else if(code >= 19968 && code <= 40869){
index = code - 19968;
strOut += "%" + z.substr(index*4,2) + "%" + z.substr(index*4+2,2);
}