Java紫微斗數排盤open source library

其實我一早就想把Fortel的core部份open source的了,不過現在才比較有空整理一下project,寫一點test case及doc。

Github: https://github.com/airicyu/Fortel

 

Fortel

Java紫微斗數排盤Library

Author: Eric Yu


Samples

排盤

排盤:一九五二年十二月十五日早子時天盤,男性

JSON Output(Formatted):


檢查宮垣

排盤:一九九零年三月十一日午時地盤,男性

檢查命盤命宮是否: 會見廉貞, 並且同時”天魁或天鉞同宮”或”不見化忌”

Output:


檢查命盤命宮是否: 會見廉貞, 並且同時”天魁或天鉞同宮”或”不見化忌”

Output:


JavaDoc:

You can view the Javadoc page at “\fortelcore\javadoc\index.html”

[Nodejs] FB Page post comment/reply event engine

岩岩寫左隻FB Page post comment/reply event engine既Nodejs module。

個module目的係幫FB page owner去mon住個FB page係咪有新comment,然後generate event & 俾個位d人自己去寫callback logic。

實際做法就係佢背底會行個schedule job去call FB graph API黎check post既new comments。

NodeJS module for keep track Facebook Page Posts New Comments

NodeJS module “fb-page-comment-event”

This module can keep track your Facebook page posts’ first level comment events. Hence, if someone commented on your post, you will be notified by an event.

This module support running an event-engine which would manage a background schedule job to check new comment and generating events. This module also support raw APIs which you can check new comments and digest as events by yourself via APIs.

 

Related Pages

Github page: https://github.com/airicyu/fb-page-comment-event
NPM: https://www.npmjs.com/package/fb-page-comment-event

 

Description

This module can keep track your Facebook page posts’ first level comment events. Hence, if someone commented on your post, you will be notified by an event.

This module support running an event-engine which would manage a background schedule job to check new comment and generating events. This module also support raw APIs which you can check new comments and digest as events by yourself via APIs.


Running the event engine

You may use the lib.pageCommentEventApp(options) API to get a event engine app and then start it with run function. This event engine app would manage a schedule job to auto pull data.

Sample:

  • Remarks: pageId is the facebook page ID. postId is the facebook page post ID of post which you want to monitor its comment. accessToken is the Facebook page access token(remember to use the long live token) which Facebook page owner can generate in developer dashboard.

Sample console log output:


(DIY) Use the APIs to check new comments and generating events

Sample:


event engine APIs

let app = lib.pageCommentEventApp({accessToken, pullInterval})

Description:

Initializing the event engine app.

parameters:

  • accessToken: The required accessToken(need permission manage_pages) for the API calls.
  • pullInterval: The sleep time(ms) interval between each scheduled page post new comment checking.

return:

The event engine app.

app.registerMonitorPost({pageId, postId})

Description:

Registering a page post which the event engine would tracking for new comments

parameters:

  • pageId: The page ID.
  • postId: The post ID.

app.run(eventsCallback)

Description:

Start running the event engine and register the new-comment-events callback. Once users write new comments, new-comment-events would be fired and handled by the callback.

parameters:

  • eventsCallback: The batch new-comment-events handling function.

app.stop()

Description:

Stop the event engine


DIY APIs

let queryPostCommentAgent = lib.api.getQueryPostCommentAgent(options)

Description:

Initialize a agent for query post comments.

parameters:

  • options: object with attribute accessToken which holding the required accessToken(need permission manage_pages) for the API calls.

return:

The agent object.

let postCommentFetcher = lib.api.getPostCommentFetcher(queryPostCommentAgent)

Description:

Initialize a fetcher for fetching new post comment.

parameters:

  • queryPostCommentAgent: The agent object which come from lib.api.getQueryPostCommentAgent(options)

return:

The fetcher object.

let postCommentObj = await postCommentFetcher.fetch(postObjId, since)

Description:

Use the fetcher object to fetch post object with comments. We can use this API to get all new comments under the target post which those comments are created since the since time.

parameters:

  • postObjId: The post object ID which is in format of ${pageId}_${postId} in Facebook Graph API.
  • since: The timestamp in second

return:

The post object with comments (All comments child objects are new comments).

let postDigestor = lib.api.getPostDigestor();

Description:

Getting a digestor object which can turn the post-comment object from postCommentFetcher.fetch() result into new-comment-events.

return:

The digestor object.

let newCommentEvents = await postDigestor.digest(postWithNewComments)

Description:

