Skip to content

Instantly share code, notes, and snippets.

View shouya's full-sized avatar

shouya

View GitHub Profile
@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 / 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 / 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
@shouya
shouya / wacom_one.sh
Last active August 29, 2015 14:07
my wacom one configuration
#!/bin/sh
xsetwacom --set 10 MapToOutput "eDP1"
xsetwacom --set 10 Rotate half
# +-------------------+
# | |
# | +---------+ + 1/4
# | | | |
# | | | |
@shouya
shouya / xclip.rb
Created November 14, 2014 02:59
rails console endowed with the power of xclip
# ~/.irbrc
class Object
def xclip
IO.popen('xclip -i -selection clipboard', 'w') do |clipboard|
clipboard.print(self.to_s)
end
end
end
@shouya
shouya / usage.md
Last active August 29, 2015 14:09
monitor on file creation and run corresponding scripts (based on inotify)

Edit the script source code

There is a baseDir variable for which you can designate the directory you want to monitor.

The variable monitors can be edited according to the lock files to be monitored and the corresponding script files to be executed when the lock files were created.

Setup udev rules

# /etc/udev/rules.d/80-filco-keyboard.rules     
#!/usr/bin/env python3
import urllib.request
from os import system
response = urllib.request.urlopen('http://ipinfo.io/country')
country = response.read().decode('utf-8').rstrip("\n")
if country == 'CN':
system("sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list")
@shouya
shouya / oauth.rb
Created May 22, 2015 05:48
oauth twitter official api in a batch
require 'twitter'
require 'twitter_oauth'
require 'json'
def oauth(ck, cs)
access_token = nil
access_secret = nil
client = TwitterOAuth::Client.new(
:consumer_key => ck,
@shouya
shouya / install-gentoo.md
Last active August 29, 2015 14:23
new gentoo install steps

preparing stage

cd /mnt/base
btrfs subvolume create SVroot
btrfs subvolume create SVhome
cp stage3.tar.bz2 SVroot
tar xjvf stage3.tar.bz2
cd /mnt
umount /mnt/base
@shouya
shouya / ngram.rb
Created June 28, 2015 21:03
a stupid bigram based segmentizer
def clean(txt)
mark = true
txt.each_char.map { |x|
if x.ascii_only? and mark
mark = false
' '
elsif x.ascii_only?
nil
else
mark = true