Skip to content

Instantly share code, notes, and snippets.

View moredure's full-sized avatar

Mykhailo Faraponov moredure

View GitHub Profile
@moredure
moredure / failover-proxy.sh
Last active January 8, 2021 21:15
Failover Proxy for service migration using iptables (like aiven do)
#!/bin/bash
iptables -t nat -A PREROUTING -p tcp --dport $PORT -j DNAT --to-destination $TARGET:$PORT
iptables -t nat -A POSTROUTING -j MASQUERADE
function localize ([fallback, ...other], b) {
return [...b('', '')].concat(...other.map(x => b(`/${x}/`, `${x}-`)))
}
@moredure
moredure / searchtree.js
Created June 18, 2020 21:48
Search Tree for complex objects
function generateSearchTreeByFields(array, fields) {
const result = {}
for (const item of array) {
for (let i = 0, field = result; i < fields.length; i += 1) {
field = field[item[fields[i]]] = (i === fields.length - 1) ? item : (field[item[fields[i]]] || {})
}
}
return result
}
// function components (path, name, components, options = {}) {
// return {
// name,
// path,
// components,
// ...options
// }
// }
@moredure
moredure / crosstab.js
Last active April 28, 2020 13:29
Authentication Across tabs with VueJs and Vuex plugin
import router from '@/router'
const userKey = 'user'
const refreshAction = 'sessions/refresh'
const logoutAction = 'sessions/logout'
const updateMutations = [
'sessions/LOGIN',
'sessions/LOGOUT',
'sessions/SIGNUP'
]
# Under bastion
route add default gw $PRIVATE_GW
# On Bastion
iptables -t nat -A POSTROUTING -p tcp -o $PUBLIC_IF -j SNAT --to-source $ANCHOR_IP
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $PUBLIC_IF -j MASQUERADE
iptables -A FORWARD -i $PRIVATE_IF -j ACCEPT
@moredure
moredure / main.go
Last active November 21, 2019 12:50
package main
type Sequencer struct {
sync.Mutex
tasks map[string]chan string
}
func (t *Sequencer) run(msg string) {
for {
select {
type consumer struct {
url string
queue string
stop chan struct{}
wg sync.WaitGroup
deliveries chan<- amqp.Delivery
}
func (e *consumer) Stop() {
type publisher struct {
url string
chPool chan *amqp.Channel
}
func (c *publisher) init() error {
conn, err := amqp.Dial(c.url)
if err != nil {
return err