Skip to content

Instantly share code, notes, and snippets.

View joekur's full-sized avatar

Joe Kurleto joekur

  • Stitch Fix
  • Metro Detroit, MI
View GitHub Profile
@joekur
joekur / timeplot.rb
Created October 28, 2016 15:00
Plot records over time in your rails console
# Example usage:
# timeplot User.all
# timeplot User.all, bucket_size: day, field: :updated_at
#
# Arguments:
# bucket_size: One of [:day, :month, :year]. Defaults to :month.
# field: Timestamp field to plot against. Defaults to :created_at.
class TimePlot
BUCKET_SIZES = [:day, :month, :year]
X_AXIS_MAX = 100
@joekur
joekur / html_safe.md
Last active February 4, 2025 18:35
Proper Use of `html_safe`

Proper use of html_safe

Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:

"#{first_name} #{last_name} #{phone}"

Great - this is very succinct, readable, and can easily be extracted to a method in a

@mattscilipoti
mattscilipoti / postgres.rake
Last active May 1, 2019 18:42
rake db:kill_postgres_connections
puts "WARN: We are patching rake tasks to support postgres. You have upgraded Rails and may not need this patch any more (lib/tasks/postgres.rake)." if Rails.version > "3.2.8"
namespace :db do
desc 'kills connections to postgres db'
task :kill_postgres_connections => :environment do
env = ENV['RAILS_ENV']
db_config = Rails.configuration.database_configuration[env]
fail(ArgumentError, "Could not find db config entry for env (#{env})") unless db_config
db_name = db_config['database']