Skip to content

Instantly share code, notes, and snippets.

View trkhanh's full-sized avatar

Tran Khanh trkhanh

View GitHub Profile
@trkhanh
trkhanh / cleancode.md
Created February 13, 2020 15:58
Cleancode summary

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@trkhanh
trkhanh / History.js
Last active February 3, 2020 03:22
History Single Page
function supports_history_api() {
return !!(window.history && history.pushState);
}
function swapPhoto(href) {
var req = new XMLHttpRequest();
req.open("GET",
"http://diveintohtml5.info/examples/history/gallery/" +
href.split("/").pop(),
false);
@trkhanh
trkhanh / go_client.go
Created January 12, 2020 14:24
go_client.go
package main
import (
"fmt"
"net"
"strconv"
"time"
)
func CheckError(err error) {
@trkhanh
trkhanh / clọck.html
Created September 24, 2019 14:27
Clock
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="400"
style="background-color:#333">
</canvas>
<script>
var canvas = document.getElementById("canvas");
@trkhanh
trkhanh / .js
Last active July 12, 2019 06:45
product-lib
import $ from 'jquery';
import prestashop from 'prestashop';
/**
* This function returns the value of the requested parameter from the URL
* @param {string} paramName - the name of the requested parameter
* @returns {string|null|object}
*/
export function psGetRequestParameter(paramName) {
let vars = {};
@trkhanh
trkhanh / .js
Created July 7, 2019 12:59
dashboard
"use strict";
var _ = require("lodash");
var blessed = require("blessed");
var HelpView = require("./views/help");
var generateLayouts = require("./generate-layouts");
var LogProvider = require("./providers/log-provider");
var MetricsProvider = require("./providers/metrics-provider");
var GotoTimeView = require("./views/goto-time-view");
var views = require("./views");
@trkhanh
trkhanh / .js
Created July 7, 2019 12:51
goto-time-view
"use strict";
var blessed = require("blessed");
var ERROR_TEXT_DISPLAY_TIME = 3000;
/**
* This is the constructor for the Goto Time View.
*
* @param {Object} options
@trkhanh
trkhanh / .js
Created July 7, 2019 06:29
default_layout_config
"use strict";
module.exports = [
[
{
position: {
grow: 3
},
views: [
{
@trkhanh
trkhanh / .json
Created July 7, 2019 06:27
layout-config-schemas
{
"type": "array",
"items": {
"$ref": "#/definitions/layout"
},
"definitions": {
"layout": {
"type": "array",
"items": {
"$ref": "#/definitions/panel"
@trkhanh
trkhanh / .js
Last active June 18, 2019 02:36
es6- switch case alternative - object literals
//Ideal
function getStates (type) {
var states = {
'order': 'Customer make order',
'payment': 'Customer did payment',
'shipping': 'Carrier is processing',
'close': `this ${order.id}'s compledted`
};
return 'The state I chose was ' + (states[type] || states['default']);
}