Skip to content

Instantly share code, notes, and snippets.

View mbergal's full-sized avatar

Misha Bergal mbergal

View GitHub Profile
from enum import Enum
from itertools import groupby
from dataclasses import dataclass
from typing import (
Callable,
Iterator,
List,
Optional,
Sequence,
Tuple,
from typing import Iterable, List
def generate_split(places: int, max: int) -> Iterable[List[int]]:
if places == 0:
yield []
elif places == 1:
yield [max]
else:
for i in range(0, max + 1):
import simpy
from scipy.stats import truncnorm
def get_truncated_normal(mean=0, sd=1, low=0, upp=1):
return truncnorm((low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd)
exam_queue = []
from abc import abstractmethod
from typing import Generic, Protocol, TypeVar
T_cov = TypeVar("T", contravariant=True)
U_cov = TypeVar("U", contravariant=True)
class Metric(Protocol[T]):
@abstractmethod
def __call__(self, gt: T, pred: T) -> float:
...
#!/bin/bash
set -e
echo $1
pushd $(dirname $1) >/dev/null
yarn > /dev/null
yarn ts-node $*
popd > /dev/null
open Jest;
let getData = (): Promise.promise(string) => Promise.resolved("some initial data");
type firstStepResult = {first: string};
type secondStepResult = {second: string};
let doFirstStep = (v: string) => {
Js.log(v);
INFO global: Vagrant version: 2.2.4
INFO global: Ruby version: 2.4.4
INFO global: RubyGems version: 2.6.14.1
INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\2.2.4\\gems\\vagrant-2.2.4\\bin\\vagrant"
INFO global: VAGRANT_EXPERIMENTAL="typed_triggers"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_LOG="debug"
WARN global: resolv replacement has not been enabled!
import { of, from } from 'rxjs';
import { switchMap, finalize, map } from 'rxjs/operators';
//emit (1,2,3,4,5)
const source = from([1, 2, 3, 4, 5]);
//add 10 to each value
const example = source.pipe(
map(val => of(val).pipe( finalize(x=>console.log('final ' + val)))),
switchMap(val=>val)
);
@mbergal
mbergal / JavaScript-exception-stack-trace.re
Created June 28, 2018 21:42
JavaScript-exception-stack-trace.re
let throwError: unit => unit = [%bs.raw
{|function () { throw new Error("aaaa"); }|}
];
try (throwError()) {
| Js.Exn.Error(e) =>
switch (Js.Exn.message(e)) {
| Some(message) => Js.log({j|Error>>>>>: $message|j})
| None => Js.log("An unknown error occurred")
}
@mbergal
mbergal / Js.Promise-error-handling.re
Last active June 28, 2018 21:41
Js.Promise-error-handling.re
exception SomeError;
exception JsError(Js.Exn.t);
let makeJsError: unit => Js.Promise.t(unit) = [%bs.raw
{|() => Promise.reject(new Error("aaaa"))|}
];
let catch_ = (ocamlhandler, jshandler, promise) => {
let a = e =>
switch (ocamlhandler(e)) {