Skip to content

Instantly share code, notes, and snippets.

View justanotherminh's full-sized avatar
🙉

Luong-Minh Nguyen justanotherminh

🙉
  • Microsoft
  • North Carolina
View GitHub Profile
class Parser:
def __init__(self, text):
self.text = ''.join(text.split())
self.pos = 0
def parse(self):
return self.parse_expression()
def parse_expression(self):
result = self.parse_term()
@justanotherminh
justanotherminh / main.c
Last active November 2, 2022 21:44
OpenSSL examples
#include <openssl/evp.h>
#include <openssl/kdf.h>
#include <openssl/objects.h>
#include <openssl/crypto.h>
#include <openssl/core_names.h>
#include <openssl/obj_mac.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ec.h>
import numpy as np
import time
np.random.seed(281)
def generate_graph(n, p, k):
G = (np.random.rand(n, n) <= p).astype(np.int32)
G[np.triu_indices(n)] = 0
# Random integer weighing scheme
for x in np.nditer(G, op_flags=['writeonly']):
@justanotherminh
justanotherminh / sudoku_solver.java
Last active July 27, 2020 22:41
Sudoku solver using depth-first search
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
File file = new File(args[0]);
char[][] board = new char[9][9];
BufferedReader buffer = new BufferedReader(new FileReader(file));
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
#Library Paths
LIB_OPENCV4_PATH=/usr/local/Cellar/opencv/4.1.0_2/lib
LIB_RS2_PATH=/Users/nguyenluongminh/librealsense/build
#Include Paths
INCLUDE_OPENCV4_PATH=/usr/local/Cellar/opencv/4.1.0_2/include/opencv4
INCLUDE_RS2_PATH =/Users/nguyenluongminh/librealsense/include/librealsense2
INCLUDE_IMGUI_PATH =/Users/nguyenluongminh/librealsense/build
#Linker
from fractions import Fraction
import numpy as np
def print_matrix(matrix):
def tostr(i):
return str(i) if i.denominator == 1 else '{}\\{}'.format(i.numerator, i.denominator)
print '\n'.join(['\t'.join([tostr(col) for col in row]) for row in matrix])
@justanotherminh
justanotherminh / repository.json
Last active January 16, 2018 05:17
Needed for headless TX2 setup
{
"package": {
"version": "3.1",
"division": [
{
"alias": "tx2_64bit",
"selected": "1",
"name": "Jetson TX2"
},
{
@justanotherminh
justanotherminh / layers.py
Last active September 1, 2018 23:40
Simple 2-layer feedforward neural networ from scratch with brand new SELU activation
import numpy as np
def sigmoid(v):
return 1 / (1 + np.exp(-v))
def one_hot(x):
N = x.size
D = x.max() + 1
# Sometimes it works, sometimes it doesn't
import numpy as np
import gym
class Net(object):
def __init__(self, input, output):
# W = 0.01 * np.random.randn(input, output)
# b = np.zeros([1, output]) # Random initialization
W = np.array([[-0.60944746, 0.45539405],
@justanotherminh
justanotherminh / rbm.py
Created February 21, 2017 13:34
Restricted Boltzmann Machine for the MNIST dataset implemented in pure NumPy
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
def sample_vector(v, w, b, bernoulli=True):
h = 1 / (1 + np.exp(-(v.dot(w) + b)))
if bernoulli:
h = np.random.binomial(1, h)
return h