Skip to content

Instantly share code, notes, and snippets.

View jgn's full-sized avatar
☂️
Messing around.

John Norman jgn

☂️
Messing around.
View GitHub Profile
class HalfAdder
attr_reader :sum, :carry
def initialize(augend, addend, logger)
@augend, @addend, @logger = augend, addend, logger
end
def compute
@carry = @augend & @addend
@sum = @augend ^ @addend
class HalfAdder
attr_reader :sum, :carry
def initialize(augend, addend, logger)
@augend, @addend, @logger = augend, addend, logger
end
def compute
@carry = @augend & @addend
@sum = @augend ^ @addend
class HalfAdder
attr_reader :sum, :carry
def initialize(augend, addend)
@augend, @addend = augend, addend
end
def compute
@carry = @augend & @addend
@sum = @augend ^ @addend
example [0, 0, 0, 0]: Fail: got nil; expected 0
example [0, 0, 0, 0]: Fail: got nil; expected 0
example [1, 0, 0, 1]: Fail: got nil; expected 0
example [1, 0, 0, 1]: Fail: got nil; expected 1
example [0, 1, 0, 1]: Fail: got nil; expected 0
example [0, 1, 0, 1]: Fail: got nil; expected 1
example [1, 1, 1, 0]: Fail: got nil; expected 1
example [1, 1, 1, 0]: Fail: got nil; expected 0
class HalfAdder
attr_reader :sum, :carry
def initialize(augend, addend)
@augend, @addend = augend, addend
end
def compute
end
end
def assert_equality(example, actual, expected)
print "example #{example}: "
if actual == expected
puts 'Pass'
else
puts "Fail: got #{actual.inspect}; expected #{expected.inspect}"
end
end
examples = [
@jgn
jgn / rozenshtein.sql
Created January 15, 2013 23:51
Sample schema from Rozenshtein, The Essence of SQL (and see The SQL Cookbook)
drop table if exists student;
create table student (
sno integer,
sname varchar(10),
age integer
);
drop table if exists courses;
create table courses (
cno varchar(5),
@jgn
jgn / dst_shifts.rb
Created November 29, 2012 04:17
Doing the "right thing" over DST shifts
require 'active_support/version'
require 'active_support/core_ext/time/zones'
require 'active_support/core_ext/time/calculations'
require 'active_support/time_with_zone'
puts "ActiveSupport: #{ActiveSupport::VERSION::STRING}"
Time.zone = 'Eastern Time (US & Canada)'
def show_time user_time
@jgn
jgn / test.md
Created July 19, 2012 23:00
Something

Foo

Bar Baz Boo

Bar

dddd

@jgn
jgn / generate_migration.rb
Created June 7, 2012 08:17
Generate migration code for single table based on current state of the database
ActiveRecord::SchemaDumper.ignore_tables = ActiveRecord::Base.connection.tables - ['table_name']
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, $stdout)