Skip to content

Instantly share code, notes, and snippets.

@j-manu
j-manu / api_auto_pagination.rb
Created May 14, 2022 06:41 — forked from fractaledmind/api_auto_pagination.rb
Generalized auto_paginate method to work with GitHub, Jira, and Slack APIs
require "httpx"
module Clientable
extend ActiveSupport::Concern
def initialize
@httpx = HTTPX
.plugin(:retries, retry_change_requests: true)
.max_retries(3)
end

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

Keybase proof

I hereby claim:

  • I am j-manu on github.
  • I am manu_j (https://keybase.io/manu_j) on keybase.
  • I have a public key whose fingerprint is 1B1E 1CDD CC94 8B33 1249 6B63 90A4 F0B2 5D81 EE5F

To claim this, I am signing this object:

@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
@j-manu
j-manu / ansible.cfg
Last active August 29, 2015 14:14 — forked from phips/ansible.cfg
[defaults]
remote_user = vagrant
hostfile = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
private_key_file = ~/.vagrant.d/insecure_private_key
if [ -f "${rvm_path}/scripts/rvm" ]; then
source "${rvm_path}/scripts/rvm"
if [ -f ".rvmrc" ]; then
source ".rvmrc"
elif [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
rvm use `cat .ruby-version`@`cat .ruby-gemset`
elif [ -f ".ruby-version" ]; then
rvm use `cat .ruby-version`
# This hack is designed to prevent a thread from implicitly checking out an AR connection by
# just accessing ActiveRecord::Base.connection. The point of doing this is to ensure that threads
# don't tie up connections that they are not using, by making sure we're explicit about where we
# need to use an AR connection.
#
# See also http://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord.html
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::ConnectionPool # ensure loaded