Skip to content

Instantly share code, notes, and snippets.

Working from home

Debasish Ghosh debasishg

Working from home
View GitHub Profile

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

View GDP.scala
trait Coercible[A, B] {
def coerce(a: A): B
def coerce[A, B](a: A)(implicit coerceAB: Coercible[A, B]): B = {
trait Newtype[+T] {
val value: T
debasishg /
Created Mar 23, 2019 — forked from ibraheem4/
Installing Postgres via Brew (OSX)

Installing Postgres via Brew


Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
debasishg / state.hs
Created Mar 11, 2019 — forked from sdiehl/state.hs
State monad implementation + example
View state.hs
import Control.Monad
-- State Monad Implementation
newtype State s a = State { runState :: s -> (a,s) }
instance Monad (State s) where
return a = State $ \s -> (a, s)
Given a dictionary, transform it to a string. Then byte encode that string. Then base64 encode it and since this will go
on a url, use the urlsafe version. Then decode the byte string so that it can be else where.
data = base64.urlsafe_b64encode(json.dumps({'a': 123}).encode()).decode()
# And the decode is just as simple...
data = json.loads(base64.urlsafe_b64decode(query_param.encode()).decode())
# Byte encode the string, base64 decode that, then byte decode, finally transform it to a dictionary
debasishg /
Created Aug 24, 2018 — forked from coacoas/
Using Scala collections from Java
package org.example;
import scala.Function1;
import scala.collection.generic.CanBuildFrom;
import scala.collection.immutable.List;
import scala.collection.immutable.List$;
import scala.collection.immutable.Vector;
import scala.collection.immutable.Vector$;
import scala.collection.mutable.Builder;
View Embedding and Tokenizer in Keras.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
debasishg / Haskell
Created Nov 3, 2017 — forked from anonymous/Haskell
Comparison of the straightforward embedding of a basic tenet of category theory in Scala vs Haskell.
View Haskell
yonedaLemma = Iso (flip fmap) ($ id)
debasishg / type-inhabitants.markdown
Created Oct 26, 2017 — forked from pchiusano/type-inhabitants.markdown
Reasoning about type inhabitants in Haskell
View type-inhabitants.markdown

This is material to go along with a 2014 Boston Haskell talk.

We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.

Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?

wrangle :: Int -> Int
debasishg / gist:f473167ac91b2af4949c6340d4aa0c1b
Created Aug 12, 2017 — forked from runarorama/gist:78c8fefbab74701afab3
Playing around with "Finally Tagless, Partially Evaluated" in Scala
View gist:f473167ac91b2af4949c6340d4aa0c1b
// Finally tagless lambda calculus
object Final {
def varZ[A,B](env1: A, env2: B): A = env1
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2)
def b[E](bv: Boolean)(env: E): Boolean = bv
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env)
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env))
def testf1[E,A](env: E): Boolean =
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env)