Skip to content

Instantly share code, notes, and snippets.

View slok's full-sized avatar
⚙️
Building reliable solutions

Xabier Larrakoetxea Gallego slok

⚙️
Building reliable solutions
View GitHub Profile
@slok
slok / pprof.md
Last active April 22, 2024 17:36
Go pprof cheat sheet

Enable profiling

Default http server

import (
    _ "net/http/pprof"
    "net/http"
)
@slok
slok / main.go
Created June 12, 2016 10:09
handler & handlerfunc golang pattern example
// Package main is an example of how handler pattern works in golang.
//
// At first you will need some sort of start point. To do this we create
// ExampleHandler interface, this interface has a trigger method that will
// execute the chain, in his case is RunExample, it accepts a writer, and a
// custom input object, as you see there is an out and an in parameter.
//
// We could work like this you can create multiple ExampleHandlers in a helper
// function and call them on in another. But this is not very handy and it smells
//
@slok
slok / main.go
Created June 4, 2018 15:36
Kubernetes controller that updates annotation on pods with `kooper: test` label
package main
import (
"os"
"path/filepath"
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@slok
slok / run_docker_x11.sh
Created February 22, 2015 11:11
x11 with docker archlinux
KEY=$(xauth list |grep $(hostname) | awk '{ print $3 }' | head -n 1)
DCK_HOST=docker-skype
xauth add $DCK_HOST/unix:0 . $KEY
docker run -it --rm -v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/.Xauthority:/tmp/.Xauthority \
-v /dev/snd:/dev/snd \
-e DISPLAY=unix$DISPLAY \
-e XAUTHORITY=/tmp/.Xauthority \
-h $DCK_HOST \
@slok
slok / ftpFileserveUploader.py
Created December 8, 2011 16:47
Python script to upload various files to fileserve with FTP.
# Copyright (c) 2011, Xabier (slok) Larrakoetxea
# Copyright (c) 2011, Iraide (Sharem) Diaz
#
# 3 clause/New BSD license:
# opensource: http://www.opensource.org/licenses/BSD-3-Clause
# wikipedia: http://en.wikipedia.org/wiki/BSD_licenses
#
#-----------------------------------------------------------------------
# This script allows to upload to Fileserve with FTP various files at the same time
#
@slok
slok / amfirer.go
Last active November 11, 2021 06:10
Alertmanager alarm tester. Fire a custom alert to your alertmanager: https://github.com/prometheus/alertmanager
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"net/url"
@slok
slok / create_github_bitbucket_mirror.md
Created December 8, 2011 11:30
Create github and bitbucket mirror in gitolite

Create Github/Bitbucket Mirror

Create SSH key and configure

Create Key (no passphrase and name mirror the key)

ssh-keygen -t rsa -N "" -f ~/.ssh/mirror
version: "prometheus/v1"
service: "myservice"
labels:
owner: "myteam"
tier: "2"
slos:
# We allow failing (5xx and 429) 1 request every 1000 requests (99.9%).
- name: "requests-availability"
objective: 99.9
description: "Common SLO based on availability for HTTP request responses."
@slok
slok / yq-k8s-tricks.md
Created March 27, 2021 08:10
yq Kubernetes tricks

Add Namespace to all

yq eval -i '.metadata.namespace |= "argo"' "${FILE}"

Add protocol: TCP to the Services that have missing.

yq eval -i 'select(.kind == "Service") |= .spec.ports[] |= select(has("protocol") | not) |= .protocol="TCP" ' ${FILE}
@slok
slok / gist:846176
Created February 27, 2011 13:18
Redland librdf installation (GNU/Linux)
--------------
Raptor2-2.0.0
--------------
[For GRDDL requieres libxml2 and libxslt]
$ tar xvf ./raptor2-2.0.0.tar.gz
$ cd ./raptor2-2.0.0
$ ./configure --prefix=/usr --libdir=/usr/lib64
$ make
$ make check
$ cd ./examples