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 / east_asian_width.rb
Created June 10, 2022 17:16
A Ruby parser which parses EastAsianWidth.txt from UAX #11 at https://www.unicode.org/reports/tr11/
# frozen_string_literal: true
# Copyright (c) 2022 Weihang Jian <https://tonytonyjan.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@tonytonyjan
tonytonyjan / base45.rb
Last active May 5, 2022 02:14
A Ruby implementation of Base45 Data Encoding
# frozen_string_literal: true
# Copyright (c) 2022 Weihang Jian <https://tonytonyjan.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@tonytonyjan
tonytonyjan / rfc_2047.rb
Last active October 18, 2020 07:50
Ruby implementation for RFC2047
# 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 August 26, 2020 08:07
wrk file upload example
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 April 11, 2020 15:19
Generate VAPID key pair by pure Ruby based on RFC8292
# 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 November 11, 2019 10:22
A Ruby client for ptx.transportdata.tw

Usage

require 'ptx_client'

client = PtxClient.new(
  app_id: ENV['APP_ID'],
  app_key: ENV['APP_KEY']
)
@tonytonyjan
tonytonyjan / copyExif.js
Last active December 16, 2023 11:43
copy EXIF from one JPEG blob to another and return a new JPEG blob.
// Copyright (c) 2019 Weihang Jian <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
Last active April 5, 2024 02:57
中華郵政包裹查詢 API
#!/bin/sh
test $# != 1 && cat <<USAGE && exit 1
Usage: $0 MAIL_ID
== Output Example ==
[
{
"datime": "20190520195647",
#!/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', 'ぎゃ' =>

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: