Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
@chelseatroy
chelseatroy / fragment_weekly_survey.xml
Created July 26, 2020 15:23
Including a Custom layout in an Existing Layout
...
<include android:id="@+id/appetite_decrease_severity_response"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/severity_question"/>
...
@chelseatroy
chelseatroy / server.py
Created July 26, 2020 03:43
Committing the Entry as the Leader
...
else:
if self.leader:
self.current_operation = string_operation
if self.current_operation.split(" ")[0] in ["set", "delete"]:
key_value_store.write_to_log(string_operation, term_absent=True)
broadcast(self, with_return_address(self, "append_entries ['" + self.current_operation + "']"))
while not self.current_operation_committed:
@chelseatroy
chelseatroy / server.py
Last active July 26, 2020 03:41
Keeping Track of Followers
class Server:
...
self.followers_with_update_status = {}
self.current_operation = ''
self.current_operation_committed = False
for server_name in other_server_names(name):
self.followers_with_update_status[server_name] = False
@chelseatroy
chelseatroy / server.py
Last active July 26, 2020 03:38
Conditional Statement—Responding to append_entries Requests
...
if string_operation.split(" ")[0] == "append_entries":
# followers do this to update their logs.
stringified_logs_to_append = string_operation.replace("append_entries ", "")
print("Preparing to append: " + stringified_logs_to_append)
logs_to_append = ast.literal_eval(stringified_logs_to_append)
[key_value_store.write_to_log(log, term_absent=True) for log in logs_to_append]
print("State machine after appending: " + str(key_value_store.data))
response = "Append entries call successful!"
@chelseatroy
chelseatroy / server.py
Created July 26, 2020 03:37
Conditional Statement—Committing for Followers
...
elif string_operation.split(" ")[0] == "commit_entries":
# followers do this to update their logs.
stringified_logs_to_append = string_operation.replace("commit_entries ", "")
print("Preparing to commit: " + stringified_logs_to_append)
logs_to_append = ast.literal_eval(stringified_logs_to_append)
[key_value_store.write_to_state_machine(command, term_absent=True) for command in logs_to_append]
response = "Commit entries call successful!"
@chelseatroy
chelseatroy / server.py
Created July 26, 2020 03:27
Marking Follower Servers Updated
...
def mark_updated(self, server_name):
self.followers_with_update_status[server_name] = True
trues = len(list(filter(lambda x: x is True, self.followers_with_update_status.values())))
falses = len(list(filter(lambda x: x is False, self.followers_with_update_status.values())))
if trues >= falses:
print("Committing entry: " + self.current_operation)
self.current_operation_committed = True
@chelseatroy
chelseatroy / server.py
Created July 26, 2020 03:21
Conditional Statement—Responding to Successful Log Replication Requests
...
elif string_operation == "Append entries call successful!":
if self.leader:
self.mark_updated(server_name)
send_pending = False
@chelseatroy
chelseatroy / server.py
Created July 26, 2020 00:53
Conditional Statement—Responding to Data Manipulation Requests
...
else: #if the request is to get, set, or delete
if self.leader:
self.current_operation = string_operation
key_value_store.write_to_log(string_operation, term_absent=True)
if self.current_operation.split(" ")[0] in ["set", "delete"]:
broadcast(self, with_return_address(self, "append_entries [" + self.current_operation + "]"))
send_pending = False
@chelseatroy
chelseatroy / i_never_said_this_was_finished.ipynb
Last active July 22, 2020 21:41
A first pass at data analysis on some ESG and Performance Data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.