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 December 11, 2023 22:57
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

# this include won't work for some reason:
# include Capistrano::Git::DefaultStrategy
module SubmoduleStrategy
# check for a .git directory
def test
test! " [ -d #{repo_path}/.git ] "
end
@joekur
joekur / security_notes.md
Created May 22, 2014 17:00
Security notes for Rails

STAY SAFE!

SQL Injection

Never interpolate user input directly in a SQL statement.

Don't:

User.where("name = #{params[:search][:name]}")
@joekur
joekur / admin.html.erb
Created March 13, 2013 01:25
Rails nested layouts
<div id="admin_menu></div>
<% content_for :body do %>
<%= yield %>
<% end %>
<%= render :file => 'layouts/application' %>