- Delegate work to helper objects.
- Use objects from different concrete classes to get different implementations for helper methods.
- strategy, state, etc.
- (from refactoring.guru) object A contains objects B; B can live without A.
| const useRecords = () => { | |
| const [record, setRecord] = useState<Record<string, string>>({ | |
| 'record 1': 'foo', | |
| 'record 2': 'foo', | |
| 'record 3': 'bar', | |
| }) | |
| return { | |
| get uniqueRecords() { | |
| const uniqueRecords = new Set(Object.values(record)) |
| def addAllNumbersFromZeroToN(n): | |
| if n > 0: | |
| return n + addAllNumbersFromZeroToN(n-1) | |
| return n | |
| print(addAllNumbersFromZeroToN(3)) #6 | |
| print(addAllNumbersFromZeroToN(2)) #3 | |
| print(addAllNumbersFromZeroToN(5)) #15 |
| const x = { | |
| a:{ | |
| b:{ | |
| c:'neat' | |
| } | |
| } | |
| } | |
| const loop = (object, path) => { | |
| let index = 0 |
| class Solution: | |
| def intToRoman(self, num: int) -> str: | |
| numerals = { | |
| 1: 'I', | |
| 4: 'IV', | |
| 5: 'V', | |
| 9: 'IX', | |
| 10: 'X', | |
| 40: 'XL', | |
| 50: 'L', |
| class Solution: | |
| def romanToInt(self, s: str) -> int: | |
| numerals = { | |
| 'I': 1, | |
| 'V': 5, | |
| 'X': 10, | |
| 'L': 50, | |
| 'C': 100, | |
| 'D': 500, | |
| 'M': 1000 |
| conversions = { | |
| 'cup': 1, | |
| 'ml': 236.588, | |
| 'tbsp': 16, | |
| 'tsp': 48 | |
| } | |
| unitAlias = { | |
| 'cups': 'cup', | |
| 'mls': 'ml', |
| let commenters = document.querySelectorAll('[data-testid="comment_author_link"]') | |
| let commenterData = {} | |
| commenters.forEach(commenter => commenterData[commenter.text] = commenter.href) | |
| console.log(commenterData) |
| // the origonal gist that this code is based off of: | |
| // https://gist.github.com/bcnzer/e6a7265fd368fa22ef960b17b9a76488 | |
| // these are refrences for firebase stuff: | |
| // https://www.googleapis.com/service_accounts/v1/jwk/[email protected] | |
| // https://www.googleapis.com/robot/v1/metadata/x509/[email protected] | |
| export default async function verifyJWT(request) { | |
| const encodedToken = getJwt(request) | |
| if (encodedToken === null) { |