Skip to content

Instantly share code, notes, and snippets.

View alaindet's full-sized avatar

Alain D'Ettorre alaindet

View GitHub Profile
@alexaandru
alexaandru / chi.go
Created February 14, 2024 16:40
Chi-like syntactic sugar layer on top of stdlib http.ServeMux
// Chi-like syntactic sugar layer on top of stdlib http.ServeMux.
package main
import (
"net/http"
"slices"
)
type (
middleware func(http.Handler) http.Handler
@alexedwards
alexedwards / Makefile
Last active September 19, 2024 16:50
Boilerplate Makefile for Go projects
# Change these variables as necessary.
main_package_path = ./cmd/example
binary_name = example
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
@candlerb
candlerb / go-project-layout.md
Last active April 24, 2024 19:22
Suggestions for go project layout

If someone asked me the question "what layout should I use for my Go code repository?", I'd start by asking back "what are you building: an executable, or a library?"

Single executable

Stage 1: single source file

Create a directory named however you want your final executable to be called (e.g. "mycommand"), change into that directory, and create the following files:

@RSheremeta
RSheremeta / go_robust_runner_test.go
Last active January 11, 2024 01:44
Pure Go implementation of BeforeEach / AfterEach and BeforeSuite / AfterSuite testing mechanisms
// DISCLAIMER:
// ideally, this snippet shouldn't be used as a separate file
// all the stuff should be divided into kinda logical parts and stored in files respectively
// it's all gathered here in one single place for the demonstration purposes only
package go_medium
import (
"fmt"
"os"
@jonlabelle
jonlabelle / npm_version_cheatsheet.md
Last active September 16, 2024 09:55
npm version cheatsheet

npm version cheatsheet

npm uses Semantic Versioning

npm uses Semantic Versioning. Given a version number MAJOR.MINOR.PATCH, increment the:

  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.
@alexedwards
alexedwards / main.go
Created November 15, 2020 10:38
JSON decoding benchmarks
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func createMovieHandlerUnmarshal(w http.ResponseWriter, r *http.Request) {
var input struct {
@rahularity
rahularity / work-with-multiple-github-accounts.md
Last active September 22, 2024 14:18
How To Work With Multiple Github Accounts on your PC

How To Work With Multiple Github Accounts on a single Machine

Let suppose I have two github accounts, https://github.com/rahul-office and https://github.com/rahul-personal. Now i want to setup my mac to easily talk to both the github accounts.

NOTE: This logic can be extended to more than two accounts also. :)

The setup can be done in 5 easy steps:

Steps:

  • Step 1 : Create SSH keys for all accounts
  • Step 2 : Add SSH keys to SSH Agent
@munho
munho / left_fn.json
Created June 3, 2020 23:55
Home, End, Page Up, Page Down keys for Logitech K380 (with Logitech Options uninstalled for fn and installed for option)
{
"title": "Home, End, Page Up, Page Down keys for Logitech K380 (with Logitech Options uninstalled)",
"rules": [
{
"description": "Change left arrow + fn to home",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "left_arrow",
@JanMalch
JanMalch / Angular - custom structural directives.md
Last active June 9, 2024 16:30
Writing your own structural directives with context variables

Writing your own structural directives with context variables

Complete code in math.directive.ts

After reading this you will be able to create a structural directive with inputs and context variables and use it like this:

<div *math="10; exponent: 3; let input; 
            let exponent = exponent; let r = root;
 let p = power; let ctrl = controller"&gt;
@RichardBronosky
RichardBronosky / Storing-git-Credentials.md
Last active July 30, 2023 05:34
Storing git Credentials