What is API?

A metaphor of API Think of an API like a menu in a restaurant. The menu provides a list of dishes you can order, along with a description of each dish. When you specify what menu items you want, the restaurant’s kitchen does the work and provides you with some finished dishes. You don’t know exactly how the restaurant prepares that food, and you don’t really need to. An API is very much the same thing as a UI, except that it is geared for consumption by software instead of humans. ...

August 20, 2020 · 2 min · 327 words · Ken Cho

How to make go to page feature

Problem To add a go to page feature in navigating file table. Details refer to this issue View files from large db #437 How Create a Go to page button match the button style with the whole webpage create btn_click class for this onclick button create input box for number, and assign id=pageTarget <style> .btn_click { border: solid 1px #0eb23c; color: #0fad59; padding: 4px 6px 3px 6px; text-decoration: none; background-color: Transparent; outline:none; } input { width: 3%; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } .text_box { color: #0fad59; background: #fff; border: solid 1px #0eb23c; outline:none; } </style> <button class="btn_click" onclick="goToPage()"><strong>Go to page</strong></button> <input type="number" id="pageTarget" class="text_box"> <a class="color-background"><strong> of <?= $files->getDataProvider()->getPagination()->getPageCount()?></strong></a> Create a goToPage() function in JavaScript document.getElementById('pageTarget').value gets the value of the input box <?php echo $model->identifier?> gets the paper ID number <?php echo $files->getDataProvider()->getPagination()->getPageCount()?> gets the max page count some requirements: disable input box arrows when userInput > max, return to max when userInput < min, return to min window.location.pathname will get current page url, will crash when go to page 2 and then press 1 so to create an array with default values: let targetUrlArray = ["", "dataset", "view", "id", pageID]; function goToPage() { var targetPageNumber = document.getElementById('pageTarget').value; var pageID = <?php echo $model->identifier?>; //To validate page number var userInput = parseInt(targetPageNumber); var max = <?php echo $files->getDataProvider()->getPagination()->getPageCount() ?>; //To output total pages // console.log(max); var min = 1; if (userInput >= min && userInput <= max) { console.log("Valid page number!"); }else if (userInput > max) { targetPageNumber = max; console.log("Error, return to " + max); } else if (userInput < min) { targetPageNumber = min; console.log("Error, return to " + min); } // var targetUrlArray = Array.apply(null, Array(5)).map(function(_,i) { return window.location.pathname.split("/")[i]});] // Create array with default values let targetUrlArray = ["", "dataset", "view", "id", pageID]; targetUrlArray.push('Files_page', targetPageNumber); window.location = window.location.origin + targetUrlArray.join("/"); // Uncomment will show the target url in console. // console.log(window.location.origin + targetUrlArray.join("/")) } Behat test PhantomJS has been discontinued, so it cannot simulate pressing action on Go to page button. In order to do so, behat.yml and docker-compose.yml need to be updated. ...

August 18, 2020 · 4 min · 842 words · Ken Cho

College Algebra in 7 hours

Learn Collage Algebra Calculus(later…), here Todo Done Reference freecodecamp Algebra YouTube Calculus YouTube

July 28, 2020 · 1 min · 13 words · Ken Cho

Commands use to run gigadb

To start a local gigaDB server docker-compose run --rm webapp Link to test if the web page is up If there are some build errors Rebuild and up the webapp containers again. docker-compose run --rm webapp If not work, restart the docker container app and rebuild the containers. If not work, check if psql, gigadb, database is presented in ~/.containers/-data and remove it. rm -rf ~/.containers-data/gigadb Run docker-compose run --rm webapp again to rebuild the containers. How to remove images List all images docker images -a Remove all images docker rmi $(docker images -a -q) How to remove container List all containers docker ps -a Stop the containers docker stop $(docker ps -a -q) Remove stopped containers docker rm $(docker ps -a -q) source digital ocean How to run a functional test in a docker environment for testing? Write unit test script and place in protected/tests/functional-test folder. Change the unit_functional script ./bin/phpunit protected/tests/functional-test --verbose --configuration protected/tests/phpunit.xml --no-coverage Run specific unit test: docker-compose run --rm test ./tests/unit_functional Output will be like this: PHPUnit 5.7.27 by Sebastian Bergmann and contributors. Runtime: PHP 7.1.30 with Xdebug 2.9.6 Configuration: /var/www/protected/tests/phpunit.xml ... 3 / 3 (100%) Time: 7.15 seconds, Memory: 14.00MB OK (3 tests, 7 assertions) How to run a functional test on a single file in docker environment? docker oneliner docker-compose run --rm test ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php Or go into docker bash and run phpunit docker-compose run --rm test bash root@45a46a8441d3:/var/www# ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php root@45a46a8441d3:/var/www# ./bin/phpunit --testsuite functional --bootstrap protected/tests/bootstrap.php --verbose --configuration protected/tests/phpunit.xml --no-coverage protected/tests/functional/AdminSiteAccessTest.php PHPUnit 5.7.27 by Sebastian Bergmann and contributors. Runtime: PHP 7.1.30 with Xdebug 2.9.6 Configuration: /var/www/protected/tests/phpunit.xml ... 3 / 3 (100%) Time: 4.18 seconds, Memory: 14.00MB OK (3 tests, 7 assertions) How to run a Behat test in a docker environment for testing Update the scenario syntax specific *.feature file, like: @ok @files Scenario: Files - Call to Actions Given I am not logged in to Gigadb web site When I go to "/dataset/101001" And I follow "Files" Then I should see a link "(FTP site)" to "ftp://climb.genomics.cn/pub/10.5524/101001_102000/101001/" with title "FTP site" Then I should see a button "Table Settings" Check if related functions in features/bootstrap/*.php needed to be updated, eg: public function iShouldSeeTabWithTable($arg1, TableNode $table) { if ("Funding" == $arg1) { $this->minkContext->getSession()->getPage()->clickLink($arg1); //| Funding body | Awardee | Award ID | Comments | foreach($table as $row) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Funding body']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Awardee']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Award ID']) ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Comments']) ); } } elseif("Files" == $arg1) { //| File name | Sample ID | Data Type | File Format | Size | Release date | link | foreach($table as $row) { $link = $row['link']; PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['File name']), "File name match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample ID']), "Sample ID match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Data Type']), "Data Type match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['File Format']), "File Format match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Size']), "Size match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Release date']), "Release date match" ); if ($link) { $this->minkContext->assertSession()->elementExists('css',"a.download-btn[href='$link']"); } } } elseif("Sample" == $arg1) { //| Sample ID | Common Name | Scientific Name | Sample Attributes | Taxonomic ID | Genbank Name | foreach($table as $row) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample ID']), "Sample ID match" ); if($row['Common Name']) { PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Common Name']), "Common Name match" ); } PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Scientific Name']), "Scientific Name match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Sample Attributes']), "Sample Attributes match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Taxonomic ID']), "Taxonomic ID match" ); PHPUnit_Framework_Assert::assertTrue( $this->minkContext->getSession()->getPage()->hasContent($row['Genbank Name']), "Genbank Name match" ); } } else { PHPUnit_Framework_Assert::fail("Unknown type of tab"); } } Assign @wip tag to the working scenario in .feature file, this can smooth the running of behat test. @wip @files Scenario: Files - Call to Actions Given I am not logged in to Gigadb web site When I go to "/dataset/101001" Run the Behat test command on specific scenario. docker-compose run --rm test bin/behat -vv --stop-on-failure --tags @wip ...

July 24, 2020 · 8 min · 1525 words · Ken Cho

How to implement Travis CI to a Hugo site

What is Travis? Travis is a continuous integration testing tool that integrates with GitHub. It allows you to run automated tests on your code each time a commit is made to the repository. How? Sign in Travis in https://travis-ci.org/ using github account. Enable Source github repo in Travis setting, eg.kencho51/gigathing Create Personal access token in github, the scopes include: repo admin:public_key admin:repo_hook user Copy the token generated and update the Travis Environment Variables as below: GH_TOKEN: paste the github GITHUB_EMAIL: [email protected] GITHUB_USERNAME: kencho51 Create .travis.yml at the directoyy top level language: go dist: xenial env: - HUGO_VERSION="0.74.2" before_install: - sudo apt-get update -qq install: true before_script: - wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.deb - sudo dpkg -i hugo_${HUGO_VERSION}_Linux-64bit.deb - rm -rf public || exit 0 script: - hugo --gc -v --minify deploy: provider: pages skip_cleanup: true keep_history: true github_token: $GH_TOKEN local_dir: public target_branch: master email: [email protected] name: kencho51 repo: kencho51/kencho51.github.io verbose: true on: branch: master Insert build status into default template, every post will have build status on it. Markdown format: [![Build Status](https://travis-ci.org/kencho51/gigathing.svg?branch=master)](https://travis-ci.org/kencho51/gigathing) Image URL: https://travis-ci.org/kencho51/gigathing.svg?branch=master Reference Using Hugo and Travis CI To Deploy Blog To Github Pages Automatically Two ways to deploy a public GitHub Pages site from a private Hugo repository DEPLOY HUGO TO GITHUB PAGES AND BUILD WITH TRAVIS CI 使用 Travis CI 部署 Hugo 博客到 Github Pages Deploy Hugo from Gitlab CI to Github Pages How I use Travis CI to automatically deploy this blog to GitHub Pages How to deploy Hugo site minimally ...

July 23, 2020 · 2 min · 244 words · Ken Cho