Skip to content

Instantly share code, notes, and snippets.

shin Tuan-T-Nguyen

View GitHub Profile
@Tuan-T-Nguyen
Tuan-T-Nguyen / box-shadow.html
Created Apr 21, 2018 — forked from ocean90/box-shadow.html
CSS3 Box Shadow, only top/right/bottom/left and all
View box-shadow.html
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;
View search-escape.js
function escapeRegExp(str) {
return str.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
regExSearch = '^' + escapeRegExp(filter) + '$';
console.log(regExSearch);
table.column(2).search(regExSearch, true, false).draw();
@Tuan-T-Nguyen
Tuan-T-Nguyen / sumConditions.sql
Created Mar 7, 2018
SUM() based on a different condition to the SELECT
View sumConditions.sql
SELECT m.member_id, m.teamname,
Sum(Case When r.track_Id = '$chosentrack'
Then total_points Else 0 End) TotalChosenTrackPoints,
Sum(Case When r.track_Id < '$chosentrack'
Then total_points Else 0 End) TotalLessThanChosenTrackPoints,
total_points as last_race_points
FROM members m
Join members_leagues l
On l.member_id = m.member_id
Join member_results r
@Tuan-T-Nguyen
Tuan-T-Nguyen / FontAwesomeAsset.php
Created Mar 5, 2018
FontAwesomeAsset yii2 installed by bower install Font-Awesome
View FontAwesomeAsset.php
<?php
namespace app\assets;
use yii\web\AssetBundle;
class FontAwesomeAsset extends AssetBundle
{
public $sourcePath = '@bower/font-awesome/web-fonts-with-css';
public $css = [
@Tuan-T-Nguyen
Tuan-T-Nguyen / example.php
Created Jan 30, 2018
Fill zero, round up to specific digit decimal
View example.php
<?php
$number = '5.2';
$re = bcadd($number, 0, 2);
echo $re;
// 5.20
?>
@Tuan-T-Nguyen
Tuan-T-Nguyen / README.md
Created Nov 17, 2017
Add Sass to Reactjs
View README.md
@Tuan-T-Nguyen
Tuan-T-Nguyen / example.php
Created Oct 19, 2017
Convert models to array in Yii 1.1
View example.php
public function convertModelsToArray(){
$criteria = new CDbCriteria();
$criteria->order = 't.display_order';
$companies = Company::model()->findAll($criteria);
/** Or using list data
$users = User::model()->findAll();
$usersArr = CHtml::listData( $users, 'id' , 'city');
**/
$return array_map(create_function('$m', 'return $m->getAttributes();'), $companies);
@Tuan-T-Nguyen
Tuan-T-Nguyen / example.js
Created Oct 17, 2017
Get URL Parameters with JavaScript
View example.js
// From: https://www.sitepoint.com/get-url-parameters-with-javascript/
// Url example: http://example.com/?product=shirt&color=blue&newuser&size=m
// Using:
// getAllUrlParams().product; // 'shirt'
// getAllUrlParams().color; // 'blue'
// getAllUrlParams().newuser; // true
// getAllUrlParams().nonexistent; // undefined
// getAllUrlParams('http://test.com/?a=abc').a; // 'abc'
function getAllUrlParams(url) {
@Tuan-T-Nguyen
Tuan-T-Nguyen / User.php
Last active Oct 16, 2017
Sort click header of custom data column in Yii 1.1
View User.php
<?php
public function search()
{
$criteria=new CDbCriteria;
$criteria -> select = ("t.*, c.display_order AS companyOrder");
$criteria->join="LEFT JOIN company c ON t.companyId = c.id ";
$sort = new CSort();
$sort->attributes = array(
'id',
'username',
@Tuan-T-Nguyen
Tuan-T-Nguyen / Rules Validator Yii.md
Last active Oct 11, 2017
Rules Validator Yii Examples
View Rules Validator Yii.md

Yii 1.1

boolean: CBooleanValidator

Validates that the attribute value is either trueValue or falseValue.

  1. trueValue, the value representing true status. Defaults to '1'
  2. falseValue, the value representing false status. Defaults to '0'
  3. strict, when this is true, the attribute value and type must both match those of {trueValue} or {falseValue}. Defaults to false, meaning only the value needs to be matched.
  4. allowEmpty, whether the attribute value can be null or empty. Defaults to true. Example:
array('name', 'boolean', 
You can’t perform that action at this time.