Skip to content

Instantly share code, notes, and snippets.

View vanhtuan0409's full-sized avatar

Tuấn Vương vanhtuan0409

View GitHub Profile
// Example problem:
// Given an array for example [1, 2, 3, 4, 5]
// Write a function to:
// + Return true if all element inside array is even number
// + Return false if at least 1 number is odd number
// Input
const evens = [0, 2, 4, 6, 8];
const odds = [1, 3, 5, 7, 9];
const mixed = [0, 1, 2, 3, 4];
@vanhtuan0409
vanhtuan0409 / fill.go
Created October 5, 2017 02:05
Fill pointer with struct
// fill copies src in dest. dest should be a pointer to src type.
func fill(src, dest interface{}) (err error) {
defer func() {
if r := recover(); r != nil {
d := reflect.TypeOf(dest)
s := reflect.TypeOf(src)
err = fmt.Errorf("destination is `%s` but should be a pointer to the source type `%s`", d, s)
}
}()
@vanhtuan0409
vanhtuan0409 / di.js
Last active December 21, 2017 08:01
// import http request library
import request from "request"
// Normal approach
function loadData(url) {
return request.get(url);
}
const middlewareA = store => next => action => {};
const middlewareB = store => next => action => {};
const middlewares = [middlewareA, middlewareB];
const storeInstace = {};
const inputAction = {};
// Combine middleware with store instance
// After combine, middleware will have the form of: next => action => {}
type IRepository interface {
Get(id string) (*User, error)
Save(*User) error
}
func NewRepository() IRepo {
dbConnection := db.GetDBInstance()
return &postgresqlRepo{
connection: dbConnection
}
// Create user
sudo useradd -m <username>
// Or we should user
sudo adduser <username>
// Set password
sudo passwd <username>
// Create home folder and set permission if needed
sudo mkdir /home/<username>
const http = require("http");
const options = {
socketPath: "/var/run/docker.sock",
path: "http://localhost/events"
};
const callback = res => {
console.log(`STATUS: ${res.statusCode}`);
res.setEncoding("utf8");
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
import axios from "axios";
import omit from "lodash/omit";
import AuthApi from "@src/apis/AuthApi";
const baseOptions = {
headers: {
"Content-Type": "application/json"
}
};
type DB interface {
Querier
Begin() (Tx, error)
Close() error
}
type Tx interface {
Querier
Commit() error
Rollback() error