Skip to content

Instantly share code, notes, and snippets.

Avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / interpret.py
Last active Aug 7, 2021
Interpreter Without Environment Poltergeist
View interpret.py
# Top level function that interprets an entire program. It creates the
# initial environment that's used for storing variables.
def interpret_program(model):
# Make the initial environment (a dict). The environment is
# where you will create and store variables.
env = {}
for structure in model.statements:
interpret(structure, env)
@chelseatroy
chelseatroy / interpret.py
Last active Aug 7, 2021
My ersatz interpreter
View interpret.py
# Top level function that interprets an entire program. It creates the
# initial environment that's used for storing variables.
def interpret_program(model):
# Make the initial environment (a dict). The environment is
# where you will create and store variables.
env = {'constants':{}, 'variables':{}}
for structure in model.statements:
interpret(structure, env)
@chelseatroy
chelseatroy / wabbit_data_model.py
Last active Jul 30, 2021
Interpreter Data Model
View wabbit_data_model.py
class Negative:
def __init__(self, value):
self.value = value
def __repr__(self):
return f"Negative({self.value})"
class Integer:
'''
Example: 42
View metal.py
# metal.py
#
# METAL, by Dave Beazley
# dabeaz.com
# One of the main roles of a compiler is taking high-level programs
# such as what you might write in C or Python and reducing them to
# instructions that can execute on actual hardware.
#
# This file implements a very tiny CPU in the form of a Python
@chelseatroy
chelseatroy / elevator.py
Created Jan 4, 2021
Elevator Implemented with a Generator
View elevator.py
import time
class ElevatorButtonPanel:
def __init__(self, elevator):
self.elevator = elevator
# Logic of the elevator
def request_button_pressed(self, floor):
self.elevator.go_to_floor(floor)
@chelseatroy
chelseatroy / elevator.py
Created Dec 28, 2020
Elevator Implementation with Threads
View elevator.py
import time
import threading
class Elevator:
def __init__(self, control, timer=Timer(), eventlog=EventLog()):
self.control = control
self.timer = timer
self.eventlog = eventlog
#Python thinks it's a dict if you
View BlogPost.swift
//
// BlogPost.swift
// ScottishGaelicTattooHandbook
//
// Created by Chelsea Troy on 7/26/20.
// Copyright © 2020 Chelsea Troy. All rights reserved.
//
import Foundation
View BlogPostService.swift
//
// BlogPostService.swift
// ScottishGaelicTattooHandbook
//
// Created by Chelsea Troy on 7/26/20.
// Copyright © 2020 Chelsea Troy. All rights reserved.
//
import Foundation
View BlogPostServiceTests.swift
//
// BlogPostServiceTests.swift
// ScottishGaelicTattooHandbookTests
//
// Created by Chelsea Troy on 7/26/20.
// Copyright © 2020 Chelsea Troy. All rights reserved.
//
import XCTest
View fragment_weekly_survey.xml
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="24dp"
android:paddingBottom="20dp"
android:textColor="@color/black"
android:text="@string/hot_flashes_flushes_in_the_last_7_days"
android:textStyle="bold"
android:textSize="26sp" />