Skip to content

Instantly share code, notes, and snippets.

# install.packages("RCurl")
library(RCurl)
URL <- "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=20150918&end_date=20150918&report_type=day&language=ch&save=csv"
# Download data from URL and set encoding to Big5
rawData <- getURL(URL, .encoding='big5')
# Convert Encoding from Big5 to UTF-8
rawData <- iconv(rawData, 'big5', 'utf8')
# Remove unnecessary Title by parsing data to Vector
@YushengLi
YushengLi / redis-autostart-osx.md
Last active September 22, 2015 12:10 — forked from subfuzion/redis-autostart-osx.md
redis auto start OS X

Install with Homebrew

brew install redis

Set up launchctl to auto start redis

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

/usr/local/opt/redis/ is a symlink to /usr/local/Cellar/redis/x.y.z (e.g., 2.8.7)

// Remember to add tabindex to <a>
body.no-js {
a.dropdown-toggle:focus {
pointer-events: none;
}
a.dropdown-toggle:focus + .dropdown-menu {
opacity: 1;
visibility: visible;
pointer-events: auto;
}
@YushengLi
YushengLi / fortigate.rb
Created September 9, 2017 14:07
A dummy script to generate Fortigate Firewall object and Reserved address batch insertion script from CSV
require 'csv'
class Fortigate
def self.export_batch_object_script(path)
File.open('firewall_address', 'w+') do |f|
f.write("config firewall address\n")
f.write(" edit all\n")
f.write(" next\n")
f.write(" edit \"SSLVPN_TUNNEL_ADDR1\"\n")
f.write(" set type iprange\n")
@YushengLi
YushengLi / led_color_switch.h
Created December 10, 2017 06:32
An Example to switch color of a RGB LED with a button
const byte redPin = 3;
const byte greenPin = 5;
const byte bluePin = 6;
const byte interruptPin = 2;
volatile byte mode = 0;
volatile byte modeChanged = 0;
unsigned long lastInterrupt;
void setup() {
setColourRgb(0,0,0);
@YushengLi
YushengLi / 4060_remote_control_blynk.ino
Created December 31, 2017 11:20
Remote Control Arduino 4060 Car Over WiFi with self hosted Blynk
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css">
<style type="text/css">
.item {
margin: 10px;
float: left;
<style>
.section {
width: 960px;
margin: auto;
border: 1px solid #888;
padding: 40px 0;
}
.clearfix {
clear: both;

為什麼用 Ransack

在網站中提供搜尋、篩選與排序功能在現在的網站中已是基本需求,畢竟大家的耐心,在 Ruby on Rails 中,由於採用了 ActiveRecord 作為 ORM 框架的緣故,要快速的組出 Search Query 並非難事。

基本上只要搭配上 Form Object 與 Query Object 模式,要優雅的完成好維護的搜尋模組還算是容易,但當你想要快速完成搜尋功能的時候,Ransack 絕對是你的好夥伴。

基本使用

Basic Configuration

Ransack 的基本設定極其簡單,只要安裝完後基本上就可以使用了。

  • 首先,在你的 Gemfile 中加入: