What is Tdd?

What is TDD? Before writing any code that adds new functionality to an application, the developer first writes an automated test describing how the new code should behave, and watches it turn red (fail to pass). They then write the code to the specification, and the test turns green (it passes). Finally, the developer takes a little time to make sure that the code just written is as clean as possible (refactoring). ...

June 10, 2020 · 4 min · 680 words · Ken Cho

Postgresql

What is PostgreSQL? PostgreSQL is an enterprise-class open source database management system. It supports both SQL for relational and JSON for non-relational queries. PostgreSQL supports advanced data types and advance performance optimization. Key features Compatible with various platforms using all major languages and middleware It offers a most sophisticated locking mechanism Support for multi-version concurrency control Compliant with the ANSI SQL standard Full support for client-server network architecture Log-based and trigger-based replication SSL Standby server and high availability Object-oriented and ANSI-SQL2008 compatible Support for JSON allows linking with other data stores like NoSQL which act as a federated hub for polyglot databases MySQL vs PostgreSQL MySQL PostgreSQL The MySQL project has made its source code available under the terms of the GNU License, and other proprietary agreements. PostgreSQL is released under PostgreSQL License. It’s now owned by Oracle Corporation and offers several paid editions. It’s free and open-source software. That means you will never need to pay anything for this service. MySQL is ACID compliant only when using with NDB and InnoDB Cluster Storage engines. PostgreSQL is completely ACID compliant. MySQL performs well in OLAP and OLTP systems where only read speed is important. PostgreSQL performance works best in systems which demand the execution of complex queries. MySQL is reliable and works well with BI (Business Intelligence) applications, which are difficult to read PostgreSQL works well with BI applications. However, it is more suited for Data Warehousing and data analysis applications which need fast read-write speeds. Advantages Can run dynamic websites and web apps. Write-ahead logging makes it a highly fault-tolerant database. Source code is freely available under an open source license. Supports geographic objects so you can use it for location-based services and geographic information systems. Supports geographic objects so it can be used as a geospatial data store for location-based services and geographic information systems. Low maintenance administration for both embedded and enterprise use. Disadvantages Changes made for speed improvement requires more work than MySQL as PostgreSQL focuses on compatibility. Many open source apps support MySQL, but may not support PostgreSQL. On performance metrics, it is slower than MySQL. Download and install Download and install postgrlSQL brew doctor brew update brew install postgresql Download and install Pgcli, for Postgres with auto-completion and syntax highlighting. brew install pgcli The path of psql brew info libpq To include in in zshrc echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc Postgre.app Postgre.app is a full-featured PostgreSQL installation packaged as a standard Mac app. ...

June 9, 2020 · 7 min · 1319 words · Ken Cho

Yii1.1 for beginners

What is Yii Model-View-Controller architecture? MVC schema Model defines relations among data in DB and rules that must be followed when saving data to DB. It also gives us tools to read/save data from/to DB. View shows data to user. It doesn’t write to DB or count difficult things. It just receives data and shows them using HTML, CSS, JS, etc. Controller processes and changes the data, handles user’s actions, decides, counts, thinks and calls models and views. It simply acts. ...

June 4, 2020 · 3 min · 532 words · Ken Cho

How to build a blog using Yii1.1

Aim To familiarize the framework of Yii 1.1. How The steps can be found here The source code is stored at github repo Docker container for Nginx and PHP=FPM webserver, link Steps to note Download the Yii 1.1 source code at here Unpack the compressed file and move to dockerfolder/app tar -xvzf yii-1.1.22.bf1d26.tar.gz Rename the folder name to yii-1.1.22 Go to the framework folder to create a skeleton application by ./yiic webapp ../blog-yii1.1 Establish DB connection in /protected/config/database.php return array( 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/blog.db', ); Allowing Gii for scafolding /protected/config/main.php 'import'=>array( 'application.models.*', 'application.components.*', ), 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'Password', 'ipFilters' = False, ), ), How to customize the rules method in /protected/models/Post.php public function normalizeTags($attribute,$params) { $this->tags=Tag::array2string(array_unique(Tag::string2array($this->tags))); } public function rules() { return array( array('title, content, status', 'required'), array('title', 'length', 'max'=>128), array('status', 'in', 'range'=>array(1,2,3)), array('tags', 'match', 'pattern'=>'/^[\w\s,]+$/', 'message'=>'Tags can only contain word characters.'), array('tags', 'normalizeTags'), array('title, status', 'safe', 'on'=>'search'), ); } How to customize the rules method in /protected/models/Tag.php public static function string2array($tags) { return preg_split('/\s*,\s*/',trim($tags),-1,PREG_SPLIT_NO_EMPTY); } public static function array2string($tags) { return implode(', ',$tags); } How to customize the relations method in protected/models/Post.php public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'author' => array(self::BELONGS_TO, 'User', 'author_id'), 'comments' => array(self::HAS_MANY, 'Comment', 'post_id', 'condition'=>'comments.status='.Comment::STATUS_APPROVED, 'order'=>'comments.create_time DESC'), 'commentCount' => array(self::STAT, 'Comment', 'post_id', 'condition'=>'status='.Comment::STATUS_APPROVED), ); } How to customize the relations method in protected/models/Comment.php class Comment extends CActiveRecord { const STATUS_PENDING=1; const STATUS_APPROVED=2; const STATUS_ARCHIVED=3 ...... How to create portlets for User Menu, Tag Cloud and Recent Comments 11.1 UserMenu portlet 11.2 TagCloud ...

June 1, 2020 · 2 min · 284 words · Ken Cho

Yii 1.1 Quick Start

What is Yii? Yii is a high-performance, component-based PHP framework for developing large-scale Web applications rapidly. It enables maximum reusability in Web programming and can significantly accelerate your Web application development process. What is Yii best for? Yii is a generic Web programming framework that can be used for developing virtually any type of Web application. Because it is light-weight and equipped with sophisticated caching mechanisms, it is especially suited to high-traffic applications, such as portals, forums, content management systems (CMS), e-commerce systems, etc. ...

May 27, 2020 · 2 min · 278 words · Ken Cho