Skip to content

Instantly share code, notes, and snippets.

View gamecreature's full-sized avatar
🎢

Rick Blommers gamecreature

🎢
View GitHub Profile
@gamecreature
gamecreature / Git Subtree basics.md
Created December 28, 2024 06:42 — forked from SKempin/Git Subtree basics.md
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@gamecreature
gamecreature / install_freebsd_bootloaders.sh
Last active January 23, 2025 10:50
Installs the FreeBSD Bootloader on all efi an freebsd-boot partitions. When installing the freebsd-boot partition it also installs the MBR. Without --commit nothings happens, only the commands are shown.
#!/bin/sh
emit() {
if [ "$arg_commit" = "1" ]; then
#echo " | $@"
echo " | $@"
$@ ## << make this the main command or run with `eval $@`
else
echo " | $@"
(exit 0)
@gamecreature
gamecreature / Capfile
Last active September 28, 2021 12:24
A snippet for deploying to multiple servers at once
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# -8<-------8<-------8<-------8<-------8<-------8<------
@gamecreature
gamecreature / turbo_stream_helpers_concern.rb
Created August 6, 2021 14:49
Chain turbo-stream responses from controllers (and auto append flash messages)
#
# What does this do:
#
# Normal: (Basic library usage, without this helper)
# --------------------------------------------------
# render turbo_stream: [
# turbo_stream.replace(:flash, partial: 'shared/flash'),
# turbo_stream.replace(:object, partial: 'partial/name', locals: { object: object } )
# turbo_stream.replace(:object2, partial: 'partial/name'2, locals: { object2: object2 } )
# ]
# Use it by including it directly in the unix-ruby script
def run_script_once
emails = %w[[email protected]]
path = "#{$0}.pid"
if File.exists?(path)
pid = IO.read(path).to_i
begin
if Process.getpgid(pid)
@gamecreature
gamecreature / schema_validations.rb
Last active November 3, 2020 11:00
Schema_validations concern for rails, replacement for the schema_validations gem (Compatible with Rails 6.1)
# Schema Validations Concern - simple basic replacement for https://github.com/SchemaPlus/schema_validations
#
# Warning, uniqueness validators are NOT Added
#
# Constraints:
# - null: false => validates ... presence: true
# - limit: 100 => validates ... length: { maximum: 100 }
#
# Data types:
# - :boolean => :validates ... inclusion: { in: [true, false] }
@gamecreature
gamecreature / keybase.md
Created January 19, 2020 15:27
Keybase

Keybase proof

I hereby claim:

  • I am gamecreature on github.
  • I am gamecreature (https://keybase.io/gamecreature) on keybase.
  • I have a public key ASBZnzJJo6X4cy5Ftg2Hq68ULyE-TxgkagXk9z1fw5HSFAo

To claim this, I am signing this object:

@gamecreature
gamecreature / pundit_extension_helper.rb
Created May 21, 2019 10:23
Pundit Helper to invoke different resolve method in Pundit scope class
module PunditExtensionHelper
# this method is the same as the pundit_scope method
# the difference is, it doesn't invoke the resolve method
def policy_scoper(scope_in, method = :resolve)
scope = scope_in.is_a?(Array) ? scope_in.last : scope_in
policy_scope_class = Pundit::PolicyFinder.new(scope).scope!
return unless policy_scope_class
begin
@gamecreature
gamecreature / find_email_addresses.rb
Created May 31, 2016 08:32
Find emailadresses in an Maildir directory tree and send them to STDOUT
#!/usr/bin/env ruby
#
# EMAIL extractor from Maildir (mbox files)
#
# extracts all emailadresses from a IMAP directory tree
chars = %w{ | / - \\ }
def find_email_addresses(base_folder)