Skip to content

Instantly share code, notes, and snippets.

View thanhdatvo's full-sized avatar
🎯
Finding a Job

ThanhDat Vo thanhdatvo

🎯
Finding a Job
View GitHub Profile
@thanhdatvo
thanhdatvo / introduce-air.conf
Created April 30, 2020 21:35
Introduce .air.conf
root = "."
tmp_dir = "tmp"
[build]
delay = 500 # ms
@thanhdatvo
thanhdatvo / introduce-nodemon.json
Created April 30, 2020 21:33
Introduce nodemon.json
{
"ignore": [
".git",
"node_modules/**/node_modules"
],
"delay": "500"
}
@thanhdatvo
thanhdatvo / gofiber-chained-middlewares.go
Created April 30, 2020 20:51
Go Fiber chained middlewares
func main() {
// initialization codes
app.Get("/verify/:status/:role/:userId", authenticate, authorize, func(c *fiber.Ctx) {
if c.Locals("isAuthenticated") == false {
c.Status(403)
c.Send("Unauthenticated. Please signup!")
return
}
c.Send("Redirecting " + c.Locals("redirectRoute").(string))
@thanhdatvo
thanhdatvo / express-app-chained-middlewares.js
Created April 30, 2020 20:36
Expressjs Chained Middlewares
function authenticate(req, res, next) {
if (req.params.status === "authenticated") {
req.isAuthenticated = true
} else {
req.isAuthenticated = false
}
next();
}
@thanhdatvo
thanhdatvo / gofiber-router-params.go
Created April 30, 2020 19:51
Go Fiber router params
/*
Route path: /users/:userId/books/:bookId
Request URL: http://localhost:3000/users/34/books/8989
req.params: { "userId": "34", "bookId": "8989" }
*/
app.Get("/users/:userId/books/:bookId", func(c *fiber.Ctx) {
c.JSON(fiber.Map{
"userId": c.Params("userId"),
"bookId": c.Params("bookId"),
})
@thanhdatvo
thanhdatvo / express-app-router-params.js
Created April 30, 2020 19:46
Expressjs router params
/*
Route path: /users/:userId/books/:bookId
Request URL: http://localhost:3000/users/34/books/8989
req.params: { "userId": "34", "bookId": "8989" }
*/
app.get('/users/:userId/books/:bookId', function (req, res) {
res.send(req.params)
})
@thanhdatvo
thanhdatvo / express-app.js
Last active April 30, 2020 16:26
Express app running file, generated by ```express-generator``` version 4.16.1
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
@thanhdatvo
thanhdatvo / gofiber-main.go
Last active April 30, 2020 18:41
Gofiber start function
package main
import (
"gofiber/starter/routes"
"github.com/gofiber/fiber"
"github.com/gofiber/logger"
"github.com/gofiber/template"
)
import 'package:flutter/material.dart';
import 'package:flutter_i18n_plugin/generated/i18n.dart';
void main() async {
runApp(App());
}
class App extends StatefulWidget {
@override
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes
//This file is automatically generated. DO NOT EDIT, all your changes would be lost.