Skip to content

Instantly share code, notes, and snippets.

View pixeltrix's full-sized avatar

Andrew White pixeltrix

View GitHub Profile
@pixeltrix
pixeltrix / postgis21.rb
Last active September 4, 2018 22:09
Formula for install postgis-2.1 with the legacy postgresql@9.4 homebrew formula
class Postgis21 < Formula
desc "Adds support for geographic objects to PostgreSQL"
homepage "http://postgis.net"
url "http://pkgs.fedoraproject.org/repo/pkgs/postgis/postgis-2.1.8.tar.gz/c33923e37424978a1306ce461c1d14ed/postgis-2.1.8.tar.gz"
sha256 "7c2380b895fe7bda34c2e70deab3fcf4c12b13ab40d7501cdaa6fa36f1a6c662"
revision 1
def pour_bottle?
# Postgres extensions must live in the Postgres prefix, which precludes
# bottling: https://github.com/Homebrew/homebrew/issues/10247
@pixeltrix
pixeltrix / sphinx.rb
Last active October 23, 2016 14:35
Formula for installing Sphinx search engine 0.9.9 on Mac OS X Sierra and Homebrew 1.0
require 'formula'
class Sphinx < Formula
url 'http://sphinxsearch.com/files/archive/sphinx-0.9.9.tar.gz'
homepage 'http://www.sphinxsearch.com'
sha256 'bf8f55ffc095ff6b628f0cbc7eb54761811140140679a1c869cc1b17c42803e4'
depends_on 'homebrew/dupes/apple-gcc42'
resource 'stemmer' do
@pixeltrix
pixeltrix / instrument.rb
Created November 9, 2015 21:48
Simple example on how to count the number queries made by Active Record
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.4'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
@pixeltrix
pixeltrix / sphinx20.rb
Last active October 13, 2018 17:54
Homebrew formula for sphinx 2.0.9
require 'formula'
class Sphinx20 < Formula
homepage 'http://www.sphinxsearch.com'
url 'http://sphinxsearch.com/files/sphinx-2.0.9-release.tar.gz'
sha256 'c4fb5d7951bc0831e46f102d17b5f32bbde11434ce3b00b20531dfe9e646869d'
head 'http://sphinxsearch.googlecode.com/svn/trunk/'
devel do
@pixeltrix
pixeltrix / http_client_comparison.rb
Created September 4, 2015 14:25
Compare different Faraday adapters against the parliament postcode to constituency API
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
@pixeltrix
pixeltrix / profiling_links.md
Created August 13, 2015 16:38
A list of links about profiling Rails and Ruby applications
@pixeltrix
pixeltrix / results.txt
Created August 13, 2015 13:59
Ruby template engine comparison
$ ruby template_engine_shootout.rb
Fetching gem metadata from https://rubygems.org/....
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using benchmark-ips 2.3.0
Using erubis 2.7.0
Using tilt 2.0.1
Using haml 4.0.7
Using temple 0.7.6
Using slim 3.0.6
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@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 / 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?