Skip to content

Instantly share code, notes, and snippets.

Avatar
🇹🇼
Available for hire

簡煒航 (Jian Weihang) tonytonyjan

🇹🇼
Available for hire
View GitHub Profile
@tonytonyjan
tonytonyjan / rfc_2047.rb
Last active Oct 18, 2020
Ruby implementation for RFC2047
View rfc_2047.rb
# Copyright (c) 2020 Jian Weihang <tonytonyjan@gmail.com>
# frozen_string_literal: true
module Rfc2047
TOKEN = /[\041\043-\047\052\053\055\060-\071\101-\132\134\136\137\141-\176]+/.freeze
ENCODED_TEXT = /[\041-\076\100-\176]*/.freeze
ENCODED_WORD = /=\?(?<charset>#{TOKEN})\?(?<encoding>[QBqb])\?(?<encoded_text>#{ENCODED_TEXT})\?=/.freeze
ENCODED_WORD_SEQUENCE = /#{ENCODED_WORD}(?:\s*#{ENCODED_WORD})*/.freeze
class << self
@tonytonyjan
tonytonyjan / multipart.lua
Created Aug 26, 2020
wrk file upload example
View multipart.lua
function read_file(path)
local file, errorMessage = io.open(path, "rb")
if not file then
error("Could not read the file:" .. errorMessage .. "\n")
end
local content = file:read "*all"
file:close()
return content
end
@tonytonyjan
tonytonyjan / vapid.rb
Created Apr 11, 2020
Generate VAPID key pair by pure Ruby based on RFC8292
View vapid.rb
# https://tools.ietf.org/html/rfc8292
require 'openssl'
require 'base64'
ec = OpenSSL::PKey::EC.generate('prime256v1')
puts(
Base64.urlsafe_encode64(ec.public_key.to_bn.to_s(2), padding: false),
Base64.urlsafe_encode64(ec.private_key.to_s(2), padding: false)
)
@tonytonyjan
tonytonyjan / README.md
Last active Nov 11, 2019
A Ruby client for ptx.transportdata.tw
View README.md

Usage

require 'ptx_client'

client = PtxClient.new(
  app_id: ENV['APP_ID'],
  app_key: ENV['APP_KEY']
)
@tonytonyjan
tonytonyjan / copyExif.js
Created Sep 23, 2019
copy EXIF from one JPEG blob to another and return a new JPEG blob.
View copyExif.js
// Copyright (c) 2019 Jian Weihang <tonytonyjan@gmail.com>
export default async (src, dest) => {
const exif = await retrieveExif(src);
return new Blob([dest.slice(0, 2), exif, dest.slice(2)], {
type: "image/jpeg"
});
};
export const SOS = 0xffda,
@tonytonyjan
tonytonyjan / chunghwa_post
Created May 21, 2019
中華郵政包裹查詢 API
View chunghwa_post
#!/bin/sh
test $# != 1 && cat <<USAGE && exit 1
Usage: $0 MAIL_ID
== Output Example ==
[
{
"datime": "20190520195647",
View ja-test
#!/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', 'ぎゃ' =>
View 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 EF91 623D 1477 800D 5701 24B6 294A EB9F 5C88 9A31

To claim this, I am signing this object:

@tonytonyjan
tonytonyjan / autoloader.rb
Created Apr 21, 2018
Autoloader loads ruby files lazily
View autoloader.rb
module AutoLoader
def self.included(mod)
caller_path, = caller(1..1).first.partition(':')
pattern = "#{File.dirname(caller_path)}/#{File.basename(caller_path, '.rb')}/*.rb"
Dir.glob(pattern).each do |path|
class_name = ::Utils.classify(File.basename(path, '.rb')).to_sym
mod.autoload class_name, path
end
end
end
@tonytonyjan
tonytonyjan / benchmark.rb
Last active Sep 20, 2017
`[4, 5].max` is slower than `[a, b].max` with ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
View benchmark.rb
require 'benchmark'
n = 100000000
Benchmark.bmbm do |x|
x.report('[4, 5].max') { n.times { [4, 5].max } }
a, b = 4, 5
x.report('[a, b].max') { n.times { [a, b].max } }
end
You can’t perform that action at this time.