Chrome – Bypass Access-Control-Allow-Origin on Mac

About a year ago, i posted an article about allowing the Javascript accessing the local file system in order to read the local JSON file.

 

So if you are using Mac, you need to quit the Chrome application. Then execute the following command in Terminal.

/usr/bin/open -a "/Applications/Google Chrome.app" --args --allow-file-access-from-files

 

Reference: Disable same origin policy in Chrome on Mac OSX

Artifactory – Upload artifact through command line

Jenkins works well with Artifactory and the built artifact will be upload to the Artifactory repository automatically.

One day, i found that the artifact is built but it is not uploaded. The Linux server doesn’t have the desktop interface so i couldn’t upload the artifact through browser. An alternative way is to use the curl command to post the artifact to the repository.

curl -X POST <target url> --data <artifact>

 

Example:

curl -X POST http://localhost:8081/artifactory/dev-snapshot-local/eureka-v0.0.1.tar.gz --data eureka-v0.0.1.tar.gz

 

Done =)

Reference: StackOverflow – How do I deploy a file to Artifactory using the command line

陶傑 – 「亞洲價值觀」

二十年前開始,亞洲經濟增長,因為勞工成本廉價,出口強勁,促成就業普遍,市場旺盛。

本來,亞洲的「奇蹟」,只是經濟現象,經濟以「價格」(Price)的競爭為本,價格只與一個「錢」字有關,但那時候,亞洲一些領袖,開始翹尾巴,在國際論壇誇誇而談,大講所謂「亞洲價值觀」。

「亞洲價值觀」是甚麼?二十年來,除了一個錢字很明確,其他一片模糊。

亞洲不同歐洲。歐洲是耶教文明地區,從芬蘭挪威,到意大利葡萄牙,連俄國和波蘭,除阿爾巴尼亞和巴爾幹的少數,都信奉同一宗教,而且在一九九一年之後,都有民主普選。歐洲基本上,是一種共識。

但是亞洲不同:亞洲表面各自發財,日本脫亞入歐,早已不屬亞洲。南韓和中國,表面上稱為「儒家文化」,其實是胡扯,中國是蘇俄馬列的共產國,跟「儒家」沒半點關係,韓國也不再是「華夏」,跟真正儒家的台灣中華民國,韓國又沒有邦交。
Continue reading 陶傑 – 「亞洲價值觀」

陶傑 – 全力拼經濟

俄國入侵烏克蘭的克里米亞半島,大戰一觸即發。英美受到冷戰結束後最大考驗。國際傳媒,紛紛評析,由歷史、國際法、文化、公義,多角度評論。

只有香港的華文傳媒,只有一個角度,就是一旦烏俄開戰,對於經濟,有何影響。各類股票市場專家、經濟學者,紛紛只講一個Point,就是經濟。

戰爭首先會生靈塗炭,破壞環境,如果英美介入,隨時升級。普京是個流氓,流氓好用暴力,他們明白的語言,亦唯暴力。

對於香港,遠方的戰爭,你隔岸觀火,是不是眼中只有經濟,也就是只關心金錢利益呢──莫斯科股市大瀉,是入貨最佳時機?然後紐約倫敦有何連鎖反應,而後油價國際之起落,將會如何影響我的荷包?股市大瀉,對於買期指的人,比屍橫遍野更令人振奮。其他一切,不必細究。跟香港的電視劇師奶講烏克蘭,她們總覺得那是一個比砵蘭街遙遠很多的地方。

因為華人社會,不論中港台,近年政府民間,流行口號,叫做「全力拼經濟」。「全力拼經濟」之下,大學讀工管,就業首選美林和摩根大通,大學學生會內閣穿一身黑衣裝,都像律師和所謂行政人員。香港不但是一座經濟城市,以中環為首,還是一座經濟動物園。
Continue reading 陶傑 – 全力拼經濟

陶傑 – 唸口訣

槍擊刀砍新聞記者,在第三世界或專制國家,確實只是一種「文化」──如果烏干達總統阿敏和中非皇帝博卡薩的部落吃人肉,根據西方左派的社會學者,不可以列為「野蠻」(Barbarity),而只是獨特的「非洲傳統文化」的話。

