Skip to content

Instantly share code, notes, and snippets.

View sxross's full-sized avatar

s.ross sxross

View GitHub Profile
@sxross
sxross / motion_model_watchable.rb
Created October 1, 2014 21:06
MotionModel Watchable
module MotionModel
module Watchable
def self.included(base)
# uncomment if private class methods
# base.extend(PrivateClassMethods)
base.extend(PublicClassMethods)
# base.instance_eval do
# Any instance specific code
# stylesheet
def remember_me_label(st)
st.frame = {bp: PADDING, l:MARGIN, h:HEIGHT, w: WIDTH / 2}
st.text = 'remember me'
end
def remember_me_switch(st)
st.frame = {rop: 10, h:HEIGHT, w:WIDTH / 2} # bp: -32,
end

This code works with the Firebase simple-auth interface. It depends on the following Gemfile:

gem 'ruby_motion_query', :git => '[email protected]:infinitered/rmq.git'
gem 'motion-firebase'
 'motion-firebase',
 'motion-firebase-auth',
]
gem 'motion-map'
@sxross
sxross / singleton_test.rb
Last active December 18, 2015 04:09
Demonstrates inheritance of singleton vars (@@vars)
module MotionModel
module Model
def self.included(base)
base.extend(PublicClassMethods)
end
module PublicClassMethods
def inherited(subclass)
p "inherited from #{subclass}"
end
@sxross
sxross / Gemfile
Created April 21, 2013 16:49
Example of using NUI with RubyMotion
source "https://rubygems.org"
gem "rake"
gem "motion-cocoapods", "1.3.0.rc1"
gem 'bubble-wrap'
@sxross
sxross / Rakefile
Last active December 16, 2015 02:59
This RubyMotion project shows an iPad app that doesn't seem to respond to upside down orientation. To build just: rake device_family=ipad
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'foo'
app.device_family = [:iphone, :ipad]
interface_orientations = [:portrait, :landscape_left, :landscape_right, :portrait_upside_down]
end
@sxross
sxross / didmovetosuperview_problem.md
Created February 22, 2013 00:04
Teacup didMoveToSuperview Problem

backtrace

constraint.rb:112:in `from_sym:': Unknown symbol :topleft (RuntimeError)
  from ui_view.rb:87:in `block in get_ns_constraints'
	from ui_view.rb:82:in `get_ns_constraints'
	from ui_view.rb:152:in `block in get_ns_constraints'
	from ui_view.rb:151:in `get_ns_constraints'
	from ui_view.rb:152:in `block in get_ns_constraints'
	from ui_view.rb:151:in `get_ns_constraints'
module SugarCube
module DateParser
# Parse a date string: E.g.:
#
# SugarCube::DateParser.parse_date "There is a date in here tomorrow at 9:00 AM"
#
# => 2013-02-20 09:00:00 -0800
def self.parse_date(date_string)
detect(date_string).first.date
end
@sxross
sxross / gist:4711848
Created February 5, 2013 03:07
Super in module context
module MotionModel
module Model
def save(*)
puts "called MM#save"
end
end
end
module MotionModel
module Paranoid
@sxross
sxross / gist:4526913
Created January 13, 2013 23:54
Spec for core_extensions.rb
# See https://gist.github.com/4526905 for the code this tests
describe "core helpers" do
it "has a 'to_us_phone' method" do
'hello'.should.respond_to? :to_us_phone
end
describe "7-digit phone numbers" do
it "formats string" do
'1112222'.to_us_phone.should == '111-2222'