Skip to content

Instantly share code, notes, and snippets.

View aryomuzakki's full-sized avatar

Muhammad Aryo Muzakki aryomuzakki

View GitHub Profile
@aryomuzakki
aryomuzakki / 1_uploadhandler.go
Created March 25, 2024 17:51
Example to handle image upload in go lang (with gorilla mux router). Save image as temp files, remove image, return image / serve image as response
/*
Handle image uploaded with multipart/form-data POST Request.
Save image to temp files,
image then removed after some process,
then return / serve the (processed) image as response.
Using gorilla mux router.
*/
package main
import (
@aryomuzakki
aryomuzakki / choco-install-dev-packages.config
Last active November 13, 2023 19:50
Windows script or bat file or command line to install chocolatey and chocolatey packages. It is helpful to install applications/tools in new windows machine.
<!--
- how to use this file: https://docs.chocolatey.org/en-us/choco/commands/install#packages.config
- how to generate this file:
- from chocolatey packages repository with script builder: https://docs.chocolatey.org/en-us/community-repository/script-builder
- from other windows machine with export command: https://docs.chocolatey.org/en-us/choco/commands/export
-->
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="googlechrome" />
@aryomuzakki
aryomuzakki / generate-secret-nodejs.md
Last active September 14, 2023 14:42 — forked from dehamzah/generate.js
Generate Secret Key with Node JS Crypto

script

require('crypto').randomBytes(64).toString('hex');
// 918fc5da09945d2f4086d2458f514bd4cacf6cab559174420f1e7d2caa8881edfdd78c417b9ad32b3c67a19ef4267bc50ff08cb913df158757b375c7f97371b6

require('crypto').randomBytes(64).toString('base64');
// hJNB4j5SI+mVxrvhoD/cSdHBMSFqWImEKlfWtMRVRSzoHp2uTSbixhBQ6iLaWtFK2mTENOUM6/mD2pD1ufgsAA==

require('crypto').randomBytes(64).toString('base64url');
// aMVKjWq3O0orHGddbW1HYQjD8hFeEtuH0Jrx80ZD0obT_wX8V9atgddDFMI3GS5InYbCoQAPVsMuzxGOJ_zi0g
@aryomuzakki
aryomuzakki / crypto-random.js
Last active September 14, 2023 12:17
Generate Random Number and String in Javascript, using Math.random(), Node JS Crypto (server side), or Web Crypto API (client side / browser)
// nodejs crypto (server side)
// Math.random() replacement
const cryptoRandom = () => parseInt(require("crypto").randomBytes(4).toString("hex"), 16) / (0xffffffff + 1)
// generate random number integer based on minimum and maximum
const cryptoRandomNumber = (min, max) => require("crypto").randomInt(min, max + 1)
// generate random string (hex/base64) based on bytes
const cryptoRandomString = (bytes, encoding = "hex") => require("crypto").randomBytes(bytes).toString(encoding)
@aryomuzakki
aryomuzakki / currentdirlisting.php
Created June 27, 2023 18:00
List Current Directory with PHP
<?PHP
# modified from https://stackoverflow.com/a/15678731/12479141
# add small capabilities to disallowed extension
# The current directory
$directory = dir("./");
# If you want to turn on Extension Filter, then uncomment this:
### $allowed_ext = array(".sample", ".png", ".jpg", ".jpeg", ".txt", ".doc", ".xls", ".notshow");
@aryomuzakki
aryomuzakki / create-bare-repo.sh
Last active June 21, 2023 08:12
Bash command in ubuntu to create a bare git repo and post commit hooks to start node js with pm2
#!/bin/bash
# USAGE:
# command example.com [OPTIONS]
#
# args desc
# example.com the domain name
#
# options args desc
# --app-name short-app-name required if --pm2-start is yes