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 / install-tmux
Last active August 29, 2015 14:19 — forked from rothgar/install-tmux
install tmux 1.9a on centos 6.5
# Install tmux on Centos release 6.5
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local
@qizhihere
qizhihere / gist:d10ab6d78fad41227d0e
Last active August 29, 2015 14:22 — forked from klovadis/gist:2549131
use optional args in node.js
// example function where arguments 2 and 3 are optional
function example( err, optionalA, optionalB, callback ) {
// retrieve arguments as array
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
// first argument is the error object
@qizhihere
qizhihere / mov2gif
Last active August 29, 2015 14:23 — forked from artursapek/mov2gif
#!/bin/bash
# mov2giv in out width
# mov2gif video_file_in.mov gif_file_out.gif 300
tmp_dir=/tmp/frames_$(date +%s)
mkdir $tmp_dir
if [ -z "$3" ]
then
size=600
@qizhihere
qizhihere / add-load-event.js
Created June 22, 2015 03:17
add multiple window.onload events
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
@qizhihere
qizhihere / disable-select.js
Created June 23, 2015 13:41
disable double click text selection using jQuery
$.fn.disableSelection = function() {
return this.attr('unselectable', 'on')
.css({
'-moz-user-select': '-moz-none',
'-moz-user-select': 'none',
'-o-user-select': 'none',
'-khtml-user-select': 'none',
'-webkit-user-select': 'none',
'-ms-user-select': 'none',
@qizhihere
qizhihere / docker-export-import-all.sh
Last active August 29, 2015 14:23
export/import all docker images
# export all images to current directory
for i in $(sudo docker images | sed -n "2,\$p" | awk '{print $1":"$2}'); do
sudo docker save $i > $(echo -n $i | tr '/' '_').tar
done
# import all images from current directory
for i in $(ls *.tar); do sudo docker load < $i; done
@qizhihere
qizhihere / is_mounted.sh
Created July 3, 2015 11:34
check if the specific device has been mounted
is_mounted () {
if [ $# -eq 1 ]; then
if [ ! -b "$1" ]; then
echo "error: invalid device:$1"
return 1
elif df | awk '{print $1}' | grep "$1" &>/dev/null; then
return 0
else
return 1
fi
@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
#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