Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@debasishg
debasishg / gist:738436be246179293c50f4ab7bef02b1
Created April 25, 2019 16:50
Getting runtime types in Scala
Can we do it with `ClassTag` ?
Adriaan:
You can't with a class tag, as it represents the erased type as known to the JVM. You could use a TypeTag
to reify the full type, but that depends on full scala reflection, which has its own downsides
(not thread safe, basically pulls in the compiler,...)
scala> import scala.reflect.runtime.universe.TypeTag
import scala.reflect.runtime.universe.TypeTag
@debasishg
debasishg / GDP.scala
Created April 14, 2019 19:41 — forked from erdeszt/GDP.scala
Ghosts of departed proofs in scala (https://github.com/matt-noonan/gdp-paper/releases)
trait Coercible[A, B] {
def coerce(a: A): B
}
def coerce[A, B](a: A)(implicit coerceAB: Coercible[A, B]): B = {
coerceAB.coerce(a)
}
trait Newtype[+T] {
val value: T
@debasishg
debasishg / postgres-brew.md
Created March 23, 2019 19:55 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@debasishg
debasishg / postgresql.txt
Created March 23, 2019 19:44
Postgresql howtos
# start postgresql
pg_ctl -D /usr/local/var/postgres start
# stop postgresql
pg_ctl -D /usr/local/var/postgres stop
@debasishg
debasishg / state.hs
Created March 11, 2019 19:43 — forked from sdiehl/state.hs
State monad implementation + example
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)
@debasishg
debasishg / encode_decode_dictionary.py
Created January 30, 2019 10:11 — forked from khornberg/encode_decode_dictionary.py
python 3 base64 encode dict
"""
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
debasishg / CollectionTest.java
Created August 24, 2018 09:40 — forked from coacoas/CollectionTest.java
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;
@debasishg
debasishg / service_types.scala
Created August 12, 2018 11:55
algebra of effects for a domain service
type Valid[M[_], A] = EitherT[M, AccountServiceException, A]
type AccountOperation[M[_], A] = Kleisli[Valid[M, ?], AccountRepository[M], A]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am debasishg on github.
  • I am debasishg (https://keybase.io/debasishg) on keybase.
  • I have a public key ASAzUhyfxB6-Sy-1fIyhLBZ5SWBaddWWW8AJLWqQZAp7_go

To claim this, I am signing this object: