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 pymongo | |
def mongo_make_client(_mongo_uri): | |
if not _mongo_uri: | |
raise ValueError("MongoURI must have a value") | |
return pymongo.MongoClient(_mongo_uri) | |
def mongo_make_database(_db_name, _mongo_uri=None, _client=None): |
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
""" | |
Turn on the credentials in your account: | |
https://developers.google.com/sheets/api/quickstart/python | |
Put the redirect uri as http://localhost:9999/ | |
""" | |
from __future__ import print_function | |
import argparse |
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
type Tuple = [unknown, unknown]; | |
export class TupleMap<T> implements Map<Tuple, T> { | |
public [Symbol.iterator](): IterableIterator<[Tuple, T]> { | |
throw new Error("Method not implemented."); | |
} | |
public keys(): IterableIterator<Tuple> { | |
throw new Error("Method not implemented."); | |
} |
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
export class TSMap<T, K> extends Map<T, K> { | |
public getByValue(value: K): T | undefined { | |
return [...this.entries()] | |
.filter((tuple) => tuple[1] === value) | |
.map(([key]) => key) | |
.pop(); | |
} | |
} |
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
export class DateFreeze { | |
private readonly originalNow: () => number = Date.now.bind(Date); | |
public constructor(private timestamp: number) {} | |
public freeze(timestamp?: number): this { | |
if (timestamp !== undefined) { | |
this.timestamp = timestamp; | |
} |
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
export class Validator<A, B> { | |
private validationBlock?: () => Promise<void>; | |
public constructor( | |
private readonly value: A, | |
private result: B, | |
private isValid: boolean = true, | |
) {} | |
public map<C>(mapper: (value: A) => C): Validator<C, B> { |
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
/** | |
* UNCONDITIONAL CODE EXAMPLE - INSPIRED BY Michael Feathers | |
* | |
* https://www.youtube.com/watch?v=AnZ0uTOerUI | |
*/ | |
// OLD CODE | |
enum MessageType { | |
EXTERNAL = "external", |
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
/* | |
A way to load string enum values from request to your domain | |
without doing nasty unsafe casts or turning off type assertion | |
Usage: | |
public deserialize(input: string): Entity { | |
const serializedEntity = JSON.parse(input) as SerializedEntity; | |
return new |Entity( | |
new StringEnumValue(serializedEntity.type, EntityType).toString(), | |
serializedEntity.entityId, |
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
#!/bin/bash | |
triesLimit=20 # Tries for 10s | |
isDatabaseReady() { | |
local lastContainerName=$(docker ps -lq) | |
local databaseReadyLogMessage="database system is ready to accept connections" | |
echo $(docker logs $lastContainerName --tail 1 | grep -c "$databaseReadyLogMessage") | |
} | |
waitForDatabase() { | |
local tries=0 |
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
const abbreviations = { | |
"A": "ampère(s)", | |
"a": "are(s)", | |
"A": "argônio", | |
"a": "assinado(a)", | |
"Å": "decimilimícron(s), ångström", | |
"A.": "aceite", | |
"A.": "alto (música)", | |
"a.": "arroba(s)", | |
"a.": "assinado(a)", |