Skip to content

Instantly share code, notes, and snippets.

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

CGH caiguanhao

🇺🇦
#StandWithUkraine
View GitHub Profile
@caiguanhao
caiguanhao / iphone.sh
Last active March 24, 2016 07:41
iPhone on sale notification
while :; do \
curl -Ls 'http://www.apple.com/cn/shop/buy-iphone/iphone-se/64gb-金色' | \
grep -q '暂无供应' && \
sleep 10 || { \
printf 'iPhone is OK to buy right now' | \
wechat-notify --raw 'oBjSswsfgSvA6FlrR0rszh5eThhI@CGH' && \
break; \
}; done
@caiguanhao
caiguanhao / ems.sh
Last active March 31, 2016 00:34
get notified every time ems info gets updated
while :; do \
export INFO="$(curl -s http://www.ems.com.cn/apple/query/EZ480728326CN | \
grep td-main | sed 's/<[^>]*>//g' | awk '{$1=$1}NF>1{print}' | tr -d '\r')"; \
test "$INFO" != "$LAST" && \
echo "$INFO" && echo "$INFO" | wechat-notify --raw oBjSswsfgSvA6FlrR0rszh5eThhI@CGH; \
export LAST="$INFO"; sleep 10; \
done
@caiguanhao
caiguanhao / questions.md
Created August 26, 2016 09:56
Questions
  1. 给出任意多个有 5 个元素的数组,如 [[10, 32, 43, 11, 4], [7, 36, 44, 9, 4], ...],数组各项合计为 100 , 如何根据和指定数组 [1, 32, 48, 17, 2] 的相似度进行排序?最好是计算每项的相似分值,然后按分值排序。
def random_distribution(size = 5)
  a = []
  (size - 1).times do |i|
    s = a.inject(&:+) || 0
    a << rand(100-s)
 end
@caiguanhao
caiguanhao / hyr.sh
Last active January 12, 2017 06:35
shell script to buy HYR products (requires curl, jq, openssl)
#!/bin/bash
set -e
KEY=b79ff42fc9d045aed383243a
TOKEN_KEY=6y9d6e9332f5428e89d2f8c2
IV=24sddexs
PREFIX='{"app_version": "iPhone[10.2]", "app_from_type": "3", "app_version_mark": "3.1.0"'
USERAGENT='HengYiRong3.0/3.1.0.5 CFNetwork/808.2.16 Darwin/16.3.0'
@caiguanhao
caiguanhao / hyr.py
Created January 24, 2017 10:01
偷步进入确认出借页面
import subprocess
import json
class Injector:
KEY = '623739666634326663396430343561656433383332343361'
IV = '3234736464657873'
def __init__(self):
return
@caiguanhao
caiguanhao / fake.sh
Created April 13, 2017 14:49
fake git commits
git log --reverse --pretty=format:"%at %s" | awk '{print "GIT_AUTHOR_DATE="$1" GIT_COMMITTER_DATE="$1" git commit --allow-empty -m \"" substr($0,12) "\""}'
@caiguanhao
caiguanhao / .tmux.conf
Last active November 27, 2021 07:13
simple tmux conf
set -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
set -g base-index 1
set -g status on
set -g status-interval 5
set -g automatic-rename on
set -g automatic-rename-format '#{b:pane_current_path}'
@caiguanhao
caiguanhao / .gitignore
Created July 28, 2017 01:18
simple gitignore
# Node
npm-debug.log
# Mac
.DS_Store
# Windows
Thumbs.db
# vi
@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;
@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()