Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / database.rb
Created May 23, 2019 16:41
Deletion Implementation
class Database
def initialize
@count = Hash.new(0)
@db = Hash.new()
end
# CRUD COMMANDS
def set(key, value)
@db[key] = value
@chelseatroy
chelseatroy / user.rb
Created May 25, 2019 18:30
Modifying User in Devise
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
...
def active_for_authentication?
super && approved?
end
def inactive_message
@chelseatroy
chelseatroy / test_database.rb
Created May 27, 2019 02:09
Commission Tests
require_relative "database"
require "test/unit"
class TestDatabase < Test::Unit::TestCase
...
def test_commit_with_transaction
db = Database.new
...
def test_rollback_with_transaction
db = Database.new
db.set "Bald", "Eagle"
assert_equal(1, db.count("Eagle"))
db.begin
db.set "Golden", "Eagle"
@chelseatroy
chelseatroy / database.rb
Last active May 27, 2019 03:01
First Pass at Transactions
class Database
def initialize
@count_versions = [Hash.new(0)]
@db_versions = [Hash.new()]
end
# CRUD COMMANDS
def set(key, value)
@db_versions[-1][key] = value
@chelseatroy
chelseatroy / database.rb
Created May 27, 2019 03:21
Space Inefficient Transactions
class Database
def initialize
@count_versions = [Hash.new(0)]
@db_versions = [Hash.new()]
end
# CRUD COMMANDS
def set(key, value)
@db_versions[-1][key] = value
@chelseatroy
chelseatroy / database.rb
Last active May 27, 2019 22:55
More Space Efficient Transaction Management
class Database
def initialize
@count_versions = [Hash.new(0)]
@db_versions = [Hash.new()]
@tier = 0
end
# CRUD COMMANDS
def set(key, value)
@chelseatroy
chelseatroy / test_database.rb
Created May 27, 2019 21:39
Test Nested Transactions
...
def test_nested_transaction
db = Database.new
db.set "Pacific", "Baza"
assert_equal(1, db.count("Baza"))
db.begin
db.set "Black", "Baza"
@chelseatroy
chelseatroy / test_database.rb
Created May 27, 2019 22:31
Test Deletion with Transaction
...
def test_transaction_with_deletion
db = Database.new
db.set "Homing", "Pigeon"
db.set "Fantail", "Pigeon"
assert_equal(2, db.count("Pigeon"))
@chelseatroy
chelseatroy / database.rb
Last active May 28, 2019 01:36
Transactions With Deletion
class Database
def initialize
@count_versions = [Hash.new(0)]
@db_versions = [Hash.new()]
@deletion_keys = [[]]
@tier = 0
end
# CRUD COMMANDS