2012年11月22日 星期四

[nginx] facebook canvas連nginx時出現 HTTP 405 Not allowed


Facebook是用POST去抓canvas/iFrame,
但是nginx處理static file預設不給POST,
workaround如下:

location / {
    error_page 405 =200 $uri;
    root /var/www/html/yoursite.com;
}

比較好的處理如下:
http://invalidlogic.com/2011/04/12/serving-static-content-via-post-from-nginx/

2012年11月19日 星期一

[SQLAlchemy] 不用primary key的table

table沒有設pirmary key會出現這個錯誤:

sqlalchemy.exc.ArgumentError: Mapper Mapper|FooTable|foo_table could not assemble any primary key columns for mapped table 'foo_table'

mapper要設:

"primary_key":(col1, col2)}

2012年11月15日 星期四

[Mac][git] git diff in Mac


如果有裝GitX的話,設定選"Enable Terminal Usage",然後

git diff | gitx


或是XCode的FileMerge/opendiff也很好用,

git difftool -t opendiff -y

可以寫到.gitconfig的

[alias]
   df = difftool -t opendiff -y

2012年11月14日 星期三

[SQLAlchemy] foreign key constraint 問題


以不delete, SET NULL為例:

1. database level
db.Column(db.Integer, ForeignKey(db.ForeignKey('category.id',ondelete='SET NULL')))

2. pythen level
db.relationship(passive_deletes=True)

2012年11月10日 星期六

2012年10月16日 星期二

Emacs 24 color theme 錯誤

是因為Emacs有內建color theme,語法改一下就好了。

參考:
http://batsov.com/articles/2012/02/19/color-theming-in-emacs-reloaded/

2012年7月3日 星期二

[tools] 找domain有無被用走的方便工具

https://github.com/zachwill/dom

$ pip install dom # 安裝
$ dom foo # 列出相關domain有無被註冊

2012年6月26日 星期二

[note] 2012 GDC Taipei - Aaron Pulkka (Rabbx) 利用AAA電腦/遊戲機遊戲開發經驗來獲得智慧手機/平板電腦遊戲的成功



AAA
------
  - big buget
  - large item
  - long development schedule
  -  requirement:
      * large scope,
      * broad feature set
  - long play time
  - high quality/ polish
  - innovation?
  - no middle in game market
  - marketing costs >= development costs


.. note:: core gamers bring high expectations but are willing to pay
.. note:: late adopters form new casual audience, but want to pay less


1. High Quality User Experiance
   - responsive
     - 0.1s good
     - 0.5s slow
   - consistent
   - clear/obvious
   - forgiving

  * Lasting Appeal
    - Ramping difficulty + Random Chance + Increasing Rewards = Replayability
    - Rollercoaster Excitement Curve

  * Quality Assurance
    - Start QA early, ramp-up from alpha through launch
    - 100 little bugs worse than 1 big bug

2. Launch Multiplatform

  * cross-platform social play allowed on mobile and can increase audience growth dramatically
  * Amortize Development & Marketing
  * Build game as native to each platform
    - meet 'cultural' expectations
    - tune for platform specific features
      * xbox live! rich presence
      * apple game center & retena display
      * android 'back'
3. Connect with yurr audience
  * Most AAA gamers target core gamers (young males)
  * konwing your audience
    * mobile has potential for broader audience
      - casual audience spends less per user
      - broader audience can increase costs
  * community anagement
      - best marketing: word-of-mouth
      - metric tracking can help filter noise
      - press is not magic entity but part of your community
      * bioware & blizzard provide great example
  * App store
    understanding how each app store search function works is key

  * Plannang
    - launch of game is just the beginning
    * plan for updates
      - DLC for AAA games usually in development before game launches
      - post-launch, be ready to modify update plan based on users

  * tools
    - metric tracking (flurry, bitpollen)
    - project management (Hansoft)
    - Feedback (Forum)

Naughty Dog (AAA developer with no project managers)


* clones copy a proven base set of features, without adding much new.
* experimental games focus more on innovation, generally at the expense of scope and polish
* AAA games focus on evolution and polish on proven features


smartphone
* short session
* always connected to Internet
tablate
* longer session
* often disconnected from Internet


