Skip to content

Instantly share code, notes, and snippets.

View kevin-shu's full-sized avatar

Kevin Shu kevin-shu

  • Apple Buds, Inc.
  • Taiwan
View GitHub Profile
function ranking(elem, index) {
if (index>=0 && index<5113) {
elem._src.rank = 1;
} else if (index>=5113 && index<10226) {
elem._src.rank = 2;
} else if (index>=10226 && index<25566) {
elem._src.rank = 3;
} else {
elem._src.rank = 4;
}
# In Helper
module MetaHelper
def meta_tag type
if type==1
return "<meta name='keywords' content='HTML,CSS,XML,JavaScript'>"
elsif type==2
return "<meta name='keywords' content='HTML,CSS,XML,JavaScript'>"
else
return "<meta name='keywords' content='HTML,CSS,XML,JavaScript'>"
end
INSERT INTO SYS_SKILLS
(name, sys_category_id)
value
(x,y),
(x,y),
(x,y),
(x,y),
(x,y),
(x,y)
....
function formToData(dom) {
var _this=this,
_i,
data;
if(dom){
_this=dom;
}
fields = _this.querySelectorAll("input, textarea, select");
for(_i=fields.length-1; i>=0; _i--){
var _key = fields[_i].name||fields[_i].id;
@kevin-shu
kevin-shu / currying
Last active December 16, 2015 21:38
function currying(fn) {
var store_args = Array.prototype.slice.call(arguments,1);
return function () {
args = store_args.concat(Array.prototype.slice.call(arguments));
return fn.apply(null, args);
};
}
#controller這樣寫:
class ConsultantController << ApplicationController
# routing: post "consultant/create" => "consultant#create"
def create
Consultant.create params[:consultant]
end
end
#view這樣寫:
<form action="/consultant/create" method="post">
@kevin-shu
kevin-shu / gist:5523194
Created May 6, 2013 03:20
Client-side resizing example
<html>
<head>
<title>Client-side resizing example</title>
</head>
<body>
<input id="file-uploader" type="file"/>
<!-- <p>Image to use:</p>
<img id="cat" src="./cat.jpg" alt="The Scream" > -->
.lb-conter a{
color:#288bac;
text-decoration:underline;
}
.lb-conter a:hover{
color:rgb(0, 153, 204);
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
# NEW WAY / EASY WAY
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
sudo dpkg -i elasticsearch-0.20.6.deb
cart = []
session[:cart].each do |key, value|
cart.push {product_id:key, amount:value}
end
Order.create cart