Skip to content

Instantly share code, notes, and snippets.

View aldy505's full-sized avatar
🐅

Reinaldy Rafli aldy505

🐅
View GitHub Profile
@aldy505
aldy505 / sql_builder.go
Last active December 1, 2021 10:12
Simple exercise for learning strings standard library and basic logic of builder query
package main
import (
"fmt"
"strings"
)
// Hello again, soldier.
//
// In today's episode, we are going to make a simple
@aldy505
aldy505 / db_migrator.go
Created November 25, 2021 16:05
Quick, simple, and straightforward database migrator in Go
package main
import (
"context"
"database/sql"
"log"
"net/url"
"os"
"strings"
"time"
@aldy505
aldy505 / coffee_machines.go
Created November 25, 2021 15:11
Simple yet annoying demonstration of concurrency stuffs in Go
package main
import (
"fmt"
"log"
"sync"
"time"
)
func main() {
@aldy505
aldy505 / fintech_company.go
Created November 25, 2021 14:11
A simple financial-technology company to learn more about structs and method in Go
// Now we're creating a fintech (financial technology) company
// that you can store money to and can buy stocks.
//
// Like the previous challenge (well, not really lol - more like a homework)
// we use struct and methods to do things. Now we'll kind of
// do the same thing.
package main
import (
"fmt"
@aldy505
aldy505 / coffee_shop.go
Created November 25, 2021 14:05
Simple coffee shop to learn about Golang structs & methods
// This is a coffee shop.
// We can order coffee and see the menu.
//
// The problem is that this coffee shop
// code is not complete yet.
//
// This is just to train your skills on
// dealing with structs, variables,
// array/slices, methods, and types.
//
@aldy505
aldy505 / main.test.js
Created October 11, 2021 17:14
go-jason!
const { test } = require('uvu')
const assert = require('uvu/assert')
const {main} = require('../src/parser')
test('1', () => {
const p = main('price lt 10000')
assert.equal(p, {
value: 'lt',
children: [
{
@aldy505
aldy505 / guessing_game.rb
Last active September 30, 2021 04:12
Rust's Guessing Game in Ruby
randomNumber = rand(100)
puts "The random number is: #{randomNumber}"
correct = false
until correct do
print "Guess the number: "
input = gets
if input.to_i > randomNumber
puts "No, it's smaller than that. Try again."
@aldy505
aldy505 / guessing_game.go
Created September 23, 2021 13:53
Rust's Guessing Game but written in Go
package main
// The program will generate a random integer between 1 and 100.
// It will then prompt the player to enter a guess.
// After a guess is entered, the program will indicate whether the guess is too low or too high.
// If the guess is correct, the game will print a congratulatory message and exit.
import (
"fmt"
"math/rand"
@aldy505
aldy505 / yaml.middleware.ts
Created August 3, 2021 04:06
YAML body parser middleware for any Node.js framework
import type { IncomingMessage, ServerResponse } from 'http';
import type { EventEmitter } from 'events';
import yaml from 'yaml'; // npm install yaml
type Next = (err?: any) => void;
type RequestWithBody<T = any> = IncomingMessage & { body?: T } & EventEmitter
async function parseYaml(req: RequestWithBody, _: ServerResponse, next: Next) {
try {
let body = '';
@aldy505
aldy505 / redis.ts
Created June 5, 2021 06:44
Async Redis functions in Typescript
/**
* @file redis.ts
* @fileoverview Async Redis functions with JSDoc annotations
* @author Reinaldy Rafli <reinaldyrfl@gmail.com>
* @copyright 2021-present MIT
*/
import path from 'path';
import * as RedisModule from 'redis';
import * as dotenv from 'dotenv';