Skip to content

Instantly share code, notes, and snippets.

View qizhihere's full-sized avatar

littleqz qizhihere

  • WuHan, Hubei Province, China
View GitHub Profile
@qizhihere
qizhihere / check-command.sh
Created July 3, 2015 13:49
check if all commands exist
command-exist-p () {
local _command_exist=0
for i in "$@"; do
type -a "$i" &>/dev/null || _command_exist=1
done
return $_command_exist
}
@qizhihere
qizhihere / btrfs-snapshot-backup.sh
Last active August 29, 2015 14:24
A simple script which package the latest btrfs snapshot(automically made by snapper) into a .tgz archive
#!/usr/bin/env bash
LOCK=/tmp/.$(basename "$0").lock
exec 200<>"$LOCK"
flock -n 200 || abort
# btrfs paritition which contains snapshots
BTRFS_DEV=/dev/sda1
# target paritition where backup archives will be saved
@qizhihere
qizhihere / merge-table.lua
Created July 4, 2015 07:47
merge two tables in lua
function table.merge(t1, t2)
for k,v in ipairs(t2) do
table.insert(t1, v)
end
return t1
end
#this script can never fail
#i use it in the fish_config
#call it with start_agent
setenv SSH_ENV $HOME/.ssh/environment
function start_agent
if [ -n "$SSH_AGENT_PID" ]
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
@qizhihere
qizhihere / random-wallpaper.sh
Created July 9, 2015 01:59
randomly pick a wallpaper from one or more directory(or directories)
#!/usr/bin/env bash
WALLPAPER_DIR="/home/xxx/Pictures/Wallpapers/normal/"
find "$WALLPAPER_DIR/" -type f -regex ".*\.\(png\|jpe?g\)" |
shuf -n1 | xargs -I__ feh --bg-scale "__"
@qizhihere
qizhihere / delay-search-prompt.js
Last active August 29, 2015 14:24
show delay prompt for search bar
function delayPrompt(event, elem, cb) {
var value = elem.prop('value');
this.lastKeyUp = event.timeStamp;
setTimeout(function() {
/* check input interval */
if (this.lastKeyUp - event.timeStamp !== 0) {
return;
}
@qizhihere
qizhihere / i3lock.sh
Created July 11, 2015 16:56
lock screen use i3lock and randomly select wallpaper or blur
#!/usr/bin/env bash
exec 2>/dev/null
exec 1>/dev/null
IMGS_DIR="$HOME/Pictures/Wallpapers/normal"
command-exist-p () {
local _command_exist=0
for i in "$@"; do
type -a "$i" &>/dev/null || _command_exist=1
@qizhihere
qizhihere / time_ago.php
Last active September 7, 2015 06:43 — forked from hubsgz/convert2timeago.php
convert timestamp to N days/hours/minutes/seconds ago
function time_ago($timestamp, $lang='cn')
{
$msg = [
'cn' => [
'day' => '天前',
'hour' => '小时前',
'minute' => '分钟前',
'second' => '秒前',
],
'en' => [
@qizhihere
qizhihere / delay.js
Created September 11, 2015 04:43
delay callback most used in keyboard events
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
// Usage
$('input').keyup(function() {
@qizhihere
qizhihere / README.md
Last active November 13, 2015 09:05 — forked from chuangbo/README.md
Python dynamic DNSPod DNS Script

替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔60秒检查一遍IP,如果修改了就更新IP。

获得domain_id可以用curl curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx"

获得record_id类似 curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&amp;login_password=xxx&amp;domain_id=xxx"