Skip to content

Instantly share code, notes, and snippets.

View alexnoz's full-sized avatar
💡

Alex Nozdriukhin alexnoz

💡
  • Third Stone from the Sun
View GitHub Profile
@alexnoz
alexnoz / remove-iptables-chain.sh
Created August 7, 2023 19:03
Remove custom iptables chain
#!bin/bash
table=$1
pattern=$2
if [[ -z "$table" ]] || [[ -z "$pattern" ]]; then
echo "Usage: $0 <iptables-table-name> <iptables-chain-name-grep-pattern>"
exit 1
fi
#!/bin/bash
kubeadm reset -f
yum remove -y kube* containerd* docker* nginx cri*
rm -rf /etc/containerd /etc/cni/net.d /home/docker /var/log/nginx /home/cert-deploy /home/containerd /etc/ansible-iptables
iptables-save | awk '/^[*]/ { print $1 }
/^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
@alexnoz
alexnoz / bellman-ford.cpp
Created August 28, 2018 19:13
Bellman-Ford algorithm in C++
#include <iostream>
#include <vector>
#include <array>
#include <climits> // INT_MAX
using namespace std;
struct Node {
int p = -1;
int d = INT_MAX;
@alexnoz
alexnoz / debounce-abort-fetch.js
Created June 13, 2018 20:11
Abort fetching data in a function when debouncing it
function debounceFetch (fn, delay, onCancel = () => {}) {
let timer = 0, isFetching = false
return function (...args) {
clearTimeout(timer)
if (isFetching) {
onCancel()
isFetching = false
}
@alexnoz
alexnoz / kafka-cheat-sheet.md
Last active July 11, 2021 18:15
Apache Kafka cheat sheet

Config

Set a setting (log rotation)

./bin/kafka-configs.sh --zookeeper zookeeper1:2181/kafka \
--alter --entity-type topics \
--entity-name test \
--add-config segment.ms=60000
@alexnoz
alexnoz / images-loaded.js
Last active June 11, 2020 15:57
Load images asynchronously and determine when the loading is finished
const getImage = url => (
new Promise((resolve, reject) => {
const image = new Image()
image.onload = e => {
resolve(image)
}
image.onerror = e => {
reject(Error("Network Error"))
@alexnoz
alexnoz / type-simulation.html
Last active May 1, 2020 18:12
Simple type simulation
<style>
.text {
position: relative;
}
.text.type-finished::before {
animation: .5s steps(2, jump-none) 0s infinite alternate pulse;
}
.text::before {
content: '';
height: 1em;
@alexnoz
alexnoz / misc.cpp
Created March 20, 2020 20:20
Misc C++ basic stuff (balanced parens, postfix evaluation, infix -> postfix convertion)
#include <iostream>
#include <stack>
#include <iomanip>
#include <map>
#include <cctype>
#include <cstdlib>
using namespace std;
#define SIZE(arr) (sizeof(arr) / sizeof((arr[0])))
@alexnoz
alexnoz / postfix_macro.rs
Last active March 19, 2020 22:47
Rust macro for evaluation of postfix expressions
macro_rules! postfix {
// Terminating rule
(() -> ($res:expr)) => {$res};
// Addition
((+ $($rest:tt)*) -> ($a:tt $b:tt $($stack:tt)*)) => {
postfix!(($($rest)*) -> (($b + $a) $($stack)*))
};
// Subtraction
@alexnoz
alexnoz / pg_hba.conf
Last active March 18, 2020 21:41
PostgreSQL master-slave replication example
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.