This file contains 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
/* | |
Some syntactic sugar for dealing with Time in Swift | |
Examples: | |
3.days.inHours | |
3.6.hours.ago | |
12.hours.inDays | |
*/ | |
This file contains 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
invalid_chars = [' ', '$', '(', ')'] | |
ActiveRecord::Base.connection.tables.each do |table_name| | |
name = table_name | |
invalid_chars.map { |ch| name = name.gsub(ch, '_') } | |
name = name.camelize | |
name = name + "_" if Module.const_defined? name | |
eval %{ | |
class #{name} < ActiveRecord::Base |
This file contains 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
def falling_disks(rings, disks) | |
min, disk = rings[0], 0 | |
rings.each_index do |ring| | |
min = rings[ring] if rings[ring] < min | |
rings[ring] = min if rings[ring] > min | |
end | |
(rings.size - 1).downto(0) do |ring| | |
disk += 1 if disks[disk] <= rings[ring] |
This file contains 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 Character < ActiveRecord::Base | |
belongs_to :player, :inverse_of => :characters, :touch => true | |
belongs_to :archetype, :inverse_of => :characters, :touch => true | |
validates_presence_of :name | |
validates_presence_of :player, :archetype, :char_type, :on => :update | |
validates_uniqueness_of :name | |
validates_format_of :char_type, :with => /g|m|r/ # General Alt, Main, Raid Alt | |
end |
This file contains 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 HashParser | |
def initialize(hash) | |
if hash.has_key? "class" | |
hash["archetype"] = hash["class"] | |
hash.delete "class" | |
end | |
hash.each do |k, v| | |
if v.is_a? Hash | |
nv = HashParser.new(v) | |
else |
This file contains 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 ToHaml | |
def initialize(path) | |
@path = path | |
end | |
def convert_all! | |
Dir["#{@path}/**/*.erb"].each do |file| | |
haml_file = file.gsub(/\.erb$/, '.haml') | |
puts "Converting #{File.basename(file)} to #{File.basename(haml_file)}" | |
`html2haml -rx #{file} #{haml_file}` |
This file contains 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 CreateInstances < ActiveRecord::Migration | |
def self.up | |
# Create the new instances table | |
create_table :instances do |t| | |
t.references :zone | |
t.references :raid | |
t.datetime :start_time | |
t.datetime :end_time | |
t.timestamps |