Skip to content

Instantly share code, notes, and snippets.

View Levi-Lesches's full-sized avatar

Levi Lesches Levi-Lesches

View GitHub Profile
@Levi-Lesches
Levi-Lesches / main.dart
Created January 12, 2023 05:12
quiet-gust-6827
import "package:flutter/material.dart";
void main() => runApp(MaterialApp(home: Home()));
class Home extends StatefulWidget {
@override
HomeState createState() => HomeState();
}
final red = HSVColor.fromColor(Colors.red);
@Levi-Lesches
Levi-Lesches / main.dart
Last active September 9, 2022 01:37
BURT's `MessageReceiver`
/// Something generated by Protobuf
abstract class Message { }
class ElectricalMessage extends Message {
final int voltage;
ElectricalMessage.fromBuffer(List data) :
voltage = data[0]; // parses raw data
}
class ScienceMessage extends Message {
@Levi-Lesches
Levi-Lesches / rsa.py
Last active January 6, 2022 03:20
An RSA Python script
import math
import secrets
import string
from argparse import ArgumentParser
from base64 import b64encode, b64decode
SUPPORTED_CHARS = 10
MIN_PRIME = 10**(SUPPORTED_CHARS + 1)
MAX_PRIME = 10**(SUPPORTED_CHARS + 2)
@Levi-Lesches
Levi-Lesches / word_search.py
Created October 22, 2020 03:26
LeetCode word search
class Solution:
# Allows us to do "for coordinate in self"
def __iter__(self): return (
(row, column)
for row in range(self.rows)
for column in range(self.columns)
)
# Allows us to do "self [coordinate]"
def __getitem__(self, coordinate): return self.board [coordinate [0]] [coordinate [1]]
@Levi-Lesches
Levi-Lesches / credits.dart
Created September 30, 2020 23:59
A prototype of the credits page for RamLife
import "package:flutter/material.dart";
// 1. Create a Programmer class to store the right data
// 2. Create a ProgrammerWidget to represent the data
// 3. Create a CreditsPage widget to show all the credits
// Each one of these classes can be modified reasonably without breaking the other widgets.
// 1. The Programmer class defines all the data.
class Programmer {
@Levi-Lesches
Levi-Lesches / Game of Life.dart
Last active September 25, 2020 12:49
Conway's Game of Life, demo in the comments
import "dart:io";
class Position {
static int rows = 13;
static int columns = 13;
static Set<Position> offsets = {
Position(-1, -1), Position(-1, 0), Position(-1, 1),
Position(0, -1), Position(0, 1),
Position(1, -1), Position(1, 0), Position(1, 1),
@Levi-Lesches
Levi-Lesches / nytimes_headlines.py
Last active September 2, 2020 06:36
Scrapes headlines from the front page of nytimes.com
import requests
from bs4 import BeautifulSoup
import json
URL = "https://www.nytimes.com/"
START_OF_JSON = "window.__preloadedData = "
def get_html():
response = requests.get(URL)
return response.text
from random import choice
import string
alphabet = string.ascii_letters
uppercaseAlphabet = alphabet.upper()
symbols = string.punctuation
numbers = string.digits
characterSets = [alphabet, symbols, numbers, uppercaseAlphabet]
import "package:flutter/material.dart";
// -------------------- Pick your colors! -------------------
// There are two ways to make colors here:
// 1. Use Color(<code>).
// The "code" is what's called a "hex color code" -- it's that 6 letter code
// Except, you need to start it with "0xff". So, for example, pastel pink is:
// "fdd0e4", so "pastelPink" (below) is "Color(0xfffdd0e4)". These color codes
// can be taken from anywhere (try Googling "hex color picker")
@Levi-Lesches
Levi-Lesches / battleship.py
Created April 19, 2020 04:17
A Python implementation of Battleship (deliberately avoiding OOP)
"""
Battleship
Concepts used:
- constants
- functions (I/O)
- if on one line
- random.choice and random.shuffle
- printing with an `end`
- tuples