Skip to content

Instantly share code, notes, and snippets.

Avatar
🐺
Typing

Rumble Huang khiav223577

🐺
Typing
View GitHub Profile
@khiav223577
khiav223577 / gist:0e9e2ba42f9ac869ba8a489678a46753
Last active Feb 9, 2021
Migrating from Travis CI to GitHub Actions
View gist:0e9e2ba42f9ac869ba8a489678a46753
# 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 Dec 28, 2020
KMP algorithm
View kmp.rb
# 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
View Using Github Deploy Key.md

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 Mar 1, 2020
error log when trying to install ruby 1.8.7 via `rvm install 1.8.7`
View make.log
[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
View 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'
View require_outer_gem.rb
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 Nov 24, 2018
2018 台北市長選舉推測票數(依各區票倉的票所數 已送/應送 比例乘上去來推測)
View gist:6a3faf5d935e2c7180ea26de35701402
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 Jul 7, 2018 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
View rails http status codes
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
View register font installation.rb
WPS = Win32API.new('kernel32', 'WriteProfileString', ['P'] * 3, 'L')
WPS.call('Fonts', font_name + ' (TrueType)', font_file_name)
View mac 的各種設定.md

Commands

顯示Library
chflags nohidden ~/Library
取消dock的延遲
defaults write com.apple.Dock autohide-delay -float 0 && killall Dock
還原dock的延遲
defaults delete com.apple.Dock autohide-delay && killall Dock
防止chrome不小心誤操作,跳到上/下一頁