Skip to content

Instantly share code, notes, and snippets.

View mgnisia's full-sized avatar

Moritz Gnisia mgnisia

View GitHub Profile
@mgnisia
mgnisia / tf_vars_sort.awk
Created February 10, 2023 10:47 — forked from yermulnik/tf_vars_sort.awk
Sort Terraform (HCL) file by Resource Block Names using `awk`
#!/usr/bin/env -S gawk -f
# for MACOS: brew install gawk
# https://gist.github.com/yermulnik/7e0cf991962680d406692e1db1b551e6
# Tested with GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
# Usage: cat variables.tf | awk -f /path/to/tf_vars_sort.awk | tee sorted_variables.tf
# No licensing; yermulnik@gmail.com, 2021-2022
{
# skip blank lines at the beginning of file
if (!resource_type && length($0) == 0) next
// Resource: https://zetcode.com/golang/find-file/
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"regexp"
)
@mgnisia
mgnisia / client_go_example.go
Created August 8, 2022 12:51
Client Go with Home Directory Example
package main
import (
"context"
"flag"
"log"
"path/filepath"
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@mgnisia
mgnisia / docker-compose.yml
Created May 10, 2022 09:21
Local Kafka Setup
version: '3.4'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx-jsmdg
spec:
replicas: 3
selector:
matchLabels:
@mgnisia
mgnisia / main.go
Created March 15, 2022 13:17
Reset Kakfa Consumer Group to specific offset
package main
import (
"context"
kafka "github.com/segmentio/kafka-go"
log "github.com/sirupsen/logrus"
"time"
)
type Config struct {
@mgnisia
mgnisia / print_tensor.py
Created October 6, 2020 08:42
Printing of three dimensional tensor
# Assumption tensor == np.array
def print_tensor(tensor):
for i3 in range(0, tensor.shape[0]):
for i1 in range(0, tensor.shape[2]):
string_line = ""
for i2 in range(0, tensor.shape[1]):
string_line += " {:3.2f} ".format(tensor[i3][i2][i1])
print(string_line)
print("------------------------------------")
@mgnisia
mgnisia / ravel_index.h
Created September 23, 2020 17:56
Transform 1D Index Notation to 3D Index notation in C++ / CPP
template<typename T>
std::array<T,3> index_3D(T index, T size) {
T x = index % size;
T tmp = (index - x) / size;
T y = tmp % size;
T z = (tmp - y) / size;
return std::array<T,3>{z,y,x};
}
@mgnisia
mgnisia / BoundaryConditions.py
Created June 4, 2020 09:36 — forked from ilciavo/BoundaryConditions.py
Poisson and Heat Equation with boundary conditions
#poisson solver
#u_xx = b(x)
%matplotlib inline
from __future__ import division
import numpy as np
from numpy import cos, sin, zeros, pi
from numpy.linalg import solve, norm
import matplotlib.pyplot as plt
from matplotlib import rcParams
@mgnisia
mgnisia / rm_string_tinydb.py
Created February 13, 2020 13:29
Remove files that contain a certain string in a value
from tinydb import TinyDB, Query
db = TinyDB("path/to/your.db.json")
q = Query()
# the items that should be remove have stringXYZ in field name
db.remove(q.name.search('stringXYZ'))