Skip to content

Instantly share code, notes, and snippets.

View AesaKamar's full-sized avatar
👾

Aesa Kamar AesaKamar

👾
View GitHub Profile
@agolovenko
agolovenko / InformationSize.scala
Created June 15, 2021 17:15
InformationSize: scala implementation for human-readable file sizes
final case class InformationSize(size: Double, unit: InformationUnit) extends Ordered[InformationSize] {
import InformationSize.{safeAdd, safeDivide, safeMultiply}
import InformationUnit._
if (size < 0d) throw new IllegalArgumentException(s"Unsupported negative size: $size")
def toBits: Double = to(Bit)
def toKiloBits: Double = to(KiloBit)
def toMegaBits: Double = to(MegaBit)
def toBytes: Double = to(Byte)
@atacratic
atacratic / ability-tutorial.output.md
Last active July 3, 2024 14:57
Unison abilities - unofficial alternative tutorial

This tutorial explains how Unison handles 'effectful' computations, like storing state or performing I/O, using abilities. It assumes you haven't come across abilities before, and covers everything from the ground up.

This is an unofficial tutorial, written before the one on unisonweb.org/docs. The approach taken here is slow and methodical. Your first stop should be the official tutorial, if you haven't seen it already.

This doc is a Unison transcript - the source is here.

Terminology note: other languages with ability systems typically call them 'effect handlers' or 'algebraic effects', but many of the ideas are the same.

Introducing abilities

@tabdulradi
tabdulradi / scalac-compiler-flags-2.13.sbt
Last active November 24, 2022 07:39
Scala Compiler flags for 2.13. Based on Tpolecat's 2.12 version
scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
// "-language:experimental.macros", // Allow macro definition (besides implementation and application). Disabled, as this will significantly change in Scala 3
"-language:higherKinds", // Allow higher-kinded types
// "-language:implicitConversions", // Allow definition of implicit functions called views. Disabled, as it might be dropped in Scala 3. Instead use extension methods (implemented as implicit class Wrapper(va
@johnynek
johnynek / RefMap.scala
Last active April 14, 2023 13:04
A wrapper on ConcurrentHashMap to use with cats.effect.Ref
package org.bykn.refmap
import cats.data.State
import cats.effect.Sync
import cats.effect.concurrent.Ref
import java.util.concurrent.ConcurrentHashMap
import cats.implicits._
/**
@pchiusano
pchiusano / monads.u
Last active April 27, 2024 08:18
Converting between algebraic effects and monads
-- This gist shows how we can use abilities to provide nicer syntax for any monad.
-- We can view abilities as "just" providing nicer syntax for working with the
-- free monad.
ability Monadic f where
eval : f a -> a
-- Here's a monad, encoded as a first-class value with
-- two polymorphic functions, `pure` and `bind`
type Monad f = Monad (forall a . a -> f a) (forall a b . f a -> (a -> f b) -> f b)
@dchowitz
dchowitz / es6-debugging-in-vscode.md
Last active August 30, 2023 06:23
Debugging ES6 in VS Code

Debugging ES6 in VS Code

My current editor of choice for all things related to Javascript and Node is VS Code, which I highly recommend. The other day I needed to hunt down a bug in one of my tests written in ES6, which at time of writing is not fully supported in Node. Shortly after, I found myself down the rabbit hole of debugging in VS Code and realized this isn't as straightforward as I thought initially. This short post summarizes the steps I took to make debugging ES6 in VS Code frictionless.

What doesn't work

My first approach was a launch configuration in launch.json mimicking tape -r babel-register ./path/to/testfile.js with babel configured to create inline sourcemaps in my package.json. The debugging started but breakpoints and stepping through the code in VS Code were a complete mess. Apparently, ad-hoc transpilation via babel-require-hook and inline sourcemaps do not work in VS Code. The same result for attaching (instead of launch) to `babel-node

@amysimmons
amysimmons / js-tricky-bits.md
Last active July 2, 2024 20:06
Understanding closures, callbacks and promises in JavaScript

#Understanding closures, callbacks and promises

For a code newbie like myself, callbacks, closures and promises are scary JavaScript concepts.

10 months into my full-time dev career, and I would struggle to explain these words to a peer.

So I decided it was time to face my fears, and try to get my head around each concept.

Here are the notes from my initial reading. I'll continue to refine them as my understanding improves.

@rgorsuch
rgorsuch / gist:b404c658551a6a8aeb35
Created July 31, 2015 13:03 — forked from jessitron/gist:8376139
scala: print all URLs on classpath
def urlses(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent)
case _ => urlses(cl.getParent)
}
val urls = urlses(getClass.getClassLoader)
println(urls.filterNot(_.toString.contains("ivy")).mkString("\n"))
@iest
iest / README.md
Last active August 11, 2022 09:20
Setting up environment variables with various shells

What the hell are environment variables?

They're just variables you set on your system that various programs/processes can read. A fairly standard example in javascript circles would be setting your NODE_ENV variable to "production" or "development", altering how node code is executed on your system (for example showing more debug messaging when in development).

With most shells there's a way to set them for the current session, and a way to set them for all sessions. The following is meant to be a guide on how to set env vars in the various shells.

Bash (The default shell on OSX)

Setting for the session:

@staltz
staltz / introrx.md
Last active July 15, 2024 15:43
The introduction to Reactive Programming you've been missing