Skip to content

Instantly share code, notes, and snippets.

View hangj's full-sized avatar
🥏
happy coding

hangj hangj

🥏
happy coding
View GitHub Profile
@hangj
hangj / vapid_helper.py
Last active March 19, 2024 11:40 — forked from cjies/vapid_helper.py
Python based VAPID key-pair generator
import base64
import ecdsa
def generate_vapid_keypair():
"""
Generate a new set of encoded key-pair for VAPID
"""
pk = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
vk = pk.get_verifying_key()
@hangj
hangj / init.fish
Last active December 8, 2023 11:34 — forked from overtrue/init.fish
config.fish set environment variables from bash_profile
# Fish shell
# REUSE ENVIRONMENT VARIABLES FROM ~/.bash_profile
bash -c '. ~/.bash_profile; env' | while read e
set var (echo $e | sed -E "s/([a-zA-Z0-9_]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/([a-zA-Z0-9_]+)=(.*)\$/\2/")
# remove surrounding quotes if existing
set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")
@hangj
hangj / s3_upload_file.sh
Created November 24, 2022 07:07
s3 upload files with shell script
#!/usr/bin/env bash
# hangj.cnblogs.com
# https://www.cnblogs.com/hangj/p/16921863.html
s3_key="Q3AM3UQ867SPQQA43P2F"
s3_secret="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
session_token="Security-Token"
bucket="bucket-log"
Readme: In the following pseudo code, [] indicates a subroutine.
Sometimes I choose to write the subroutine inline under the [] in order to maintain context.
One important fact about the way rollbacks are handled here is that we are storing state for every frame.
In any real implementation you only need to store one game state at a time. Storing a game
state for every frame allows us to only rollback to the first frame where the predicted inputs don't match the true ones.
==Constants==
MAX_ROLLBACK_FRAMES := Any Positive Integer # Specifies the maximum number of frames that can be resimulated
FRAME_ADVANTAGE_LIMIT := Any Positive Integer # Specifies the number of frames the local client can progress ahead of the remote client before time synchronizing.
@hangj
hangj / vps_setup.sh
Last active September 2, 2022 07:40
setup shadowsocks server for my vps
#!/usr/bin/env bash
# change the working directory to where this file is located
full_file_path=`realpath $0`
absolute_dir=`dirname $full_file_path`
cd $absolute_dir
# crate new user if not exists
username="bot"
userpassword="password123456"
@hangj
hangj / inject.lua
Last active February 8, 2022 06:16
local function run(src, level)
local level = level or 1
level = level + 3
assert(level >= 3)
local function get(t, k)
-- print('get:', k)
-- print('bt:', debug.traceback())
local level = level + 1
@hangj
hangj / windowsVolumeAdjust.py
Last active July 6, 2021 08:11
python 调节 Windows 系统音量
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pip3 install pycaw -i https://pypi.douban.com/simple
# https://docs.microsoft.com/en-us/windows/win32/api/endpointvolume/nf-endpointvolume-iaudioendpointvolume-getvolumerange
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
@hangj
hangj / fuckgfw.sh
Last active December 3, 2019 06:01
backup proxy solution
#!/usr/bin/env bash
# https://www.cnblogs.com/hangj/p/11838259.html
IP=localhost
FILE=proxy.pac
# 找到一个可用的 port
SOCKSPORT=`python -c 'import socket; s=socket.socket(); s.bind(("localhost", 0)); print(s.getsockname()[1]); s.close()'`
HTTPPORT=`python -c 'import socket; s=socket.socket(); s.bind(("localhost", 0)); print(s.getsockname()[1]); s.close()'`
@hangj
hangj / exif.js
Last active October 8, 2022 08:55
exif.js for miniprogram 小程序获取照片exif元信息
(function() {
// https://github.com/exif-js/exif-js
var debug = false;
var root = this;
var self = window || this;
var Blob = Blob || function () {}
var DOMParser = DOMParser || function () {}
var EXIF = function(obj) {
@hangj
hangj / myredis.lua
Created September 24, 2019 12:15
a little wrapper for lua-resty-redis.lua
local redis = require "resty.redis"
local M = {}
local function set_keepalive(p, red, opts)
while true do
if 'dead' == coroutine.status(p) then
break
end