{
client: 'pg',
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
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 Blog(django.model): | |
name = models.CharField(null=False, max_length=64) | |
def list_articles(self): | |
return [ | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
] |
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 json | |
import re | |
filename = './swedish.txt' | |
print('Start reading') | |
dictionary = {} | |
with open(filename, encoding="utf-8") as file: | |
while line := file.readline(): | |
line = line.rstrip().split(' ') |
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
use std::collections::HashSet; | |
fn is_anagram(word: &str, candidate: &str) -> bool { | |
if word.to_lowercase() == candidate.to_lowercase() { | |
return false; | |
} | |
let mut a = word.to_lowercase().chars().collect::<Vec<char>>(); | |
let mut b = candidate.to_lowercase().chars().collect::<Vec<char>>(); | |
a.sort(); | |
b.sort(); |
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 PIL import Image | |
img = Image.open("star.jpg") | |
pixels = img.rotate(90).load() | |
density = "Ñ@#W$9876543210?!abc;:+=-,._ " | |
for i in range(img.size[0]): | |
for j in range(img.size[1]): | |
r, b, g = pixels[i, j] |
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 { pipe } from "fp-ts/lib/function"; | |
const add = | |
(first: number) => | |
(second: number): number => { | |
return first + second; | |
}; | |
const add1 = add(1); | |
const add3 = add(3); |
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 * as E from "fp-ts/Either"; | |
import * as F from "fp-ts/function"; | |
const minxLength = (s: string): E.Either<Error, string> => { | |
return s.length < 8 ? E.left(new Error("Password is too short")) : E.right(s); | |
}; | |
const oneCapital = (s: string): E.Either<Error, string> => | |
/[A-Z]/g.test(s) | |
? E.right(s) |
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 axios, { AxiosResponse } from "axios"; | |
import * as F from "fp-ts/function"; | |
import * as E from "fp-ts/Either"; | |
import * as T from "fp-ts/Task"; | |
import * as TE from "fp-ts/TaskEither"; | |
type ToDo = { | |
userId: number; | |
id: number; | |
title: string; |
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 * as TE from "fp-ts/TaskEither"; | |
import { pipe } from "fp-ts/function"; | |
const createUser = (username: string): TE.TaskEither<Error, string> => { | |
return TE.right(`UserId-${username}`); | |
}; | |
const createOrder = (userId: string): TE.TaskEither<Error, string> => { | |
return TE.right(`Order-${userId}`); | |
}; |
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
# dataclass saves the trouble of writing __init__ implementations | |
# frozen=True makes the class instances immutable (so no hidden mutable state) | |
@dataclass(frozen=True) | |
class UserConnector: | |
def get_user(id: str) -> User: | |
return User.objects.get(id=id) | |
@dataclass(frozen=True) | |
class OrgConnector: | |
def get_org(id: str) -> Org: |
NewerOlder