Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
syu-id committed Jan 3, 2014
0 parents commit d6b5ce6
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .watsonrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# watson rc
# watson - inline issue manager
# [goosecode] labs


# Directories
[dirs]
./


# Tags
[tags]
todo
fix
review


# Ignores
[ignore]
.git
*.swp
77 changes: 77 additions & 0 deletions bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env ruby
# coding: utf-8
# desc: backup files according to a yaml file
# author: eric
require 'yaml'

BACKUP_DIR_PREFIX = "#{Dir.home}/.sync/"
DATA_PATH = "#{Dir.home}/.backup.yaml"

def sync_exec args
rsync_opt = '--times --recursive'
file = args[:file]
dest = args[:dest]

if args[:relative] == true
rsync_opt << " --relative"
# don't sub! this will change args[:file] too.
file = file.sub(args[:strip], "") if args[:strip]
end

cmd = %[rsync #{rsync_opt} '#{file}' '#{dest}']

# pass "test" as command parameter to dry-run.
unless ARGV.include? "test"
if system cmd
print "[" + "\e[32m" + "done" + "\e[0m" + "]" # done: green
else
print "[" + "\e[31m" + "failed" + "\e[0m" + "]" # failed: red
end
puts args[:file]
else
puts cmd
end
end

def sync list
dest = BACKUP_DIR_PREFIX + list['backup_dir']
# relative copy
if list['relative_copy'] == true
# if need to strip prefix
if list['strip_prefix']
Dir.chdir list['strip_prefix'] do
list['files'].each do |file|
sync_exec file: file,
dest: dest,
relative: true,
strip: list['strip_prefix']
end
end
# standard relative copy
else
list['files'].each do |file|
sync_exec file: file,
dest: dest,
relative: true
end
end
# normal copy
else
list['files'].each do |file|
sync_exec file: file, dest: dest
end
end
end

# main
data = File.open(DATA_PATH) { |f| YAML.load f }
data.each do |list|
if ARGV.include? "test"
print "\e[32m"
print list['strip_prefix'] + ' ' if list['strip_prefix']
print "=> #{BACKUP_DIR_PREFIX}#{list['backup_dir']}"
print "\e[0m" + "\n"
end

sync list
end
47 changes: 47 additions & 0 deletions gset
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby
# coding: utf-8
# desc: gsettings automation based on yaml data
# author: eric
require 'yaml'

data = File.expand_path "~/.gset.yaml"
settings = YAML.load_file data

general = settings['general']
keybindings = settings['keybindings']

def exc cmd
if system cmd
print "[" + "\e[32m" + "done" + "\e[0m" + "]" # done: green
else
print "[" + "\e[31m" + "failed" + "\e[0m" + "]" # failed: red
end

print cmd + "\n\n"
end

# general settings
general.each do |cfg|
cfg['setting'].each do |key, value|
exc %[gsettings set #{cfg['schema']} #{key} "#{value}"]
end
end

# custom keybindings
keybindings_path = []

keybindings.size.times do |i|
path = "'/org/gnome/settings-daemon/plugins/media-keys/" +
"custom-keybindings/custom#{i}/'"
keybindings_path << path

keybindings[i].each do |key, value|
exc %[gsettings set ] +
%[org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:] +
%[#{path.delete "'"} #{key} "#{value}"]
end
end

exc %[gsettings set ] +
%[org.gnome.settings-daemon.plugins.media-keys custom-keybindings ] +
%["[#{keybindings_path.join(", ")}]"]
30 changes: 30 additions & 0 deletions pacbundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/zsh
# after base system and DE is installed...
pkg=(
base-devel abs
tp_smapi dosfstools
htop lsof net-tools strace
openssh ntp powertop lm_sensors rsync namcap
cmus wget aria2 opencc units xsel imagemagick
git hgsvn ctags
dos2unix python2-eyed3
ffmpeg vorbis-tools flac mediainfo
atool p7zip unrar file-roller
xorg-fonts-type1 ttf-freefont ttf-droid
gvim vim-systemd xterm
ibus ibus-rime
firefox firefox-i18n-zh-cn flashplugin
wine winetricks
virtualbox
jre7-openjdk jdk7-openjdk icedtea-web-java7
pidgin skype
uget
smplayer smplayer-themes vlc gecko-mediaplayer
puddletag
audacity
nomacs gimp
faenza-icon-theme
arch-wiki-lite arch-wiki-docs
)

sudo pacman -S --needed $pkg
14 changes: 14 additions & 0 deletions paste3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
if test $IS_PHONE != true ; then
case $DISTRO in
cygwin)
echo -n "$@" > /dev/clipboard
;;
*)
echo -n "$@" | xsel -ib
echo -n "$@" | xsel -ip
;;
esac
fi

echo "$@" > ~/.p
9 changes: 9 additions & 0 deletions rimedm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#/bin/sh
# desc: rime dict manager
rime_conf_dir=$HOME/.config/ibus/rime

# change directory in a subshell.
(
cd $rime_conf_dir
rime_dict_manager "$@"
)
64 changes: 64 additions & 0 deletions seaf-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env ruby
# coding: utf-8
# usage: send this script and .seaf.yaml to device, and sync.
# [todo] - sync per list
require 'yaml'
require 'highline/import'

# constants
SEAF_PATH = File.expand_path "~/.seafile-client"
LIBRARY_DATA_PATH = File.expand_path "~/.seaf.yaml"
Lib = Struct.new "Lib", :server, :account, :password, :name, :uuid, :dir

# method
def sync lib
puts "Name: #{lib.name}"
puts "UUID: #{lib.uuid}"
puts "Sync directory: #{lib.dir}"

cmd = %[seaf-cli sync -s '#{lib.server}' -l '#{lib.uuid}'
-d "#{lib.dir}" -u '#{lib.account}' -p '#{lib.password}']

if system cmd
sleep 5
puts "." * 24
end
end

# main
# initialize seafile if hasn't
system %[seaf-cli init -d #{SEAF_PATH}] if not Dir.exist? SEAF_PATH

# read all libraries into lib_all
lib_all = []
data = File.open(LIBRARY_DATA_PATH) { |d| YAML.load d }
data.each do |list|
# [todo] - ask for password only if there is unsynced libs in the list.
# get password for this list
puts "Server: #{list['server']}"
puts "Account: #{list['account']}"
password = ask("Your Password: ") { |q| q.echo = "*" }
puts "=" * 24

# add libraries into lib_all
list['libraries'].each do |lib|
lib_all << Lib.new( list['server'], list['account'], password,
lib['name'], lib['uuid'],
File.expand_path(lib['dir'])
)
end
end

# get unsynced libraries
synced_uuid = %x[seaf-cli list].scan /\h{8}-\h{4}-\h{4}-\h{4}-\h{12}/
lib_unsynced = lib_all.delete_if { |l| synced_uuid.include? l.uuid }

# sync libraries
lib_unsynced.each do |lib|
if $? !=nil and not $?.success?
puts "[seaf-init]" + "\e[31m" + "Erro occured." + "\e[0m"
break
end

sync lib
end
76 changes: 76 additions & 0 deletions tenseijingo
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env ruby
# coding: utf-8
# desc: get today's Tenseijingo column
# author: eric
require 'date'
require 'moji'

Encoding.default_internal = "UTF-8"

# variables
file = Dir.home + '/.sync/diudiudui/tensei/tensei.txt'

today = Date.today
yesterday = today.prev_day

cache_dir = Dir.home + '/.sync/diudiudui/tensei/cache/'
cache_file = cache_dir + "tensei-#{today.strftime '%y%m%d'}.txt"
cache_file_yesterday = cache_dir +
"tensei-#{yesterday.strftime '%y%m%d'}.txt"

title_date = Moji.han_to_zen "#{today.year}年 #{today.mon}#{today.day}日"

page_url = 'http://www.asahi.com/paper/column.html'
element = '#MainInner .ArticleText'

# main
puts "tenseijingo downloader"

if File.exist? cache_file
puts "today's job is already done."
exit
end

# get today's content
require 'nokogiri'
require 'open-uri'

begin
puts "fetching web content..."
page = Nokogiri::HTML open(page_url, 'r:eucjp')
rescue
p $!
puts "error occured, exit."
exit
else
puts "content got"
end

content = page.css(element).text.strip
success_message = "column is downloaded."

# check newspaper holiday
if File.exist? cache_file_yesterday
content_yesterday = File.read( cache_file_yesterday,
{ encoding: 'sjis' }
).chomp

if content == content_yesterday
content = "【休刊日】"
success_message = "oops, newspaper holiday :)"
end
end

# write cache
File.open(cache_file, 'w:sjis') { |f| f.puts content }

# add to file
File.open file, 'a:sjis' do |f|
f.puts
f.puts "[#5字下げ]#{title_date}[#「#{title_date}」は中見出し]"
f.puts
f.puts content
end

# done
puts success_message
Loading

0 comments on commit d6b5ce6

Please sign in to comment.