This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choice | |
import string | |
alphabet = string.ascii_letters | |
uppercaseAlphabet = alphabet.upper() | |
symbols = string.punctuation | |
numbers = string.digits | |
characterSets = [alphabet, symbols, numbers, uppercaseAlphabet] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Battleship | |
Concepts used: | |
- constants | |
- functions (I/O) | |
- if on one line | |
- random.choice and random.shuffle | |
- printing with an `end` | |
- tuples |
NewerOlder