容忍言論批評,讓新聞記者擁有自由,二百年來,只是西方世界尤其是英語國家的文化。由伏爾泰開始到美國憲法的條款精神,美國開國元老傑佛遜說:「在沒有政府和沒有報紙之間,我寧願選擇沒有政府」。西方世界尤其英語國家,尊重新聞自由,有他們的傳統。

英國首相、美國總統、加拿大和澳洲總理,無論如何兇狠,名下統領幾多特務,看見動搖自己的權力的內幕報道,都不會對新聞人出動暗殺和暗算。

首先,暗殺和偷襲,在英語世界,是陰暗卑瑣的行為,英國講紳士精神,競技場上的Fair Play,應用在生活裏。與仇敵光明正大的決鬥,請評判站中間,雙方持鎗,背道而行,一聲令下,才向政敵開火──決鬥要講公平的規則,英語世界的紳士精神,為何是如此重要的文明?因為紳士原則,就不容偷襲暗算的小人和流氓。
Continue reading 陶傑 – 唸口訣

陶傑 – 誰是王八蛋

《明報》前總編輯劉進圖被斬,到底是何因由,以西方的邏輯學,審視當前的中國式思維,是很有趣的中學通識課。

許多中國人讀了一些MBA或西洋書,也模仿着白人的思考,聲稱「沒有證據顯示劉進圖遇襲與新聞自由有關」,可能出於「個人恩怨」。既然「沒有證據」,即「不宜過早判斷」,既然不宜「過早判斷」,則劉氏被斬,與一名普通香港市民,包括三合會人士出於個人恩怨而遇襲,地位和性質相同。

但是一名普通市民或三合會人士遇刀襲,一年發生多宗,絕不會引起「不分左中右」的「全城譴責」,連特首、立法會主席、司局級官員,紛紛慰問、探視、「譴責兇徒有意識地殘忍」。

一名普通市民遇刀襲,既無此「不分左中右」的「全城公憤」隆重待遇,但劉先生卻「享受」了,很明顯,是因為劉先生的「新聞工作者」職業。

這就怪了:既然「沒有證據,不要扯上新聞自由」,那麼難道從事新聞工作的香港公民有特權?
Continue reading 陶傑 – 誰是王八蛋

Django REST framework – Create endpoints for custom actions

We have talked about how to use Django REST framework to create a RESTful backend for model CRUD.

 

But sometimes we would like to have some backend endpoints for non-model actions. Here is a very good article written by Jeremy Satterfield about non-model endpoints on Django REST framework.

 

The Django REST framework offer us a few ways to implement the web service. Some of them are very convenience to use but in return giving you less flexibility. The following example will make use of the APIView class to create a custom GET request end point.
Continue reading Django REST framework – Create endpoints for custom actions

Django – Schedule django-admin command using django-chronograph

Previously we talked about setting up some custom command in a Django project.

 

I would like to run the custom command in a regular interval. I could use Linux cronjob but it’s hard to manage and check the run history. It would be great if i could setup and manage these scheduled commands on the Django web portal.

django-chronograph, written by wnielson, is a Python Package which allows us to schedule any django-admin command through the web interface. It works well with the UTC timezone but if you have set the TIME_ZONE in your Django project setting.py, there would be time discrepancy.

For more detail about the bug, you can refer to the Issue #36 – Job doesn’t follow the Django’s TIME_ZONE setting.
Continue reading Django – Schedule django-admin command using django-chronograph

Django – Create custom django-admin command

We could manage our Django project by executing some commands which could be invoked through the manage.py. For example:

# Sync database
python manage.py syncdb

# Start the webserver
python manage.py runserver 0.0.0.0:8000

 

Not only this built-in commands, we can write our own command too.

1. Create a new Django project and in this example i called it custom_command. (Django 1.6.5)

django-admin.py startproject custom_command

Continue reading Django – Create custom django-admin command

Dream BIG and go for it =)