Skip to content

Instantly share code, notes, and snippets.

@fisherds
fisherds / rosegraphics.py
Created March 2, 2023 19:07
Helper library used at Rose-Hulman for simple graphics
"""
rosegraphics.py - a simple Graphics library for Python.
Its key feature is:
-- USING this library provides a simple introduction to USING objects.
Other key features include:
-- It has a rich set of classes, methods and instance variables.
In addition to classes like Circles that are natural for students,
it has other kinds of classes like RoseWindow and SimpleTurtle
@fisherds
fisherds / firestore_model_utils.dart
Last active November 6, 2024 00:19
I've been using this utility file to make getting fields un-crashable.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class FirestoreModelUtils {
// A few date time helpers that really don't belong here, but it's easy:
static DateTime fromTimestampToDateTime(Timestamp value) => value.toDate();
static Timestamp fromDateTimeToTimestamp(DateTime value) => Timestamp.fromDate(value);
static TimeOfDay fromDateTimeToTimeOfDay(DateTime value) {
DateTime epochDate = DateTime(1970, 1, 1, 0, 0);
Duration delta = value.difference(epochDate);
// One possible solution
enum TicTacToeMark { none, x, o }
enum TicTacToeState { xTurn, oTurn, xWon, oWon, tie }
class TicTacToeGame {
var board = List<TicTacToeMark>.filled(9, TicTacToeMark.none);
var state = TicTacToeState.xTurn;
void pressedSquare(int index) {
// These methods could be added to your existing class.
/**
* Read button - Gets the state of the fake pushbutton (0 or 1)
* method: GET
* path: /api/readbutton
* expected request body: none
* side effects: none (the pushbutton is always random)
* response: {"button": 0} or {"button": 1}
*/
@fisherds
fisherds / main.js
Last active February 14, 2022 05:04
Code for the main.js starting point in the Pi Simulator
var rhit = rhit || {};
rhit.PiSimulatorController = class {
constructor() {
// No separate model object. Just do it within the controller.
this.button = 1;
this.leds = {red: 0, yellow: 1, green: 0};
this.servos = [-45, 0, 90];
@fisherds
fisherds / main.css
Created February 14, 2022 04:34
CSS file that goes along with the Pi Simulator given index.html file.
body {
background: #DDDDDD;
}
.navbar {
background-color: #800000;
color: white;
}
.page-container {
@fisherds
fisherds / index.html
Created February 14, 2022 04:23
HTML code for the Pi Simulator
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons">
<link rel="stylesheet" href="styles/bootstrap-material-design.min.css">
<link rel="stylesheet" href="styles/main.css">
<title>Pi Simulator</title>
@fisherds
fisherds / CantStopGame.js
Last active January 2, 2022 03:36
Given code for the Cant Stop model object
rhit.CantStopGame = class {
static NUM_DICE = 3; // Hardcoded but easy to change if making a different game.
static MAX_FIRST_ROLL_VALUE = 3; // Hardcoded but easy to change
static RoundState = {
PLAYER_1_ACTIVE: "Player 1's Turn",
PLAYER_1_BUST: "Player 1 Bust!",
PLAYER_2_ACTIVE: "Player 2's Turn",
PLAYER_2_BUST: "Player 2 Bust!",
}
@fisherds
fisherds / app.js
Last active February 16, 2022 02:36
Starting point for boilerplate app.js code.
var express = require("express");
var app = express();
app.use('/', express.static("public"));
app.use('/api/', express.json());
let data = {};
// let data = []; // or an empty array depending on the instructions for your specific exam
const fs = require("fs");
const serverSideStorage = "../data/db.json";
@fisherds
fisherds / test_sensors.py
Created May 4, 2021 16:53
Helper program I used to work out the details for my sensor methods
"""
Authors: Dave Fisher and PUT_YOUR_NAME_HERE.
"""
# TODO: 1. Put your name in the above.
import time
import rosebot
def main():