如何在開發的過程中加入測試。
- Model
- Repository
- Controller
- Auth
| from unittest import TestCase | |
| import testing.mysqld | |
| MYSQLD_FACTORY = testing.mysqld.MysqldFactory(cache_initialized_db=True) | |
| def tearDownModule(): | |
| """Tear down databases after test script has run. | |
| https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass | |
| """ |
| import unittest | |
| import db_model | |
| TEMP_DB_FILE = ':memory:' | |
| class TestCoreBasic(unittest.TestCase): | |
| def setUp(self): | |
| self.db_url = 'sqlite:///{}'.format(TEMP_DB_FILE) | |
| self.engine, self.session = db_model.db_init(self.db_url) |
| from sqlalchemy import Column, Integer, String, DateTime | |
| from sqlalchemy.dialects.sqlite import DATETIME | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| Base = declarative_base() |
| def assertSQLEqual(first, second): | |
| if isinstance(first, str) and isinstance(second, str): | |
| first = "".join(first.split()) | |
| second = "".join(second.split()) | |
| if first != second: | |
| raise AssertionError('{} != {}'.format(first, second)) | |
| else: | |
| raise TypeError('Both {} and {} should be str.'.format(first, second)) |
| # delete local tag '12345' | |
| git tag -d 12345 | |
| # delete remote tag '12345' (eg, GitHub version too) | |
| git push origin :refs/tags/12345 | |
| # alternative approach | |
| git push --delete origin tagName | |
| git tag -d tagName |
| 標題: Spark 線上競賽平台 | |
| 大綱:市面上很多線上解題平台例如LeetCode,但是目前沒有一個平台可以讓使用者在線上用 spark 解題. | |
| 為了推廣 spark 應用,SparkTW 自行建置了一線上平台,可以供使用者使用 Spark 解題. | |
| 使用者可以在線上即時的使用 scala 或 python 編輯,當送出答案時,伺服器會在 runtime 編譯使用者的 code,並呼叫 Spark 比對答案. | |
| 使用者可以線上看到自己的每一題的註冊次數,花費的時候,以及其他好手們的成績. | |
| 演講內容會包括搭建平台時技術上的細節,包括前端如何支援 Code Highlight,如何將 Code 送到執行 Spark 的伺服器,以及如何將結果回傳. | |
| 為了增進使用者體驗,平台端花了很多時間解決像是 Spark Job 排程問題, 加快 Scala 編譯的速度,以及透過 RDD 直接比對結果等細節. | |
| 解題平台(https://codefight.sparktw.ml/)已於 2017/9/30 正式上線使用, |
| def inverse_normal_cdf(p, mu=0, sigma=1, tolerance=0.00001): | |
| """find approximate inverse using binary search""" | |
| # if not standard, compute standard and rescale | |
| if mu != 0 or sigma != 1: | |
| return mu + sigma * inverse_normal_cdf(p, tolerance=tolerance) | |
| low_z, low_p = -10.0, 0 # normal_cdf(-10) is (very close to) 0 | |
| hi_z, hi_p = 10.0, 1 # normal_cdf(10) is (very close to) 1 | |
| while hi_z - low_z > tolerance: |
| from math import ( | |
| pi, | |
| cos, | |
| sin, | |
| log, | |
| atan, | |
| exp | |
| ) |
| #!/bin/sh | |
| # | |
| # chkconfig: 35 99 99 | |
| # description: Node.js /home/nodejs/sample/app.js | |
| # | |
| . /etc/rc.d/init.d/functions | |
| USER="nodejs" |