Skip to content

Instantly share code, notes, and snippets.

@YannickDot
YannickDot / ReadFile.ts
Created April 21, 2022 11:01
Read file contents in React.js
import { ChangeEventHandler, useCallback, useRef } from "react";
const ReadFile = () => {
const fileReader = useRef<FileReader | null>(null);
const parseFile = useCallback((fileContentStr: string) => {
// parse yo shit
}, []);
const handleFileRead = useCallback(() => {
@YannickDot
YannickDot / notes.md
Last active February 8, 2019 23:07
Purescript newbie

Things I wish I knew when I started learning PureScript

Editor config

  • If your editor doesn't show the tooltips, completions, and doesn't output any error, close your editor (VSCode or Atom) and then delete the .psc-ide-port file in your project folder. More info about this here : nwolverson/atom-ide-purescript#196
@YannickDot
YannickDot / purescript-getting-started.md
Last active August 24, 2018 13:22
Getting started with PureScript 0.12 in less than 5 minutes

Getting started with PureScript 0.12 in less than 5 minutes

Install the compiler, package manager and build tool

npm install -g purescript pulp psc-package

Create a project

@YannickDot
YannickDot / Main.purs
Last active December 5, 2017 15:31
Pattern Matching in PureScript
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, logShow)
type Point = { x :: Int, y :: Int }
anotherPoint :: Point
@YannickDot
YannickDot / idx-either.js
Created March 26, 2017 00:53
idx using Either
const Right = x => ({
chain: f => f(x),
map: f => Right(f(x)),
fold: (f, g) => g(x),
inspect: () => `Right(${x})`,
});
const Left = x => ({
chain: f => Left(x),
map: f => Left(x),
@YannickDot
YannickDot / task.js
Last active January 1, 2017 19:57
Created my own task implementation in JS !
function chain (cb) {
const previousTask = this
const chainedTask = Task((resolve, reject) => {
let nextCancelCb
let previousCancel = previousTask.fork(
reject,
(val) => {
try {
let nextTask = cb(val)
let nextCancel = nextTask.fork(reject, resolve)
const insertAtIndex = (arr, item, index) => arr.splice(index, 0, item);
@YannickDot
YannickDot / OptionalCata.swift
Created October 25, 2016 13:18
Functional Swift
extension Optional {
func cata<T>(onNothing: (Void -> T), _ onSome: ((Wrapped) -> T)) -> T {
switch self {
case .Some(let a):
return onSome(a)
case nil:
return onNothing()
}
}
@YannickDot
YannickDot / OptionalCata.swift
Created October 25, 2016 13:18
Functional Swift
extension Optional {
func cata<T>(onNothing: (Void -> T), _ onSome: ((Wrapped) -> T)) -> T {
switch self {
case .Some(let a):
return onSome(a)
case nil:
return onNothing()
}
}
@YannickDot
YannickDot / flattenArray.js
Last active September 28, 2016 20:29
Flatten Array in JS
const reducer = (f) => (acc, curr) => {
if(Array.isArray(curr))
return acc.concat(f(curr))
acc.push(curr)
return acc
}
const f = (arr) => arr.reduce(reducer(f), [])