Skip to content

Instantly share code, notes, and snippets.

View brandondrew's full-sized avatar

Brandon Zylstra brandondrew

  • UC Berkeley
  • the tubes
View GitHub Profile
@hirogeek
hirogeek / whenever_console_completion_fix.rb
Created January 4, 2023 10:16
Fix issue with whenever Ruby 3.2 and arrow up in console
# frozen_string_literal: true
module Whenever
class JobList
attr_reader :roles
def self.respond_to?(name, include_private = false)
@set_variables&.has_key?(name) || super
end
end
@davidlormor
davidlormor / example_resource.rb
Last active April 2, 2024 16:21
Avo resource view helpers
# frozen_string_literal: true
class ExampleResource < Avo::BaseResource
include ResourceExtensions
field :id, as: :id
field :name, as: :text
index do
field :some_field, as: :text
@stevenharman
stevenharman / gemfresh
Last active December 29, 2023 16:05
gemfresh: A handy script for determining the freshness of dependencies in a Ruby code base. Leverages bundler and libyear-bundler.
#!/usr/bin/env bash
# shellcheck disable=SC2059
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
NO_COLOR='\033[0m'
CLEAR_LINE='\r\033[K'
@startergo
startergo / Sleepless.md
Created April 17, 2021 20:10
Turn PreventUserIdleSystemSleep and PreventUserIdleDisplaySleep into a BASH alias sleepless
alias sleepless="pmset -g assertions | egrep '(PreventUserIdleSystemSleep|PreventUserIdleDisplaySleep)'"
@letiesperon
letiesperon / Rails credentials
Last active January 18, 2024 21:08
What I need to know about Rails 6 credentials and master key
The credentials are stored in the "credentials.yml.enc" file, encrypted.
To decrypt the credentials file, you need a master key that is set on either:
* config/master.key file (for local development)
* ENV["RAILS_MASTER_KEY"] (for deployed environments)
What should you commit?
* The file config/master.key should be ignored in gitignore (you should not commit the master key)
* The file credentials.yml.enc should be commited along with the codebase (but don't worry, only those who have the master key can decrypt it)
@brandondrew
brandondrew / upgrading_ruby_for_rails
Last active January 3, 2023 04:46
How To Upgrade Ruby for your Rails App, Locally & on a Server with Passenger
Overview
--------
Consider the commands given to be examples, not to necessarily be precisely
what you will use. They were based on my circumstances, in which
* my local platform is macOS,
* where Homebrew is the de facto package manager;
* my laptop (and the server) are managing Ruby with rbenv;
* vim is my remote editor of choice, and an acceptable local editor; and
@huobazi
huobazi / deploy.rb
Created February 21, 2019 02:32 — forked from Epigene/deploy.rb
Mina deployment file for rails applications
# Mina Deploy
# ===========
#
# Adapted from Creative deploy stack in Manabalss v4, Mar.2015, updated to support staging on Jun.2015
# On first deploy do: mina setup --verbose
# Then do : mina deploy[initialize] --trace
#
# Usage examples:
# mina deploy[soft,seed,compile] to=staging # deploy task with all options | a simple `mina deploy` will deploy to production
# mina rake[db:seed] # for multi-argument tasks # mina 'rake[payments:refund[arg1\,arg2]]'
@mankind
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@CrCs2O4
CrCs2O4 / gems_homepages.rb
Last active June 4, 2018 19:04
Get ruby gems homepages fo fast googling. Sometimes 'gem list' is not enough
#!/usr/bin/env ruby
# bundler exec ruby gems_homepages.rb
# based on http://stackoverflow.com/questions/5177634/list-of-installed-gems
require 'rubygems'
def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end
puts local_gems.map{ |name, specs|