Skip to content

Instantly share code, notes, and snippets.

View jaredonline's full-sized avatar

Jared McFarland jaredonline

View GitHub Profile
@jaredonline
jaredonline / gist:1224439
Created September 17, 2011 22:19
Method deprecation helper
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]}"
@jaredonline
jaredonline / gist:1231156
Created September 21, 2011 03:22
Homeworks
/* 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
*/
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
hash = { ... some stuff ... }
keys = hash.keys
random_key = keys[(rand(keys.count)]
hash[random_key]
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
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() }
}
}
use std::io;
use std::rand::Rng;
struct Monster {
strength: int,
life: int,
charisma: int,
weapon: int,
name: String
}
@jaredonline
jaredonline / makefile-osx
Created August 21, 2014 02:32
Makefile for OS X Mavericks for libtcod
# 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`
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>
}
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