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
module MethodDeprecator | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def deprecate_method(method, replacement) | |
class_eval <<-DEPRECATE_METHOD_END | |
def #{method.to_s}_with_deprecation | |
puts "WARNING: Deprecated method #{self.class}##{method.to_s} called, use #{replacement} instead. Called from #{Kernel.caller[0]}" |
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
/* Here's what you've got */ | |
/* | |
Problem 2: You are asked to implement an automated number-to-language translation system for a phone com- pany. Write a C program that receives as an input an integer number and converts each digit of the number to an English word. The integer number can be of any length. | |
Sample program execution: | |
Please enter your phone number: 2345769854 two three four five seven six nine eight five four | |
*/ |
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 percent_asset_split | |
plan.best_investment(risk_index).map do |symbol, percentage| | |
::Position.new(:symbol => symbol.to_s, :amount => percentage.to_f, :account => self.account).asset_allocation | |
end.sum.compress.to_percent | |
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
hash = { ... some stuff ... } | |
keys = hash.keys | |
random_key = keys[(rand(keys.count)] | |
hash[random_key] |
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
require 'benchmark' | |
Benchmark.bm(30) do |x| | |
x.report("Test One") do | |
# .. code for your first version here .. | |
end | |
x.report("Test Two") do | |
# .. code for your second version here .. | |
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
impl<R: Monster> MonsterCreator for R { | |
fn new(life: int) -> R { | |
R { life: life, strength: 35, charisma: 91, weapon: 2, name: | |
"Industrial Raver Monkey".to_str() } | |
} | |
} |
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
use std::io; | |
use std::rand::Rng; | |
struct Monster { | |
strength: int, | |
life: int, | |
charisma: int, | |
weapon: int, | |
name: String | |
} |
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
# libtcod makefile | |
# to build debug version, run "make -f makefile-linux debug" | |
# to build release version, run "make -f makefile-linux release" | |
SRCDIR=src | |
INCDIR=include | |
#dependencies | |
# SDL | |
SDL_FLAGS=`sdl-config --cflags` | |
SDL_LIBS=`sdl-config --libs` |
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
pub struct Game<'a> { | |
pub exit: bool, | |
pub window_bounds: Bound, | |
pub rendering_component: Box<RenderingComponent>, | |
pub stats_window: Box<WindowComponent>, | |
pub map_window: Box<WindowComponent>, | |
pub input_window: Box<WindowComponent>, | |
pub messages_window: Box<WindowComponent> | |
} |
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
structs.rs:48:23: 48:28 error: mismatched types: expected `Box<State+'a>`, found `Box<BadState>` (expected trait State, found struct BadState) | |
structs.rs:48 self.state = state; | |
^~~~~ | |
error: aborting due to previous error |
OlderNewer