Monday, February 25, 2013

Perl git auto commit tool

昨天做火車想到的靈感

偶而會有一個資料夾想要一直寫東西然後存檔後自動 push 到 git 上面的需求

於是寫了以下 script ,不過寫完後才發現,這樣會弄髒 commit log ,反而是不實用 lol

純練習




#!/usr/bin/perl                                                                 
                                                                                
use 5.014;                                                                      
                                                                                
my $dir = $ARGV[0] // `pwd`;                                                    
chdir $dir;                                                                     
say "start auto commit under: " . `pwd`;                                        
                                                                                
while (1) {                                                                     
    my $diff = `git diff`;                                                      
    if ($diff) {                                                                
        my $t = `date +"%F [%T]"`;                                              
        `git add .`;                                                            
        `git commit -m "auto commit @ $t"`;                                     
        `git push`;                                                             
    }                                                                           
    sleep 10;                                                                   
}

Tuesday, February 19, 2013

emacs ansi-term mode


身為偉大的作業系統,內建一個支援 ansi 的 Terminal emulator  也是很正常的

M-x ansi-term

比較重要的

C-c C-j line mode    # ling scrolling
C-c C-k char mode





http://www.emacswiki.org/emacs/AnsiTerm

注意事項:


Also note that ansi-term remaps your default ‘C-x’ key to ‘C-c’.

In Emacs 22, try prefixing actions that aren’t recognized by their standard key commands with ‘C-x’. For example, ‘M-x’ becomes ‘C-x M-x’.




搭配 luit 可以開心的上 BBS 惹 ^q^

http://www.pps.univ-paris-diderot.fr/~jch/software/luit/

in bashrc

alias telnet="/usr/bin/luit -encoding big5 /usr/bin/telnet"

不過 BBS 的話可以在 .emacs 裡面寫防 idle 斷線


; anti idle for BBS                                                              
(defvar antiidle)                                                                
(defun enable-anti-idle ()                                                       
  (interactive)                                                                  
    (setq antiidle                                                               
      (run-with-timer 0 180 '(lambda ()                                          
        (term-send-up)                                                           
          (term-send-down)))))                                                   
                                                                                 
(defun disable-anti-idle ()                                                      
  (interactive)                                                                  
    (cancel-timer antiidle))

Tuesday, February 12, 2013

builtin http server


有時候會有需要臨時開個 http server ,傳東西或是啥得很方便




Python 有內建


[update] Python 3 這個 module 換了名字  0w0

$ python3 -m http.server 5566
$ python2 -m SimpleHTTPServer 5566


Perl 的話可以用這個 CPAN  module

$ perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>5566); $s->mount("/"=>{path=>"./"}); $s->start'


Ruby 也有內建,不過也是比較醜

$ ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 5566, :DocumentRoot => Dir.pwd).start'


php 5.4 後也有內建... 不過誰有 php54 呢(逃

$ php -S localhost:8000 -t ./

Linux change fonts

你需要一個路邊撿的 LiHeiPro


cp -r fontdir /usr/share/fonts
換字型就直接把裝字型的資料夾 cp -r 到 /usr/share/fonts 下面

sudo fc-cache -fv && sudo fc-list : file
更新 font cache


更多請參考鳥哥

http://linux.vbird.org/linux_basic/0590xwindow.php#fc-cache

Saturday, February 2, 2013

guess anonymous plurk's owner

匿名噗是噗浪近期提供的新功能

主要用意是讓大家可以趁亂告白講出內心的話

不過,猜猜噗主的真實身份其實也挺有趣的

寫了一個簡單的腳本來做這件事

其中 $p 是 plurk 的 API 物件,請參考其他機器人的 code


Usage:

給定一個 plurk link ,Ex. http://www.plurk.com/p/asdfgh

看 source code 可以拿到該噗的 plurk_id      Ex. data-pid="1094072786">

傳給這個 function 即可得到統計資料分析出可能的匿名噗擁有者

原理:紀錄該噗回應的好友交集,假若交集愈大的話愈可能是匿名噗的主人


sub guess_anon_by_pid {                                                         
    my $pid = shift;                                                            
    my %pool;                                                                   
    my @rank = ();                                                              
                                                                                
    my $response = $p->callAPI('/APP/Responses/get', plurk_id => $pid);                                                                
    for my $f_list (keys $response->{friends}) {                                
        my $fri = $p->callAPI('/APP/FriendsFans/getFriendsByOffset', user_id => $f_list, limit => 300);
        for (@$fri) {                                                           
            $pool{$_->{display_name}}++ if ($_->{display_name});                
        }                                                                       
    }                                                                           
                                                                                
    for (keys %pool) {                                                          
        push @rank, [$_, $pool{$_}];                                            
    }                                                                           
                                                                                
    @rank = sort {$b->[1] >= $a->[1]} @rank;                                    
                                                                                
    say $_->[0], " => ", $_->[1] for (@rank[0..10]);                            
}