This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from BubbleWrap | |
def rgba_color(r, g, b, a=1) | |
UIColor.colorWithRed((r/255.0), green:(g/255.0), blue:(b/255.0), alpha:a) | |
end | |
class MyApplicationController < UIViewController | |
def viewDidLoad | |
font = UIFont.fontWithName('Inconsolata', size:20) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NewGameController | |
@synthesize game_info; | |
@synthesize table_data; | |
@synthesize table_view; | |
#pragma mark View lifecycle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
old_save = User.save # the unbound save method | |
def new_save(self): # in python, you have to pass in self, it's just another variable | |
print "MONKEY" | |
ret = old_save(self) | |
print "PATCHED | |
return ret | |
User.save = new_save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyStylesheet < Teacup::Stylesheet | |
style :shadow, { | |
shadow_color: :black.uicolor, | |
shadow_offset: 3, | |
shadow_radius: 1, | |
} | |
style :icon, { extends: :shadow, | |
margin: 2, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def self.inherited(subclass) | |
puts "self.inherited: #{subclass}" | |
@childclasses ||= 0 | |
@childclasses += 1 | |
@@subclasses ||= Hash.new { |hash,key| | |
hash[key] = 0 | |
} | |
klass = subclass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo: | |
def bar(self): | |
print self | |
# add logging to bar | |
old_bar = Foo.bar | |
def log_bar(self): | |
print 'Logging' | |
r = old_bar(self) | |
print 'Done logging' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Differences between decorators, callables, and descriptors | |
""" | |
def fn_decorator(fn): | |
return fn | |
class ClassDecorator(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inline styles | |
@calculate_button = UIButton.named(I18n.t(:calculate_button)).style(color: 0xFFFFFF, align: :center, vertical_align: :center, top: 10, left: 30, width: 120, height: 40) | |
# External styles | |
# /app/stylesheets/application.rb | |
class ApplicationStylesheet < Stylesheets::Base | |
# Stylesheets for UI-Elements | |
# usage: @element.outfit(:awesome_default) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Teacup::Stylesheet.new(:iphone) do | |
# enable orientations - you have to declare "top-level" | |
# things true/false values here. also, i'm testing out | |
# the block syntax | |
style(self) do | |
portrait true | |
upsidedown false | |
landscape true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FirstController < TeacupViewController | |
stylesheet :iphone | |
layout do | |
subview(UIView, :background) do | |
subview(UILabel, :label) | |
end | |
end |