Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Roza patroza

View GitHub Profile
View react-fp.ts
/**
*
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)
View basic.ts
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 Apr 9, 2020
ESLint for matechs-effect
View .eslintrc.js
module.exports = {
"env": {
"browser": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
View 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) =>
View validation.sample.1.ts
type Input = {
trainTripId: string
pax?: Pax
startDate?: Date
travelClass?: string
}
const validateStateProposition = ({
pax,
startDate,
View todos.ts
// 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 Nov 4, 2019 — forked from stzr1123/twoSum.scala
Interview type problems
View twoSum.scala
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] = {
View 1.useMatchFetch.js
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 Sep 18, 2020
Literal Controller/Presenter/Interactor implementation sample (naive), I prefer MediatR instead for most cases :) from http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/
View controller-presenter-interactor.cs
// "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 Jul 5, 2017
Running windows commands with .envrc (dynamically converting exports) from WSL (Bash on Windows)
View docker-compose.sh
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"