Skip to content

Instantly share code, notes, and snippets.

View colinta's full-sized avatar
🏠
Working from home

Colin T.A. Gray colinta

🏠
Working from home
View GitHub Profile
@colinta
colinta / my_application_controller.rb
Created May 15, 2012 00:20
glowing custom font
# 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)
@implementation NewGameController
@synthesize game_info;
@synthesize table_data;
@synthesize table_view;
#pragma mark View lifecycle
@colinta
colinta / save.py
Created May 17, 2012 12:45
monkey patch save method
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
class MyStylesheet < Teacup::Stylesheet
style :shadow, {
shadow_color: :black.uicolor,
shadow_offset: 3,
shadow_radius: 1,
}
style :icon, { extends: :shadow,
margin: 2,
}
class Foo
def self.inherited(subclass)
puts "self.inherited: #{subclass}"
@childclasses ||= 0
@childclasses += 1
@@subclasses ||= Hash.new { |hash,key|
hash[key] = 0
}
klass = subclass
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'
"""
Differences between decorators, callables, and descriptors
"""
def fn_decorator(fn):
return fn
class ClassDecorator(object):
@colinta
colinta / gist:2864117
Created June 3, 2012 16:42 — forked from Cosmo/gist:2864098
css dsl for rubymotion
# 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)
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
class FirstController < TeacupViewController
stylesheet :iphone
layout do
subview(UIView, :background) do
subview(UILabel, :label)
end
end