Use the digestor object to digest post-comment object into new-comment-events

parameters:

  • postWithNewComments: The post object with attaching new comments.

return:

New comment event objects

關於blockchain的少少個人理解與想法

講少少個人理解,blockchain大概是一種在處理asset擁有及轉移的應用技術。
對於這種應用,傳統社會的做法牽涉大量trust與資訊交換機制與成本。而因為trust issue, 所以形態上是很多parties各自的centralized trust機制,所以加大了交易成本。

blockchain的做法,是去中心化的trust(rathet than only data storage層面)機制。
藉着公有公開驗證的做法,所有資產轉移都是自帶驗證。
所以大大解決了trust與驗證的成本。(這是blockchain的最大價值)

但當然,技術還技術上的價值,應用上仍然可以是空殼廢紙,所以把資產本質由實體($)轉為虛擬貨幣的應用,用家進入市場有很大風險。

另外,在應用層面,blockchain一定是資產轉移流水帳的use case。若否,則blockchain技術不會帶來太大價值。

另外,blockchain需要公開帳目,我沒仔細研究過,但我懷疑仍有可能由transaction之間去trace back到account持有者身份。
例如,我是e store, 我賣了一件貨給某人,進行了某bitcoin交易,那應該有一條transaction是若干bit coin由某人銀包轉移到我銀包。那我是否能由“某人銀包”去識別出其他關於某人的bitcoin交易?若我掌握大量銀包識別資訊,那會否讓我能知道大眾的帳目資訊?
(我不熟這範疇,純粹ff 想想而已)

Airic API Gateway

Just for fun.
最近斷斷續續前後用左幾個星期左右,自己用NodeJS寫左個REST API Gateway。
 
簡單講隻REST API Gateway做d乜就是:
有個API config server,可以o係上面register隻app+import個swagger,
之後就可以create client同reg API key,
之後就可以用d API key經gateway去call果d REST API。
 
隻Gateway帶黎既benefits係:
– 隔左一層as protection layer,
– 有得落Quota rule去set quota (quota rule =/= spikearrest),
– 會收集到usage stat (1minute bucket),事後可以睇得到某時間內咩人call過邊個app邊個rest operation幾多次。
 
 

Project code name:

Airic API Gateway
 
 
 

基本Features:

 
– 冇UI…(其實依個唔係feature…)
因為我好怕攪frontend野太煩sosad, 所以直頭完全冇攪UI。
CRUD app API﹑CRUD client﹑register API key全部management operation靠REST API去做。
 
– app API definition係食swagger。
 
– support quota rule (1m, 5m, 1h, 1d, 1week, 1Month)。
quota rule可以apply落app level, operation tag level, 或者operation level。(app/tag/operation係跟據swagger spec而判斷)
 
– support對應同一app之下,唔同client分別用唔同quota plan (可以同時apply多個quota plan)
 
– 會log低API usage statistic & 可以用REST API query返出黎,睇到每隻app/operation/client o係某段時間內call左幾多次之類。
 
 

Performance

 
load test今日有試過下。
local PC用jmeter做load test (200 Testing thread), nodejs cluster x 4, 有enable 3條quota rule。
 
throughput都做到~2800 req/s。
random take sample既純粹入gateway processing直至response完成時間(而唔計proxy call背後API既時間)大約係0.x ms至10ms之間。
 
之後我再試多次,code果度直頭完全唔proxy call後面API,直接response返去,咁就真係可以計到純粹gateway processing直至response既時間& throughput。
咁樣load test係可以去到~5200 res/s。
random sample 入gateway到response時間都大約係0.x至10ms之間。
 

project status:

 
算係做左prototype,functionally基本叫做workable…
不過test我都只係人手test冇mocha unit test, 亦都冇寫doc。
(遲D執返好晒D野少少, 得閒先放上github吧~XD)
 
 

Component有邊幾樣野?

1) API config server – 儲住App﹑API config definition既核心。
2) API gateway – 就係隻gateway
3) API stat server – 儲住usage stat
(原本諗住寫多隻key server由config server拆出黎, 但我發覺key同config好難拆得開,我懶+怕煩就冇攪喇)
 
 
 

Database用左乜

1) App Config可以用MySQL或者Mongo或者Memory (好似Mongo方便dd, 不過我MySQL都係用json type儲, 所以差唔多)
 
2) API key可以用MySQL或者Mongo或者Memory (MySQL或者Mongo都冇所謂)
 
