Skip to content

Instantly share code, notes, and snippets.

@dnaumenko
dnaumenko / CalcBrain.m
Created July 24, 2012 18:45
Recursive desribeOparandOnStack
+(NSString *)describeOperandOnStack:(NSMutableArray *)stack withRootOperation:(NSString *)rootOperation {
NSString *result = @"";
id topOfStack = [stack lastObject];
if (topOfStack) [stack removeLastObject];
if ([topOfStack isKindOfClass:[NSNumber class]]) {
result = [NSString stringWithFormat:@"%@", topOfStack];
} else if ([topOfStack isKindOfClass:[NSString class]]) {
NSString* operation = topOfStack;
@dnaumenko
dnaumenko / 0_reuse_code.js
Created June 10, 2014 11:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dnaumenko
dnaumenko / gist:a7af8bfa662518ae8a3436e3bd5f5284
Created December 3, 2017 12:03
Phone Ex from Chapter 11 in Haskell book
{-# LANGUAGE ParallelListComp #-}
module Phone where
import Data.Char
import Data.List
import Data.Foldable
type Presses = Int
data Digit = One | Two | Three | Four | Five | Six | Seven | Eight | Nine | Zero | STAR | HASH deriving (Eq, Show)
@dnaumenko
dnaumenko / vpn.md
Created April 16, 2018 12:01 — forked from joepie91/vpn.md
Don't use VPN services.

Don't use VPN services.

No, seriously, don't. You're probably reading this because you've asked what VPN service to use, and this is the answer.

Note: The content in this post does not apply to using VPN for their intended purpose; that is, as a virtual private (internal) network. It only applies to using it as a glorified proxy, which is what every third-party "VPN provider" does.

(A Russian translation of this article can be found here, contributed by Timur Demin.)

Why not?

import cats.data.ReaderT
import cats.effect.{Concurrent, IO, Sync}
import cats.mtl.ApplicativeLocal
import fs2.Stream
object UpdateLocalContextProblem extends App {
type Ctx = String
type Header = String
type ReaderIO[A] = ReaderT[IO, Ctx, A]
# clean maven targets
find . -type d -name target -prune -exec rm -rf {} \;
// from https://gitter.im/typelevel/cats-effect?at=5cdae78a5a887e1cd9e8a334
trait Shifter[F[_]] {
def shiftFair[A](fa: F[A]): F[A]
}
def fairShifter(n: Int): F[Shifter[F]] =
Ref.of(0).map {
new Shifter[F] {
def shiftFair(fa: F[A]): F[A] = ref.modify(i => (i+1, i%n == 0).ifM(shift >> fa, fa)
# vcs
brew install git
# jvm
brew install maven
brew install jenv # jenv local/global 1.8 to change if needed
# export PATH="$HOME/.jenv/bin:$PATH" in bash profile
# eval "$(jenv init -)"
# scala
@dnaumenko
dnaumenko / zioexit.scala
Last active February 15, 2020 13:10
Convert from ZIO exit to your own exit
sealed trait Exit[+A] {
def toEither: Either[Throwable, A]
}
object Exit {
final case class Success[+A](value: A) extends Exit[A] {
override def toEither: Either[Throwable, A] = Right(value)
}
sealed trait Failure extends Exit[Nothing]
trait Env[Ctx, +A] {
def map[B](f: A => B): Env[Ctx, B]
def flatMap[B](f: A => Env[Ctx, B]): Env[Ctx, B]
def void: Env[Ctx, Unit] = map(_ => ())
}