2012年12月31日 星期一

[Postgres] Populate Calendar Table


create table Calendar
(
    date date primary key
);


insert into Calendar
select '1900-01-01'::date + ( n || 'day')::interval
from generate_series(0, ('2100-12-31'::date - '1900-01-01'::date)) n;

Feliz año nuevo 2013


冷到死。

2012年12月26日 星期三

[objective-c] hide internal from header files

原本的樣子:

StocktotalPostgres.h
#import <Foundation/Foundation.h>
#include "libpq-fe.h"

@interface StocktotalPostgres : NSObject {
    const char *conninfo;
    PGconn *conn;
}

@end

StocktotalPostgres.m
#import "StocktotalPostgres.h"

@implementation StocktotalPostgres

- (id)init {
    self = [super init];
    
    if (self) {
        conninfo = "";
        conn = PQconnectdb(conninfo);
        
        if (PQstatus(conn) != CONNECTION_OK) {
            PQfinish(conn);
        }
    }
    NSLog(@"init StocktotalPostgres instance");
    return self;
}

- (void)dealloc {
    PQfinish(conn);
    NSLog(@"dealloc StocktotalPostgres instance");
}

@end

header file 全都洩,而且 interface 照字面就是 interface,外在,而不是內部。這不是什麼好現象。那就用 Objective-C class extension 藏東西吧!


StocktotalPostgres.h
#import <Foundation/Foundation.h>

@interface StocktotalPostgres : NSObject 

@end

StocktotalPostgres.m
#import "StocktotalPostgres.h"

#include "libpq-fe.h"



@interface StocktotalPostgres()

@property(nonatomic) const char *conninfo;
@property(nonatomic) PGconn *conn;

@end



@implementation StocktotalPostgres

- (id)init {
    self = [super init];
    
    if (self) {
        self.conninfo = "";
        self.conn = PQconnectdb(self.conninfo);
        
        if (PQstatus(self.conn) != CONNECTION_OK) {
            PQfinish(self.conn);
        }
    }
    NSLog(@"init StocktotalPostgres instance");
    return self;
}

- (void)dealloc {
    PQfinish(self.conn);
    NSLog(@"dealloc StocktotalPostgres instance");
}

@end

接下來就可以安心寫咚咚嘍。

《財報分析》1726











[objective-c] tight coupling


Although the framework classes are separate from the language, their use is tightly wound into coding with Objective-C and many language-level features rely on behavior offered by these classes.

Objective-C 是躲不掉了。

2012年12月25日 星期二

我愛你

說無聊。

「好啦好啦,那就找點事做唄,要不我們結婚去。」

[mac] PostgreSQL lib for iOS


https://devcenter.spacialdb.com/iOS.html

Git: git clone git://github.com/spacialdb/libpq-ios.git

iOS 好像不能 dynamic link libpq.5.dylib,老是噴 dyld library not loaded libpq.5.dylib 的錯誤,改拉 libpq.a 也不能動,想抓 source code 喵的直接 build libpq.a,但想到底下這句:
千萬不要搞自己。

抓現成,又有 source code 的就可以了,剛好,就那麼剛好,SpacialDB 公司剛好有提供 library for mac,雖然是兩年前的,照用,輪子能滾就好了,自己造的輪子不見得能動。

因為 Objective-C, XCode 不熟,才剛摸一天,也就是今天,怎麼加 library?直接按圖操作就好了,跑起來果然可以,舒服。

備份一下操作流程 ((測過OK)):
  1. In order to use the libpq.a in your own iOS app, simply drag and drop the libpq-ios.xcodeproj/ inside your XCode's project navigator under your current project.
  2. After that you want to add the libpq-ios as a Target Dependency in the Build Phases of our iOS app. ((XCode 畫面太豐富了,常常找不到設定要往那設))
  3. Then we add the libpq.a static library to Link it with our binary and we move the libpq.a into our Frameworks group. ((這又要找在哪裡設,就當做 XCode 操作練習吧))
  4. Finally we add the libpq headers so that we can include it inside our code. Simply right click on the Support Files group and select the Add Files to... item and select the include folder inside the root of the libpq-ios repository. Make sure you have selected the Create groups for any added folders option.
  5. Finally you can now call the libpq include file: libpq-fe.h inside your app and the project should compile without any issues.

寫 code 就請看 http://www.postgresql.org/docs/9.2/interactive/libpq-example.html,這是所謂的 test case。


最後,我得好好學 Objective-C ((http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html)),幫 stocktotal 寫個 iPhone application!

2012年12月24日 星期一

[ubuntu] stocktotal deployment


是由

