Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthias Kadenbach mattes

View GitHub Profile
@mattes
mattes / resque.rb
Created Oct 30, 2020
Resque in distroless docker container
View resque.rb
# config/initializers/resque.rb
module Resque
class Worker
# Monkey patch linux_worker_pids because the original function tries to shell out.
# Since we run distroless in production, there is no shell.
# https://github.com/resque/resque/blob/7f6b88404dd18698f6f4023e18fdc1ae8318e5e5/lib/resque/worker.rb#L839
def linux_worker_pids
[Process.pid]
end
end
@mattes
mattes / rails-google-compute-deploy.md
Last active Nov 1, 2020
My own Heroku in 30 mins
View rails-google-compute-deploy.md

Deploy Rails apps to Google Cloud Compute Engine

  • Zero Downtime
  • Graceful shutdowns
  • Via Github Actions
  • Zero infrastructure management overhead

Overview

The general idea is to have Github Actions test, build and deploy a Rails app to Google Cloud Compute Engine.

View gist:ca80926ba997ba881ae9339f8b47a36d
docker system prune -a
docker rm $(docker ps -a -f status=exited -q)
https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
@mattes
mattes / script.sh
Created Sep 10, 2020
Get access token via curl for default service account on Google Cloud Compute Engine
View script.sh
METADATA=http://metadata.google.internal/computeMetadata/v1
SVC_ACCT=$METADATA/instance/service-accounts/default
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token | cut -d'"' -f 4)
View gist:90565c73072c9f07ad64ebda3ca2916c
gcloud config configurations list
gcloud config configurations activate MY_OLD_CONFIG
gcloud_switch xxx
View gist:8af42a0939d030b0d3ef36ddf7869cb8
# https://cloud.google.com/compute/docs/disks/add-persistent-disk#resize_partitions
sudo growpart /dev/sda 1
sudo resize2fs /dev/sda
sudo resize2fs /dev/sdb
@mattes
mattes / redis.lua
Created Jan 21, 2020
delete redis keys in bulk with pattern
View redis.lua
eval "for i, name in ipairs(redis.call('KEYS', 'pattern-*')) do redis.call('DEL', name); end" 0
View gist:6c0bc186a7f013482d2b2d1c67a485ed
ws = new WebSocket("ws://localhost:8080");
ws.onopen = function(evt) {
console.log("OPEN");
}
ws.onclose = function(evt) {
console.log("CLOSE");
ws = null;
}
View gist:3674e3769240fcc3adc02f08ee115c35
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
esptool.py v2.5.1
Serial port /dev/ttyUSB0
Connecting........_
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, Embedded Flash
MAC: d8:a0:1d:40:89:c4
Uploading stub...
Running stub...
Stub running...
You can’t perform that action at this time.