Skip to content

Instantly share code, notes, and snippets.

View khiav223577's full-sized avatar
🐺
Typing

Rumble Huang khiav223577

🐺
Typing
View GitHub Profile
@khiav223577
khiav223577 / taiwan_districts.json
Created September 29, 2024 15:47
台灣行政區郵遞區號 JSON
{"臺北市":[{"zip":"100","name":"中正區"},{"zip":"103","name":"大同區"},{"zip":"104","name":"中山區"},{"zip":"105","name":"松山區"},{"zip":"106","name":"大安區"},{"zip":"108","name":"萬華區"},{"zip":"110","name":"信義區"},{"zip":"111","name":"士林區"},{"zip":"112","name":"北投區"},{"zip":"114","name":"內湖區"},{"zip":"115","name":"南港區"},{"zip":"116","name":"文山區"}],"基隆市":[{"zip":"200","name":"仁愛區"},{"zip":"201","name":"信義區"},{"zip":"202","name":"中正區"},{"zip":"203","name":"中山區"},{"zip":"204","name":"安樂區"},{"zip":"205","name":"暖暖區"},{"zip":"206","name":"七堵區"}],"新北市":[{"zip":"207","name":"萬里區"},{"zip":"208","name":"金山區"},{"zip":"220","name":"板橋區"},{"zip":"221","name":"汐止區"},{"zip":"222","name":"深坑區"},{"zip":"223","name":"石碇區"},{"zip":"224","name":"瑞芳區"},{"zip":"226","name":"平溪區"},{"zip":"227","name":"雙溪區"},{"zip":"228","name":"貢寮區"},{"zip":"231","name":"新店區"},{"zip":"232","name":"坪林區"},{"zip":"233","name":"烏來區"},{"zip":"234","name":"永和區"},{"zip":"235","name":"中和區"},{"zip":"236","name":"土城區"},{"zip":"237","name":"三峽區"},{"zip":"238","name":"樹林區"},{
@khiav223577
khiav223577 / gist:0e9e2ba42f9ac869ba8a489678a46753
Last active February 9, 2021 14:03
Migrating from Travis CI to GitHub Actions
# Migrating from Travis CI to GitHub Actions
git checkout -b feature/migrate_from_travis_to_github_actions
rm .travis.yml
ruby -e "File.write('README.md', File.read('README.md').gsub('travis-ci.org', 'github.com').sub('.svg?branch=master', '/workflows/Ruby/badge.svg').sub(/(khiav223577\/\w+)\)/, '\1/actions)'))"
git add .
git commit -m 'remove travis'
@khiav223577
khiav223577 / kmp.rb
Last active December 28, 2020 04:37
KMP algorithm
# frozen_string_literal: true
def kmp_table(pattern)
i = 0
j = 1
table = [0]
while j < pattern.size
if pattern[i] == pattern[j]
i += 1

What / Why

Deploy key is a SSH key set in your repo to grant client read-only (as well as r/w, if you want) access to your repo.

As the name says, its primary function is to be used in the deploy process, where only read access is needed. Therefore keep the repo safe from the attack, in case the server side is fallen.

How to

  1. Generate a ssh key
@khiav223577
khiav223577 / make.log
Created March 1, 2020 19:52
error log when trying to install ruby 1.8.7 via `rvm install 1.8.7`
[2020-03-02 03:45:28] __rvm_make
__rvm_make ()
{
\make "$@" || return $?
}
current path: /home/khiav/.rvm/src/ruby-1.8.7-p374
GEM_HOME=/home/khiav/.rvm/gems/ruby-2.5.5
GEM_PATH=/home/khiav/.rvm/gems/ruby-2.5.5:/home/khiav/.rvm/gems/ruby-2.5.5@global
PATH=/home/khiav/.rvm/gems/ruby-2.5.5/bin:/home/khiav/.rvm/gems/ruby-2.5.5@global/bin:/home/khiav/.rvm/rubies/ruby-2.5.5/bin:/home/khiav/.rvm/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Razer/ChromaBroadcast/bin:/mnt/c/Program Files/Razer/ChromaBroadcast/bin:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Razer Chroma SDK/bin:/mnt/c/Program Files/Razer Chroma SDK/bin:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/iCLS:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/iCLS:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c
@khiav223577
khiav223577 / PG::Error: ERROR: new encoding (UTF8) is incompatible
Created February 21, 2019 11:59 — forked from amolkhanorkar/PG::Error: ERROR: new encoding (UTF8) is incompatible
Postgres PG::Error: ERROR: new encoding (UTF8) is incompatible
======= Prolbem =================================================================================================================
I have installed : ruby-2.0.0,postgres-9.2 , now in rails app when I execute:
rake db:create , command I get:
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "my_db_name" ENCODING = 'unicode'.......
bin/rake:16:in `load'
module Kernel
def require_outer_gem(path)
gem_path = "#{Gem.path.first}/gems"
extract_gem_name = ->(gems_paths){ gems_paths.map{|s| s[/gems\/([^\/]+)\/lib$/, 1] }.compact }
outer_gems = extract_gem_name[Dir["#{gem_path}/*/lib"]] - extract_gem_name[$LOAD_PATH]
outer_gems = outer_gems.lazy
.map{|s| s.rpartition('-') }
.map{|gem_name, _, version| [gem_name, version] }
.sort_by{|_, v| Gem::Version.new(v) } # 多版本的話選最新版號
@khiav223577
khiav223577 / gist:6a3faf5d935e2c7180ea26de35701402
Last active November 24, 2018 15:51
2018 台北市長選舉推測票數(依各區票倉的票所數 已送/應送 比例乘上去來推測)
require 'httparty'
class ApiService
include HTTParty
base_uri 'http://vote.2018.nat.gov.tw/mobile/zh_TW/TC'
def load(code)
response = self.class.get("/#{code}.html").parsed_response
response =~ /已送\/應送:&nbsp;(\d+)\/(\d+)/
@khiav223577
khiav223577 / rails http status codes
Created July 7, 2018 15:27 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
WPS = Win32API.new('kernel32', 'WriteProfileString', ['P'] * 3, 'L')
WPS.call('Fonts', font_name + ' (TrueType)', font_file_name)