Skip to content

Instantly share code, notes, and snippets.

View makoru-hikage's full-sized avatar
🐮
Perhaps

Kurt Ma. Coll makoru-hikage

🐮
Perhaps
View GitHub Profile
@makoru-hikage
makoru-hikage / palindrome.py
Last active June 30, 2021 13:22
An O(log_n) palindrome check algorithm, the number of letter iterations is halved (rounded up when the half is a rational number).
#!/bin/bash/python
#
# Requires Python 3 and above
#
# Example
#
# R A D A R
# 1 2 3 4 5
#
# H A N N A H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ARRAY_LENGTH 6
/* Assuming arrays start at zero*/
int find_opposite(int n, int count){
/* If arrays start at one, one can use (count+1) - n */
return count - n;

Architecture

This is a web app run by NodeJS, written in Javascript, and made using fastify web microframework.

The architecture of this source code is loosely based on Explicit Architecture which is based on Domain-Driven Design (DDD) and Hexagonal Architecture. Take note that business logic is strictly separated from infrastructure logic. The app is a monolith designed to be broken down into microservices in the near future. This app is divided into services which is contained inside the "services" folder of this app. Each service has its own folder and an index.js file in their folder. Since fastify-cli is used, each service can be run independent of each other with their own ENV files.

A service here represents a Bounded Context in DDD.

Folder Structure

The folder structure of a _se

@makoru-hikage
makoru-hikage / change_bsconfig.js
Created August 2, 2021 07:11
A script for Node: changes a Rescript project's bsconfig.json's "package-specs".
const fs = require('fs');
const rawData = fs.readFileSync('bsconfig.json')
var bsconfig = JSON.parse(rawData)
var choice = process.argv[1]
// There's a chance this code is run like this: 'node <this script>'
if (process.argv[0] !== __filename){
choice = process.argv[2]
@makoru-hikage
makoru-hikage / matchmedia.re
Last active September 30, 2021 09:50
A Rescript code used to check if a browser is in Dark Mode
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList
type mediaQueryList = {
matches: bool,
domString: string
}
// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
@val @scope("window")
external matchMedia: string => mediaQueryList = "matchMedia"
@makoru-hikage
makoru-hikage / non-recursive-fibonacci.py
Last active May 31, 2023 17:37
To avoid stack overflow, I implemented a Fibonacci using a for loop.
#!/usr/bin/python
def fibonacci (t):
if t <= 1:
return t
return (fibonacci(t - 1) + fibonacci(t - 2))
def fibonacci_set(t):
if t == 0:
return [0]
@makoru-hikage
makoru-hikage / leap-year.py
Last active May 23, 2023 14:20
A leap year is divisible by 4, not divisible by 100 only, and divisible by 400.
#!/usr/bin/python
def is_leap_year (n):
if n % 100 == 0:
dividedBy100 = n / 100
if dividedBy100 % 4 == 0:
return True
else:
return n % 4 == 0