Skip to content

Instantly share code, notes, and snippets.

View shawn42's full-sized avatar

Shawn Anderson shawn42

  • Cisco
  • Holland, MI
View GitHub Profile
@shawn42
shawn42 / gamebox_hash_perf.txt
Created January 8, 2011 16:06
Gamebox Spatial Hash Performance
DEFS:
lots: 1000
small_grid: 5 medium_grid: 80 large_grid:
small_object: 2 medium_object: 20 large_object: 100
w/ lots of small objects in small size grid 0.040000 0.000000 0.040000 ( 0.038262)
w/ lots of medium objects in small size grid 0.110000 0.000000 0.110000 ( 0.108360)
w/ lots of small objects in medium size grid 0.040000 0.000000 0.040000 ( 0.046014)
w/ lots of medium objects in medium size grid 0.050000 0.000000 0.050000 ( 0.047339)
w/ lots of large objects in small size grid 1.160000 0.010000 1.170000 ( 1.172766)
/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'
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ObjectionInjector *injector = [Objection createInjector];
[Objection setGlobalInjector:injector];
}
- (void)viewDidLoad {
id myModel = [[Objection globalInjector] getObject:[MyModel class]];
}
@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)
@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
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
# 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
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
require 'actor'
class Bacteria < Actor
has_behaviors :graphical, :updatable, :physical => {
:shape => :circle,
:mass => 10,
:radius => 45,
:friction => 1.7,
:moment => 150
}
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