Skip to content

Instantly share code, notes, and snippets.

View simukti's full-sized avatar
🏠
Working from home

Sarjono Mukti Aji simukti

🏠
Working from home
View GitHub Profile
@pseudomuto
pseudomuto / main_1.go
Last active May 17, 2024 08:07
Blog Code: Clean SQL Transactions in Golang
package main
import (
"database/sql"
"log"
)
func main() {
db, err := sql.Open("VENDOR_HERE", "YOUR_DSN_HERE")
handleError(err)
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@vielhuber
vielhuber / V1.MD
Last active October 17, 2023 06:22
recursive select of child-/parent (this only works in postgresql, not mysql) #sql

without path

create table
CREATE TABLE _test(id SERIAL PRIMARY KEY, item_id INT NOT NULL, parent_id INT);
INSERT INTO _test(item_id, parent_id) VALUES (1, null), (2, 1), (3, 1), (3, 5), (4, 3), (5, 5);
get children recursively
@sosedoff
sosedoff / 1_simple.go
Created July 16, 2016 18:45
Golang Custom Struct Tags Example
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"

Go vs. Scala (Akka) Concurrency

A comparison from 2 weeks using Go.

Actors vs. Functions

Akka's central principle is that there you have an ActorSystem which runs Actors. An Actor is defined as a class and it has a method to receive messages.

@lachesis
lachesis / letsencrypt_notes.sh
Last active December 13, 2023 11:02
Set up LetsEncrypt using acme.sh without root
# How to use "acme.sh" to set up Lets Encrypt without root permissions
# See https://github.com/Neilpang/acme.sh for more
# This assumes that your website has a webroot at "/var/www/<domain>"
# I'll use the domain "EXAMPLE.com" as an example
# When this is done, there will be an "acme" user that handles issuing,
# updating, and installing certificates. This account will have the following
# (fairly minimal) permissions:
# - Host files at http://EXAMPLE.com/.well-known/acme-challenge
@bcomnes
bcomnes / git-gpg.md
Last active February 13, 2024 07:33
my version of gpg on the mac
  1. brew install gnupg, pinentry-mac (this includes gpg-agent and pinentry)

  2. Generate a key: $ gpg --gen-key

  3. Take the defaults. Whatevs

  4. Tell gpg-agent to use pinentry-mac:

    $ vim ~/.gnupg/gpg-agent.conf 
    
@iamralch
iamralch / subcommand.go
Created July 4, 2015 15:50
flag package: subcommand example
package main
import (
"flag"
"fmt"
"os"
)
func main() {
askCommand := flag.NewFlagSet("ask", flag.ExitOnError)
@LoadLow
LoadLow / cf_pull_auth.macro
Created March 16, 2015 20:31
Nginx/Cloudflare pull authentication, Certificate and information here : https://origin-pull.cloudflare.com
if ($ssl_client_i_dn != "/C=US/O=CloudFlare, Inc./OU=Origin Pull/L=San Francisco/ST=California/CN=origin-pull.cloudflare.net") {
return 403;
}
ssl_verify_client on;
ssl_client_certificate /etc/nginx/ssl/origin-pull-ca.pem;
ssl_verify_depth 1;
if ($ssl_client_verify != "SUCCESS") {
return 403;
@josephspurrier
josephspurrier / httprouterwrapper.go
Last active April 13, 2017 16:08
Golang - Making julienschmidt/httprouter compatible using gorilla/context
// Source: http://nicolasmerouze.com/guide-routers-golang/
// Package httprouterwrapper allows the use of http.HandlerFunc compatible funcs with julienschmidt/httprouter
package httprouterwrapper
import (
"net/http"
"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"