Skip to content

Instantly share code, notes, and snippets.

package pprof
import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"runtime"
rpprof "runtime/pprof"
"runtime/trace"
@ThiagoBarradas
ThiagoBarradas / config.yml
Created March 16, 2018 19:07
Auto rollback with circleci 2.0
## 1) GENERATE AN API TOKEN (https://circleci.com/gh/<gh-user>/<gh-repo-name>/edit#api)
## 2) ADD ENV VAR WITH NAME "CIRCLE_API_TOKEN" WITH PREVIOUS GENERATED TOKEN
version: 2
jobs:
build:
machine: true
steps:
- run:
name: Build App
@ddieppa
ddieppa / InstallChocolateyPackages.ps1
Last active January 19, 2025 12:36
My "must" chocolatey packages
function main {
Update-Windows-Configuration
Install-Utils
Install-Browsers
Install-Fonts
@thomasdarimont
thomasdarimont / readme.md
Created February 23, 2018 09:21
Wait for HTTP Service to become available with timeout (bash)
timeout 40s /bin/bash -c "while ! httping -qc1 http://somehost:8080/app ; do sleep 1 ; done; echo OK" || echo TIMEOUT

If the service cannot be reached within 40s then TIMEOUT will be printed otherwise OK.

@jaytaylor
jaytaylor / delete-from-v2-docker-registry.md
Last active February 11, 2025 15:28
One liner for deleting images from a v2 docker registry

One liner for deleting images from a v2 docker registry

Just plug in your own values for registry and repo/image name.

registry='localhost:5000'
name='my-image'
curl -v -sSL -X DELETE "http://${registry}/v2/${name}/manifests/$(
    curl -sSL -I \
        -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
@rushilgupta
rushilgupta / GoConcurrency.md
Last active July 11, 2024 12:52
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines

@posener
posener / go-shebang-story.md
Last active March 15, 2025 16:08
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@jirikuncar
jirikuncar / README.md
Last active September 3, 2024 09:40
Traefik - header matching

Traefik routing

Proxy to services based on Accept header.

Run

docker-compose up -d

Test

@posener
posener / go-function-error-reporting.md
Last active February 12, 2024 05:32
Function Failure reporting: Error or OK

Function Failure Reporting: Error or OK

Go's "multiple return values" feature, can be used for several purposes. Among them for failure reporting to the function caller. Go has two conventions for failure reporting, but currently, no clear convention for which to use when. I've encountered different programmers that prefer different choices in different cases. In this article, we will discuss the two, and try to make the process of choosing our next function signature more conscious.

The Basics

Ideas on generics in Go

As we all know, Go 2 is on its way and despite the hesitations, it's clear that without generics, it would end up being a disappointment. And although we are still gathering real-life use-cases, or experience reports, there's nothing bad about starting to think about how generics in Go could look like. I've come up with a few ideas which I'd love to share. So, here we go!

What's already achievable?

Now, Go 1 has no generics, but has interfaces. Interfaces (sometime accompanied by reflection)