By Unknown | Friday, January 18, 2013
Posted in: , , | 0 comments

DBIx::Class UTF8

剛剛用DBIx::Class上傳Excel的內容後發現,中文居然都變亂碼了,上網搜尋一下,原來只要在連線時設定utf8就可以了


$schema = LIB::Table->connect($dsn,$user,$pass,
    {
        mysql_enable_utf8 => 1
    }
);

Read more
By Unknown | Sunday, January 13, 2013
Posted in: , | 0 comments

TheSchwartz

為了想要建構一個Job Queue的系統,從好幾個月前就一直在看及思考怎樣的方案會比較好,後來因為手邊的程式大都數都以perl撰寫,所以就決定在perl的套件當中尋找。本來是想要利用proc-fork這類的套件去做實現,但是後來發現雖然這樣的套件很多,但是在工作submit出去之後,仍然沒有一個管理的機制去對排程的工作去做管理,而且怎樣去管理這些worker也是一個問題。

後來東看看西瞧瞧找到了這東西,這一兩個禮拜大概試出了一點東西,所以稍微紀錄。

安裝&基本跑法

大概的過程我全都寫在我的github上面,其實還滿簡單的

排程器

這邊我目前想到這樣做,先把要執行的工作包成一個worker,大概內容差不多如下
Loading ....
然後主要的程式如下
Loading ....
接著如果是要在command line下操作,只要利用list_jobs這類的function就可以把目前正在執行的工作顯示出來,稍微可以達到我想要的工作監控的情形。接著在web端,我利用mojo寫一個簡單的程式去顯示目前正在跑的工作,大概類似下面

 15 get '/job' => sub {
 16     my $self = shift;
 17
 18     my $client = TheSchwartz->new( databases =>
 19         [{
 20             dsn => $db_set->[0]{dsn},
 21             user => $db_set->[0]{user},
 22             pass => $db_set->[0]{pass}
 23         }]
 24     );
 25
 26     my @all = $client->list_jobs(
 27         { funcname => ['Process2','Process1']}
 28     );
 29
 30     $self->render('job', 'job' => \@all);
 31 };
 .
 .
 55 __DATA__
 56 @@ job.html.ep
 57 <!DOCTYPE html>
 58 <html>
 59     <body>
 60         <h1>THis is Hello</h1>
 61         The magic numbers are <%= $job %>
 62         <ul>
 63         % foreach my $j (@$job) {
 64             <li><%= $j->jobid %></li>
 65         % }
 66         </ul>
 67     </body>
 68 </html>
其實還有像是gearman這樣很多人在用的工作排程器,只可惜他工作丟出去了我不曉得要怎樣管理執行狀況(或許是我沒看到也說不定),不然他在各種語言上都有實作,也是個很不錯的選擇。有看到另外一種用法是用gearman丟工作到TheSchwartz,不過我現在還不明白為何要這樣做的原因。

接著就是要寫網頁的控制端,先筆記一下mojo::templatewiki,之後可能還會花些時間k他的表示法。

Read more
By Unknown | Thursday, January 10, 2013
Posted in: | 0 comments

背單字的好網站

第一個網站是大陸那邊的網站,超方便,只要上去註冊然後選擇字彙範圍跟每天要複習的字數,之後就只要每天上去報到就可以了。我選了每天100個字,現在有點後悔.....
http://www.shanbay.com/books/index/

下一個是國外的網站,主要都是非英語系的,作用跟上面的網站很像,但是內容比較多樣化,可以選擇不同課程,我覺得也滿不錯的,用這來複習幾個還記的的法文字
http://www.memrise.com/courses/english/

Read more
By Unknown | Tuesday, January 08, 2013
Posted in: , , , | 0 comments

Livereload in sublime 2

記得這個應該是ruby的套件,沒想到現在Windows上也可以直接配合sublime使用,只需要安裝套件就全部搞定,因為太高興了所以馬上記下來。

教學來源
  1. http://shoogledesigns.com/blog/blog/2012/07/23/sublime-text-2-package-control-and-livereload/
  2. http://kevintsengtw.blogspot.tw/2012/02/sublime-text-2-part3-package-control.html#.UOvX8m-miCh
