Skip to content

Instantly share code, notes, and snippets.

View shawn42's full-sized avatar

Shawn Anderson shawn42

  • Cisco
  • Holland, MI
View GitHub Profile
class Color
def self.from_css(hex)
if hex < 0x1000000
hex = hex >> 8
hex = hex & 0x000000FF
end
r = hex >> 24
g = (hex & 0x00FF0000) >> 16
TTF.setup
full_name = "/path/to/font.ttf"
size = 20
font = TTF.new(full_name, size)
text_image = font.render "hey there", true, [250,250,250,255]
text_image.blit screen
require 'actor'
class Bacteria < Actor
has_behaviors :graphical, :updatable, :physical => {
:shape => :circle,
:mass => 10,
:radius => 45,
:friction => 1.7,
:moment => 150
}
class Object
# Define a deep_freeze method in Object (based on code posted by flavorrific
# http://flavoriffic.blogspot.com/2008/08/freezing-deep-ruby-data-structures.html)
# that will call freeze on the top-level object instance
# the method is called on and any child object instances contained in the
# parent. This patch will also raise an IndexError if keys from
# ‘deeply frozen’ Hashes or Arrays are accessed that do not exist.
# adapted by shawn42 from
# http://www.semintelligent.com/blog/articles/29/freezing-ruby-data-structures-recursively
# add these to your apache config
# courtesy of http://www.webdeveloper.com/forum/showthread.php?t=162526
AddType application/vnd.ms-word.document.macroEnabled.12 docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
Dr. Suess as a Network Wizard
[email protected]
Here's an easy game to play.
Here's an easy thing to say....
If a packet hits a pocket on a socket on a port,
and the bus is interupted as a very last resort,
and the address of the memory makes your floppy disk abort
@shawn42
shawn42 / rails2_reloadable_template.rb
Created October 25, 2010 14:12
rails2.3.x lib/action_view/reloadable_template.rb
module ActionView #:nodoc:
class ReloadableTemplate
...
def register_template_from_file(template_full_file_path)
if !@paths[relative_path = relative_path_for_template_file(template_full_file_path)] && File.file?(template_full_file_path)
register_template(ReloadableTemplate.new(relative_path, self))
end
end
@shawn42
shawn42 / rails3_resolver.rb
Created October 25, 2010 14:16
rails3 template/resolver.rb
module ActionView
# = Action View Resolver
class Resolver
...
def find_templates(name, prefix, partial, details)
path = build_path(name, prefix, partial, details)
query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats])
end
def query(path, exts, formats)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ObjectionInjector *injector = [Objection createInjector];
[Objection setGlobalInjector:injector];
}
- (void)viewDidLoad {
id myModel = [[Objection globalInjector] getObject:[MyModel class]];
}
/Users/shawn42/code/games/unexpected_outcome/src/actors.rb:38:in `block in invoke': undefined method `index' for #<Chingu::Animation:0x00000100ae00a0> (NoMethodError)
from /Users/shawn42/code/games/unexpected_outcome/src/actors.rb:38:in `each'
from /Users/shawn42/code/games/unexpected_outcome/src/actors.rb:38:in `all?'
from /Users/shawn42/code/games/unexpected_outcome/src/actors.rb:38:in `invoke'
from /Users/shawn42/code/games/unexpected_outcome/src/player.rb:78:in `block in space'
from /Users/shawn42/code/games/chingu/lib/chingu/traits/collision_detection.rb:254:in `block (3 levels) in each_collision'