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 math | |
| class FourInARow: | |
| def __init__(self) -> None: | |
| self.map = [] | |
| for _ in range(6): | |
| self.map.append([EMPTY] * 7) | |
| def calculate_column_scores(self) -> list[int]: |
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 __future__ import annotations | |
| class GeneratorWithHistory: | |
| def __init__(self, generator) -> None: | |
| self.generator = generator | |
| self.memory = [] | |
| self.index = 0 | |
| def next(self, needed_index: int): |
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
| struct FooStore { | |
| value: i32, | |
| } | |
| struct ConcreteCompUnit<T> { | |
| unit: T, | |
| } | |
| enum CompUnit<T> { | |
| Concrete(ConcreteCompUnit<T>), |
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
| use std::{ | |
| collections::{HashMap, HashSet, VecDeque}, | |
| sync::{Arc, Mutex}, | |
| thread, | |
| time::Duration, | |
| }; | |
| #[derive(Debug)] | |
| struct TopologicalBatchProvider { | |
| unavailable: HashSet<usize>, |
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
| class Foo | |
| def bar(val, key:) | |
| puts("BAR #{val} #{key}") | |
| end | |
| end | |
| def spy_on(object, method) | |
| did_call = false | |
| aliased = "#{method}_spied".to_sym |
Sorbet can help with type inference in tests if the setup is right. Otherwise types will be reduced to T.untyped.
class Test < ActiveSupport::TestCase
def setup # Don't use `dev setup`.
@user = make_fixture(User, :alex) # Don't forget `T.let`(This is just one recommendation - and doesn't talk about error-free data structure design.)
Let's say there is a Project class that needs a convenience builder for testing.
This Project consist of a company who owns the project and a list of tickets - where a ticket is just a name and the same company denormalized (for reasons).
Since this company attribute is just a denormalization - it is/must-be consistent.
NewerOlder