Skip to content

Instantly share code, notes, and snippets.

View haolian9's full-sized avatar
🐢
make it work, make it right

高浩亮 haolian9

🐢
make it work, make it right
View GitHub Profile
@haolian9
haolian9 / yii2-wechat-authclient.php
Last active October 15, 2015 03:53
Yii 2 authclient for wechat-public-account
<?php
namespace app\modules\stuff\oauthclients;
use CURLFile;
use yii\authclient\OAuthToken;
use yii\base\DynamicModel;
use yii\web\HttpException;
use yii\helpers\Json;
# 读取管道中传递的文件, 并用vim打开
function vip
{ # {{{
local lines=''
# 从管道中读取
while read x; do
if [[ ! "${x}" ]]; then continue; fi
# 绝对路径, 忽略文件夹
x="$(realpath $x)"
function recover-last-version
{ #{{{
local commit_ref=$1
if [ ! "${commit_ref}" ]; then return 2; fi
for i in $(git diff HEAD "${commit_ref}" --name-only); do
vim -c 'Gvsplit HEAD~1:% | windo diffthis' -- "${i}"
done;
} #}}}
@haolian9
haolian9 / docker-tags
Last active November 24, 2017 06:22
shell script that lists all tags of a given image, inspired by [answer](https://stackoverflow.com/a/39454426)
#!/usr/bin/env bash
image="$1"
if [ -z "$image" ]; then
echo "usage: script-name full-image-name"
exit 1
fi
declare -A tags
@haolian9
haolian9 / escape.sh
Created June 4, 2018 16:54
escape filename using shell script
#!/usr/bin/env bash
# todo
# follow convention
# * echo -n | awk '{ print $0 }'
# * echo | awk '{ print $0 }'
read_escape() {
while read -r filename; do
escape $filename
@haolian9
haolian9 / i3config.py
Last active August 11, 2021 05:48
simple implementation about generating i3wm config with include directive, [upstream](https://gitlab.com/haoliang-terraform/squidward/-/blob/master/i3/.config/i3/gencfg)
#!/usr/bin/env python3
import logging
import re
import shutil
import subprocess
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from os import fdopen, unlink
from pathlib import Path
from tempfile import mkstemp
@haolian9
haolian9 / .tmux.conf
Created June 12, 2021 14:49
interactive tmux resize-pane
# resize pane
# take a look at `-i` option of command-prompt
bind R command-prompt -i -p 'resize-pane' 'run-shell "~/.scripts/:resize %%"'
@haolian9
haolian9 / main.py
Created July 7, 2021 06:04
trio version blessed.Terminal.inkey
#!/usr/bin/env python3
import os
import trio
from trio.lowlevel import FdStream
from blessed import Terminal
from blessed.keyboard import Keystroke, resolve_sequence
@haolian9
haolian9 / are_threre_race_conditions_in_swoole_coroutines.php
Last active August 31, 2021 09:37
ensure no race condition in swoole coroutines
<?php
# Swoole\Coroutine::enableScheduler();
Co\run(function () {
$flag = 1;
go(function() use(&$flag) {
assert($flag == 1);
$flag += 1;
@haolian9
haolian9 / server.nim
Last active February 21, 2022 13:05
a simple async chat server in nim
import std/[asyncdispatch, asyncnet, nativesockets, asyncfutures]
import std/[tables, deques]
type Nursery = object
tasks: seq[Future[void]]
proc startSoon(self: ref Nursery, fut: Future[void]) =
asyncCheck fut
self.tasks.add fut