Skip to content

Instantly share code, notes, and snippets.

View mramirid's full-sized avatar

Amir Muhammad Hakim mramirid

View GitHub Profile
@mramirid
mramirid / slugify.js
Last active January 31, 2022 05:01 — forked from codeguy/slugify.js
Create slug from string in Javascript
/**
* Convert a string to a URL slug
* @param {string} str - The string to be slugified.
* @returns {string} The slugified string.
*/
function toSlug(str) {
str = str.replace(/^\s+|\s+$/g, ""); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
@mramirid
mramirid / AppName.php
Created April 5, 2020 14:45 — forked from isluewell/AppName.php
[6.0] Command app:name
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Composer;
use Symfony\Component\Finder\Finder;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
@mramirid
mramirid / auto-bind-this.ts
Last active January 31, 2022 13:18
Automatically bind methods to their class instance
/**
* It binds the function to the class instance.
*/
function AutoBind(_: any, __: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value
const adjustedDescriptor: PropertyDescriptor = {
configurable: true,
enumerable: false,
get() {
const boundFunction = originalMethod.bind(this)
@mramirid
mramirid / typescriptreact.json
Last active July 31, 2021 17:14
VSCode function component snippets for React Web & React Native (TSX)
{
"TSX Function Component for React Web": {
"prefix": "cmp-web",
"body": [
"interface $1Props {}\n",
"export default function $1(props: $1Props) {",
"\treturn (",
"\t\t<div>",
"\t\t\t<p>$1</p>",
"\t\t</div>",
@mramirid
mramirid / avl.c
Last active March 24, 2021 10:17
AVL Tree implementation in C (from GeeksforGeeks)
#include <stdio.h>
#include <stdlib.h>
#undef max
struct Node_AVL
{
int value;
int height;
struct Node_AVL *left, *right;
@mramirid
mramirid / auto-setuju-survey-siamik-upnjatim.js
Last active January 7, 2023 02:15
Auto setuju survei lembaga di Siamik UPN Jawa Timur - untuk anda yang malas mengisi survei saat mendaftar UTS/UAS
document.querySelectorAll('[value="Setuju"]').forEach((setuju) => (setuju.checked = true));
document.getElementById("securityCode").scrollIntoView();
@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;
@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 / 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 / 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)