Skip to content

Instantly share code, notes, and snippets.

View Trying MSpec
using System;
using Machine.Specifications;
using Given = Machine.Specifications.Establish;
using When = Machine.Specifications.Because;
using Then = Machine.Specifications.It;
namespace TryMSpec {
public class TicketCalculator{
private decimal _ticket_price = 11m;
public void StartPurchase(int runtime, DayOfWeek day, bool isParquet, bool is3D) {}
View TotalCalculator
// TotalCalculator.js
function TotalCalculator() {
TotalCalculator.prototype.calculate = function(quantity, price) {
var _quantity = parseInt(quantity);
if (isNaN(_quantity))
return 'N/A';
var _price = parseInt(price.replace('$', ''));
adomokos / JavaScript Calculator with Closure
Created Nov 7, 2010
A JavaScript Calculator with Closure
View JavaScript Calculator with Closure
function Calculator() {
this.add = function(input) {
var result = 0;
for(i = 0; i<input.length; ++i) {
result += input[i];
return result;
adomokos / Error Publisher in Haml
Created Nov 10, 2010
Since this was - rightly - removed from Rails 3
View Error Publisher in Haml
module ApplicationHelper
def error_publisher(model)
# Thanks Joe!
return unless model.errors.any?
item_errors = ''
model.errors.full_messages.each do |e|
item_errors += "<li>#{e}</li>"
adomokos / tracks_controller.rb
Created Apr 15, 2011
This code is to demonstrate how I use test doubles for Rails.
View tracks_controller.rb
class TracksController < ApplicationController
def index
def new
@track =
def create
adomokos / visitor_pattern_example.rb
Created May 24, 2011
The Visitor Pattern implementation in Ruby from the Wikipedia example
View visitor_pattern_example.rb
class CarElement
def accept(visitor)
module Visitable
def accept(visitor)
adomokos / get_out_of_my_controller_spec.rb
Created Sep 7, 2011
The supporting code for my blog entry: "Get out of my Controller! And from Active Record, too!"
View get_out_of_my_controller_spec.rb
module ActiveRecord; class Base; end; end
# The AR Models Rails give you
class User < ActiveRecord::Base
# These fields are defined dynamically by ActiveRecord
attr_accessor :id, :full_name
class Discussion < ActiveRecord::Base
# These fields are defined dynamically by ActiveRecord
adomokos /
Created Oct 2, 2011
Hackibou (09/01/2011) CoffeeScript file - working on the String Calculator kata
class StringCalculator
calculate: (input) ->
result = 0
result += parseInt(splitValue) for splitValue in @splitValues(input)
validateArgument: (input) ->
adomokos / sort_with_other.rb
Created Oct 5, 2011
A special kind of sorting algorithm, where "Other" has to be the last item when sorted
View sort_with_other.rb
require 'ostruct'
module SortWithOther
def <=>(other)
if self.send(sort_field).downcase == "Other".downcase
elsif other.send(sort_field).downcase == "Other".downcase
self.send(sort_field) <=> other.send(sort_field)
adomokos /
Created Nov 19, 2011
The TicTacToe game's ScoreBoard class is taking shape
class App.ScoreBoard
permutations =
[['A_1', 'B_1', 'C_1'],
['A_2', 'B_2', 'C_2'],
['A_3', 'B_3', 'C_3'],
['A_1', 'A_2', 'A_3'],
['B_1', 'B_2', 'B_3'],
['C_1', 'C_2', 'C_3'],