Skip to content

Instantly share code, notes, and snippets.

Avatar

Levi Lesches Levi-Lesches

View GitHub Profile
@Levi-Lesches
Levi-Lesches / lost_and_found.dart
Last active Feb 20, 2020
Lost and Found page
View lost_and_found.dart
import "package:flutter_web/material.dart";
import "package:flutter_web/cupertino.dart";
import "package:flutter_web_ui/ui.dart" as ui;
// Lines like these are comments (only read by people, ignored by computer)
/// Lines like these (three slashes) explain only the class/function/variable right underneath them
// Any part of a comment in [brackets] are either defined here in this file or
// can be searched for at https://api.flutter.dev
@Levi-Lesches
Levi-Lesches / Stocks.dart
Last active Feb 20, 2020
Simple stock market code
View Stocks.dart
class Range {
final num buy, sell;
const Range(this.buy, this.sell);
}
Range maxProfit(List<double> points) {
// We want to find a range by examining a list of local minima and maxima
// We can assign a new list (think about what type it would hold) of those minima and maxima
// To find that list, we go through the list of points, two at a time, watching
// for changes in whether the points are increasing or decreasing.
@Levi-Lesches
Levi-Lesches / Sensor.ino
Last active Feb 20, 2020
Arduino Ultrasonic sensor
View Sensor.ino
#define echo 2
#define trigger A0
#define threshold 6
long getDistance() {
// This function returns the distance of an object from the sensor in cm
//
// An ultrasonic sensor sends a sound wave pulse outwards, and then waits for it to hit an
// object and bounce back to the sensor.
//
@Levi-Lesches
Levi-Lesches / car_drive.ino
Created Jan 3, 2020
A sketch to control an H-Bridge
View car_drive.ino
// These "#define" statements are *like* variables, but not really
// Variables can be changed to any other value, but these cannot
// They don't even stay in memory! What happens is, when you press compile,
// the Arduino replaces all the times the name comes up in the code with the
// value before sending it to the Arduino board. So it's not really a variable
// you can control, but rather just another name for a value.
//
// The define statement looks like this: #define NAME VALUE. Note that NAME can
// not contain spaces, because then it would be interpreted as VALUE.
@Levi-Lesches
Levi-Lesches / tutor.dart
Created Feb 4, 2020
RamLife Tutoring data types
View tutor.dart
enum Subject {history, english} // ...
enum Reviewer {teacher, student}
class User {
String first, last;
int rating;
}
class Tutor extends User {
int yearGraduated;
@Levi-Lesches
Levi-Lesches / nrf.ino
Last active Feb 20, 2020
Arduino NRF radio controls
View nrf.ino
/*
This script is for one NRF to send data to the other. The NRF sending the data
called the server, and the device receiving the data is called the client.
The setup for both devices is the same, the looping is what's different.
Here is a pinout for both devices:
* CE --> 9
* CSN --> 10
* MOSI --> 11
@Levi-Lesches
Levi-Lesches / sports_page.dart
Last active Feb 21, 2020
Ram Life Sports Page
View sports_page.dart
import "package:flutter/material.dart";
@immutable
class Time {
/// The hour in 24-hour format.
final int hour;
/// The minutes.
final int minutes;
@Levi-Lesches
Levi-Lesches / sports_builder_admin.dart
Created Feb 21, 2020
Ram Life admin sports builder
View sports_builder_admin.dart
import "package:flutter/material.dart";
enum Sport {baseball, basketball, hockey, tennis, volleyball, soccer}
const Map<String, Sport> stringToSports = {
"baseball": Sport.baseball,
"basketball": Sport.basketball,
"hockey": Sport.hockey,
"tennis": Sport.tennis,
"volleyball": Sport.volleyball,
@Levi-Lesches
Levi-Lesches / schedule_search.dart
Created Mar 3, 2020
Searches for class in schedule
View schedule_search.dart
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
}
Map<Letters, List<int>> getSubjectInSchedule() {}
class Subject {
@Levi-Lesches
Levi-Lesches / battleship.py
Created Apr 19, 2020
A Python implementation of Battleship (deliberately avoiding OOP)
View battleship.py
"""
Battleship
Concepts used:
- constants
- functions (I/O)
- if on one line
- random.choice and random.shuffle
- printing with an `end`
- tuples