Skip to content

Instantly share code, notes, and snippets.

Andrew White pixeltrix

Block or report user

Report or block pixeltrix

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pixeltrix
pixeltrix / toy_robot.rb
Created May 15, 2019
Ruby implementation of the common code exercise
View toy_robot.rb
require "matrix"
require "readline"
class ToyRobot
PROMPT = "> "
PLACE = /\APLACE\s+(\d+),(\d+),(NORTH|SOUTH|EAST|WEST)\z/
COMMAND = /\ALEFT|RIGHT|MOVE|REPORT\z/
QUIT = /\AQUIT\z/
LEFT = Matrix[[0, 1], [-1, 0]]
RIGHT = Matrix[[0, -1], [ 1, 0]]
View routes.html
<!DOCTYPE html>
<html>
<head>
<title>FSM</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css" type="text/css">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, Sans-Serif;
margin: 0;
@pixeltrix
pixeltrix / rails-32083.rb
Created Mar 9, 2018
Example for issue #32083
View rails-32083.rb
# frozen_string_literal: true
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
@pixeltrix
pixeltrix / turbolinks_helpers.rb
Last active Oct 31, 2017
Assert redirect helper for Turbolinks (untested code)
View turbolinks_helpers.rb
@pixeltrix
pixeltrix / 20171004211734_add_timestamps_everywhere.rb
Created Oct 4, 2017
Migration to add timestamps easily to a bunch of tables
View 20171004211734_add_timestamps_everywhere.rb
class AddTimestampsEverywhere < ActiveRecord::Migration[5.1]
def change
now = Time.current
%i[
candidates
evaluations
interviewers
questions
responses
@pixeltrix
pixeltrix / date_and_time_compatibility_test.rb
Created Feb 25, 2017
Enhanced Date/Time compatibility tests
View date_and_time_compatibility_test.rb
require "abstract_unit"
require "active_support/time"
require "time_zone_test_helpers"
class DateAndTimeCompatibilityTest < ActiveSupport::TestCase
include TimeZoneTestHelpers
def setup
@utc_time = Time.utc(2016, 4, 23, 14, 11, 12)
@date_time = DateTime.new(2016, 4, 23, 14, 11, 12, 0)
@pixeltrix
pixeltrix / behaviour.rb
Last active Feb 24, 2017
Script to output behaviours of Time, Date and DateTime across Ruby versions
View behaviour.rb
require 'date'
require 'time'
ENV['TZ'] = 'America/New_York'
time = Time.new(2017, 1, 1, 0, 0, 0, "+02:00").freeze
date = Date.new(2017, 1, 1).freeze
datetime = DateTime.new(2017, 1, 1, 0, 0, 0, Rational(2, 24)).freeze
# Time
puts "Time#to_time | #{RUBY_VERSION} "
@pixeltrix
pixeltrix / download-petitions.rb
Created Feb 22, 2017
Ruby script to download archived petition data
View download-petitions.rb
require 'csv'
require 'faraday'
require 'json'
require 'uri'
url = URI.parse('https://petition.parliament.uk/archived/petitions.json')
response = Faraday.get(url)
unless response.success?
@pixeltrix
pixeltrix / postgis21.rb
Last active Sep 4, 2018
Formula for install postgis-2.1 with the legacy postgresql@9.4 homebrew formula
View postgis21.rb
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 Oct 23, 2016
Formula for installing Sphinx search engine 0.9.9 on Mac OS X Sierra and Homebrew 1.0
View sphinx.rb
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
You can’t perform that action at this time.