Skip to content

Instantly share code, notes, and snippets.

View YBogomolov's full-sized avatar

Yuriy Bogomolov YBogomolov

View GitHub Profile
@YBogomolov
YBogomolov / addbinding.bat
Last active December 26, 2015 12:29
Add IIS website binding from command line
C:\Windows\System32\Inetsrv\appcmd.exe set site /site.name: %1 /+bindings.[protocol='http',bindingInformation='*:80:%2']
@YBogomolov
YBogomolov / gist:8093485
Created December 23, 2013 08:32
Embed third-party assembly as a resource
// 1. Set build action 'Embedded Resourse'.
// 2. Run this handler as early as possible:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string resourceName = "Your.Assembly.Name.Here." + new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream == null)
@YBogomolov
YBogomolov / fix.js
Last active January 23, 2018 21:46
Y-combinator in JavaScript (ES6) with memoization
// `fix` is an Y-combinator implementation (recursive calls in lambda calculus):
// Y = \f -> (\x -> f (x x))(\x -> f (x x))
// fix :: (a -> a) -> a
const fix = f => (x => f(y => (x(x))(y)))(x => f(y => (x(x))(y)));
// Generator function. Inner signature should correspond to actual function interface.
// mapgen :: ((a -> b) -> [a] -> [b]) -> (a -> b) -> [a] -> [b]
const mapgen = map => f => list => list.length === 0 ? [] : [f(list[0]), ...map(f)(list.slice(1))];
@YBogomolov
YBogomolov / tagless.ts
Created April 30, 2019 06:17
#monadicmonday ep.5: Tagless Final
import { log } from 'fp-ts/lib/Console';
import { Type, URIS } from 'fp-ts/lib/HKT';
import { identity, URI as IdURI } from 'fp-ts/lib/Identity';
import { none, Option, some } from 'fp-ts/lib/Option';
import { randomInt } from 'fp-ts/lib/Random';
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task';
import { createInterface } from 'readline';
export interface ProgramSyntax<F extends URIS, A> {
map: <B>(f: (a: A) => B) => _<F, B>;
@YBogomolov
YBogomolov / profunctors.ts
Last active September 12, 2019 06:19
Profunctor instances for UpStar and DownStar
import { Functor } from 'fp-ts/lib/Functor';
import { HKT, Kind3, URIS3 } from 'fp-ts/lib/HKT';
export type Fn<A, B> = (a: A) => B;
export interface Profunctor<F extends URIS3, G> {
dimap: <A, B>(ab: Fn<A, B>) => <C, D>(cd: Fn<C, D>) => (fbc: Kind3<F, G, B, C>) => Kind3<F, G, A, D>;
}
export type UpStar<F, A, B> = (a: A) => HKT<F, B>;
@YBogomolov
YBogomolov / AppendInjective.idr
Last active May 2, 2020 10:17
Proof that a ++ b = a ++ c -> b = c and a ++ c = b ++ c -> a = b
module AppendInjective
import Data.List.Views
%access export
%default total
appendInjectiveRight : (a, b, c : List x) -> a ++ b = a ++ c -> b = c
appendInjectiveRight [] _ _ prf = prf
appendInjectiveRight (_ :: xs) b c prf = appendInjectiveRight xs b c (cong { f = drop 1 } prf)
@YBogomolov
YBogomolov / fsm_cb.ts
Created March 24, 2019 09:14
FSM using Circuit Breaker
import AbortController from 'abort-controller';
import { circuitBreaker, defaultBreakerOptions } from 'circuit-breaker-monad/lib';
import { BreakerClosed, BreakerOpen, BreakerState } from 'circuit-breaker-monad/lib/types';
import { Either, left } from 'fp-ts/lib/Either';
import { Lazy } from 'fp-ts/lib/function';
import { IORef } from 'fp-ts/lib/IORef';
import fetch from 'node-fetch';
const fetcher = circuitBreaker<User[]>().run(defaultBreakerOptions);
@YBogomolov
YBogomolov / tf-streams.ts
Last active August 23, 2020 14:14
Tagless Final example with functional streams
import { Do } from 'fp-ts-contrib/lib/Do';
import { array } from 'fp-ts/lib/Array';
import { constUndefined, identity, Lazy } from 'fp-ts/lib/function';
import { Kind, URIS } from 'fp-ts/lib/HKT';
import * as Id from 'fp-ts/lib/Identity';
import { Monad1 } from 'fp-ts/lib/Monad';
import { none, Option } from 'fp-ts/lib/Option';
import { Traversable1 } from 'fp-ts/lib/Traversable';
declare module 'fp-ts/lib/HKT' {
@YBogomolov
YBogomolov / either_tuple.ts
Created April 13, 2020 15:02
Encoding Either<E, A> as a tuple
export type Either<E, A> = [E, null] | [null, A];
type Fn<A, B> = (a: A) => B;
export const left = <E, A>(e: E): Either<E, A> => [e, null];
export const right = <E, A>(a: A): Either<E, A> => [null, a];
export const isLeft = <E, A>(e: Either<E, A>): e is [E, null] => e[1] === null;
export const isRight = <E, A>(e: Either<E, A>): e is [null, A] => e[0] === null;
@YBogomolov
YBogomolov / 0_README.md
Created June 7, 2020 13:34
Idris 2 DevContainer

How to use Idris 2 in devcontainer

Step 1: build executable and libraries

Use the Dockerfile below to build the Idris 2 executable and standard library:

docker build --tag=idris2 .