Skip to content

Instantly share code, notes, and snippets.

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 / index.js
Created January 14, 2022 17:00
Monad prsing inspired parsing in JS / copy from codesandbox just not to lose it
View index.js
const skip = (parser) => (text) => {
const parsed = parser(text);
if (parsed.length === 0) {
return parsed;
}
return [{ parsed: [], text: parsed[0].text }];
};
const chain = (f) => (parser1) => (parser2) => (text) => {
const parsed = parser1(text);
if (parsed.length === 0) {
@DKurilo
DKurilo / queue.js
Last active September 24, 2021 14:14
Simple TypeScript and JavaScript queues
View queue.js
const mkQueue = (sameTimeCount, delay, maxRepeats) => {
const queued = [];
const inWork = [];
const removeFromInWork = (frr) => {
const i = inWork.indexOf(frr);
inWork.splice(i, 1);
if (inWork.length < sameTimeCount && queued.length > 0) {
const [newFrr] = queued.splice(0, 1);
// eslint-disable-next-line no-use-before-define
addToInWork(newFrr);
@DKurilo
DKurilo / README.md
Last active January 21, 2022 20:50
Static Analisys of TypeScript code with SonarQube
View README.md

Static Analysis of TypeScript code with SonarQube

  1. Install sonarqube-scanner
npm install --save-dev sonarqube-scanner sonarqube-verify jest-sonar
  1. Create configuration for project: sonar-project.properties
sonar.projectKey=secure-typescript-boilerplate
@DKurilo
DKurilo / lcs.hs
Created March 21, 2021 01:02
Largest common sequence problem in Haskell
View lcs.hs
{-# 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
@DKurilo
DKurilo / syrniks.md
Last active March 8, 2021 16:31
Syrniks recipe
View syrniks.md

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)
View color-highliter-annotator.hs
-- 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 / solution.js
Created January 27, 2020 18:28
My solutions for problems for junior developers from Google and Microsoft.
View solution.js
// 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) {
@DKurilo
DKurilo / cata.hs
Last active January 25, 2020 03:11
Catamorphisms in Haskell
View cata.hs
{-|
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
View ghci.conf
: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 / .vimrc
Last active January 6, 2023 00:48
View .vimrc
" 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