Skip to content

Instantly share code, notes, and snippets.

View emnopal's full-sized avatar

Muhammad Naufal emnopal

  • 09:01 (UTC +07:00)
View GitHub Profile
eyJzYWx0IjogIkl4RS9LQyt4L1c5aVpWbko4MzlmUWxycExUTnl0dWlCdmkvS2UxOFR6enZUMnBjempsV2F1bzRmVkRSbEhYVmUxZEtkWGphcTFkOHBoNDRLTU53Ujg0WGNvVm1tN3UrdDI4NUhMeCtKamlrdGVuaGVQYkxFb3FXbDBxeTFheE1yS2s0TXF3elFVTHF2R0RBc1NteEVNUU42bGx3dWU5TUczbldxQ3NxMm5zZz0iLCAibm9uY2UiOiAiTVUzU2J5V3grY3ZVRFF6YyIsICJjaXBoZXJ0ZXh0IjogInZxdndPQWk4cTBYcEpSRXg0MXlaOFpNYzlCM0k5Zkh0c0NyY25RRkVoaG9yWWtUMndxSjVIS2pxVDcwbjRvMVJMK0c0ZmVWZ0d5TGlVWnFZUEJ2M05aR085ZkdUQ1d2SU9hdCtwbVhpVGJjNXhHY0VYc0JLL3VHNXVTbTlzV2hkSDJ4S21WZW8wdWdNZWF5N0ZOYmtraG11dEJlQWhRdVZLTWFmQjhBelh2eFhFTVpzS2ZwR1Z2QXFFbUhyODIzQSt6MUZ2Lzl2OU9Rc1VyZU8ySFd6UXFXbUxMTG5MMHBPN0tnNi9qbGxXVXkxclhPWXFkajJoZ004a1FkZlc2NFJQbTlkR2oyRjI0YXZ3RWlldTlDQ25UMy9Ua1dnQm82dmFXNTdIOHNySGhSdktZWFJOZUlWbzFJRWtoSEsyc1NJWmNhKzZGM25tUG5teVZDdURSZDZwVXRQZUVVbGxvQjIzbmlsTzljM1J1eGIyTWppaEhxaDl4ajdZVXRzNU1wQU8rcWsrVWxVSlltNFpnN0JvWkZVNEsyVFVwa2dKNVBoQnV0VGpmb0FRVWhNUFlNM0V5d0Vtb2RFN3I2dnNhczdJOUpVVEQ1L2ZGMGJZVmNZemRmZ3JqMlZyYzZYNEN4VzFVUWhBOXNhOU82WlVUTDN3UEltQ2N6S3ZOUmFXZXcyTmcyQyszSU9wcFovTHE5MVV1OS9BMjh6aXBp
@emnopal
emnopal / envProvider.tsx
Created November 6, 2024 12:01
spreading env to across next app (since .env which is defined while running `next dev` is not same with `next start`)
"use client";
import { createContext, useContext, useEffect, useState } from "react";
import { getEnv } from "./env";
const EnvContext = createContext({});
type envType = Record<string, string | undefined>;
export const EnvProvider = ({
/*
*
* Validate Internal / Private IP both IPv4 and IPv6
*
*/
const isInternalIP = (ip?: string): boolean => {
if (!ip || ip.trim() === "") return false;
const ipv4InternalRegex = /^(?:0\.0\.0\.0|10(?:\.\d{1,3}){3}|127(?:\.\d{1,3}){3}|169\.254\.(?:[1-9]|1\d{1,2}|2[0-4]\d|25[0-4])\.\d{1,3}|172\.(1[6-9]|2\d|3[01])(?:\.\d{1,3}){2}|192\.168(?:\.\d{1,3}){2})$/;
const ipv6InternalRegex = /^(?:fc[0-9a-f]{2}(?::[\da-f]{1,4}){0,7}|fe[89ab][\da-f]{2}(?::[\da-f]{1,4}){0,7})$/i;
from flask import Flask, request, abort, jsonify
from werkzeug.exceptions import HTTPException
app = Flask(__name__)
def wrapper(func):
def inner(*args, **kwargs):
try:
headers = request.headers
kwargs['headers'] = headers

Mount exFAT WSL

First, change custom kernel here: Custom WSL2 Kernel. This custom kernel enable support for exFAT filesystem.

Finally, follow these instructions:

Mount to WSL (on Windows)

  1. Check physical disk address with:

wmic diskdrive list brief

package main
import (
"math"
)
func ceil(num interface{}) int {
switch v := num.(type) {
case int:
return v
@emnopal
emnopal / deploy.sh
Last active July 6, 2024 03:05
Deploy Next.js
#!/bin/bash
# TODO:
# FIRST CREATE ~/app_name FILE, CD TO THAT DIRECTORY
# THEN PUT YOUR APP RELEASE BUILD (STILL IN ZIP) HERE
CURRENT_DIR=$(pwd)
DIR="$CURRENT_DIR/app"
RELEASE_FILE="put_the_name.zip"
@emnopal
emnopal / nextjs-build.yml
Last active July 6, 2024 03:05
Build and Release Next.js using GitHub Actions
name: NextJS Build
on:
push:
branches:
- main
# Add another branch?
jobs:
build:
echo "C:\Users\{WINDOWS_USER}\.ssh\ /home/{WSL_USER}/.ssh drvfs rw,noatime,uid=1000,gid=1000,case=off,umask=0077,fmask=0177 0 0" >> /etc/fstab
const foo = document.getElementsByTagName('ytmusic-responsive-list-item-renderer');
const musicObj = {}
for (let i = 0; i < foo.length; i++){
let newObj = foo[i];
let otherObj = newObj.getElementsByTagName('yt-formatted-string');
for (let j = 0; j < otherObj.length; j++){
let a = otherObj[j];
let aObj = a.getElementsByTagName('a');
let aObjGHTML = aObj[0];