Skip to content

Instantly share code, notes, and snippets.

View DKurilo's full-sized avatar
🔬
∀ f. Functor f ⇒ (a → f b) → s → f t

Dima DKurilo

🔬
∀ f. Functor f ⇒ (a → f b) → s → f t
View GitHub Profile
@DKurilo
DKurilo / fun-with-functional-dependencies.hs
Last active June 26, 2019 18:06
Haskell allow to use Functional dependencies. Using FD one can do Prolog-like things with types and classes. In compile time. Further: http://www.cse.chalmers.se/~hallgren/Papers/hallgren.pdf
{-# LANGUAGE FlexibleInstances, FunctionalDependencies, UndecidableInstances #-}
-- Esoteric programming with Haskell:
-- http://www.cse.chalmers.se/~hallgren/Papers/hallgren.pdf
-- https://repl.it/repls/AquaGainsboroSquares
module Fun where
data True
data False
@DKurilo
DKurilo / functional-dependency-fib.hs
Last active June 26, 2019 18:05
Fibonacci in compile time
{-# LANGUAGE FlexibleInstances, FunctionalDependencies, UndecidableInstances #-}
-- Esoteric programming with Haskell:
-- http://www.cse.chalmers.se/~hallgren/Papers/hallgren.pdf
-- https://repl.it/repls/AquaGainsboroSquares
module Main where
import System.IO
u = undefined
module Main where
import Data.Char
import Data.ByteString.Char8 hiding (all, putStrLn)
import System.IO
getStr _ 0 _ = return ""
getStr h n p = do
c <- unpack <$> hGet h 1
if all p c
" https://github.com/neoclide/coc.nvim#example-vim-configuration
set hidden
set cmdheight=2
set shortmess+=c
" This is only necessary if you use "set termguicolors".
set termguicolors
" Coc.nvim
" Some servers have issues with backup files, see #649.
set nobackup
:set prompt "\ESC[1;34m\x03BB> \ESC[m"
:set prompt-cont "\ESC[1;34m > \ESC[m"
:seti -XGADTSyntax
:seti -XGeneralizedNewtypeDeriving
:seti -XInstanceSigs
:seti -XLambdaCase
:seti -XPartialTypeSignatures
:seti -XScopedTypeVariables
:seti -XTypeApplications
:seti -XOverloadedStrings
@DKurilo
DKurilo / cata.hs
Last active January 25, 2020 03:11
Catamorphisms in Haskell
{-|
Here is examples from these lectures:
https://www.youtube.com/watch?v=PAqzQMzsUU8
https://www.youtube.com/watch?v=jpl7FE2TZTE
Also a great article is here:
https://www.schoolofhaskell.com/user/bartosz/understanding-algebras
I just wrote down examples from lectures as accurate as I could.
As I feel it, playing with this code allow to understand lectures better and to find why and where you need this.
This code available here:
https://gist.github.com/DKurilo/5e5563f4c2a8e8ca53a7b98ebf59e9f1
@DKurilo
DKurilo / solution.js
Created January 27, 2020 18:28
My solutions for problems for junior developers from Google and Microsoft.
// https://medium.com/javascript-in-plain-english/interviewing-at-google-javascript-assessment-questions-f9bf0c0df157
// Utils.
const generateWord = k => l => 'a'.repeat(l).split('').map(_ => k[Math.round(Math.random() * k.length + .5)]).join('');
// Exercise 1.
const collectFruits = bins => trees => {
let btypes = new Set(), fruits = [], collected = 0;
for (let i = 0; i < trees.length; i++) {
if (btypes.size < bins) {
-- to add colors like dark-green or dark\ngreen in this algorithm you need to add each different phrase
-- as sparate phrase or to modify AhoCorassick to use wildcards. It's possible and even easy to do it.
-- But you need to change package.
module Main where
import Data.Char (isAlphaNum)
import Data.List.Split (splitOn)
import qualified Data.Map as M
import System.Environment
import System.IO
@DKurilo
DKurilo / syrniks.md
Last active March 8, 2021 16:31
Syrniks recipe

Syrniks

As I promised here is the recipe for syrniks.
In case I just don't know the name for something in English that I can just buy, tell me, please. I'm too lazy to do something I don't need to do.

You need:

  • milk: half a gallon
  • flour: 70-80 gramms
  • eggs: 1 1/2. I'm using 1 egg and 1 yolk. But you can also use 3 yolks.
  • sugar: 3-5 tablespoons
  • vanilla extract: 1 teaspoon (or as much as you want, it's not a required component)
@DKurilo
DKurilo / lcs.hs
Created March 21, 2021 01:02
Largest common sequence problem in Haskell
{-# OPTIONS_GHC -O2 -threaded #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.Monad (forM_)
import Control.Monad.ST
import Data.Array (Array, array, listArray, (!))
import Data.Array.ST
lcs :: (Eq a) => [a] -> [a] -> Int