3) API call quota可以用Redis或者Mongo或者Memory (Prefer Redis, 好似快好多咁, 依part是用key-value lookup的)
 
4) API usage stat可以用MySQL或者Memory (Prefer MySQL, 只用來事後Aggregate, 其實用Mongo做都ok不過我冇整到)
 

Software developer的價值在於什麼

作為一個Software developer,我有時會想Software developer的價值在於什麼?

寫code﹑productivity?

我當你做同一件feature,你用3個月時間去做。
而假設同一件事,一個普通大陸developer,是要用5個月時間去做。
那麼我假設,用3個普通大陸developer,可能3個月時間都做得完。
其實從codiing﹑productivity角度,你的價值就只是3個普通大陸developer。
一個developer人工幾多?3個普通大陸developer人工幾多?

而且,寫code層面,你從市場上很容易找到人去replace。
所以我常常跟朋友說,technical野不值錢,寫code不值錢。
你計計自己寫code的productivity,in terms of 幾多個普通大陸productivity,就會發覺自己不值錢。
(當然,如果你做的是冷門的programming language skillset,市場供求問題,你價值會高一點。但那也有drawback,在此從略。)

所以我覺得,作為一個developer,
最重要的是找到/去develop一些自己的價值, which is coding & productivity以外的價值, 而那不可能被簡單地用3個普通大陸developer去replace你。

責任﹑視野﹑innovation﹑執行力﹑溝通能力…這些東西都是比起coding & productivity重要得多。
對於freshgrad, 入行做左一兩年左右的developer,我覺得這是很值得他們想想的問題。

從Framework user角度去如何做Framework

如果我是product team,我的想法就是以做好我的product為我的最優先piority。
Framework什麼﹑其他application什麼,他們應該是想想如何幫助到我的pain point,而不是為我製造更大的effort。
而我也只concern對我的product角度有value的事才是真正的有value。
我是面向market﹑customer﹑business﹑user﹑…那些才是最重要的事。

反過來,我自己做Framework人,
我會同情地了解著product team角度地去做返我自己(Framework人)。

我往往是從story角度開始去思考/validate問題,technical問題都只是為要實現story才出現的。
當然,technical不可行也就說不下去。
但story層面想不通的話,technical問題也就不太需要想。

在technical之前的問題是,關於story,我們說的是what? who? when? why? how?

—————————————

做Framework人其實有時有少少人格分裂,

因為要有頂帽是用framwork的一般product角度,
有頂帽是站在公司最重要的very important application角度,
有頂帽是一般developer user角度(product developer本身不一定與product的角度align的),
有頂帽是大環境culture角度,
有頂帽是management睇野角度,
有頂帽是technical可行性及延展性角度。

點做一件事,其實背後唔係純粹technical問題,
背後有好多可能自己不知不覺做左都唔為意既tradeoff。

我當初做個紫微斗數網係點做?

最初最初,我同朋友(user)傾開知道佢地每次起盤(operation)都要用一d好唔方便既tool,而且好唔dynamic,所以每次用都要做好多操作﹑print幾十張紙。
睇到個大致有painpoint,之後我再同佢地傾details少少painpoint bottleneck﹑點樣先幫到佢地﹑佢地點睇個問題。

user講到既最表面問題就係:
1) 每次operation要好多人手操作
2) 每次都要print幾十張紙出黎係咁搵野

於是解決件事同時,我親身去學果樣野,化身為一個user,去了解個問題。
in parallel去分析個問題。
其實問題係舊有既tool互動性﹑資訊性太差,所以好多野要offline做,好白痴。

所以solution係要:
1) 增強操作介面互動性,從而將operation搬返去online度做。(呢個point係由user直接講到俾我聽)
2) 增加一d必須既資訊,有得好方便去search﹑filter。(呢個point係我真正企入去了解個問題之後,自己further諗出黎,佢地初頭foresee唔到就同我講係optional)

第2點,我都唔係自己係咁做做做。
我都係做個minimum viable feature出黎,然後去問下d user覺得正唔正,有冇value,有value我就再enhance。

搵錢其實搵唔到,因為我唔想攪。
雖然我其實一早駁好晒paypal,technically收錢系統根本加少少野就整到個member subscription。
但我唔想諗點計錢,亦唔想收錢攪到d同學唔想用,我想對佢地有用多過搵錢,就係咁。

我唔覺得成件事有咩成功。
我只係想講做product係應該類似咁做。
依d野冇人教我亦冇人指點過我,但我覺得依d係common sense。