Skip to content

Instantly share code, notes, and snippets.

@sazid
sazid / init.vim
Created March 27, 2019 16:59
(n)vim config file
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
" set smarttab
set expandtab
" set number
set relativenumber
// Holds the graph
map<char, vector<char>> graph;
// Status of each node - UNVISITED, VISITING, VISITED
map<char, int> status;
// This will denote whether the graph has cycles
bool hasCycles = false;
// Status codes
void dfs(char node) {
status[node] = VISITING;
for (char child : graph[node]) {
if (status[child] == UNVISITED)
dfs(child);
else if (status[child] == VISITING) {
hasCycles = true;
return;
}
int main() {
// Input graph here
for (char c : {'A', 'B', 'C'})
if (status[c] == UNVISITED)
dfs(c);
if (hasCycles) {
// Do something
}
// Holds the graph
map<char, vector<char>> graph;
// Status of each node - UNVISITED, VISITING, VISITED
map<char, int> status;
// This will denote whether the graph has cycles
bool hasCycles = false;
// Status codes
@sazid
sazid / redhat_nginx_setup.md
Created November 30, 2020 21:25
Redhat Enterprise Linux 8 nginx setup
  1. Create /etc/nginx/sites-available /etc/nginx/sites-enabled directories
  2. Add "include /etc/nginx/sites-enabled/*;" in http block
user ec2-user;  # SET THE PROPER USER HERE!
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
@sazid
sazid / go_seek_handle.go
Created June 10, 2021 12:35
Demonstration of file seek handle in Go.
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
)
@sazid
sazid / IOStream.java
Last active July 21, 2021 17:54
Trying out different I/O streams in Java.
import java.io.*;
import static java.lang.System.out;
public class Main {
public static void main(String[] args) {
try (var in = new FileInputStream("hello.txt")) {
var buf = new byte[4];
int n = in.read(buf);
while (n != -1) {
@sazid
sazid / DBUtils.kt
Created August 30, 2021 06:59
Database utilities for JDBC
package io.github.sazid
import java.sql.Connection
import java.sql.Date
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.time.LocalDate
import javax.sql.DataSource
typealias RowMapper<T> = (ResultSet) -> T
@sazid
sazid / main.go
Last active April 13, 2022 09:14
A small generic function for retrying in go.
func main() {
db, err := util.Retry(120, time.Second, func() (*pgxpool.Pool, error) {
return pgxpool.Connect(...)
})
if err != nil {
log.Fatal("failed to initialize new postgres db pool")
}
}