Skip to content

Instantly share code, notes, and snippets.

@shouya
shouya / ngram.rb
Created June 28, 2015 22:37
an improved bigram word segmentating algorithm
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
@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
@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 / 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 / oauth.rb
Last active August 16, 2016 00:29
twitter oauth
#!/usr/bin/env ruby
# license: WTFPL
# Gems:
# $ gem install twitter twitter_oauth
require 'twitter'
require 'twitter_oauth'
# CONSUMER_KEY = '3nVuSoBZnx6U4vzUxf5w'
#!/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 / 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     
@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 / change.rb
Last active September 27, 2015 02:55
presentation @ gzruby, oct 2014
class Operation < Struct.new(:name, :args, :block)
class << self
attr_accessor :opposite_operations
end
def self.define_opposite_operations(name, name_of_opposite)
@opposite_operations ||= {}
@opposite_operations[name] = name_of_opposite
@opposite_operations[name_of_opposite] = name
end
@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
# | | | |
# | | | |