Skip to content

Instantly share code, notes, and snippets.

@shouya
shouya / backupgentoo.sh
Last active August 29, 2015 14:07
system-wide backup to btrfs with rsync
#!/bin/sh
PART_LABEL=linuxbackup
DEST_DIR=/mnt/backup
snapshot_name=`date +bak_%Y%m%d`
echo "Before running this script, please make sure have your fstab set up."
echo "A working example looks like:"
cat <<EOF
/dev/sdb2 / <FS> <MOUNT_OPTS> 0 1

##ss-redir 的 iptables 配置(透明代理)

透明代理指对客户端透明,客户端不需要进行任何设置就使用了网管设置的代理规则

创建 /etc/ss-redir.json 本地监听 7777 运行ss-redir -v -c /etc/ss-redir.json

iptables -t nat -N SHADOWSOCKS
# 在 nat 表中创建新链
iptables -t nat -A SHADOWSOCKS -p tcp --dport 23596 -j RETURN
# 23596 是 ss 代理服务器的端口,即远程 shadowsocks 服务器提供服务的端口,如果你有多个 ip 可用,但端口一致,就设置这个
@shouya
shouya / commands.sh
Created July 25, 2014 12:17
gfw dns solution
#!/bin/sh
# this script is only written for gentoo
# if you're using other distro, modify part of it as needed
#
# please run this script run once, as su
sh dns.sh
iptables-save > /etc/iptables-local
cat > /etc/local.d/iptables-restore <<<EOF
#!/bin/sh
@shouya
shouya / bfsolver.hs
Last active August 29, 2015 13:58
A haskell brainf**k solver (largely referred to niklasb/haskell-brainfuck)
-- A simple brainfuck solver
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.State
import Data.Char (ord, chr)
import Data.Word
import Control.Applicative hiding ((<|>), many)
import Text.ParserCombinators.Parsec
data BFInst = Next
@shouya
shouya / 20-intermediate-haskell-exercises.hs
Last active August 29, 2015 13:57
The solutions to the '20 intermediate haskell exercises'. (http://blog.tmorris.net/posts/20-intermediate-haskell-exercises/)
import Control.Monad
import Control.Arrow
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
-- Relative Difficulty: 1
instance Fluffy [] where
@shouya
shouya / auto_set_bg.sh
Last active December 29, 2015 14:39
Automatically change wallpaper randomly every X minutes.
#!/bin/bash
export HOME=/home/shou
export BG_DIR="$HOME/Pictures/Anime/wallpapers"
export DISPLAY=':0'
rand_bg() {
find "$BG_DIR" -iname "*.jpg" -o -iname "*.png" | shuf | head -n1
}
@shouya
shouya / konachan.rb
Created October 18, 2013 07:59
konachan picture downloader
require 'nokogiri'
require 'open-uri'
require 'ap'
BASE_URI = 'http://konachan.com/post?tags=%s'
link_list = []
def save_list(list)
@shouya
shouya / gist:6782190
Last active December 24, 2015 10:09
favorited project names
espero (eo: hope)
kreskato (eo: crescat)
malespero (eo: despair)
katido (eo: kitten)
amo -> kiso
animo (eo: soul)
deziro
aspiro
cxiopova (eo: omnipotent)
@shouya
shouya / freerice.rb
Last active December 17, 2015 20:29
Charged rice
require 'rest_client'
require_relative 'threadpool'
require 'ruby-progressbar'
HEADERS_HASH = {
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel" \
"Mac OS X 10_7_4) AppleWebKit/534.57.5 (KHTML, like Gecko) V" \
"ersion/5.1.7 Safari/534.57.4"
}
@shouya
shouya / kting_downloader.rb
Created May 12, 2013 05:38
Download audio books from kting.cn.
require 'nokogiri'
require 'open-uri'
require 'json'
if ARGV.length != 2
puts "usage: #{$0} http://www.kting.cn/xxx/xx /path/to/target/dir"
exit
end