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 / 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
@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 / 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 / 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]

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

#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;
@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
@makoru-hikage
makoru-hikage / summation_notation.py
Last active October 12, 2017 11:47
A simple implementation of summation notation in Python
"""
## Derived from here:
## https://math.stackexchange.com/questions/1694311/is-sigma-sigma-a-mathematical-way-of-doing-a-for-loop/1694322
## (c) CC-BY-SA 3.0
"""
## Definition
def sum_notation(i=0, end=1, f= lambda x : x):
return f(i) + sum_notation(i+1, end, f) if (i <= end) else 0
@makoru-hikage
makoru-hikage / is_prime.py
Created October 10, 2017 02:58
A simple "IS PRIME?" algorithm made while being allergic to "else" statement
def is_prime(x):
divisor = 1
while divisor < x:
if divisor > 1 and (x % count) == 0:
return False
divisor += 1
return True
@makoru-hikage
makoru-hikage / someRandomSnippet.php
Created August 25, 2017 00:55
What can you infer? This is a function that fetches a certain student record. It's validated and authenticated.
<?php
public function getChecklist($request, $response, $urlParams){
$input = $request->getQueryParams();
$input['student_number'] = $urlParams['student_number'];
$output = (new MultipleReadModule ($input))
->setRepository(new CentralRepository)
->setModelService('DeltaX\Aegis\ModelServices\GradesRegistry\StudentChecklist')