Send Email Attachments with Unicode Filenames in Django

使用 MIMEApplication 並設置 attachment 的 header 不然如果檔名有中文的話 用 Gmail 收到的附件檔名會是 noname def withdraw_send_email(request, pk): withdraw = get_object_or_404(Withdraw, pk=pk) email = '[email protected]' subject = _(u'Packer 數位發行服務') body = render_to_string('dps/email/withdraw_notice.html', {}) message = EmailMessage( subject=subject, body=body, to=[email, ], ) message.content_subtype = 'html' from email.mime.application import MIMEApplication # 檔名包含中文的話,要用這種方式 Gmail 收到的附件檔名才不會是 noname filename = '%s 結算表.xlsx' % (withdraw.serial_number[:6].encode('utf-8'))… Read More

Upload your Java Artifacts to Maven Central Repository

你需要: 一個使用 Maven 管理的 Java project(廢話) 一個 GPG key(deploy 的時候會用來 sign 要提交的 .jar) 一個 Sonatype JIRA 的帳號 開一張 JIRA 的 ticket 告訴 Sonatype 的人你要發佈 library,告知他們你的 groupId 按照 Requirements 的指示完善你的 pom.xml deploy 到 snapshot repository deploy 到 staging repository 在 OSSRH 的 Staging Repositories 把你剛剛 deploy 的 library 給 close 掉,這樣才算是 release 回到那張 ticket,通知 Sonatype 讓他們把你的… Read More

Maven: The De Facto Build Tool for JVM Projects

Install # on Mac OS X $ brew install maven $ brew install maven-completion ref: https://maven.apache.org/index.html Commands # create project: interactive mode $ mvn archetype:generate \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=true # create project: non-interactive mode $ mvn archetype:generate \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false \ -DgroupId=ws.vinta.pangu \ -DartifactId=pangu # download dependencies $ mvn dependency:copy-dependencies # download dependencies to… Read More

coverage.py: Python code coverage

coveralls.io 跑 python project 的覆蓋率就是用 coverage.py nose 也是用 coverage.py 基本上 Python 社群幾乎都是用這個 ref: http://nedbatchelder.com/code/coverage/ http://www.cnblogs.com/coderzh/archive/2009/12/01/1614874.html Install $ pip install coverage Configuration in .coveragerc [run] branch = True source = email_confirm_la omit = email_confirm_la/migrations/* email_confirm_la/south_migrations/* email_confirm_la/tests/* [run] 底下的 include 和 omit 是用來指定 filename pattern 而 source 是用來指定 package 或目錄 omit 是「忽略」的意思 ref: http://nedbatchelder.com/code/coverage/config.html Usage # 會自動套用當前目錄下的… Read More