Skip to content

Instantly share code, notes, and snippets.

View StarpTech's full-sized avatar

Dustin Deus StarpTech

View GitHub Profile
@StarpTech
StarpTech / docker-network-fix.sh
Created December 13, 2021 20:42
Change docker network daemon defaults to avoid DNS collisions
#!/bin/bash
set -e
cat <<EOT >> /etc/docker/daemon.json
{
"bip": "172.31.0.1/16",
"default-address-pools":
[
{"base":"172.32.0.0/16","size":24}
]
@StarpTech
StarpTech / script.mjs
Last active September 25, 2021 09:58
ZX script to prefix the PR title with the linear ticket from the branch name or PR description. Can only run in GitHub CI.
#!/usr/bin/env zx
let token = process.env.GITHUB_TOKEN;
let branchName = process.env.GITHUB_HEAD_REF;
let pullNumber = process.env.PULL_NUMBER;
let apiUrl = process.env.GITHUB_API_URL;
let repo = process.env.GITHUB_REPOSITORY;
let issuePrefix = process.env.ISSUE_PREFIX
let allowFailure = process.env.ALLOW_FAILURE
service:
enabled: true
type: LoadBalancer
# Additional annotations (e.g. for cloud provider specific config)
annotations:
load-balancer.hetzner.cloud/location: nbg1
# ensure that the load balancer communicates via private network
load-balancer.hetzner.cloud/use-private-ip: "true"
# ensures that the load balancer is not removed
load-balancer.hetzner.cloud/name: "traefik"
@StarpTech
StarpTech / algolia-places-hook.js
Last active October 12, 2021 13:07
Algolia Places React Hook - SSR compatible - https://github.com/algolia/places
// ###################
// #### React hook ######
// ###################
import { useEffect, useRef, useState } from 'react';
/* eslint-disable global-require */
const Places = typeof window !== 'undefined' && require('places.js');
export default function useAlgoliaPlaces({ options, events }) {
@StarpTech
StarpTech / command_publish.go
Last active January 4, 2020 21:36
Run command and publish events
func (c *CommandBus) HandleCommand(cmd Command) {
events := c.CommandHandler.HandleCommand(cmd)
c.stan.Publish("eventstore.events", events)
}
@StarpTech
StarpTech / tracker_tanle
Created January 4, 2020 19:14
Processor Tracker table
id | last_processed_event_id | processor_name
+--------------------+----------------------------+-----------------+
517800172974768129 | 01DXRWAVGFZ46AV38EA2CYXFQJ | reactor
517800173095550977 | 01DXRWAVGFZ46AV38EA2CYXFQJ | order-projector
@StarpTech
StarpTech / tracker.go
Last active January 5, 2020 11:32
Tracker to store last processed event id
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
// check if event was already processed
if p.tracker.IsDuplicateOperation(p.name, event.ID) {
log.WithFields(eventLogFields).WithFields(subLogFields).Trace("duplicate")
if err := m.Ack(); err != nil {
log.WithFields(eventLogFields).WithFields(subLogFields).WithError(err).Error("ack duplicate event")
}
return
}
@StarpTech
StarpTech / dump
Last active January 7, 2020 16:50
NATS message SQL table
id | version | data | timestamp
+----+---------+----------------------------------------------------------------+---------------------+
1 | 1 | {"PositionID": "Auftragsfreigabe", "PositionOrderID": "A1212"} | 1578079632531167629
1 | 2 | {"PositionID": "Abteilung A", "PositionOrderID": "A1213"} | 1578079669618870080
@StarpTech
StarpTech / proxy.go
Last active January 5, 2020 13:20
Proxy events to stream processors
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
// TODO check if event was already processed
stan.PublishAsync("eventstore.events.order-projection", m.Data)
stan.PublishAsync("eventstore.events.order-reactor", m.Data)
// TODO track event as processed
// ack message
if err := m.Ack(); err != nil {
log.WithFields(eventLogFields).WithFields(r.baseLogFields).WithError(err).Error("ack event")
@StarpTech
StarpTech / sub.go
Last active January 4, 2020 22:35
Event Store subscription
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
// your code
if err := m.Ack(); err != nil {
// event is redelivered
return
}
},
stan.maxInFlight(1),
stan.AckWait("30s"),