Skip to content

Instantly share code, notes, and snippets.

@alfie-max
alfie-max / list_tables.rb
Created August 26, 2022 14:15 — forked from davidleandro/list_tables.rb
Rails list all tables count
tables = []
ActiveRecord::Base.connection.tables.each do |t|
count = ActiveRecord::Base.connection.exec_query("select count(*) from #{t}").rows[0][0]
tables << [t, count.to_i]
end
tables.sort_by { |t| t[1] }.reverse!
@alfie-max
alfie-max / rails-upgrade.rb
Created May 12, 2022 15:18 — forked from andynu/example.sh
rails-upgrade script, a helper for moving pins and doing other checks during ruby upgrades
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'thor'
gem 'rainbow'
gem 'awesome_print'
gem 'terminal-table'
gem 'terminal-emojify'
/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*
@alfie-max
alfie-max / rake_benchmark.rb
Created September 7, 2020 12:25 — forked from harley/rake_benchmark.rb
Benchmarking a rake task
# Put this in Rakefile (doesn't matter where)
require 'benchmark'
class Rake::Task
def execute_with_benchmark(*args)
bm = Benchmark.measure { execute_without_benchmark(*args) }
puts " #{name} --> #{bm}"
end
alias_method :execute_without_benchmark, :execute
@alfie-max
alfie-max / deploy.rb
Created May 28, 2019 01:01 — forked from gilcierweb/deploy.rb
Mina deploy ruby on rails 5.1 ++
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
# require 'mina/rvm' # for rvm support. (https://rvm.io)
set :application_name, 'my_app'
set :domain, 'my_server'
set :deploy_to, '/home/rails/my_app'
set :repository, 'git@bitbucket.org:my_user/my_app.git'
set :branch, 'master'
2.3.1 :031 > a = Hash.new([])
=> {}
2.3.1 :032 > a[:b]
=> []
2.3.1 :033 > a[:b].push(4)
=> [4]
2.3.1 :034 > a
=> {}
2.3.1 :035 > a[:b]
=> [4]
module Foo
def self.included(base)
base.class_eval do
def self.method_injected_by_foo
...
end
end
end
end
@alfie-max
alfie-max / gist:82d0083f9d78837f3771d9971b435713
Created January 14, 2017 10:19 — forked from shripadk/gist:552554
Setting up Heroku Hostname SSL with GoDaddy SSL Cert
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
class ProfileProject < ApplicationRecord
acts_as_votable
scope :join_votes, (lambda do
joins(sanitize_sql_array([%(
LEFT JOIN votes ON votes.votable_id = profile_projects.id
AND votes.votable_type = 'ProfileProject'
)
]))
end)
config.log_level = :debug
config.middleware.use LogPrettyJson