Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
royratcliffe / hash_to_ostruct.rb
Last active August 29, 2015 14:06
Converts a hash to an OpenStruct along with all its nested hashes. The hash and all its sub-hashes become OpenStruct instances in the resulting structure.
require 'ostruct'
class OpenStruct
def self_and_field_pairs
each_pair.map { |field, _| [self, field] }
end
end
class Hash
# Converts a hash to an OpenStruct along with all its nested hashes. The hash
# Eliminate asset, template and test fluff. Shut down asset generation, ERB
# templates, as well as tests and their fixtures.
config.generators do |g|
g.assets false
g.template_engine false
g.test_framework false
end
@royratcliffe
royratcliffe / pg_role_create.rake
Created November 19, 2014 14:59
Creates PostgreSQL database roles.
# The production database uses a non-default user name for PostgreSQL
# connections. The user name corresponds to the app name. Use this Rake task to
# create the corresponding PostgreSQL role.
namespace :pg do
namespace :role do
task :create => :environment do
ActiveRecord::Base.configurations.select { |env, config|
config['adapter'] == 'postgresql'
}.collect { |env, config|
config['username']
@royratcliffe
royratcliffe / XCTestCase+NSBundle
Last active August 29, 2015 14:14
Bundle-based XCTestCase extensions
// XCTest XCTestCase+NSBundle.swift
//
// Copyright © 2015, Roy Ratcliffe, Pioneering Software, United Kingdom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@royratcliffe
royratcliffe / .gitignore
Last active August 29, 2015 14:17
Defines a Rack configuration which loads _other_ Rack configurations where the relative path to the configuration file defines the Rack server path. For example, it loads the Rack applications at `path/to/app.ru` and `another/path/to/config.ru` to `path/to/app` and `another/path/to` respectively. It automatically strips the `config` from the sec…
We couldn’t find that file to show.
// PS UIViewController+PS.swift
//
// Copyright © 2015, Roy Ratcliffe, Pioneering Software, United Kingdom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// UITableView TableViewData.h
//
// Copyright © 2015, Roy Ratcliffe, Pioneering Software, United Kingdom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Foundation NSObject+Properties.h
//
// Copyright © 2015, Roy Ratcliffe, Pioneering Software, United Kingdom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Foundation NSObject+ObjCProperties.h
//
// Copyright © 2015, Roy Ratcliffe, Pioneering Software, United Kingdom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
namespace :heroku do
desc "Push current branch to Heroku master"
task :push do
current_git_branch = %x(git branch).split("\n").select { |line| line =~ /^\* / }.map { |line| line[2..-1] }[0]
puts "Pushing branch #{current_git_branch} to Heroku"
%x(git push heroku #{current_git_branch}:master)
end
end