Skip to content

Instantly share code, notes, and snippets.

View crazyoptimist's full-sized avatar
🐌
crawling

crazyoptimist crazyoptimist

🐌
crawling
View GitHub Profile
@crazyoptimist
crazyoptimist / config.def.h
Created November 6, 2024 15:16
DWM Color Scheme - Gruvbox Dark
// ... snip ...
/* https://github.com/morhetz/gruvbox */
static const char col_normfg[] = "#fbf1c7"; /* fg0 */
static const char col_normbg[] = "#282828"; /* bg0 */
static const char col_normborder[] = "#504945"; /* bg2 */
static const char col_selfg[] = "#1d2021"; /* bg0_h */
static const char col_selbg[] = "#98971a"; /* green */
static const char col_selborder[] = "#b8bb26"; /* light green */
@crazyoptimist
crazyoptimist / clean-architecture-summary.md
Created October 17, 2024 09:02
Clean Architecture Summary (Note to myself)

Uncle Bob

  • The goal of software architecture is to minimize the human resources required to build and maintain the required system.
  • The only way to go fast, is to go well.
  • Any organization that designs a system will produce a design whose structure is a copy of the organization's communication structure. (Conway's law)

SOLID

  • SRP: Each software module has one, and only one, reason to change. (This is NOT "A function should do one, and only one, thing, and do it well.") A module should be responsible to one, and only one, actor. (actor == user or stakeholder)

  • OCP: For software systems to be easy to change, they must be designed to allow the behavior of those systems to be changed by adding new code, rather than changing existing code. A software artifact should be open for extension but closed for modification.

@crazyoptimist
crazyoptimist / login.js
Last active October 3, 2024 19:59
Postman Script for JWT Login
// Locate the "Scripts" tab in Postman. Select "Post-response" left side tab. Copy, paste, and edit this script.
const jsonData = pm.response.json()
// Make sure necessary variables exist in the response
pm.test("Access Token exists", function () {
pm.expect(jsonData.access_token).to.not.equal(undefined);
});
pm.test("Refresh Token exists", function () {
pm.expect(jsonData.access_token).to.not.equal(undefined);
@crazyoptimist
crazyoptimist / select-usage.md
Last active November 5, 2024 16:24
How to use select in Go

In Go, the select statement is used to handle multiple channel operations and simplify concurrent communication and synchronization problems. The select statement is similar to the switch statement, but each case must be a channel operation.

Basic syntax of the select statement:

select {
    case <-chan1:
        // Executed when chan1 has data to receive
    case chan2 <- value:
        // Executed when data can be sent to chan2
@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