Skip to content

Instantly share code, notes, and snippets.

View caiguanhao's full-sized avatar
🇺🇦
#StandWithUkraine

CGH caiguanhao

🇺🇦
#StandWithUkraine
View GitHub Profile
func appendStringsIfMissing(slice []string, elements ...string) (out []string) {
out = slice
outer:
for _, element := range elements {
for _, e := range slice {
if e == element {
continue outer
}
}
out = append(out, element)
@caiguanhao
caiguanhao / README.md
Last active December 6, 2021 11:00
ffmpeg parallel batch/bulk convert opus to mp3 with meta data
# install parallel if you don't have one
brew install parallel

chmod +x convert.sh
./convert.sh

# delete opus files
find . -type f -name '*.opus' -delete
@caiguanhao
caiguanhao / wx_pay.rb
Created July 6, 2021 15:44
wx_pay hotfix
require 'http'
require 'openssl'
require 'digest/md5'
module WxPay
class << self
attr_accessor :appid, :mch_id, :key, :appsecret
attr_reader :apiclient_cert, :apiclient_key
def apiclient_cert=(cert)
@caiguanhao
caiguanhao / go.mod
Created September 5, 2020 06:25
fake requests
module github.com/caiguanhao/fake-req
go 1.14
require github.com/google/uuid v1.1.1
@caiguanhao
caiguanhao / net-ssh-key.rb
Created March 18, 2020 15:35
net/ssh login with public key string
host = 'host'
user = 'user'
options = {
keys_only: true,
keys: [],
key_data: [ server_ssh_private_key ],
user_known_hosts_file: [],
known_hosts: Class.new do
def self.search_for(host, options={})
fingerprint = server_ssh_fingerprint.split(/\s+/).last
const { RawSource } = require('webpack-sources')
class WebpackAssetsManifest {
apply (compiler) {
compiler.hooks.emit.tapAsync('WebpackAssetsManifest', (compilation, callback) => {
let entrypoints = compilation.entrypoints
for (const [name, entrypoint] of entrypoints) {
const js = []
const css = []
entrypoint.getFiles().forEach(file => {
@caiguanhao
caiguanhao / tencent_cloud_sms.rb
Last active November 29, 2019 05:29
腾讯云短信(接口鉴权 v3 / TC3) Ruby / Rails
# gem 'http'
def send_tencent!(country_code, cellphone, code)
number = "+#{country_code}#{cellphone}"
json = {
PhoneNumberSet: [ number ],
TemplateID: '<YOUR TEMPLATE ID>',
TemplateParamSet: [ code.to_s ],
SmsSdkAppid: Rails.application.credentials.tencent_cloud_sms_app_id,
}.to_json
@caiguanhao
caiguanhao / sticky-header.js
Created November 22, 2019 07:20
simple solution to add sticky header for bootstrap 4 tables
let style = document.createElement('style')
document.head.appendChild(style)
document.addEventListener('scroll', () => {
let table = document.querySelector('.table')
if (!table) return
let navbar = document.querySelector('.navbar')
if (!navbar) return
let offset = table.getBoundingClientRect().top + window.scrollY - navbar.offsetHeight
let second = document.querySelector('.table > thead > tr:nth-child(2) > th')
let secondOffset = 0
@caiguanhao
caiguanhao / action_cable_wx.js
Created November 29, 2017 03:45
action_cable for wx
class Cable {
constructor(options) {
this.options = options || {}
this.polled = 0
wx.onSocketOpen(() => {
if (this.options.connected) {
this.options.connected()
}
this.resubscribe()
this.stopPolling()
@caiguanhao
caiguanhao / README.md
Created August 31, 2017 06:44
在GBK编码HTML网页显示正常(UTF-8编码的)中文
$ gem install htmlentities
$ echo -n '测试文本' | ruby -r htmlentities -e "puts HTMLEntities.new.encode(STDIN.read, :decimal)"
&#27979;&#35797;&#25991;&#26412;