Skip to content

Instantly share code, notes, and snippets.

View aldy505's full-sized avatar
🐅

Reinaldy Rafli aldy505

🐅
View GitHub Profile
@aldy505
aldy505 / redis.js
Last active August 18, 2024 02:08
Async Redis function in CommonJS
"use strict";
/**
* @file redis.ts
* @fileoverview Async Redis functions with JSDoc annotations
* @author Reinaldy Rafli <[email protected]>
* @copyright 2021 MIT
*/
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const RedisModule = require("redis");
@aldy505
aldy505 / redis.mjs
Last active August 18, 2024 02:08
Async Redis function in ESM
/**
* @file redis.ts
* @fileoverview Async Redis functions with JSDoc annotations
* @author Reinaldy Rafli <[email protected]>
* @copyright 2021 MIT
*/
import { fileURLToPath } from 'url';
import * as RedisModule from 'redis';
import * as dotenv from 'dotenv';
const envPath = fileURLToPath(new URL('.env', import.meta.url));
@aldy505
aldy505 / redis.ts
Last active August 18, 2024 02:07
Async Redis functions in Typescript
/**
* @file redis.ts
* @fileoverview Async Redis functions with JSDoc annotations
* @author Reinaldy Rafli <[email protected]>
* @copyright 2021 MIT
*/
import path from 'path';
import * as RedisModule from 'redis';
import * as dotenv from 'dotenv';
@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 / 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 / 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 / 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 / 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 / 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_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() {