Skip to content

Instantly share code, notes, and snippets.

@viettranx
viettranx / Vagrantfile
Created August 27, 2022 13:00
Simple Vagrant File - Create a VM with Ubuntu OS
# -*- mode: ruby -*-
# vi: set ft=ruby :
$install_docker_script = <<SCRIPT
echo "Installing dependencies ..."
sudo apt-get update
echo Installing Docker...
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker vagrant
SCRIPT
@viettranx
viettranx / vnpay_payment_url.go
Created August 15, 2021 08:31
VNPay Payment URL
package payment
import (
"crypto/sha256"
"encoding/hex"
"net/http"
"sort"
"strings"
"time"
)
@viettranx
viettranx / 200lab_golang_training_food_delivery.sql
Created April 18, 2021 06:51
This is an example DB schema for Food Delivery training project
DROP TABLE IF EXISTS `carts`;
CREATE TABLE `carts` (
`user_id` int NOT NULL,
`food_id` int NOT NULL,
`quantity` int NOT NULL,
`status` int NOT NULL DEFAULT '1',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`,`food_id`),
CREATE TABLE `restaurants` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_id` int(11) NULL,
`name` varchar(50) NOT NULL,
`addr` varchar(255) NOT NULL,
`city_id` int(11) DEFAULT NULL,
`lat` double DEFAULT NULL,
`lng` double DEFAULT NULL,
`cover` json NULL,
`logo` json NULL,
@viettranx
viettranx / Dockerfile
Created September 29, 2018 10:36
A Dockerfile (multi stage) to build and run a very simple web application
FROM golang:latest as builder
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o demoApp .
FROM alpine:latest
WORKDIR /app/
COPY --from=builder /app .
CMD ["/app/demoApp"]
@viettranx
viettranx / Dockerfile
Last active September 29, 2018 09:19
A Dockerfile to build and run a very simple web application
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o demoApp .
CMD ["/app/demoApp"]
@viettranx
viettranx / main.go
Created September 29, 2018 09:03
A simple web application - Golang
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, "<center><h1>Welcome to my page<h1></center>")
@viettranx
viettranx / merge_images.go
Created September 7, 2018 06:14
This program merges all images in "./input" folder to "/output" folder horizontally
/**
* This program merges all images in "./input" folder to "/output" folder horizontally
* Ex: ./input/1.jpg + ./input/2.jpg => ./output/12.jpg
**/
package main
import (
"fmt"
@viettranx
viettranx / FreezeAndSeal.example.js
Created August 26, 2018 18:08
How to make a private variable in Class and prevent add/delete it with freeze and seal function.
// ES6
// A normal object
class iPhoneX {
secretName = 'iPhoneX'
constructor(price) {
this.price = price
}
setPrice = (value) => {
@viettranx
viettranx / TaskList+MobX.js
Created April 13, 2018 09:27
Demo simple component use MobX Store
import React, { Component } from 'react'
import {
StyleSheet,
Text,
TouchableOpacity,
FlatList,
View
} from 'react-native'
import taskListStore from './../mobx/TaskListStore'