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 / 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",
@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 {
"您想刪除其他重複登入的連線嗎" {
@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 / 1-README.md
Last active June 21, 2023 06:14
Remote React Components Loading
@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 / 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 / rails_42_with_active_support.rb
Last active May 18, 2022 10:31
session cookie decrypter for Rails
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)
@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 / 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') } }