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
By Unknown | Wednesday, December 19, 2012
Posted in: , | 0 comments

Linked List

這個禮拜最令我傷神的,不過幸好很久以前有想過一次,所以要回復記憶比較沒有那麼困難。首先我先把C++版本的linked list刻出來,當然骨幹是參考別人的,然後自己有改了些東西,沒花多久時間很快就用出來了。

以下是標頭檔:

class CKLinkList{
    private:
        struct node {
            int x;
            int y;
            int z;
            node *link;
        } *p;

        int count_i;

    public:
        CKLinkList();
        void append(int);
        void insert_after(int,int);
        void insert_first(int);

        void display(void);
        void display_line(void);
        int length(void);
        void del(int);
        ~CKLinkList();
};

接下來是實作

#include <iostream>
#include "linklist.h"

using namespace std;

CKLinkList::CKLinkList(){
    p = NULL;
    count_i = 0;
};

int CKLinkList::length(){
    return count_i;
};

void CKLinkList::del(int num){
    node *q, *r;
    q = p;

    // No node
    if (p == NULL) return;

    // Delete the first node
    if (q->x == num){
        p = q->link;
        delete q;
        count_i--;
        return;
    }

    // Delete the remainder
    r = q;
    while( q != NULL){
        if (q->x == num){
            r->link = q->link;
            delete q;
            count_i--;
            return;
        }

        r = q;
        q = q->link;
    }
};

void CKLinkList::insert_first(int num){

    node *q, *t;
    q = p;

    t = new node;
    t->x = num;
    t->y = num*2;
    t->z = num*3;

    t->link = q;
    p = t;
    count_i++;
};

void CKLinkList::insert_after(int start_val,int num){
    node *q, *t;

    if (start_val != 0){
        q = p;
        while(q->link != NULL){
            if (q->x == start_val){

                t = new node;
                t->x = num;
                t->y = num*2;
                t->z = num*3;
                t->link = q->link;
                q->link = t;

                count_i++;
                return;
            }

            q = q->link;
        }
    }
};

void CKLinkList::append(int num){
    node *q, *t;

    if (p == NULL){
        p = new node;
        p->x = num;
        p->y = num*2;
        p->z = num*3;
        p->link = NULL;
    } else {
        q = p;
        while(q->link != NULL){
            q = q->link;
        }

        t = new node;
        t->x = num;
        t->y = num*2;
        t->z = num*3;
        t->link = NULL;
        q->link = t;
    }

    count_i++;
};

void CKLinkList::display_line(void){
    node *q;

    for(q = p; q != NULL; q = q->link){
        cout << " <- " << q->x;
    }

    cout << endl;
};

void CKLinkList::display(void){
    node *q;

    for(q = p; q != NULL; q = q->link){
        cout << "This is : " << q->x << ", " << q->y << ", " << q->z << endl;
    }
};

CKLinkList::~CKLinkList(){
    node *q;
    if (p == NULL) return;

    while (p != NULL){
        q = p->link;
        delete p;
        p = q;
    }
};

接下來我看到了一個使用C++ template去實作的版本,應該說是某個老師的教學課程(參考第10,11,12章),我就順便把她的課程講義看過一遍,然後把他的版本做出來。第一次使用C++的template,雖然滿麻煩的,但是真的是很強大,看來以後搞不好我的每個程式都要用template去做出來。以下是template的版本:

#include <iostream>
using namespace std;

template <class T>
class ChainNode {
    private:

    public:
        T data;
        ChainNode<T> *link;

        ChainNode(void){};
        ChainNode(const T& data){ this->data = data; };
        ChainNode(const T& data, ChainNode<T> *link){
            this->data = data;
            this->link = link;
        };
};

template <class T>
class Chain {
    private:
        ChainNode<T> *first;
        int count;

    public:
        Chain(void){ first = NULL; count = 0; };
        bool isEmpty() const {return first == NULL;}
        int IndexOf(const T&) const;
        int size(void){return count;}
        void Delete(int);
        void Insert(int,const T&);
        void Display(void);
        ~Chain();
};

// Destruction
template <class T>
Chain<T>::~Chain() {

    while (first != NULL){
        ChainNode<T> *next = first->link;
        delete first;
        first = next;
    }
};

template <class T>
int Chain<T>::IndexOf(const T& theElement) const{

    ChainNode<T> *currentNode = first;
    int index = 0;
    while(currentNode != NULL && currentNode->data != theElement){
        currentNode = currentNode->link;
        index++;
    }

    if (currentNode == NULL)
        return -1;
    else
        return index;
};

