Skip to content

Instantly share code, notes, and snippets.

View twerth's full-sized avatar

Todd Werth twerth

View GitHub Profile
@twerth
twerth / gist:848c9484ad63781ed60d
Last active August 29, 2015 14:17
TOL about new layout method and find_or_append feature for RMQ/RedPotion
class MainScreen < PM::Screen
title "My Screen"
layout MyLayout
stylesheet MainScreenStylesheet
def on_load
stylesheet.layout
set_state user_logged_in: false, first_name: "n/a", last_name: "n/a"
end
@twerth
twerth / gist:d39028cdc4c0b4811d15
Last active August 29, 2015 14:02
Some styles
def pbi(st)
st.frame = 'a0:j8'
st.background_color = color.pbi
st.z_position = 1
st.hidden = true
st.clips_to_bounds = true
end
def instruction_image(st)
st.frame = 'a11:j15'
@twerth
twerth / ns_rails.rb
Created December 31, 2013 01:08
Patch for NSRails to allow for additional_query_parameters
class NSRConfig
# In AppDelegate: NSRConfig.defaultConfig.additional_query_parameters = {auth_token: 'yourtoken'}
attr_accessor :additional_query_parameters
end
class NSRRequest
alias :old_http_request :HTTPRequest
def HTTPRequest
if additional_params = self.config.additional_query_parameters
self.queryParameters = {} unless self.queryParameters
@twerth
twerth / Test.rb
Last active December 30, 2015 17:39
RubyMotion - Comparing some objects to same object in WeakRef fails tickets 1420 filed
(main)> a = ‘test’
=> "test"
(main)> b = WeakRef.new(a)
=> "test"
(main)> b == a
=> true
(main)> a == b
=> true
(main)> c = UIViewController.alloc.init
=> #<UIViewController:0×963c630>
@twerth
twerth / system_sounds.rb
Created May 6, 2013 02:20
Playing system sounds in RubyMotion
# Add the following to your Rakefile
# app.frameworks += ['MediaPlayer']
class SystemSounds
class << self
BASE_AUDIO_PATH = "#{NSBundle.mainBundle.resourcePath}/audio/"
@@system_sounds = {}
def play_system_sound(file_name)
path = "#{BASE_AUDIO_PATH}#{file_name}"
@twerth
twerth / rubymotion_arc.rb
Created April 13, 2013 16:13
Rubymotion: Static vendor code with ARC support
# Foo folder in vendor with .h and .m files
app.vendor_project('vendor/Foo', :static, :cflags => '-fobjc-arc'
@twerth
twerth / UIView.rb
Created April 3, 2013 02:24
RubyMotion: Adding a block to Teacup's animate_to_style, for completion
# RubyMotion: Adding a block to Teacup's animate_to_style, for completion. You can do something like this
#
# popup.animate_to_style( duration: 0.9, left: 5) do |finished|
# popup.animate_to_style( duration: 0.3, left: 105) do |finished|
# popup.animate_to_style( duration: 0.5, top: 300) do |finished|
# popup.hidden = true
# end
# end
# end
#
@twerth
twerth / example.rb
Created March 23, 2013 17:58
A simple example of creating a UIView with a UICollectionView as a subview in RubyMotion using Teacup for styling
# A simple example of creating a UIView with a UICollectionView as a subview
# in RubyMotion using Teacup for styling
#
# Your controller will need to set the stylesheet: stylesheet :example
# and create this view like so: subview Example, :my_example_view
class Example < UIView
CELL_IDENTIFIER = 'example_cell'
def initWithFrame(frame)
@twerth
twerth / color.rb
Last active December 15, 2015 01:08
A simple Color wrapper for RubyMotion
# RubyMotion
class Color < UIColor
class << self
alias :clear :clearColor
alias :white :whiteColor
alias :lightgray :lightGrayColor
alias :gray :grayColor
alias :darkgray :darkGrayColor
alias :black :blackColor
#!/bin/bash
mongod -vvvv --profile=2 --logpath /usr/local/var/log/mongodb/mongod.log -f /usr/local/etc/mongod.conf --fork
echo 'mongodb started'