Skip to content

Instantly share code, notes, and snippets.

View chungquantin's full-sized avatar
:shipit:
Extreme learning

Tin Chung chungquantin

:shipit:
Extreme learning
View GitHub Profile
@chungquantin
chungquantin / postgres.md
Created June 19, 2022 07:25 — forked from phortuin/postgres.md
Set up postgres + database on MacOS (M1)

Based on this blogpost.

Install with Homebrew:

$ brew install postgresql

Run server:

@chungquantin
chungquantin / decorators.py
Created June 5, 2022 18:07 — forked from dzhou/decorators.py
useful python decorator utils
#!/usr/bin/env python
#
import os
import time
import thread
import warnings
import signal
import traceback
from threading import Timer
fn build_adjacent_matrix(n: i32, edges: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut adjacent_m: Vec<Vec<i32>> = vec![vec![i32::MAX; n as usize]; n as usize];
for edge in edges {
let (s, t, w) = (edge[0], edge[1], edge[2]);
adjacent_m[s as usize][t as usize] = w;
}
for i in 0..n as usize {
adjacent_m[i][i] = 0;
@chungquantin
chungquantin / floyd-warshall-algorithm.rs
Last active May 14, 2022 11:13
Shortest Path Finding: Floyd Warshall Algorithm (All pairs shortest path finding)
pub fn floyd_warshall_algorithm(n: i32, edges: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut m = build_adjacent_matrix(n, edges);
for k in 0..n as usize {
for i in 0..n as usize {
for j in 0..n as usize {
if m[i][k] == i32::MAX || m[k][j] == i32::MAX {
continue;
}
m[i][j] = std::cmp::min(m[i][j], m[i][k] + m[k][j])
}
@chungquantin
chungquantin / q1334.rs
Created May 14, 2022 10:55
Leetcode 1334: Find the City With the Smallest Number of Neighbors at a Threshold Distance
impl Solution {
pub fn find_the_city(n: i32, edges: Vec<Vec<i32>>, distance_threshold: i32) -> i32 {
let mut m = Solution::build_adjacent_matrix(n, edges);
for k in 0..n as usize {
for i in 0..n as usize {
for j in 0..n as usize {
if m[i][k] == i32::MAX || m[k][j] == i32::MAX {
continue;
}
m[i][j] = std::cmp::min(m[i][j], m[i][k] + m[k][j])
@chungquantin
chungquantin / gist:7aa02a45766f0d7380763cde3bc77f3b
Created January 12, 2021 15:54
ElectionSmartContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
contract Election{
// Model a candidate
struct Candidate {
uint id;
string name;
uint voteCount;
}
{
"defaultSeverity": "error",
"extends": ["tslint:latest", "tslint-config-prettier"],
"jsRules": {},
"rules": {
"no-console": false,
"member-access": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"interface-name": false,
module.exports = {
apps: [
{
name: "React Typescript GraphQL boilerplate",
script: "src/index.ts",
instances: 2,
cwd: __dirname,
autorestart: true,
max_memory_restart: "1G",
exec_mode: "cluster",
@chungquantin
chungquantin / gist:5f464c34084c5a20921e281c96cf71ca
Created November 25, 2020 11:21
Mongo File Upload GridFS
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const path = require('path');
const util = require('util');
const multer = require('multer');
const GridFsStorage = require('multer-gridfs-storage');
const storage = new GridFsStorage({