template <class T>
void Chain<T>::Delete(int theIndex){
    if (first == NULL) throw "Can not delete empty chain";

    ChainNode<T> *deleteNode;
    if (theIndex == 0){
        deleteNode = first;
        first = first->link;
        delete deleteNode;
        count--;

    } else {
        ChainNode<T> *p = first;
        for(int i =0; i< theIndex-1; i++){
            if (p == NULL) throw "Element not exist";
            p = p->link;
        }

        deleteNode = p->link;
        p->link = p->link->link;
        delete deleteNode;
        count--;
    }
}

template <class T>
void Chain<T>::Insert(int theIndex, const T& theElement){
    if (theIndex < 0) throw "Bad";

    if (theIndex == 0){
        first = new ChainNode<T>(theElement,first);
        count++;
    } else {
        ChainNode<T> *p = first;
        for(int i = 0; i < theIndex-1; i++){
            if (p == NULL) throw "Not Exist";
            p = p->link;
        }
        
        p->link = new ChainNode<T>(theElement, p->link);
        count++;
    }
};

template <class T>
void Chain<T>::Display(void){

    ChainNode<T> *p = first;

    while(p != NULL){
        cout << " <- " << p->data;
        p = p->link;
    }
    cout << endl;
};

int main() {
    cout << "This is LinkList .." << endl;

    Chain<int> *list = new Chain<int>;
    cout << "Size: " << list->size() << endl;

    list->Insert(0,1);
    list->Display();
    list->Insert(0,2);
    list->Display();
    list->Insert(1,3);
    list->Display();
    list->Insert(1,4);
    list->Display();
    list->Insert(0,5);
    list->Display();
    list->Delete(2);
    list->Display();

    cout << "Size: " << list->size() << endl;
}

繼續努力加油吧,這星期把linked list搞完之後還有很多要充實的,以上的source code都公布在github上看(其實blog根本不適合看這麼多程式碼是吧XD)。

Read more
By Unknown | Friday, December 14, 2012
Posted in: | 0 comments

Tempo Run

剛剛喵了一下我的跑步計畫,Tempo Run的配速看了之後覺得還有些不輕鬆。約8KM的距離速度在pace 5左右。根據最近這兩個禮拜在操場跑下來的結果,似乎400m@120s需要熱個將近10圈之後才有可能,所以我看短時間還是先把目標速訂在130s然後再慢慢加到120s。

Read more
By Unknown | Friday, December 14, 2012
Posted in: | 0 comments

Sublime 2快捷鍵

從網路上轉貼來的sublime2快捷鍵,我想我應該滿需要的

快捷鍵說明
Ctrl + X刪除一整行。(windows中會被剪下蓋掉,但是也可以用來快速把一行拿掉)
Ctrl + Enter在游標所在的那一行下方,插入一空白行
(若只按Enter,游標後方若有字會被一併換到下行去)
Ctrl + Shift + Enter在游標所在的那一行上方,插入一空白行。
Ctrl +  Shift  + ↑將你游標所在那行往上搬移。
Ctrl +  Shift  + ↓將你游標所在那行往下搬移。
Ctrl + L選取游標所在的單行,當你連續按時,他會往下繼續選取。
Ctrl + D選取游標所在的單字,當你連續按時,他會選取在同個檔案裡面的相同字。
Ctrl + M跑到離自己最近的父母去。(例如大/小括號{},())
Ctrl + Shift + M選取同父母的其他行。(例如大/小括號{},())
Ctrl + KK刪除游標所在那行後面的文字
Ctrl + K + ⌫刪除游標所在那行前面的文字。
Ctrl + ]往後縮排。
Ctrl + [往前縮排
Ctrl + Shift + D複製游標所在那行,並且貼在該行下方。
Ctrl + J將游標所在的下一行,加入到游標所在的行數最後方。
Ctrl + /單行註解/解除註解( // )
Ctrl +  Shift  + /區域註解( /**/)
Ctrl + Y重複上次的動作
Ctrl +  Shift  + V跟Ctrl+V的差別在於,此快捷鍵會將你的paste的字,自動作縮牌動作。
Ctrl + Uundo功能,跟Ctrl+Z的差別在於,此快捷鍵會先前去到你上次所變更的行數,當你續按的時候才會將他undo。

快捷鍵說明
Ctrl + P用名字快速打開檔案
Ctrl + R用名字快速找到function或標籤(ex:html的id)
Ctrl + ;在該檔案找最接近的字。                                                                            
Ctrl + G在該檔案前往該行
Ctrl +  Shift  + P命令提示
Ctrl + KB隱藏會顯示side bar
Ctrl + F尋找該檔案裡的
Ctrl + H 替換字
Ctrl +  Shift  + F尋找所有檔案裡的字 
Ctrl + Shift + t開啟上次關閉的檔案
Ctrl + PgUp在檔案視窗中切換(往上一個檔案)
Ctrl + PgDn在檔案視窗中切換(往下一個檔案)
Ctrl + ⇆在檔案視窗中切換   

Read more