Skip to content

Instantly share code, notes, and snippets.

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@j-manu
j-manu / authentication.rb
Created January 25, 2022 16:05 — forked from bjeanes/authentication.rb
Example of custom code to emulate a programmatic core in Rodauth
# frozen_string_literal: true
module Authentication
# Rodauth is pretty coupled to being in a request context, but this will provide the minimum necessary to be able
# to generate correct URLs
def self.rodauth(configuration_name = :user, params: {})
url_options = Rails.application.config.action_mailer.default_url_options
host = url_options[:host]
host += ":#{url_options[:port]}" if url_options.key?(:port)
base_url = "#{url_options[:protocol] || 'http'}://#{host}"
require 'rodauth'
module Rodauth
# Clean up how we configure all of our tables, columns, etc., to use values which are more consistent with Rails than
# the defaults as well as use Rails mailers
Feature.define(:rails_conventions, :RailsConventions) do
depends :rails # rodauth-rails feature
def post_configure
# Rodauth uses dash-separated paths by default, so we'll make these underscores by default
@j-manu
j-manu / migrate_from_devise.rb
Created January 25, 2022 16:05 — forked from bjeanes/migrate_from_devise.rb
Rodauth feature to migrate from Devise, including maintaining all Devise columns (that I was using) in case a rollback was necessary (it wasn't)
# frozen_string_literal: true
require 'rodauth'
# In order for Rails to reload this constant in dev, we need `require_dependency` because Rodauth expects the features
# in a specific load path, but it defines a constant against Rails' expectations, which breaks reloading.
require_dependency 'rodauth/features/remote_ip'
module Rodauth
Feature.define(:migrate_from_devise, :MigrateFromDevise) do
@j-manu
j-manu / iptableflip.sh
Created January 26, 2016 12:56 — forked from lewisd32/iptableflip.sh
Snippet of Unbounce script for restarting HAProxy with zero downtime
echo "Flipping tables! (╯°□°)╯︵ ┻━┻"
num_rules=3
real=3 # exposed to the ELB as port 443
test=4 # used to install test certs for domain verification
health=5 # used by the ELB healthcheck
blue_prefix=855
green_prefix=866
module Capybara::Poltergeist
class Client
private
def redirect_stdout
prev = STDOUT.dup
prev.autoclose = false
$stdout = @write_io
STDOUT.reopen(@write_io)
prev = STDERR.dup
module Capybara::Poltergeist
class Client
private
def redirect_stdout(to)
prev = STDOUT.dup
prev.autoclose = false
$stdout = to
STDOUT.reopen(to)
prev = STDERR.dup
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
# for Mountain Lion 10.8.3 - 10.8.4
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.1-10.8.2 and Lion 10.7.5
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.0 and Lion 10.7.4 BELOW
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
# for Mountain Lion 10.8.3 - 10.8.4
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.1-10.8.2 and Lion 10.7.5
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.0 and Lion 10.7.4 BELOW
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|
@j-manu
j-manu / easy_way.rb
Created September 2, 2012 11:31 — forked from mislav/easy_way.rb
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end