Skip to content

Instantly share code, notes, and snippets.

View twtw's full-sized avatar

Cheng-Yen Liu twtw

View GitHub Profile
@twtw
twtw / chinese_random_names.sh
Last active August 16, 2020 01:02
Random Chinese names and Lorem ipsum.
#!/bin/sh
# simple script to generate random chines names from richyli's website.
if [ "$#" -eq 0 ]; then
COUNT=3
else
COUNT=$1
fi
curl -s -d name_count=$COUNT\&break=2 http://www.richyli.com/name/index.asp | piconv -f big5 -t utf8 | sed -n 88p | awk -F', #' '{print $1}' | sed -e 's/ //g'
# encoding: utf-8
require 'ostruct'
require 'hpricot'
require 'hpricot_scrub'
require 'open-uri'
require 'curb'
require 'uri'
class Page
attr_reader :doc
@twtw
twtw / do_change.rb
Created April 12, 2012 08:10
update calendar, schedule column by sequel
# encoding: UTF-8
# example records
#id|odate|opentime|m|n|e|start|end
#12|2012-01-12|8:00~23:00|0|0|0|0|0
#13|2012-01-13|學期考結束Final Exams end 8:00~23:00|0|0|0|0|0
#14|2012-01-14|選舉Election Day 休館一天Closed|0|0|0|0|0
#15|2012-01-15|9:00~17:00|0|0|0|0|0
#16|2012-01-16|寒假開始Winter Vacation begins 8:00~21:00|0|0|0|0|0
def change_mne(open)
@twtw
twtw / get_count.rb
Created April 18, 2012 05:16
parse TANet roaming members domain and name
# get count number from html file
require 'hpricot'
doc=Hpricot(open('online.txt'))
>> doc.search("tr").size
=> 61
>> doc.search("tr")[0].at('td').innerText
=> "online people : 50"
msg = doc.search("tr")[0].at('td').innerText
count = msg.split(':')[1].strip
@twtw
twtw / simple.rb
Created October 14, 2012 04:53
sinatra single file example
# -*- encoding: utf-8 -*-
# detail at http://ithelp.ithome.com.tw/question/10103736
require 'sinatra'
require 'net/http'
require 'open-uri'
require 'json'
require 'yaml'
get '/' do
"Hi, 鐵人五<br /><a href='/env'>環境變數</a>"
@twtw
twtw / parse_rank.rb
Created March 9, 2013 00:07
parse nations rank in Natixis Global Retirement Index http://ngam.natixis.com/docs/12/1010/Global_Retirement_Index,0.pdf
# _*_ encoding: utf-8 _*_
# parse nations rank in http://ngam.natixis.com/docs/12/1010/Global_Retirement_Index,0.pdf
line=File.readlines('./rank.txt').map(&:chomp)[0]
hash = {}
@index = 1
line.split(/(\d+)/).each do |x,i|
unless x.to_i.zero?
@index = x.to_i
else
hash[@index] = x
@twtw
twtw / backup-ror.service
Last active April 12, 2017 14:34
using rvm and create ruby app startup script at systemd
# create systemd service file for rails 2.3.x startup
[Unit]
Description=rails 2.3.x web server
[Service]
Type=simple
RemainAfterExit=yes
User=username
PIDFile=/home/username/WEBSERVER/tmp/pids/thin.pid
WorkingDirectory=/home/username/WEBSERVER
@twtw
twtw / javascript.md
Last active December 17, 2015 18:18
列常用的連結資源
@twtw
twtw / gist:6265001
Created August 19, 2013 01:10
crontab for schedule to play music
# crontab for schedule to play music
39 * * * * /usr/sbin/ntpdate -s ntp.ntu.edu.tw > /dev/null 2>&1
0 10 * * 1-5 /usr/bin/mpg321 --list /home/user/M/ten.txt
0 12 * * 1-5 /usr/bin/mpg321 -g 40 --list /home/user/M/noon.txt
0 13 * * 1-5 /usr/bin/mpg321 --list /home/user/M/wakeup.txt
0 15 * * 1-5 /usr/bin/mpg321 --list /home/user/M/teatime.txt
@twtw
twtw / dot.aliases.sh
Last active August 16, 2020 03:26
.bashrc useful settings
alias ls='ls --color=auto'
alias v='ls -l'
alias lh='ls -lh'
alias dh='df -h'
alias ll='ls -al'
alias irb='irb --simple-prompt'
alias ltips='less $HOME/tips.txt'
alias path='echo $PATH | sed -e "s/:/\n/g"'
# old linux server