Skip to content

Instantly share code, notes, and snippets.

View bil-bas's full-sized avatar

Bil Bas bil-bas

View GitHub Profile
@bil-bas
bil-bas / font.rb
Created May 31, 2011 12:08
scaled font render
module Gosu
class Font
class << self
attr_accessor :factor_stored, :factor_rendered
end
self.factor_stored = 2 # How much larger is it stored as a font.
self.factor_rendered = 0.5 # How much smaller it is rendered.
alias_method :original_initialize, :initialize
@bil-bas
bil-bas / enumerable.rb
Created June 8, 2011 10:27
Enumerable#each_method
# calls a method many times with different args
# sort of an inverted Enumerable#each(&Symbol)
module Enumerable
def each_method(method_name, object = Kernel, &block)
each do |*args|
object.send(method_name, *args, &block)
end
end
end
@bil-bas
bil-bas / fibers.rb
Created June 11, 2011 10:31
Gosu/fibers minimal fail
# True fibers. WORKS!
require 'fiber'
class Fibers
def initialize
@fiber = Fiber.new do
10.times do
puts "hello"
Fiber.yield
@bil-bas
bil-bas / leap.rb
Created June 12, 2011 10:13
Spatzerny leap years
# Equivalent is:
# (year % 4 == 0) and not ((year % 100 == 0) and (year 400 != 0))
def leap_year?(year)
(year % 4 == 0) and ((year % 100 != 0) or (year 400 == 0))
end
puts "Gimmeh the starting year:"
year_start = gets.to_i
puts "Gimmeh the end year:"
year_end = gets.to_i
@bil-bas
bil-bas / roman.rb
Created June 12, 2011 14:12
Spatzerny roman to int and int to roman
class Integer
INT_TO_ROMAN = {
1000 => 'M',
500 => 'D',
100 => 'C',
50 => 'L',
10 => 'X',
5 => 'V',
1 => 'I',
}
@bil-bas
bil-bas / window.rb
Created June 13, 2011 11:20
Gosu 0.7.32.0 hotfix
module Gosu
class Window
%w(update draw needs_redraw? needs_cursor?
lose_focus button_down button_up).each do |callback|
define_method "protected_#{callback}" do |*args|
begin
# Turn into a boolean result for needs_cursor? etc while we are at it.
@_exception ? false : !!send(callback, *args)
rescue Exception => e
# Exit the message loop naturally, then re-throw
### Overriding global customization
Pry.config settings apply to all Pry instances, but some values can be overridden for a specific instance. The values that can be overridden are: `input`, `output`, `print`, `exception_handler`, `prompt`, and `hooks`. To override a given value, pass a new value as a hashed option for the method that initiates Pry.
Example: Overriding a global default at instantiation
```ruby
Pry.config.input = File.open("test.rb")
# Use a string-io for this specific instance.
@bil-bas
bil-bas / gist:1065047
Created July 5, 2011 15:22
binaryloader
app_path = __FILE__.chomp(File.extname(__FILE__))
binary_extensions = %w[.bundle .so]
binary_extensions.unshift ".#{RUBY_VERSION[0..2]}.so" if defined? RUBY_VERSION
found = binary_extensions.any? do |extension|
file = "#{app_path}#{extension}"
if File.exist? file
require file
true
@bil-bas
bil-bas / gist:1065113
Created July 5, 2011 15:54
renet 0.1.7 errors
spooner@Fish:~$ gem install renet-0.1.7.gem
Building native extensions. This could take a while...
ERROR: Error installing renet-0.1.7.gem:
ERROR: Failed to build gem native extension.
/home/spooner/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
creating Makefile
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -fPIC -o unix.o -c unix.c
unix.c:19:23: error: enet/enet.h: No such file or directory
unix.c:34: error: conflicting types for ‘socklen_t’
@bil-bas
bil-bas / gist:1065208
Created July 5, 2011 16:35
renet 0.1.12 error
spooner@Fish:~/renet_tests$ gem install renet-0.1.12.gem
Building native extensions. This could take a while...
ERROR: Error installing renet-0.1.12.gem:
ERROR: Failed to build gem native extension.
/home/spooner/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
creating Makefile
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -fPIC -o unix.o -c unix.c
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-f