Skip to content

Instantly share code, notes, and snippets.

View narqo's full-sized avatar
🌕
Berlin, +22°

Vladimir Varankin narqo

🌕
Berlin, +22°
View GitHub Profile
@narqo
narqo / backoff.go
Last active October 26, 2022 09:50
Go by examples
// Backoff is a simple backoff implementation.
type Backoff struct {
MaxAttempts int
Backoff func(int) time.Duration
attempts int
err error
nextCh chan struct{}
}
var ErrMaxAttemptsReached = errors.New("max attempts reached")
#!/usr/bin/env sh
# Usage:
# > to_deploy.sh <branch> <base_branch>
branch=${1:-HEAD}
base=${2:-"origin/master"}
declare -r mains=$(go list -json ./... | jq --compact-output '. | select(.Name == "main") | {ImportPath: .ImportPath, Deps: .Deps}')
declare -r changed=($(git diff --name-only ${base}...${branch} \
@narqo
narqo / main.go
Last active July 27, 2020 19:56
A boilerplate for a new Go application
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
)
# cloud-config
hostname: pi-4
manage_etc_hosts: true
write_files:
- content: |
network:
ethernets:
eth0:
// pkg/svc
type SettingsService struct {
db DB // DB is an interface
}
func (svc *SettingsService) IsProCustomer(token Token) bool {
v := svc.db.GetProCustomer(makeProPKFromToken(token))
return v == "1"
}
@narqo
narqo / aerospike-README.md
Last active February 10, 2020 21:05
Aerospike Server systemd configuration @ rpi (Ubuntu 19.10, aarch64)
@narqo
narqo / producer-consumer.js
Created December 29, 2013 19:41
"Producer-Consumer" example implementation using generators. See http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators for more about coroutine
/* jshint esnext:true */
/**
* "Producer-Consumer" implementation using generators.
* @see http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators
*/
var SIZE = 3,
queue = newQueue();
package main
import (
"net"
"net/http"
)
const addr = ":8080"
func main() {