This file contains hidden or 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
| { | |
| "css.format.newlineBetweenRules": false, | |
| "debug.onTaskErrors": "debugAnyway", | |
| "diffEditor.codeLens": true, | |
| "editor.accessibilitySupport": "off", | |
| "editor.autoClosingBrackets": "never", | |
| "editor.autoClosingQuotes": "never", | |
| "editor.copyWithSyntaxHighlighting": false, | |
| "editor.dragAndDrop": false, | |
| "editor.formatOnType": true, |
This file contains hidden or 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 contextlib import contextmanager | |
| @contextmanager | |
| def mocked_func(name, func=None, value=None): | |
| """Within this context, the function with name `func` will act as `func`, or as the literal `value`.""" | |
| def inner(*args, **kwargs): | |
| return func(*args, **kwargs) if func else value | |
| backup_globals = globals().copy() | |
| globals()[name] = inner |
This file contains hidden or 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
| def match(text: str, pattern: str) -> bool: | |
| """Determine whether the text matches the glob pattern. | |
| >>> match('', '') | |
| True | |
| >>> match('abc', 'abc') | |
| True | |
| >>> match('abcd', 'abc') | |
| False | |
| >>> match('aabc', 'abc') |
This file contains hidden or 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
| def factorial_row(n, length): | |
| """Create 1d array whose product is the factorial of n, padded to length""" | |
| return np.pad(np.arange(1, n + 1), (0, length - n), 'constant', constant_values=1) | |
| def sum_factorial(nums): | |
| """Sum the factorials of the numbers in nums.""" | |
| factorial_matrix = np.vstack([factorial_row(n, max(nums)) for n in nums]) | |
| return factorial_matrix.prod(axis=1).sum() |
This file contains hidden or 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 logging | |
| LOGGER = logging.getLogger(__name__) | |
| LOGGER.addHandler(logging.StreamHandler()) | |
| LOGGER.setLevel('INFO') | |
| class Demands: | |
| """A way to mark off satisfied demands""" | |
| def __init__(self, demands): | |
| """Initialize a sequence of given demands as unsatisfied. |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <!-- This is a single-file version of the code from chapter 16 of Eloquent Javascript | |
| https://eloquentjavascript.net/16_game.html ("Project: A Platform Game") --> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Platform Game</title> | |
| <style> | |
| .background { | |
| background: rgb(52, 166, 251); |
This file contains hidden or 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
| function* fib(upTo) { | |
| let a = b = 1; | |
| while (a < upTo) { | |
| yield a; | |
| [a, b] = [b, a + b]; | |
| } | |
| } | |
| console.log(...fib(1e10)); |
This file contains hidden or 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
| //Solution to Final Karel excercise - https://stanford.edu/~cpiech/karel/lessons.html#/english/unit12/lesson1 | |
| function goStraight() { | |
| while (frontIsClear()) { | |
| move(); | |
| } | |
| } | |
| function putDiagonally() { | |
| putBeeper(); | |
| while (frontIsClear()) { |
This file contains hidden or 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
| # My playing around with dataclass addition, to see how I'd implement this example without a static method: | |
| # https://stackoverflow.com/a/49269322/493553 | |
| from copy import copy | |
| from dataclasses import dataclass | |
| @dataclass | |
| class Stats: | |
| strength: int = 0 | |
| speed: int = 0 | |
| intellect: int = 0 |
This file contains hidden or 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
| """A first try at a ChatGPT diagnosing bot; it's definitely not production ready, but I'm amazed that this works""" | |
| import json | |
| import openai | |
| openai.api_key = "?" | |
| completion = openai.ChatCompletion.create( | |
| model='gpt-3.5-turbo', | |
| messages=[ |