Skip to content

Instantly share code, notes, and snippets.


Vlad Patryshev vpatryshev

View GitHub Profile
View terminology.pdf
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kristopherjohnson /
Last active August 15, 2020 19:23
Translation of classic Lunar Lander game from FOCAL to Rust
//! Translation of
//! <>
//! by Jim Storer from FOCAL to Rust.
use std::error::Error;
use std::io;
use std::io::prelude::*;
use std::marker::{Send, Sync};
use std::process;
use std::str::FromStr;
View LinVect.scala
object LinVect {
type K = Double
trait NAT[N] { val nat: Int }
def NAT[N: NAT]: NAT[N] = implicitly
def nat[N: NAT]: Int = NAT[N].nat
trait NAT_10
implicit object NAT_10 extends NAT[NAT_10]
zraffer / CAT.scala
Created November 6, 2016 15:18
sample of abuse of Java/Scala type system for simulate given formal system
View CAT.scala
package cat
object CAT {
// system traits
sealed trait Type[Self <: Type[Self]]
sealed trait Of[Self <: Of[Self, T], T <: Type[T]]
// types
case class Ob()
zraffer / CCC.scala
Created November 4, 2016 12:26
Scala Types are objects of Cartesian Closed Category
View CCC.scala
// Scala Types are objects of Cartesian Closed Category
// (w/o equalities, probably not a category, sorry)
object CCC {
// category structure
def id[T0]: T0=>T0 = x0=>x0
def mul[T1, T2, T3](f23: T2=>T3, f12: T1=>T2): (T1=>T3) = x1 => f23(f12(x1))
// terminal object; adjunction;
type _1_ = Unit
zraffer / package.scala
Last active April 26, 2017 11:17
a few operations with functors
View package.scala
package object types {
import scala.language.reflectiveCalls
import scala.language.higherKinds
// quantifiers aka (co)ends
type Forall[+F[_]] = { def apply[X]: F[X] }
type Exists[+F[_]] = F[_]
// basic categorical notions
jaytaylor / EnvHacker.scala
Created August 21, 2014 02:41
Setting environment variables in Scala JVM
View EnvHacker.scala
trait EnvHacker {
* Portable method for setting env vars on both *nix and Windows.
* @see
def setEnv(newEnv: Map[String, String]): Unit = {
try {
val processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment")
val theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment")
soc / ::.scala
Last active December 18, 2015 05:59
View ::.scala
final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B]
override def head: B = hd
override def tail: List[B] = tl
override def isEmpty: Boolean = false
private def readObject(in: ObjectInputStream): Unit =
val firstObject = in.readObject()
hd = firstObject.asInstanceOf[B]
assert(hd != ListSerializeEnd)
var current: ::[B] = this
vmarquez / TxMapTest.scala
Last active November 28, 2021 12:33
A mini STM if you will. I've made a'Transactional' map that mutates in a referentially transparent way.
View TxMapTest.scala
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.CountDownLatch
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
object TxMapTest {
* Example Usage
* We want to show two threads working with the same data source having both of their effects succeed