Skip to content

Instantly share code, notes, and snippets.

View mramirid's full-sized avatar

Amir Muhammad Hakim mramirid

View GitHub Profile
@mramirid
mramirid / README.md
Last active November 28, 2023 02:21
Running Zookeeper, 5 Kafka brokers, Kafka UI, and kafka-init using docker compose on Windows

Running Kafka Brokers on Docker Containers

How to Run

This config uses Docker images created by wurstmeister.

  1. Retrieve the IPv4 address of the host machine and assign it to the environment variable HOST_IP.
@mramirid
mramirid / query-failed-exception.filter.ts
Last active March 28, 2023 06:22
NestJS & TypeORM QueryFailedError Exception Filter
import { PG_UNIQUE_VIOLATION } from '@drdgvhbh/postgres-error-codes';
import {
ArgumentsHost,
Catch,
ConflictException,
HttpException,
InternalServerErrorException,
} from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import { QueryFailedError } from 'typeorm';
@mramirid
mramirid / index.md
Last active November 28, 2023 02:18
Creating Indexes During Table Creation

Creating Indexes During Table Creation

We can add an index to a table right when creating that table - like this:

CREATE TABLE <table_name> (
    ... column definitions,
    INDEX <index_name> (<column>)
);
@mramirid
mramirid / index.md
Last active November 26, 2023 04:11
Updating & Removing SQL Foreign Key Constraints

Updating & Removing SQL Foreign Key Constraints

Besides adding foreign key constraints at creation time (i.e. when using CREATE TABLE), we can also add such constraints after a table has been created with help of ALTER TABLE. We can also remove foreign key constraints from an existing table.

Adding Foreign Key Constraints Via ALTER TABLE

MySQL & PostgreSQL

ALTER TABLE <table_name>
@mramirid
mramirid / TopUpCategories.tsx
Last active January 6, 2023 02:51
React TypeScript component with call signature example
import { useId } from "react";
import { formatIDR } from "utils/format";
export default function TopUpCategories(props: { className: string }) {
return (
<section className={props.className}>
<h2 className="text-lg fw-medium color-palette-1 mb-14">
Top Up Categories
</h2>
@mramirid
mramirid / Enabling MongoDB Replication.md
Last active January 30, 2023 03:00
Enabling MongoDB replication to solve this error when running transactions: "MongoServerError: Transaction numbers are only allowed on a replica set member or mongos".

Enabling MongoDB Replication

  1. Stop Mongod Service/Daemon/Process.

  2. Find & open the mongod.conf.

    • Windows: <MongoDB-Server-Bin-Path>/mongod.conf
    • Linux: /etc/mongod.conf
  3. Add the following to the File:

@mramirid
mramirid / app.py
Last active January 7, 2023 02:09
Twitter API - request tweets by hastag
import tweepy
import csv
# input your credentials here
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
@mramirid
mramirid / app.py
Last active January 7, 2023 02:10
Twitter API - request tweets of a user
import twitter, re, datetime, pandas as pd
class Twitter_Miner():
request_limit = 20
api = False
data = []
twitter_keys = {
'consumer_key': '',
'consumer_secret': '',
@mramirid
mramirid / rupiah.ts
Last active January 7, 2023 02:11 — forked from faisalman/Rupiah.as
Convert a number to a string of its equivalent in rupiah (TypeScript)
// JavaScript Code Snippet
// Convert integer to Rupiah & vice versa
// https://gist.github.com/845309
//
// Copyright 2011-2012, Faisalman
// Licensed under The MIT License
// http://www.opensource.org/licenses/mit-license
/**
* Convert a number to a string of its equivalent in rupiah
@mramirid
mramirid / height-calculator.js
Last active January 7, 2023 02:14
Calculate the height of an image based on its aspect ratio and width
/**
* Calculate the height of an image based on its aspect ratio and width
* @param {number} width
* @param {number} ratioWidth
* @param {number} ratioHeight
* @returns the calculated height
*/
function getHeight(width, ratioWidth, ratioHeight) {
const ratio = width / ratioWidth;
const height = ratio * ratioHeight;