Skip to content

Instantly share code, notes, and snippets.

@shrekuu
shrekuu / homebrew-mirror-in-china.sh
Last active August 15, 2023 02:42
homebrew 中国镜像服务, 清华大学与中科大
# 清华大学:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 手动修改 bottles 地址:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
# 或:
@shrekuu
shrekuu / settings.json
Created July 23, 2023 15:00
VS Code Config 2023-07-23
{
"editor.fontFamily": "'Fira Code', Monaco, Menlo, Consolas, 'PingFang SC', 'Yahei Consolas Hybrid', 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.scrollBeyondLastLine": false,
"terminal.integrated.fontFamily": "'MesloLGS NF', 'Fira Code',Monaco, Menlo, Consolas, 'PingFang SC', 'Yahei Consolas Hybrid', 'Courier New', monospace",
"terminal.integrated.fontSize": 15,
"emmet.includeLanguages": {
"smarty": "html"
},
"emmet.triggerExpansionOnTab": true,
@shrekuu
shrekuu / requestWithRetry.md
Last active February 5, 2023 15:15
给 API 请求增加出错重试, 每次出错延迟请求时间递增
// Round 1
// time: 21:26 - 21:44
// 默认最多尝试 3 次, 每次用时递减
// 缺点: 每次用时多少并不知道
// 失败: setTimeout 那里并没有 resolve, reject
function requestWithRetry(url, attempts = 3) {
  const attemptsLeft = attempts - 1;
  const maxDelayMS = 30000; // 30 seconds
  const minDelayMS = 3000; // 3 seconds
@shrekuu
shrekuu / debug-mode.js
Last active November 22, 2022 16:02
Click 5 times of an item to enable debug mode
import * as Cookies from 'js-cookie'
import { fromEvent } from 'rxjs'
import { buffer, debounceTime, filter, map } from 'rxjs/operators'
// debug 模式配置
// 连续 5 次快速点击, 切换 debug 模式
const FAST_CLICK_COUNT = 5
const DEBUG_COOKIE_KEY = 'debug'
const clickStream = fromEvent(document, 'click')
@shrekuu
shrekuu / demo.js
Created September 27, 2022 08:54
jquery CORS request example
return $.ajax({
url: 'https://another-domain.com/api/user/',
type: 'GET',
dataType: 'json',
xhrFields: {
withCredentials: true, // this line is required
},
});
@shrekuu
shrekuu / ffmpeg-remove-a-section-from-the-middle-of-a-video.sh
Last active March 13, 2022 04:21
Remove a section from the middle of a video
# cut from the beginning of the video to the beginning of the unwanted part
ffmpeg.exe -ss 00:00:00.000 -t 00:19:00.000 -i original.mp4 -c:v copy -c:a copy part1.mp4
# cut from the ending of the unwanted part to the end of the video
ffmpeg.exe -ss 00:20:28.000 -t 01:26:25.000 -i original.mp4 -c:v copy -c:a copy part2.mp4
# create a list file
touch list.txt
echo file part1.mp4 > list.txt
echo file part2.mp4 >> list.txt
@shrekuu
shrekuu / fixing-locale-error-on-ubuntu-server-14-and-16.sh
Last active July 24, 2021 11:15
fixed: manpath: can't set the locale; make sure $LC_* and $LANG are correct
# I know you've got stuck for too long ^_^Y
# Locale is not configured correct. I don't know what broke that. Maybe time did.
# I fixed it on my ubuntu 14 & 16 servers.
# Follow the steps below or run this script on your machine.
# step 1
# ensure this line in `/etc/default/locale` file and `/etc/environment` file
# LANG="en_US.UTF-8"
sudo echo '\nLANG="en_US.UTF-8"' >> /etc/default/locale && /etc/environment
@shrekuu
shrekuu / ensure-wifi-connection-deprecated.sh
Last active March 25, 2021 14:16
ensure-wifi-connection.sh
#!/bin/bash
if ethtool wlp2s0 | grep -q "Link detected: no"; then
echo connecting
echo $(nmcli d connect wlp2s0)
else
echo connected
fi
// ref: https://codepen.io/shrekuu/pen/zYoQoBd?editors=1010
var container;
var camera, scene, renderer;
// Sphere 1
var sphereGeometry1, sphereMaterial1, sphereMesh1;
// Sphere 2
var sphereGeometry2, sphereMaterial2, sphereMesh2;
@shrekuu
shrekuu / checkwlanup.sh
Created December 24, 2019 09:49
reconnect to wifi when wifi is down, crontab job
#!/bin/bash
# ref: https://askubuntu.com/a/421751/596437
wlan=`/sbin/ifconfig wlp2s0 | grep inet\ addr | wc -l`
if [ $wlan -eq 0 ]; then
/sbin/ifconfig wlp2s0 down && /sbin/ifconfig wlp2s0 up
else
echo "interface is up"
fi