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 / README.md
Last active December 17, 2015 03:49
Retrieve download URL from YouTube.
  1. Go to YouTube to find the video that you want to download.
  2. Copy the script to your browser navigation bar, then you'll get the download URL.
  3. You can save it to your bookmark.

Note: This script does not support HTML5 player since it's much easier to retrieve the source URL by viewing the source page.

  1. 到 YouTube 瀏覽你要下載的的影片網址。
  2. 將程式碼貼到網址列上(含前面的 javascript:),你將得到一個載點。
  3. 你可以將此程式碼存到你的書籤。
@tonytonyjan
tonytonyjan / speech-control.js
Last active December 19, 2015 06:59
Speech control plugin for Reveal.js.
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.lang = 'cmn-Hant-TW';
recognition.onerror = function(event){console.error(event)}
recognition.onresult = function(event){
str = event.results[event.resultIndex][0].transcript
switch(true){
case /下一?頁$|next page$|next$/.test(str):
Reveal.next();
console.info(str);
@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 / rails-on-windows.md
Last active December 27, 2015 00:19
一些 Rails 在 Windows 環境的拆地雷方法。

安裝 sqlite3 gem

  1. 官方網站下載兩個東西:
    1. Source Code (for header file)

    2. Precompiled Binaries for Windows (for DLL file)

      給 64 bit 使用者

由於 SQLite3 官方沒有提供 64 位元的 DLL,我們得自己編譯,好消息是當我們按照 DevKit 安裝手冊完成安裝後就有編譯器可用,以筆者為例,位置在 C:\DevKit\mingw\bin\gcc.exe

專案名稱:Logdawn 部落格網站

主旨:打造一個給理工人使用的部落格網站

基本功能

  • 使用者可以使用 FB、G+、GH 登入

發表文章

@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 / 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 / chat.rb
Created March 23, 2016 14:02
Simple thread based chat server
require 'socket'
class Client
def initialize server, socket
@server, @socket = server, socket
start
end
def send message
@socket.puts message
@tonytonyjan
tonytonyjan / 0-main.rb
Created March 11, 2016 09:23
Use regular expression to solve integer factorisation problem
n = ARGV.first.to_i
fact = Hash.new(0)
while match_data = /^(.{2,}?)\1+$/.match('.'*n)
fact[match_data[1].length] += 1
n /= match_data[1].length
end
fact[n] += 1
puts fact.sort.map!{|k,v| "#{k}#{"**#{v}" if v > 1}"}.join(' * ')
@tonytonyjan
tonytonyjan / interactor.rb
Last active July 20, 2016 15:25
Minimal service object implementation
class Interactor
attr_reader :error
def self.perform(*args)
new(*args).tap { |interactor| catch(:fail) { interactor.perform } }
end
def success?
@error.nil?
end