Skip to content

Instantly share code, notes, and snippets.

View crazyoptimist's full-sized avatar
🐌
crawling

crazyoptimist crazyoptimist

🐌
crawling
View GitHub Profile
@crazyoptimist
crazyoptimist / self-sign.ps1
Last active August 6, 2024 07:45
Generate a self-signed certificate and sign your windows binaries with it.
; Credits: https://www.the-automator.com/
; Create certificate
$cert = New-SelfSignedCertificate -Subject "{CertName}" -CertStoreLocation "cert:\CurrentUser\My" -HashAlgorithm sha256 -type CodeSigning
; Create password
$pwd = ConvertTo-SecureString -String "{123456}" -Force -AsPlainText
; Export Certificate to a file
Export-PfxCertificate -cert $cert -FilePath {CertName}.pfx -Password $pwd
@crazyoptimist
crazyoptimist / recover.go
Created July 31, 2024 20:05
Guide on using recover()
package main
import (
"fmt"
"time"
)
var index int = 0
func main() {
@crazyoptimist
crazyoptimist / timezone-guide.go
Created July 25, 2024 17:24
Guide for using time zone in go.
package main
import (
"fmt"
"time"
_ "time/tzdata" // Embed the timezone database
)
func main() {
utcTime := time.Date(2024, time.Now().Month(), 26, 1, 30, 0, 0, time.UTC)
@crazyoptimist
crazyoptimist / prompt.sh
Created March 14, 2024 07:39
Minimal Bash Prompt
# new line + workdir + $
export PS1="\n\w $ "
export PROMPT_DIRTRIM=2
@crazyoptimist
crazyoptimist / semaphore.go
Last active February 4, 2024 03:46
Semaphore Concurrency Pattern with Buffered Channel in Go
package main
import (
"fmt"
"time"
)
const (
NUM_WORKERS = 100
NUM_JOBS = 1000
@crazyoptimist
crazyoptimist / workerpool.go
Last active February 3, 2024 04:05
Worker Pool Concurrency Pattern in Go
package main
import (
"fmt"
"sync"
)
const (
NUM_WORKERS = 10
NUM_JOBS = 10000
@crazyoptimist
crazyoptimist / compose.yaml
Last active April 10, 2024 00:56
Kafka Cluster Setup with Provectus KafkaUI for Local Development Environment
name: kafka_cluster
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.5.3
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
@crazyoptimist
crazyoptimist / deploy_spa.yml
Last active May 1, 2024 09:38
Deploy SPA into AWS Cloudfront & S3
name: Deploy SPA
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
@crazyoptimist
crazyoptimist / build_spa.yml
Created June 7, 2023 10:52
Build SPA in GHA
name: Build SPA
on:
pull_request:
types: [opened, edited, synchronize, reopened, closed]
branches:
- main
jobs:
build:
@crazyoptimist
crazyoptimist / monitor-memory-usage.ts
Created June 6, 2023 07:43
Monitor Memory Usage in NodeJS
function formatMemoryUsage(data: number) {
return `${Math.round((data / 1024 / 1024) * 100) / 100} MB`;
}
function getCurrentMemoryUsage(): Object {
const memoryData = process.memoryUsage();
return {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,