Skip to content

Instantly share code, notes, and snippets.

In a lot of languages callbacks are really common. You might call a function
with another function as an argument and at some point
in the body of the called function the callback function gets called. You said
this is done with pointers in C... not sure how
common this is there so bear with me.
# This is (psuedo-code) based on javascript where callbacks are really common
because it's asynchronous (i.e. you often need a callback to be notified when
the function you've called is complete). First two function definitions:
require 'acceptance/support/acceptance_helper'
feature "Add manual timesheet to payroll report", %q{
In order to tweak the payroll report
As an admin
I want to manually attach timesheets to the report
} do
background do
generate_full_payroll_data
gem 'rake', '~> 0.8.7'
#
# Cookbook Name:: crontab
# Definition:: crontab
#
#sets the crontab for a user
define :crontab, :username => :root, :filename => nil do
filename = params[:filename]
apt-get -y update
locale-gen en_GB.UTF-8
/usr/sbin/update-locale LANG=en_GB.UTF-8
aptitude -y safe-upgrade && aptitude -y full-upgrade
apt-get -y update
rvm gemset create moof
rvm gemset use moof
rails new moof
cd moof
emacs Gemfile <- add rspec
bundle
rails g rspec:install
rake -T
<excerpt>
def new
@timesheet = Timesheet.new
@timesheet.employee = Employee.find(params[:employee_id]) rescue nil
end
CREATE DATABASE database_name CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost' IDENTIFIED BY 'your_password';
scenario "Payroll report" do
sign_in :then_visit => reports_payroll_path
save_and_open_page
visit timesheets_path
save_and_open_page
end
class Object
def self.my_accessor(*accessor_names)
accessor_names.each do |name|
define_method name do
instance_var_name = "@#{name.to_s}".to_sym
self.instance_variable_get(instance_var_name)
end
writer_name = "#{name.to_s}=".to_sym
define_method writer_name do |value|
instance_var_name = "@#{name.to_s}".to_sym