AAA to mobile
* smaller scope
- app store
- more qualtiy
- more budget
+ larger possible audience
+ core gamers willing to pay to play


New Territory
---------------
TV + Mobile:
* Google TV
* Apple TV
* Transmedia
TV + Console + Mobile:
* MS Smart Glass
Tactile Controls:
* joysticks and buttons on mobile? (we missed buttons)


[note] 2012 GDC Taipei - Metro Style Game for Windows 8

Metro App min resolution: 1024x768
如果Metro App resolution大於1366x768+會在前景另外開一個APp (Snap View?)
Tile 動態磚, 每個是不同Entry Point, 同一個遊戲可有不同進入點 (從不同關卡進去)
Data sync:
* App Data(setting...)
* User Data (music, library...) -  live.com 帳號
Game可在任意時間(電動打一半)分享, 分享給個social service, 或"另一個App" (puzzle...)
統一Settings (Setting的framework?), 統一使用者體驗
http://ie.microsoft.com/testdrive/

2012年6月10日 星期日

好fish shell, 不用嗎

shell很多了: bash, ksh, dash, zsh... 在PyCon Taiwan 2012聽到這個很好用的fish shell,目前我只能發現自動補齊和指令顏色顯示很方便,不用很複雜的設定,就很好用了。

1. 在Mac OSX用brew安裝:
brew install fish
2. 設定檔在: ~/.config/fish/config.fish (自己新增) 顯示git branch,
    參考: https://wiki.archlinux.org/index.php/Fish#Configuration_Suggestions

3. 換預設shell:
chsh -s /usr/local/bin/fish
4. 以上出現"non-standard shell"錯誤, 到/etc/shells加"/usr/local/bin/fish"

但是指令和bash/zsh不太合。

2012年5月7日 星期一

Git 強制pull

git pull時出現 error: Untracked working tree file 'foo.bar' would be overwritten by merge. Aborting
git fetch --all
git reset --hard origin/master
ref: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull

2012年5月2日 星期三

[Python][Javascript] Python抓Javascript產生的頁面 (phantomJs)

一向都是用Python的Beautiful Soup來parse網頁,現在出到第四版,更好用文件也好看多了。
from BeautifulSoup import BeautifulSoup
改成
from bs4 import BeautifulSoup
method name也有改,參考。 不過這次遇到的是內容是javascript產生的,如play.google.com,以前可能看一下js的code,學他送http request出去就可抓回來,現在的js越來越複雜,不好搞。
幸好有PhantomJS這種東西(headless WebKit with JavaScript API),就可以很方便的用webkit把網頁內容全開出來(跑完javascript)。 既然是javascript,DOM的selector就用jquery吧(page.injectJs("jquery.min.js"))。
var page = require('webpage').create(),
    t, address;

if (phantom.args.length === 0) {
    //console.log('Usage: loadspeed.js ');
    phantom.exit();
} else {
    address = phantom.args[0];
    page.open(address, function (status) {
        if (status !== 'success') {
            //console.log('FAIL to load the address');
        } else {
          
           if (page.injectJs("jquery.min.js")) {
                //console.log("jQuery loaded...");
            }

            var get_data = page.evaluate(function () {
              var data = {}
              data['title'] = $('h1.doc-banner-title').text();
              data['content'] = $('#doc-original-text').text();
              data['icon'] = $('.doc-banner-icon img').attr('src');
              var img_list = []
              $('.screenshot-carousel-content-container img').each(function(){ img_list.push($(this).attr('src')) });
              data['images'] = img_list

              return JSON.stringify(data);
            });
          console.log(get_data);
          phantom.exit();
        }

    });
}
command line執行$ phantomjs my_scrapy.js my_url console.log裡的資料就回跑出來了。 Python裡用commands.getoutput,再json.loads把JSON拆成dict,大改就這樣吧。
import commands
import json

out = commands.getoutput(my_cmd)
data = json.loads(out)

[Flask] multiple file input 上傳多檔案

這個害我傷腦筋好久,Flask處裡form的post,透過Werkzeug處理,如果是單一name,用request.values()(串列list)或request.form(dict),就可以抓到。如過是多重name,如:
<input name="animal" type="checkbox" value="lion" />
<input name="animal" type="checkbox" value="tiger" />
就要用request.form.getlist('animal')取的list。

