Skip to content

Instantly share code, notes, and snippets.

@adomokos
adomokos / tracks_controller.rb
Created April 15, 2011 03:50
This code is to demonstrate how I use test doubles for Rails.
class TracksController < ApplicationController
def index
signed_in_user
end
def new
@track = Track.new
end
def create
@adomokos
adomokos / Error Publisher in Haml
Created November 10, 2010 03:08
Since this was - rightly - removed from Rails 3
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>"
end
@adomokos
adomokos / JavaScript Calculator with Closure
Created November 7, 2010 04:01
A 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;
}
// 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('$', ''));
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) {}