Skip to content

Instantly share code, notes, and snippets.

View jacklynrose's full-sized avatar

Jacklyn Rose jacklynrose

  • Australia
View GitHub Profile
@jacklynrose
jacklynrose / view_controller.rb
Last active December 27, 2015 01:19
The crazy method I created to refactor out code duplication around creating views and making them testable! Ewwww...
# This one!
def viewNamed(view_name, ofClass: class_reference)
var_name = view_name[0].downcase + view_name[1, view_name.length - 1].gsub(/\s/, '')
instance_variable_get("@#{var_name}") or instance_variable_set("@#{var_name}", class_reference.new).tap do |view|
view.accessibilityLabel = view_name
yield view if block_given?
end
end
@jacklynrose
jacklynrose / vertical_centering_with_vfl.rb
Created October 27, 2013 10:35
This is how I managed to hack the visual format language to center a few views vertically (most other ways put them at the top and bottom, or just the top, or just the bottom). Basically what I'm doing is saying that the top margin should be less than or equal to half the portrait height minus the total height of all the views you'll be centring…
totalCombinedViewHeight = 100
Motion::Layout.new do |layout|
layout.view view
layout.subviews "state" => @state, "action" => @action
layout.metrics "margin" => 20, "height" => 40, "halfHeight" => ((view.bounds.size.height - totalCombinedViewHeight) / 2), "halfWidth" => ((view.bounds.size.width - 100) / 2)
layout.vertical "|-(<=halfHeight)-[state]-margin-[action]-(>=halfWidth)-|"
layout.horizontal "|-margin-[state]-margin-|"
layout.horizontal "|-margin-[action]-margin-|"
end
@jacklynrose
jacklynrose / routes.rb
Created May 12, 2011 04:56
Admin Controller + Subdomain Restriction + Whole URL Glob + Root Route for subdomains, no subdomain, and www subdomain
require 'Subdomain'
CMS::Application.routes.draw do
namespace "admin" do |admin|
resources :pages # Admin::PagesController Routes
end
constraints(Subdomain) do
match '/' => "pages#root" # Route for Root URL for Subdomains
@jacklynrose
jacklynrose / post-receieve
Created April 19, 2011 08:17
post-receive git hook to pull changes to your source folder
#!/bin/sh
cd ~user/ProjectRepo
env -i git pull