Skip to content

Instantly share code, notes, and snippets.

View twtw's full-sized avatar

Cheng-Yen Liu twtw

View GitHub Profile
@twtw
twtw / rotateMailLog.sh
Created August 16, 2020 02:59
archive everyday maillog or multi website logs to every file. origin from solaris rotate script.
#! /bin/sh
# in crontab:
# 59 23 * * * /home/user/bin/rotateMailLog.sh
# save one or many logs in one folder to other folder
LOGDIR=/var/log
if test -d $LOGDIR
then
cd $LOGDIR
for LOG in maillog messages.log
do
@twtw
twtw / useGithubAs.adoc
Last active January 20, 2018 02:44
use github as
@twtw
twtw / proxy.rb
Created December 31, 2017 06:28 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@twtw
twtw / dot.aliases.sh
Last active August 16, 2020 03:26
.bashrc useful settings
alias ls='ls --color=auto'
alias v='ls -l'
alias lh='ls -lh'
alias dh='df -h'
alias ll='ls -al'
alias irb='irb --simple-prompt'
alias ltips='less $HOME/tips.txt'
alias path='echo $PATH | sed -e "s/:/\n/g"'
# old linux server
@twtw
twtw / gist:6265001
Created August 19, 2013 01:10
crontab for schedule to play music
# crontab for schedule to play music
39 * * * * /usr/sbin/ntpdate -s ntp.ntu.edu.tw > /dev/null 2>&1
0 10 * * 1-5 /usr/bin/mpg321 --list /home/user/M/ten.txt
0 12 * * 1-5 /usr/bin/mpg321 -g 40 --list /home/user/M/noon.txt
0 13 * * 1-5 /usr/bin/mpg321 --list /home/user/M/wakeup.txt
0 15 * * 1-5 /usr/bin/mpg321 --list /home/user/M/teatime.txt
@twtw
twtw / javascript.md
Last active December 17, 2015 18:18
列常用的連結資源
@twtw
twtw / backup-ror.service
Last active April 12, 2017 14:34
using rvm and create ruby app startup script at systemd
# create systemd service file for rails 2.3.x startup
[Unit]
Description=rails 2.3.x web server
[Service]
Type=simple
RemainAfterExit=yes
User=username
PIDFile=/home/username/WEBSERVER/tmp/pids/thin.pid
WorkingDirectory=/home/username/WEBSERVER
@twtw
twtw / parse_rank.rb
Created March 9, 2013 00:07
parse nations rank in Natixis Global Retirement Index http://ngam.natixis.com/docs/12/1010/Global_Retirement_Index,0.pdf
# _*_ encoding: utf-8 _*_
# parse nations rank in http://ngam.natixis.com/docs/12/1010/Global_Retirement_Index,0.pdf
line=File.readlines('./rank.txt').map(&:chomp)[0]
hash = {}
@index = 1
line.split(/(\d+)/).each do |x,i|
unless x.to_i.zero?
@index = x.to_i
else
hash[@index] = x
@twtw
twtw / simple.rb
Created October 14, 2012 04:53
sinatra single file example
# -*- encoding: utf-8 -*-
# detail at http://ithelp.ithome.com.tw/question/10103736
require 'sinatra'
require 'net/http'
require 'open-uri'
require 'json'
require 'yaml'
get '/' do
"Hi, 鐵人五<br /><a href='/env'>環境變數</a>"
@twtw
twtw / get_count.rb
Created April 18, 2012 05:16
parse TANet roaming members domain and name
# get count number from html file
require 'hpricot'
doc=Hpricot(open('online.txt'))
>> doc.search("tr").size
=> 61
>> doc.search("tr")[0].at('td').innerText
=> "online people : 50"
msg = doc.search("tr")[0].at('td').innerText
count = msg.split(':')[1].strip