Skip to content

Instantly share code, notes, and snippets.

View gabrielgiordano's full-sized avatar
🏠
Working from home

Gabriel Giordano gabrielgiordano

🏠
Working from home
View GitHub Profile
@gabrielgiordano
gabrielgiordano / abstract_binding_tree.ml
Created July 4, 2021 03:11
Simple Abstract Binding Tree implementation
(*
Simple Abstract Binding Tree implementation inspired by Robert Harper book and Neel Krishnaswami blog post:
https://semantic-domain.blogspot.com/2015/03/abstract-binding-trees.html
This version is not modular but it's simpler to understand.
*)
type var = string
(* set of variables *)
module V = Set.Make(struct type t = var let compare = compare end)
#################################################################################
def foobar
if hello
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
end
end
def check_target_ruby
return if KNOWN_RUBIES.include?(target_ruby_version)
msg = if OBSOLETE_RUBIES.include?(target_ruby_version)
"Unsupported Ruby version #{target_ruby_version} found in " \
"#{target_ruby_source}. #{target_ruby_version}-compatible " \
'analysis was dropped after version ' \
"#{OBSOLETE_RUBIES[target_ruby_version]}."
else
"Unknown Ruby version #{target_ruby_version.inspect} found in " \
######################################################################
# INPUT MODULE
import copy
class LineStorage:
def __init__(self, linelist):
self.line_storage = copy.copy(linelist)
def lines(self):
return len(self.line_storage)
######################################################################
# INPUT MODULE
import copy
class LineStorage:
def __init__(self, linelist):
self.line_storage = copy.copy(linelist)
def lines(self):
return copy.copy(self.line_storage)
# Ability to go back into the past, and see what a user's todo list
# looked like at any point in time.
# Explain how this would work for todo lists that already exist.
#
# This feature wouldn't work for a time before it was implemented.
# Every modification made in a list would create a new record,
# the list would be immutable. If a user choose to go back in time
# we could delete the versions that were created after the time selected.
class User
1. Derive a program with the following precondition and postcondition:
{ x > 0 } S { x − 1 > 0 }
Draft:
{ [E/v]x-1>0 } x := E { x−1>0 }
{ [E/x]x-1>0 } x := E { x−1>0 }
{ [x+1/x]x-1>0 } x := x+1 { x-1>0 }
{ x>0 } x := x+1 { x-1>0 }
Proof:
class FieldName:
def __init__(self, name):
self.name = name.lower()
def __str__(self):
return self.name
def __hash__(self):
return hash(self.name)
@gabrielgiordano
gabrielgiordano / todo.rb
Last active October 24, 2018 11:29
Design Exercise
# Ability to go back into the past, and see what a user's todo list
# looked like at any point in time .
# Explain how this would work for todo lists that already exist.
#
# Since I haven't implemented any timestamp tracking for the resources and
# my repository is deleting resources from the project, it seems like
# that this feature wouldn't work for a time before it was implemented.
# A possible implementation would be to add a timestamp and a flag to every
# entity and change the delete and update method in the repository to just
# set the flag as 1 and create a new entity.
@gabrielgiordano
gabrielgiordano / tic_tac_toe.rb
Created October 22, 2018 05:39
Exercise answer
require 'pry'
class Position
attr_reader :row, :column
def initialize(row:, column:)
@row = row
@column = column
end