目前計劃把 stocktotal deploy 到 Amazon EC2,玩遊戲必須瞭解他的遊戲規則,撇開技術不談,先看鬼島慣老闆最愛砍的價錢:Amazon EC2 Pricing

Linux/UNIX Usage 明顯比 Windows Usage 便宜。但便宜不見得成事,不會用 Linux/UNIX,再便宜也沒用,剛好我就是那個不會用的。這些事都只是昨天的事,現在要我學 Linux/UNIX,恐怕有吃不完的苦頭了 ((年紀大學不動了))

為了學 Linux,最好方式就是灌一套 Linux dist. 來玩。virtual machine/dual operating system,我採 virtual machine,vmware/virtualbox,我採 virtualbox ((免費優先))。Linux dist. 選擇很多,原本打算裝 CentOS,不過裝起來很難動 ((yum update 一直卡在 nameserver 設定))。最後挑軟的吃:ubuntu ((ubuntu 12.10))

我的初衷只是把 stocktotal deploy 到便宜的作業系統,不用搞自己。



硬體規格及軟體準備

MacBook Air 13-inch.
Mac OS X version 10.7.4.
Processor: 1.8 GHz Intel Core i5.
Memory: 8 GB 1600 MHz DDR3 ((就是基本款的電腦))

VirtualBox: Base memory: 1024 MB ((其餘都是預設值,一直點下去就是了))

ubuntu iso: http://www.ubuntu.com/download/desktop。VirtualBox 第一次啓動 vm instance 會要求放 iso,就把這個賞給他吧。安裝過程頗順,開心。



Install Apache2
sudo apt-get install apache2
按 y 繼續,安裝過程也很順,開心。http://localhost => It works! 結案。



Install PHP

先把 test case 寫好:/var/www/phpinfo.php,內容是 <?php phpinfo(); ?> 用 ubuntu 預先灌好的 firefox 開,空空如也。

來裝 php5:
sudo apt-get install php5 libapache2-mod-php5

Restart Apache2:
sudo /etc/init.d/apache2 restart

重連一次 http://localhost/phpinfo.php,成功。((version 5.4.6-lubuntu1.1))



Install Postgres

PostgreSQL: http://www.postgresql.org/download/linux/ubuntu/

接著改 postgres 密碼 ((非常重要,千萬不要用萬用密碼 psql)):
sudo -u postgres psql
\password postgres;

為了方便操作,我會另外裝 pgadmin3,不用搞自己:
sudo apt-get install pgadmin3

裝完後直接在 terminal 下 pgadmin3 指令就可叫出 GUI 畫面。

參考資料:http://www.binarytides.com/install-postgresql-phppgadmin-pgadmin-ubuntu/



Deploy Stocktotal Database

因為我的 stocktotal modules 都在 host 端,我們得 VirtualBox => Install Guest Additions...。接著把 stocktotal home directory share 出來 ((VirtualBox => Share Folders...)),最後用 Linux mount:
sudo mount -t vboxsf stocktotal /home/plover/Desktop/stocktotal/

接著把 role: stocktotal 建起來,為 stocktotal 開 stocktotal database,用 postgres 身份 backup restore 回去就行了。



Deploy Portal
sudo cp -a /home/plover/Desktop/stocktotal/portal /var/www/

就只是單純拷貝唄。然後打開來看,空空如也。php PDO drivers 空空如也 ((請看之前寫好的 phpinfo.php,找 PDO 資訊)),那就裝上唄:
sudo apt-get install php5-pgsql

然後什麼都不用做,重刷 portal,我的好乖乖,出現了。


收工!

2012年12月22日 星期六

《財報分析》3481 奇美電

3481

有營收支持,不可任意放空。ROE 為負,或許早已反應在股價上。









2012年12月21日 星期五

Stocktotal Portal Demo


原本有 DataTables,不過怎麼貼都貼不上去,真怪。



Stocktotal Analysis: 2330


ROE Analysis

There are three components in the calculation of ROE: the net profit margin, the asset turnover, and the equity multiplier.

Financial Structure Analysis

The equity ratio should be larger than 50%.

Current/Rapid Ratio Analysis

The current ratio should be larger than 1. The rapid ratio should be larger than 2.

Non-operating Income Analysis

Long-term Investments Analysis

Operating Income Analysis

Profit Margin Analysis

Cash Flow Analysis

Cash Conversion Cycle Analysis

The cash conversion cycle (CCC) measures how long a firm will be deprived of cash if it increases its investment in resources in order to expand customer sales. It is thus a measure of the liquidity risk entailed by growth.

Capital Structure Summary

Investment Strategy