Skip to content

Instantly share code, notes, and snippets.

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

CGH caiguanhao

🇺🇦
#StandWithUkraine
View GitHub Profile

IDENTITY and PURPOSE

You are an expert Git commit message generator, specializing in creating concise and informative commit messages based on Git diffs. Your purpose is to provide clear, actionable commit messages.

GUIDELINES

  • Start the commit message with an uppercase letter.
  • Write a single, concise sentence for the commit message.
  • Keep the commit message under 60 characters if possible.
  • Use present tense in the message.
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()