Skip to content

Instantly share code, notes, and snippets.

View cilindrox's full-sized avatar
💭
:suspect:

Gaston Festari cilindrox

💭
:suspect:
View GitHub Profile
@cilindrox
cilindrox / prom-k8s-request-limits.md
Created February 3, 2021 15:18 — forked from max-rocket-internet/prom-k8s-request-limits.md
How to display Kubernetes request and limit in Grafana / Prometheus properly

CPU: percentage of limit

A lot of people land when trying to find out how to calculate CPU usage metric correctly in prometheus, myself included! So I'll post what I eventually ended up using as I think it's still a little difficult trying to tie together all the snippets of info here and elsewhere.

This is specific to k8s and containers that have CPU limits set.

To show CPU usage as a percentage of the limit given to the container, this is the Prometheus query we used to create nice graphs in Grafana:

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name) /
/** I was told to write comments, but thats erelephant
* _ _
* / \__/ \_____
* / / \ \ `\
* ) \''/ ( |\
* `\__)/__/'_\ / `
* //_|_|~|_|_|
* ^""'"' ""'"'
*/

Introduction

Some people like to run tools such as test runners outside their editor. Perhaps manually or perhaps via some file watching utility. They then review the output, switch back to their editor, and navigate to the appropriate location.

I prefer to explicitly invoke an external program from my editor, review the output, and allow my editor to jump to the first error. As well as storing a list of the locations of any other errors, a list that I may

@cilindrox
cilindrox / iptables-nat.md
Created August 31, 2020 13:51 — forked from DavidWittman/iptables-nat.md
iptables n'at

iptables n'at

Source NAT

Source NAT changes the source address in IP header of a packet. It may also change the source port in the TCP/UDP headers. The typical usage is to change the a private (rfc1918) address/port into a public address/port for packets leaving your network. Available only in the POSTROUTING chain in iptables.

Syntax

iptables -t nat -A POSTROUTING -i eth1 -j SNAT --to-source 1.2.3.4[:port]

Example

@cilindrox
cilindrox / States-v3.md
Created June 29, 2020 19:49 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@cilindrox
cilindrox / gist:cc8e112873a956b502777cb831e5f42f
Created March 30, 2020 14:22
Simple node.js code style tips to improve code quality

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

@cilindrox
cilindrox / zoom_fix.md
Created July 11, 2019 12:14 — forked from karanlyons/ZoomDaemon.yara
Fix for Unexpected Zoom Behavior

If you're using macOS, run these commands:

pkill "ZoomOpener"; rm -rf ~/.zoomus; touch ~/.zoomus && chmod 000 ~/.zoomus;
pkill "RingCentralOpener"; rm -rf ~/.ringcentralopener; touch ~/.ringcentralopener && chmod 000 ~/.ringcentralopener;

These two commands do the same thing for the two most popular "brands" of Zoom (Zoom, and RingCentral). They first kill the hidden server if it is running, and then regardless deletes it from its hidden directory if it exists there. Finally they create an empty file

@cilindrox
cilindrox / style.css
Created April 13, 2019 20:28
style.css
body {
font-family: Liberation Sans, Arial, sans-serif;
background-color: #fffaf7;
line-height: 1.3;
}
main {
max-width: 70ch;
padding: 2ch;
margin: auto;
}
@cilindrox
cilindrox / balance.go
Created February 16, 2019 14:57
Local Load Balancer implementation in go
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build OMIT
package main
import (
"container/heap"

acme.sh

# root's required due to lighttpd perms and pihole struct
sudo -i

curl https://get.acme.sh | sh -s email=email@example.com
# Alternatively, clone and exec locally.

mkdir -p /etc/lighttpd/certs/pihole.mylab.domain/