Skip to content

Instantly share code, notes, and snippets.

View repejota's full-sized avatar

Raül Pérez repejota

View GitHub Profile
@repejota
repejota / signal.go
Created September 24, 2018 10:08 — forked from reiki4040/signal.go
signal handling example for golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
Testing Functions for Go
========================
Below is a small collection of testing functions for Go. You don't need to import this as a dependency. Just copy these to your project as needed.
No, seriously. They're tiny functions. Just copy them.
```go
import (
@repejota
repejota / Makefile
Created December 19, 2017 20:03 — forked from prwhite/Makefile
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
@repejota
repejota / functional-options.md
Created November 26, 2017 09:13 — forked from travisjeffery/functional-options.md
How to do functional options in Golang

Here's the simplest example showing how to do functional options in Golang.

They're a great way to enable users to set options and ease adding new options later.

package main

import (
	"flag"
	"fmt"
@repejota
repejota / functional-options.md
Created November 26, 2017 09:13 — forked from travisjeffery/functional-options.md
How to do functional options in Golang

Here's the simplest example showing how to do functional options in Golang.

They're a great way to enable users to set options and ease adding new options later.

package main

import (
	"flag"
	"fmt"
curl -s https://myurl.com/script.sh | bash /dev/stdin param1 param2
@repejota
repejota / pipes
Created May 3, 2017 21:05 — forked from msimpson/pipes
2D Bash version of the Pipes screensaver.
#!/bin/bash
declare -i f=75 s=13 r=2000 t=0 c=1 n=0 l=0
declare -ir w=$(tput cols) h=$(tput lines)
declare -i x=$((w/2)) y=$((h/2))
declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
[10]="\x9b" [11]="\x81" [12]="\x93"
[21]="\x97" [22]="\x83" [23]="\x9b"
[30]="\x97" [32]="\x8f" [33]="\x81" )
OPTIND=1
#!/bin/sh
sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
Evar (
concurrent = 5
semaphoreChan = make(chan struct{}, concurrent)
)
func doWork(item int) {
semaphoreChan <- struct{}{} // block while full
go func() {
defer func() {
<-semaphoreChan // read to release a slot
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"