Skip to content

Instantly share code, notes, and snippets.

View netzfisch's full-sized avatar
🐋
swim w/ friends

harm netzfisch

🐋
swim w/ friends
View GitHub Profile
@netzfisch
netzfisch / exit_the_cloud.md
Created October 9, 2024 21:11 — forked from rameerez/exit_the_cloud.md
☁️ How I got off the cloud and migrated everything from AWS to a VPS in Hetzner

☁️ How I got off the cloud and migrated everything from AWS to a VPS in Hetzner

This is an opinionated handbook on how I migrated all my Rails apps off the cloud and into VPS.

This is how I manage real production loads for my Rails apps. It assumes:

  • Rails 7+
  • Ruby 3+
  • PostgreSQL
  • Ubuntu Server 24.04
  • Capistrano, Puma, Nginx

Configurations to Remember

boot & shutdown

/etc/default/grub => get back to terminal messages

/etc/systemd/system.conf => limit start-/stop-jobs to 3s

@netzfisch
netzfisch / readme.md
Created December 5, 2018 14:54 — forked from thomasdarimont/readme.md
Example for decoding a JWT Payload with your Shell (bash, zsh...)

Setup

Add this to your .profile, .bashrc, .zshrc...

decode_base64_url() {
  local len=$((${#1} % 4))
  local result="$1"
  if [ $len -eq 2 ]; then result="$1"'=='
  elif [ $len -eq 3 ]; then result="$1"'=' 
  fi
 echo "$result" | tr '_-' '/+' | openssl enc -d -base64
@netzfisch
netzfisch / my_awesome_rspec_hacks.rb
Created September 30, 2018 09:51 — forked from jalkoby/my_awesome_rspec_hacks.rb
My awesome RSpec hacks
## Context + metadata
shared_context 'Logged as a user', role: true do
let(:user) { |example| create :user, example.metadata[:role] }
before { login_as user }
end
scenario "Login as a client", role: :client
scenario "Login as a customer", role: :customer
scenario "Login as an admin", role: :admin

Connect to linux box behind NAT

destination (10.0.0.3) <- |NAT| <- source (192.168.1.105)

  1. SSH from the destination to the source (with public ip)

    ssh -f -N -R 19999:localhost:22 [email protected]

  2. SSH from source to destination through above tunel

@netzfisch
netzfisch / strong_parameters.rake
Created December 3, 2017 13:56
Rake task helping to migrate a rails 3 app to rails 4 with 'strong_parameters' instead of 'attr_accessible'
# Rake task to help migrating a rails 3 app to rails 4 strong_parameters.
# The task generates source code for helper methods for each model class
# to 'permit' the attributes.
# The generated methods are intended as starting point to copy&paste in the
# controller and than edit the permitted attributs.
# Some common names of non-editable attributes are already filtered,
# like 'id', 'password' or 'created_at'.
# The output is written to stdout so you can pipe it into a file
#
# Dependencies:
@netzfisch
netzfisch / gist:1a09308a7f3bc44db692
Last active September 15, 2015 15:36 — forked from alex-zige/gist:5795358
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@netzfisch
netzfisch / post_policy_spec.rb
Created June 26, 2014 13:51
RSpec example for rails authorisation with Pundit's policy_scope method
describe PostPolicy do
let(:scope) { Post.where(:published => true }
subject(:policy_scope) { PostPolicy::Scope.new(user, scope).resolve }
permissions ".scope" do
context "for an ordinary user"
let(:user) { User.new(:admin => false) }
it "hides unpublished post" do
post = Post.create(:published => false)
@netzfisch
netzfisch / testing_will_paginate.rb
Created May 18, 2013 21:08
working example of testing "will_paginate" view helper
require 'will_paginate/array'
describe "recurrences/index" do
let(:recurrences) do [
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-05"),
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-12"),
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-19")
]
end
@netzfisch
netzfisch / testing_will_paginate.rb
Created May 18, 2013 20:42
failing example of testing will_paginate with a stub
require 'will_paginate/array'
describe "recurrences/index" do
let(:recurrences) do [
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-05"),
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-12"),
FactoryGirl.build(:recurrence, scheduled_to: "2012-07-19")
]
end