Skip to content

Instantly share code, notes, and snippets.

View tonytonyjan's full-sized avatar
🪲
Making bugs

簡煒航 (Weihang Jian) tonytonyjan

🪲
Making bugs
View GitHub Profile
@tonytonyjan
tonytonyjan / pascal.rb
Created January 6, 2016 18:50
Pascal's triangle
exit if (level = ARGV[0].to_i) <= 0
def combination n, r
return 1 if r == 0
n.downto(n-r+1).inject(:*) / r.downto(1).inject(:*)
end
max_length = combination(level-1, (level-1)/2).to_s.length
ary = [1]
0.upto(level-1).each do |i|
@tonytonyjan
tonytonyjan / 1_bulls_cows.rb
Last active January 6, 2016 17:36
Bulls and Cows
answer = 0.upto(9).to_a.sample(4).join
while true
puts 'wrong format, should be 4 digits.' until (guess = gets.chop!) =~ /^\d{4}$/
a = b = 0
guess.each_char.each_with_index do |c1, idx1|
answer.each_char.each_with_index do |c2, idx2|
if c1 == c2
idx1 == idx2 ? a += 1 : b += 1
@tonytonyjan
tonytonyjan / ja-test.rb
Created December 26, 2015 21:17
日文五十音練習程式
#!/usr/bin/env ruby
# frozen-string-literal: true
平仮名 = {
清音: {'あ' => 'a', 'か' => 'ka', 'さ' => 'sa', 'た' => 'ta', 'な' => 'na', 'は' => 'ha', 'ま' => 'ma', 'や' => 'ya', 'ら' => 'ra', 'わ' => 'wa', 'い' => 'i', 'き' => 'ki', 'し' => 'shi', 'ち' => 'chi', 'に' => 'ni', 'ひ' => 'hi', 'み' => 'mi', 'り' => 'ri', 'う' => 'u', 'く' => 'ku', 'す' => 'su', 'つ' => 'tsu', 'ぬ' => 'nu', 'ふ' => 'fu', 'む' => 'mu', 'ゆ' => 'yu', 'る' => 'ru', 'ん' => 'n', 'え' => 'e', 'け' => 'ke', 'せ' => 'se', 'て' => 'te', 'ね' => 'ne', 'へ' => 'he', 'め' => 'me', 'れ' => 're', 'お' => 'o', 'こ' => 'ko', 'そ' => 'so', 'と' => 'to', 'の' => 'no', 'ほ' => 'ho', 'も' => 'mo', 'よ' => 'yo', 'ろ' => 'ro', 'を' => 'o'},
濁音: {'が' => 'ga', 'ざ' => 'za', 'だ' => 'da', 'ば' => 'ba', 'ぱ' => 'pa', 'ぎ' => 'gi', 'じ' => 'ji', 'ぢ' => 'ji', 'び' => 'bi', 'ぴ' => 'pi', 'ぐ' => 'gu', 'ず' => 'zu', 'づ' => 'zu', 'ぶ' => 'bu', 'ぷ' => 'pu', 'げ' => 'ge', 'ぜ' => 'ze', 'で' => 'de', 'べ' => 'be', 'ぺ' => 'pe', 'ご' => 'go', 'ぞ' => 'zo', 'ど' => 'do', 'ぼ' => 'bo', 'ぽ' => 'po'},
拗音: {'きゃ' => 'kya', 'ぎゃ' =>
@tonytonyjan
tonytonyjan / README.md
Last active December 15, 2015 18:33
Taiwanese gem contributors 2015

方法

  1. https://github.com/orgs/rubytaiwan/teams/rubyists 取得 GitHub 帳號。
  2. 使用 GitHub API 取得個別帳號下的所有 public repo,尋找 *.gemspec,並取得 gem name。
  3. 透過 RubyGems API 用 gem name 尋找 gem owner。

聲明

  • 有些 gem 有複數個 owner,可能會有老外混進去。
  • 有的人會把知名專案用 fork 以外的方式 push 到自己的帳號,導致 repo 真正的作者與 repo 帳號擁有者不一致。
@tonytonyjan
tonytonyjan / 1-ptt.tcl
Last active January 2, 2024 08:22
PTT 每天自動登入 / PTT automatically login
#!/usr/local/bin/expect -f
set timeout 60
log_file -noappend $env(HOME)/log/ptt.log
spawn telnet ptt.cc
expect "new"
send "$env(PTT_ID)\r"
expect ":"
send "$env(PTT_PWD)\r"
expect {
"您想刪除其他重複登入的連線嗎" {
#include <stdio.h>
#define SWAP(a,b) do{ typeof(a) tmp = a; a = b; b = tmp; }while(0)
void permutate(int* v, int n, int i) {
int j;
if (i == n) {
for(j = 0; j < n; j++) printf("%d ", v[j]);
printf("\n");
}else
for(int j = i; j < n; j++) {
# ~/.config/fish/functions/fish_prompt.fish
set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_hide_untrackedfiles 1
set -g __fish_git_prompt_color_branch magenta bold
set -g __fish_git_prompt_showupstream "informative"
set -g __fish_git_prompt_char_upstream_ahead "↑"
set -g __fish_git_prompt_char_upstream_behind "↓"
set -g __fish_git_prompt_char_upstream_prefix ""
@tonytonyjan
tonytonyjan / bm.rb
Last active April 12, 2020 11:17
中華民國身分證字號驗證器
require 'benchmark'
require 'id_check'
require 'taiwanese_id_builder'
require 'TaiwanUserID'
n = 100000
Benchmark.bmbm do |x|
x.report('wayne5540 '){ n.times{ TaiwaneseIdBuilder.valid?('A123456789') } }
dummy = Object.new.extend(TaiwanUserID)
x.report('kaochenlong'){ n.times{ dummy.is_valid?('A123456789') } }
@tonytonyjan
tonytonyjan / keybase.md
Created January 18, 2015 20:15
keybase.md

Keybase proof

I hereby claim:

  • I am tonytonyjan on github.
  • I am tonytonyjan (https://keybase.io/tonytonyjan) on keybase.
  • I have a public key whose fingerprint is F30B 53C9 A9CC B71C A034 4E2A 055A F90B C74E 4F4C

To claim this, I am signing this object:

@tonytonyjan
tonytonyjan / Vagrantfile
Last active August 29, 2015 14:10
Vagrantfile Rails development.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, guest: 3000, host: 3000
end