Skip to content

Instantly share code, notes, and snippets.

View patroza's full-sized avatar

Patrick Roza patroza

View GitHub Profile
/**
*
const something = {}
assert.strictEqual(shallowEqual({ a: O.none }, { a: O.none }), true)
assert.strictEqual(shallowEqual({ a: O.some(1)}, { a: O.some(1) }), true)
assert.strictEqual(shallowEqual({ a: O.some(something)}, { a: O.some(something) }), true)
assert.strictEqual(shallowEqual({ a: O.some(something)}, { a: O.none }), false)
assert.strictEqual(shallowEqual({ a: E.left(something)}, { a: E.left(something) }), true)
assert.strictEqual(shallowEqual({ a: E.right(something)}, { a: E.left(something) }), false)
type MyA = {}
type SomeF<A, B> = (a: A) => [A, B]
type MyF = SomeF<MyA, boolean>
declare const f1: MyF
declare const f2: MyF
declare const f3: MyF
function imperative() {
@patroza
patroza / .eslintrc.js
Last active April 9, 2020 22:22
ESLint for matechs-effect
module.exports = {
"env": {
"browser": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
@patroza
patroza / fetch.ts
Last active April 5, 2020 20:50 — forked from ColemanGariety/fetch.ts
import * as TE from "fp-ts/lib/TaskEither"
import { pipe } from "fp-ts/lib/pipeable"
import { Do } from "fp-ts-contrib/lib/Do"
type Error1 = { errors: object[]; type: "1" }
type Error2 = { errors: object[]; response: Response; type: "2" }
type Error3 = { errors: object[]; result: unknown; type: "3" }
type Errors = Error1 | Error2 | Error3
export const post = (url: string, body: object) =>
type Input = {
trainTripId: string
pax?: Pax
startDate?: Date
travelClass?: string
}
const validateStateProposition = ({
pax,
startDate,
// 3. Presentation/Root
const start = () => {
const getCompletedTodosRequestHandler = async (ctx) => {
const result = await getCompletedTodosResolved(ctx.params.id)
ctx.body = JSON.stringify(result)
}
const completeTodoRequestHandler = async (ctx) => {
await completeTodoResolved(ctx.params.id)
ctx.status = 204
@patroza
patroza / twoSum.scala
Last active November 4, 2019 21:10 — forked from stzr1123/twoSum.scala
Interview type problems
import scala.annotation.tailrec
object ShittySolution {
// Given an array of integers, return indices of the two numbers such that they add up to a specific target.
//
// You may assume that each input would have exactly one solution, and you may not use the same element twice.
// https://leetcode.com/problems/two-sum/
// NB: More efficient solution would iterate once over the array and keep a Map of values and indicies
def twoSum(nums: Array[Int], target: Int): Array[Int] = {
import { useState, useEffect } from "react";
export const render = result => match =>
result.pending ? match.pending()
: result.error ? match.error(result.error)
: result.data ? match.data(result.data)
: null // prettier-ignore
export const useMatchFetch = url => {
const [result, setResult] = useState({ pending: true, initial: true });
@patroza
patroza / controller-presenter-interactor.cs
Last active September 18, 2020 03:00
Literal Controller/Presenter/Interactor implementation sample (naive), I prefer MediatR instead for most cases :) from http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/
// "controller"
(ctx, next) => {
let presenter = new Presenter(ctx)
let interactor = new Interactor(presenter)
interactor.handle(getRequestFrom(ctx))
}
class Presenter {
constructor(ctx) { this.ctx = ctx }
present(response) {
@patroza
patroza / docker-compose.sh
Last active July 5, 2017 07:55
Running windows commands with .envrc (dynamically converting exports) from WSL (Bash on Windows)
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"