Skip to content

Instantly share code, notes, and snippets.

View TechMaster's full-sized avatar

Trinh Minh Cuong TechMaster

View GitHub Profile
@TechMaster
TechMaster / perceptron_AND.py
Created September 14, 2019 16:52
Build Perceptron to simulate AND, OR logic. Corner stone to build complex neural network
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
# Code này chạy tốt với AND, OR
def sigmoid(z):
return 1.0 / (1 + np.exp(-z))
@TechMaster
TechMaster / crud.py
Created September 12, 2019 10:19
Python Sanic CRUD user
from sanic import Sanic
from sanic import response
app = Sanic()
# users = [] # Bước 0: Khởi tạo một danh sách user rỗng
# Bước 4: vào Mockaroo để sinh dữ liệu JSON đểu chạy tạm cái đã
# Bước 6: đóng gói các phương thức tác động lên danh sách user vào một class. Cách này là thủ thuật lập trình hướng đối tượng
# kinh phết đấy!
@TechMaster
TechMaster / mnist_cnn.py
Created September 11, 2019 16:19
Sử dụng CNN để nhận dạng chữ số viết tay MNIST
# Importing the required Keras modules containing model and layers
import tensorflow as tf
from tensorflow.keras import layers
print(tf.__version__)
print("GPU Available: ", tf.test.is_gpu_available())
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# Reshaping the array to 4-dims so that it can work with the Keras API
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
@TechMaster
TechMaster / postgresql_step_by_step.md
Last active May 9, 2018 04:45
Hướng dẫn thực hành Postgresql

Cài đặt portainer để quản lý Docker container docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Khởi động postgresql container

docker run --name db -e POSTGRES_PASSWORD=123 -d -p 5432:5432 postgres:alpine

Cài đặt pgadmin bằng docker

Huớng các lệnh của psql

Lợi ích của Database schema

  1. To allow many users to use one database without interfering with each other.
  2. To organize database objects into logical groups to make them more manageable.
  3. Third-party applications can be put into separate schemas so they do not collide with the names of other objects.

Does each microservice really need its own database?

  1. Private-tables-per-service – each service owns a set of tables that must only be accessed by that service
  2. Schema-per-service – each service has a database schema that’s private to that service
@TechMaster
TechMaster / printBinary.c
Created October 16, 2017 12:28
Print all binary numbers
#include <iostream>
void printBinary(int n) {
int k;
char *str = (char*) malloc(n * sizeof(char));
memset(str,'0', n); //set str = '00...00'
printf("%s\n", str); //print base string
while (1) {
k = n - 1; //Tinh tu ky tu cuoi
while (k >=0) {
if (str[k] == '0') {
@TechMaster
TechMaster / main.cpp
Created October 15, 2017 17:11
Move all even numbers to left, odd numbers to right
#include <iostream>
#include <vector>
using namespace std;
/*
Chuyển số chẵn về bên trái, số lẻ về bên phải
http://algorithms.tutorialhorizon.com/separate-even-and-odd-integers-in-a-given-array/
int [] arrA = {1,2,3,4,6,8,7,12};
Output: [12, 2, 8, 4, 6, 3, 7, 1]
*/
@TechMaster
TechMaster / separateOddEven.cpp
Created October 15, 2017 16:56
Demo Catch.hpp to test the function move all even numbers to left, all odd numbers to right
#include <iostream>
#include <vector>
using namespace std;
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
vector<int> separateOddEven(vector<int> arr) {
auto left = arr.begin();
auto right = arr.end() - 1;
@TechMaster
TechMaster / checkString.c
Created September 19, 2017 14:53
Check parentheses matching in String
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int checkHopQuy(char* string);
int main()
{
char string1[] = "a[b]c";
char string2[] = "} abc {";
char string3[] = "<ok string [good]>";
@TechMaster
TechMaster / Demo.swift
Created July 11, 2017 08:18
Lỗi ở file demo.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var txtField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}