Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@danidiaz
danidiaz / TeasingOutFields.hs
Last active April 15, 2018 13:52
Teasing out fields
{-# LANGUAGE RankNTypes #-}
data Person = Person { _name :: String , _age :: Int } deriving Show
makeLenses 'Person
example :: Person
example = Person "Bob" 55
pry :: Lens' r x -> Iso' r (x -> r,x)
pry l = iso (\r -> (\x -> set l x r, view l r)) (uncurry ($))
@danidiaz
danidiaz / jshell.txt
Last active March 29, 2018 15:24
jshell help
jshell> /set editor gvim
jshell> /help
| Type a Java language expression, statement, or declaration.
| Or type one of the following commands:
| /list [<name or id>|-all|-start]
| list the source you have typed
| /edit <name or id>
| edit a source entry
| /drop <name or id>
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<OutAndIn<?>> boo = new ArrayList<>();
boo.add(new OutAndIn<String>("ffoo"));
boo.add(new OutAndIn<Integer>(34));
@danidiaz
danidiaz / Capslock2Ctrl.ahk
Last active February 23, 2025 12:06
Emulating the "United States-International (AltGr Dead Keys)" keyboard layout on a plain US layout.
; https://autohotkey.com/docs/misc/Remap.htm
Capslock::Ctrl
{-# LANGUAGE GADTs, Rank2Types, KindSignatures, ScopedTypeVariables, TypeOperators, DataKinds, PolyKinds, MultiParamTypeClasses, FlexibleInstances, TypeFamilies, DoRec, ExtendedDefaultRules #-}
import Control.Applicative
import Control.Category
import Control.Comonad
import Control.Monad.Fix
import Control.Monad (ap)
import Data.Functor.Identity
import Data.Typeable
import Data.Monoid
import Data.Unique
@danidiaz
danidiaz / Main.java
Last active April 3, 2018 05:55
Java's try-with-resources as a Monad, just for the kicks. Very crude: verbose, nests exceptions with each bind, can't return values.
package danisoft.posts;
import java.io.File;
import java.io.FileReader;
public class Main {
public static void main(String[] args) {
Managed.manage(() -> fileReader(new File("/tmp/dummyFileA")))
.flatMap(r1 -> Managed.manage(() -> fileReader(new File("/tmp/dummyFileB")))
@danidiaz
danidiaz / InjectionExperiment.hs
Last active December 3, 2017 22:07
injection experiment
{-# LANGUAGE MultiParamTypeClasses, TypeFamilies,
GeneralizedNewtypeDeriving, DeriveGeneric,
ConstraintKinds, FunctionalDependencies, UndecidableSuperClasses, RankNTypes, TypeApplications, ScopedTypeVariables,
DefaultSignatures, FlexibleInstances #-}
module Main where
import Data.Proxy
import Control.Monad.IO.Class
import Control.Monad.State.Strict