Skip to content

Instantly share code, notes, and snippets.

View kaochenlong's full-sized avatar
🖐️
World Peace!

Eddie Kao kaochenlong

🖐️
World Peace!
View GitHub Profile
require 'net/http'
require 'json'
require 'erb'
class Webpage
def call(env)
locations = get_ubike
content = ERB.new(File.read("map.html"))
[200, {'Content-Type' => 'text/html'}, [content.result(binding)]]
end
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Complex icons</title>
<style>
html, body {
height: 100%;
margin: 0;
require 'net/http'
require 'json'
class Webpage
def call(env)
content = File.read("map.html").gsub("{{locations}}", get_ubike)
[200, {'Content-Type' => 'text/html'}, [content]]
end
private
def add_zero(n, digit = 0)
"#{"0" * digit}#{n}"[-digit..-1]
end
puts add_zero(3, 5) #=> 00003
puts add_zero(13, 8) #=> 00000013
puts add_zero(43, 10) #=> 0000000043
@kaochenlong
kaochenlong / block.rb
Last active January 30, 2016 10:18
Ruby block demo
greeting_and_do_something = Proc.new do |message|
puts "Hello, #{message}"
yield(message) if block_given?
puts "wish you have a good time"
message
end
# callback demo
def trainingWithCompletion(&block)
puts "training begin..."
@kaochenlong
kaochenlong / mm.rb
Created January 7, 2016 14:03
Module test
module Cc
def hello
world
end
def world
puts "world"
end
end
week 01 環境設定 + 第一個 Rails 應用程式
week 02 HTML/CSS + 終端機指令
week 03 用 Git 來控制你的人生
week 04 Ruby for Rails, MVC
week 05 View + Twitter Bootstrap
week 06 Active Record
week 07 好棒棒的套件介紹
week 08 寄發 email + 背景工作處理
week 09 會員系統 + 網站後台 + 商品上架
week 10 購物車
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
module ActiveRecord
public :around_save
end
end
<% flash.each do |flash_type, message| %>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<%= message %>
</div>
<% end %>
@kaochenlong
kaochenlong / gist:bb6b6567d6e4db7f71f2
Last active August 29, 2015 14:18
Rake Combo Tasks
desc "Happy Combo Tasks"
task :happy => :environment do
puts "Log Clear!"
Rake::Task["log:clear"].invoke # 執行 rake log:clear
puts "DB Migrate!"
Rake::Task["db:migrate"].invoke # 執行 rake db:migrate
puts "whatever you want!" # 還有其它你想做的事