Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@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 / BirdListViewController.swift
Created June 30, 2020 19:41
Example of Setting Accessory Type on Cell
...
//to put a checkmark on the trailing side of the view
self.accessoryType = .checkmark
//to remove an accessory (such as a checkmark) from the trailing side of the view
self.accessoryType = .none
...
@chelseatroy
chelseatroy / BirdListViewController.swift
Last active June 30, 2020 19:43
Example of Setting Accessory View on Cell
...
//to set the little flame icon, which is one of the iOS system icons (there are many you can use)
let flame = UIImageView(frame: CGRect(x: 0, y: 65, width: 25, height: 30))
flame.image = UIImage(systemName: "flame.fill")
flame.tintColor = .systemRed
self.accessoryView = flame
//to remove an icon that you have set on the cell view
self.accessoryView = .none
@chelseatroy
chelseatroy / strings.xml
Created June 1, 2020 03:14
Interpolating a String
...
<string name="greeting">Hello, %1$s!</string>
...
@chelseatroy
chelseatroy / MainActivity.kt
Last active June 1, 2020 03:12
Change the Top Bar Text
class MainActivity : AppCompatActivity(), Updatable {
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//CHANGING THE TEXT OF THE TOP BAR
val toolbarTitle = findViewById<TextView>(R.id.title)
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
@chelseatroy
chelseatroy / LoginActivity.kt
Created May 31, 2020 04:56
Save Session Data Upon Successful Login
class LoginActivity : AppCompatActivity() {
...
fun authenticate() {
...
if (session?.token != null) {
//HERE'S WHERE WE SAVE THE SESSION DAA
saveSessionData(session!!.name, session!!.token)
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
@chelseatroy
chelseatroy / LoginActivity.kt
Created May 31, 2020 04:54
Save Session Data
import androidx.preference.PreferenceManager
//SEE IMPORT ABOVE
class LoginActivity : AppCompatActivity() {
...
private fun saveSessionData(name: String?, token: String?) {
val preferences =
PreferenceManager.getDefaultSharedPreferences(this)
@chelseatroy
chelseatroy / build.gradle (app)
Created May 31, 2020 04:53
Add Preference Dependency
dependencies {
...
implementation "androidx.preference:preference-ktx:1.1.0"
}
@chelseatroy
chelseatroy / LoginActivity.kt
Created May 31, 2020 04:49
Showing and Hiding the ProgressBar
package com.chelseatroy.canary
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
signInButton.setOnClickListener { view ->
if (isNetworkConnected()) {
//HERE'S WHERE WE SHOW THE PROGRESS BAR
progressBar.visibility = View.VISIBLE
@chelseatroy
chelseatroy / activity_login.xml
Last active May 31, 2020 04:46
Adding a ProgressBar to the Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
...
android:layout_height="match_parent">
...
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"