Skip to content

Instantly share code, notes, and snippets.

View sigevsky's full-sized avatar

sigevsky

View GitHub Profile
package com.example.demo
import reactor.core.Disposable
import reactor.core.publisher.Mono
import java.time.Duration
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
class DelayedAggregation<K, T> {
private val pending: ConcurrentMap<K, State<T>> = ConcurrentHashMap()
@sigevsky
sigevsky / lease.rs
Created May 15, 2023 09:03
Lease resource
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use time::Duration;
use tokio::sync::mpsc;
use tokio::{select, time};
use tokio_util::sync::CancellationToken;
use tracing::trace;
pub struct Leased<A> {
// Resource that the lease is for
version: '3.9'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.2
restart: always
environment:
- discovery.type=single-node
- ELASTIC_PASSWORD=test123_
ulimits:
memlock:
@sigevsky
sigevsky / lease.rs
Last active February 6, 2022 20:28
use futures_delay_queue::{delay_queue, DelayHandle, ErrorAlreadyExpired};
use tokio::sync::oneshot;
use tokio::sync::oneshot::error::TryRecvError;
use tokio::sync::oneshot::Receiver;
use tokio::time::Duration;
struct Lease<A> {
val: A,
dur: Duration,
compl_handle: Receiver<()>,
@sigevsky
sigevsky / scraper.hs
Last active August 11, 2022 10:53
chmod +x scraper.hs && ./scraper.hs --url http://url.to/wordlist
#!/usr/bin/env stack
-- stack --resolver lts-18.28 script --package aeson,cassava,text,scalpel,http-client,http-client-tls,bytestring,unliftio,deepseq,directory,optparse-applicative
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
@sigevsky
sigevsky / Dockerfile
Created December 17, 2020 21:59
Stanford CoreNLP french docker file 2020
FROM openjdk:8u272
ENV VERSION=4.2.0
RUN wget http://nlp.stanford.edu/software/stanford-corenlp-${VERSION}.zip; \
unzip stanford-corenlp-${VERSION}.zip; \
mv stanford-corenlp-${VERSION} /opt/corenlp
RUN wget http://nlp.stanford.edu/software/stanford-corenlp-${VERSION}-models-french.jar; \
mv stanford-corenlp-${VERSION}-models-french.jar /opt/corenlp
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Amb where
import Control.Monad.Reader
import Control.Monad.Cont
import Data.Maybe (isJust)
import Data.List (find)
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.Reader
import Data.IORef
import Data.List (intercalate)
type Frame = IORef [Int]
type Stack = [Frame]
type SM a = ReaderT Stack IO a
@sigevsky
sigevsky / 3ch.rkt
Last active November 28, 2020 12:54
; exercise 3.1
(define (make-accumulator)
(define var 0)
(define (inc . args)
(set! var (foldl + 0 args))
var)
inc)
; exercise 3.2
(define (make-monitoring f)

Desc

We will start with a brief description of how we form our DSLs with the help of free monads/tf constraints and what the general rules to form such structures are. Then we will jump to the concrete example that shows nested structuring of the languages with one-way dependence.

Free monads

We describe our DSL as a bunch of constructors having polymorphic parameter and lifted with Free.liftF method to free monad. General rules for forming those constructors are the following: 0. Add type parameter to your algebra making it functorial.

  1. If the step of computation expects a value from the interpreter context then it should be shaped as a function from expected value to the continuation of the Monad A:
ReadLine[A](line: String => A) extends Console[A]