Skip to content

Instantly share code, notes, and snippets.

@shrekuu
shrekuu / keybindings.json
Last active July 17, 2024 16:14
VS Code Config 2024-07-18
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "alt+cmd+z",
"command": "git.revertSelectedRanges"
},
{
"key": "ctrl+tab",
"command": "workbench.action.nextEditor"
},
@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 / 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
@shrekuu
shrekuu / Auto Swtich
Created November 6, 2019 03:07
Auto Swtich Rules for google chrome extension SwitchOmega
[SwitchyOmega Conditions]
@with result
*.fonts.googleapis.com +A
*.bootstrapcdn.com +A
*.regex101.com +A
*.sentry-cdn.com +A
*.google.com +A
*.cloudinary.com +A
*.jsplumbtoolkit.com +A
@shrekuu
shrekuu / load-Font-awesome.js
Created May 27, 2019 07:47
小程序动态加载 fontawesome 字体图标
import environment from './environment'
// 把字体资源放到后端服务器上
// 使这样可以访问到 ${environment.baseURL}/vendor/fontawesome-5.8/webfonts/fa-regular-400.woff
// 服务器要上 https + CORS
// 更多参考: https://developers.weixin.qq.com/miniprogram/dev/api/wx.loadFontFace.html
// 如果实在不稳定, 就使用 http://fontello.com/ 生成 base64 样的字体内嵌风格 css 使用
// 尝试动态加载的字体图标
const fontAwesomeFonts = [