Skip to content

Instantly share code, notes, and snippets.

View diyan's full-sized avatar

Oleksii Diian diyan

View GitHub Profile
@diyan
diyan / error_handling_styles.go
Created March 14, 2017 16:37
Error handling in Golang with style =)
func UpgradeDB_BoringStyle(databaseURL string) error {
box, err := rice.FindBox("postgres")
if err != nil {
return errors.Wrap(err, "can not find db migrations")
}
sourceDriver, err := source.WithInstance(box)
if err != nil {
return errors.Wrap(err, "can not init source driver for db migrations")
}
m, err := migrate.NewWithSourceInstance("go.rice", sourceDriver, databaseURL)
@diyan
diyan / sentry_store_event_payload.go
Last active April 8, 2018 02:27
Payload for storing event in the Sentry. This only scratches the surface - each json.RawMessage is a nested JSON object.
type StoreEventRequest struct {
EventID string `json:"event_id"`
ProjectID int `json:"-"` // TODO type?
Logger string `json:"logger"`
Platform string `json:"platform"`
Culprit string `json:"culprit"`
Extra map[string]interface{} `json:"extra"`
Release string `json:"release"`
Timestamp *time.Time `json:"timestamp"`
Fingerprint []string `json:"fingerprint"`
@diyan
diyan / sql_nullxyz_vs_pointer.md
Last active April 8, 2018 02:27
sql.NullXYZ vs dbr.NullXYZ vs null.XYZ vs ntypes.XYZ vs pointer samples

sql.NullXYZ vs dbr.NullXYZ vs null.XYZ vs ntypes.XYZ vs pointer samples

Struct declarations

*string, *time

NOTE helper is optional - https://github.com/AlekSi/pointer

models.User{
  ID: 1,
  Login: "Jonh",
@diyan
diyan / go_http_clients.md
Last active October 14, 2019 08:11
Go HTTP clients. Sample code in two common use-cases

Go HTTP clients. Sample code in common use-cases

  • Use case #1: Work with JSON using strings, make a HTTP POST
  • Use case #2: Work with JSON using structs, make a HTTP POST

Describe how to change various HTTP request attributes that usually differs from one request to another:

  • HTTP headers
  • Request timeout
  • TODO query string parameters
@diyan
diyan / fstab
Last active April 8, 2018 02:27
$ cat /etc/fstab
#
# /etc/fstab: static file system information
#
# <file system> <dir> <type> <options> <dump> <pass>
LABEL=EFI /boot vfat defaults,noatime,discard 0 1
/dev/mapper/vgcrypt-root / ext4 defaults,noatime,discard 0 1
/dev/mapper/vgcrypt-home /home ext4 defaults,noatime,discard 0 2
# See https://wiki.archlinux.org/index.php/Mac#Yosemite_and_later
@diyan
diyan / renderer.go
Created November 14, 2016 22:45
labstack/echo renderer + pongo2 + go.rice
package template
import (
"io"
rice "github.com/GeertJohan/go.rice"
"github.com/flosch/pongo2"
"github.com/labstack/echo"
)
GitHub stats at 2016-11-04

repo stars forks lang
wg/wrk 9976 741 C
rakyll/boom 4746 358 Go
tsenart/vegeta 4536 239 Go
gatling/gatling 2672 554 Scala
machinezone/tcpkali 1418 115 C
JoeDog/siege 1281 119 C
processone/tsung 1081 254 Erlang
yandex/yandex-tank 959 101 Python

@diyan
diyan / terraform_plan_sg.md
Created June 7, 2016 19:47
Example of how `terraform plan` looks like after one CIDR was changes in AWS Security Group

Example of how terraform plan looks like after one CIDR was changes in AWS Security Group

~ aws_security_group.sg-xxxxxxxx-de-team
    ingress.2929851676.cidr_blocks.#:     "6" => "0"
    ingress.2929851676.cidr_blocks.0:     "127.0.0.1/32" => "" <<< OLD CIDR
    ingress.2929851676.cidr_blocks.1:     "127.0.0.2/23" => ""
    ingress.2929851676.cidr_blocks.2:     "127.0.0.3/32" => ""
    ingress.2929851676.cidr_blocks.3:     "127.0.0.4/32" => ""
    ingress.2929851676.cidr_blocks.4:     "127.0.0.5/32" => ""
    ingress.2929851676.cidr_blocks.5:     "127.0.0.6/32" => ""
package main
import (
"encoding/csv"
"log"
"strings"
"strconv"
"net/http"
"github.com/gosuri/uitable"
"fmt"