簡單說明
  1. 先在sublime 2安裝Package Control,使用快捷鍵Ctrl+`打開命令列,再把下面這一長串打進去執行。
  2. import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); 
    os.makedirs(ipp) if not os.path.exists(ipp) else None; 
    urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); 
    open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); 
    print 'Please restart Sublime Text to finish installation'
  3. 安裝完之後,打開Preferences/Package Control,選擇install package,打入Livereload,接著就開始安裝。
  4. Google Chrome及Firefox都有livereload套件,把它裝進去後,在設定的地方打開Allow access to file URLs
  5. 基本上到這邊就結束了,可以找一個HTML檔測試,記得要點選瀏覽器Livereload圖示他才會啟動,然後就可以正常使用。

Read more
By Unknown | Sunday, January 06, 2013
Posted in: | 0 comments

B777-300ER

B777-300ER
seating-capacity: 386
lenght: 242ft
wingspan: 212ft
cabin width: 19ft
typical cruise speed: 0.84M
max cruise spped: 0.89M
max range: 7930 nmi
direct market competitor: A330-300, A340, MD11, A350, 787

EVA
架數:15
發動機:GE90-115B
速度:0.84M
最高巡航高度:43100ft
座艙配置
312座位
318座位

Read more
By Unknown | Sunday, December 30, 2012
Posted in: | 0 comments

2012-12-30聽力

SA 60s Science

Forest Canopy Color Reveals CO2 Uptake

When autumn rolls around, the leaf peepers come out in force. Armed with digital cameras, they record the most spectacular displays of fall foliage. Well according to a study in the journal Functional Ecology [Toshie Mizunuma et al., The relationship between carbon dioxide uptake and canopy colour from two camera systems in a deciduous forest in southern England], those images may be more than just pretty pictures. They may represent a new way to monitor climate change.
Trees take carbon dioxide, or CO2, from the atmosphere and convert it into biomass. By sopping up CO2 they help to stabilize the climate. But at the same time, they’re also affected by climate, for example, budding earlier in the season as global temperatures rise.
To understand how all this balances out, ecologists monitor how forests take up CO2. It’s a costly business that involves using a network of 500 instrument towers worldwide. So researchers got to wondering whether there might be an easier way to keep an eye on photosynthesis. And they found that digital cameras do the trick.
Analyzing two years’ worth of snaps taken every half hour in a forest in southern England, the researchers discovered that a tree’s leafy colors provide a good proxy for its photosynthetic productivity. So next time you go for a walk in the woods, take only photos. And leave only data points.

Humidity Levels Explain U.S. Flu Winter Peak 

Cases of the flu peak in winter in the U.S. But why? A new study suggests it’s not the heat, but the humidity. Or lack thereof. Because in temperate regions, the influenza virus fares best when the weather is dry. That’s according to work published in the journal PLoS One. [Wan Yang, Subbiah Elankumaran and Linsey C. Marr, Relationship between Humidity and Influenza A Viability in Droplets and Implications for Influenza’s Seasonality]
Scientists have long debated why flu erupts when the days grow chilly. Is it that we spend more time cooped up together indoors? Or is there something about the virus that likes it cold and dry? To find out, researchers suspended influenza virus in a solution that mimics human mucus. They incubated this infectious soup at different humidities and measured viral survival.
And they found that at low humidity, the fake mucus dries up and the virus does just fine. But when the humidity tops 50%, the droplets only partially evaporate, leaving behind a solution that’s too salty for the virus to thrive.
Interestingly, the virus does well again when the humidity reaches 100 percent, evaporation stops and the salinity of the mucus bath is juuust right. That could explain why the flu prefers to hit the tropics in rainy season. And why you should always keep your nose clean, but moist.

Telecommuters Work Longer Hours than Office Goers

When I say “telecommuting,” do you picture yourself easing into the workday in a pair of fuzzy slippers? Well, so does your boss. But the reality is, you’re both dreaming. Because a new study shows that folks who work at home at least some of the time put in more hours than those who stay at the office. That’s according to work published in the journal Monthly Labor Review. [Mary C. Noonan and Jennifer L. Glass, The hard truth about telecommuting]
Telecommuting for a portion of the workweek certain has its appeal. Avoiding the time and cost involved in commuting and presumably having a more flexible schedule and a better work-life balance are all potential pluses. But are employees really able to take advantage of such work-at-home perks?
Researchers took advantage of labor information from census bureau surveys and were surprised by what they found. First off, the proportion of people who work remotely remained unchanged from the mid-’90s to the mid-2000s the most recent data available. Second, those who do telecommute are more likely to work overtime, an additional 5 to 7 hours on top of the standard 40.
Which means that people who work from the comfort of home are not slackers in slippers. They’re more likely tech-savvy self-starters—who don’t know when to stop.

Read more
By Unknown | Thursday, December 27, 2012
Posted in: , | 0 comments

Calculation dihedral angle from 2 vectors

計算acos的簡單範例,先用以下公式求出cos值,再利用acos得到角度





/* acos example */
#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = acos (param) * 180.0 / PI;
  printf ("The arc cosine of %lf is %lf degrees.\n", param, result );
  return 0;
}

參考

Read more