Skip to content

Instantly share code, notes, and snippets.

View pixeltrix's full-sized avatar

Andrew White pixeltrix

View GitHub Profile
@pixeltrix
pixeltrix / awaiting_moderation_test.rb
Created May 16, 2014 08:30
Response to James Coglan's 'An ActiveRecord conumdrum': https://gist.github.com/jcoglan/4ccf434cd2e1305d1c5c
require 'active_record'
require 'logger'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :texts do |t|
t.string :title
@pixeltrix
pixeltrix / unsafe_query_check.rb
Created May 20, 2014 11:00
Tool to report whether a Rails application may be vulnerable to 'Unsafe Query Risk in Active Record'
# Run this code inside your Rails application
#
# Rails 2.3:
# script/runner unsafe_query_check.rb
#
# Rails 3.0 and later
# rails runner unsafe_query_check.rb
connection = ActiveRecord::Base.connection
tables = connection.tables
en:
short_names:
default:
male: "Mr %{surname}"
female: "Ms %{surname}"
full_names:
default:
male: "%{given_name} %{surname}"
female: "%{given_name} %{surname}"
not_specified: "%{given_name} %{surname}"

Keybase proof

I hereby claim:

  • I am pixeltrix on github.
  • I am pixeltrix (https://keybase.io/pixeltrix) on keybase.
  • I have a public key whose fingerprint is 64AC 62AF 61FE B618 2F5B D9AA E2AE 198C 7AE0 543D

To claim this, I am signing this object:

class Kid
attr_reader :name, :naughty, :nice
def initialize(name, options = {})
@name = name
@naughty = options.fetch(:naughty, false)
@nice = options.fetch(:nice, false)
end
alias_method :naughty?, :naughty
@pixeltrix
pixeltrix / things-to-do-in-cape-town.html
Created January 29, 2015 22:57
Things to do in Cape Town
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
h1,
h2,
h3,
h4,
@pixeltrix
pixeltrix / person.rb
Created February 26, 2015 09:52
Use individual components for setting a date
class Person < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 255 }
validates :date_of_birth_day, presence: true, format: /\A\d{1,2}\z/
validates :date_of_birth_month, presence: true, format: /\A\d{1,2}\z/
validates :date_of_birth_year, presence: true, format: /\A\d{4}\z/
validates :date_of_birth, presence: true
validate do
if building_date_of_birth?
@pixeltrix
pixeltrix / _appointment_time.html.erb
Last active August 29, 2015 14:16
Example of using an object to build dates and times using individual fields
<%= f.label :appointment_time %><br>
<%= f.fields_for :appointment_time, @person.appointment_time do |t| %>
<%= t.text_field :day, size: 2, placeholder: 'DD' %> /
<%= t.text_field :month, size: 2, placeholder: 'MM' %> /
<%= t.text_field :year, size: 4, placeholder: 'YYYY' %> -
<%= t.text_field :hour, size: 2, placeholder: 'HH' %> :
<%= t.text_field :min, size: 2, placeholder: 'MM' %>
<% end %>
@pixeltrix
pixeltrix / profiling_links.md
Created August 13, 2015 16:38
A list of links about profiling Rails and Ruby applications
From 832c042e2c8eba2200627cc62de2854edcfb07c1 Mon Sep 17 00:00:00 2001
From: thedarkone <nobody>
Date: Wed, 11 Feb 2009 21:39:48 +0100
Subject: [PATCH] Port fast reloadable templates from rails-dev-boost.
---
actionmailer/test/abstract_unit.rb | 1 +
actionmailer/test/mail_service_test.rb | 2 +-
actionpack/lib/action_controller/rescue.rb | 2 +-
actionpack/lib/action_view.rb | 1 +