This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) | |
| } | |
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // import http request library | |
| import request from "request" | |
| // Normal approach | |
| function loadData(url) { | |
| return request.get(url); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 => {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type IRepository interface { | |
| Get(id string) (*User, error) | |
| Save(*User) error | |
| } | |
| func NewRepository() IRepo { | |
| dbConnection := db.GetDBInstance() | |
| return &postgresqlRepo{ | |
| connection: dbConnection | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; -*- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios from "axios"; | |
| import omit from "lodash/omit"; | |
| import AuthApi from "@src/apis/AuthApi"; | |
| const baseOptions = { | |
| headers: { | |
| "Content-Type": "application/json" | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type DB interface { | |
| Querier | |
| Begin() (Tx, error) | |
| Close() error | |
| } | |
| type Tx interface { | |
| Querier | |
| Commit() error | |
| Rollback() error |
OlderNewer