檔案上傳:
<input name="icon[]" type="file" />
就要用request.files,是一個werkzeug自定的ImmutableMultiDict。 如果是同一個name的多檔案(input array)
<input name="image[]" type="file" />
<input name="image[]" type="file" />
request.files裡有值,但是用for j in request.files:同一個input name只能抓第一個出來,有人說Flask-WTF的FileField可以解決(沒試過)。後來去看了Werkzeug的原始碼:
class MultiDict
...
def iteritems
...
學他用
for key, values in dict.iteritems(request.files):
     for value in values:
         print key, value
就可以了。

2012年4月23日 星期一

[Flask][Flask-WTF]

Flask-WTF升級到0.6,{{ form.csrf }}要改成{{ form.csrf_token }}

2012年4月16日 星期一

[Django] 圖片上傳錯誤

換了新的VPS後上傳圖片出現錯誤:
(jpg才會出現)

"上傳一個有效的圖片。你上傳的檔案不是圖片,否則就是壞掉的圖。"
英文:
"Upload a valid image. The file you uploaded was either not an image or a corrupted image."

果然是PIL的問題,找不到libjpeg吧,用pip或apt重裝/upgrade PIL, libjpeg等都沒用。

懶得自己重編,最後是以下順序成功了:
sudo pip uninstall PIL
sudo apt-get install libjpeg-dev
sudo pip install PIL

2012年4月14日 星期六

[WebDesign] 10 things every designer needs to know about forms (心得文摘)

via: 10 things every designer needs to know about forms

其實很多都是「常識」了,不過再實作時還是會常常忘記。

1. 不用特別標示「必填欄位」,使用者通常只會直接按送出,然後再看有什麼沒填完的。
2. 不要用HTML5的"spinner",按鈕小不好按,用普通的TextField或Select就好了
spinner: http://www.html5tutorial.info/html5-number.php
3. 表單有很多按鈕時,要把最重要的「送出」特別標出,不然容易迷失自我。
4. 欄位多可以分區塊,人是視覺的動物
5. 表單的用詞遣字可多用心,讓使用者覺的填這資料是有意義的,而不是冷冰冰格子。(想一下例子)
6. 日期欄位用動態跳出的月曆來選很酷,但是要考慮各地風水民情不同,年月日順序等(用Select簡單又方便)
7. Server端檢查不容易,但還是一定要做好 (工程師的事)
8. 不要設橫向欄位,或是用tab,從上到下就好了
9. 簡化欄位,如地址不要用xx路xx巷xx號、電話不要分區碼,直接用一格就好了
10. 別用機掰語氣做錯誤檢查,如:出生選成2028年,不要寫「你是未來出生的嗎」

2012年3月29日 星期四

[Flask][WTForms] 要在HTML的Select tag, 新增一個"空"的預設選項

本來想用jQuery來後製,但其實不用那麽麻煩,WTForms果然都想好了:
QuerySelectField的話,加上
allow_blank=True, blank_text=u'-- please choose --'


wtforms doc

2012年3月8日 星期四

時常出現HTTP 403 Forbidden

Forbidden

You don't have permission to access xxx on this server.

通常發生在圖很多的頁面,兇手是Apache防DOS的mod_evasive
果然是被保護機制擋掉了...

2012年2月17日 星期五

[Python] 像PHP的associate array一樣初始Dict

Python的dict不能像PHP的associate array一樣"任意給值",當不知道dict有幾維時很麻煩。
有一個defaultdict可以用,只是不好看,哈哈!

cat = {} # 先初始一個dict
for k, v in foo_list:
cat.setdefault(k, []).append(v)


ref: collections

2012年2月15日 星期三

2012年2月8日 星期三

domain transfer

Godaddy -> Namecheap

1. 登入Godaddy,Domain Manager左邊Domain Information的Authorization Code:按Send by Email,
就會寄一封EPP Code的信來
2. 到Namecheap申請domain transfer, 付完錢後會寄一封信來, 給你一個認證網址, 再輸入剛才godaddy寄來的EPP code. 輸入後再等一封transfer認證信(不會馬上).
3. 收到認證信後, 點一個"terms and conditions of the Agreement"的連結, 看完按Approval, 等結果