Skip to content

Instantly share code, notes, and snippets.

View twerth's full-sized avatar

Todd Werth twerth

View GitHub Profile
@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 / colors
Created July 22, 2011 15:47
List colors in shell
#!/bin/bash
echo -e "\033[0mCOLOR_NC (No color)"
echo -e "\033[1;37mCOLOR_WHITE\t\033[0;30mCOLOR_BLACK"
echo -e "\033[0;34mCOLOR_BLUE\t\033[1;34mCOLOR_LIGHT_BLUE"
echo -e "\033[0;32mCOLOR_GREEN\t\033[1;32mCOLOR_LIGHT_GREEN"
echo -e "\033[0;36mCOLOR_CYAN\t\033[1;36mCOLOR_LIGHT_CYAN"
echo -e "\033[0;31mCOLOR_RED\t\033[1;31mCOLOR_LIGHT_RED"
echo -e "\033[0;35mCOLOR_PURPLE\t\033[1;35mCOLOR_LIGHT_PURPLE"
echo -e "\033[0;33mCOLOR_YELLOW\t\033[1;33mCOLOR_LIGHT_YELLOW"
@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 / 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'
#!/usr/bin/env ruby -wKU
#
require 'rexml/document'
xml = `curl -s "http://www.google.com/ig/api?weather=94123"`
doc = REXML::Document.new(xml)
condition = doc.root.elements["weather/current_conditions/condition"].attributes['data']
wind_condition = doc.root.elements["weather/current_conditions/wind_condition"].attributes['data']
wind_condition = wind_condition.match(/\d+/).to_s
temp_f = doc.root.elements["weather/current_conditions/temp_f"].attributes['data']