Skip to content

Instantly share code, notes, and snippets.

@suhailshergill
suhailshergill / keybase.md
Created March 30, 2014 20:27
keybase proof

Keybase proof

I hereby claim:

  • I am suhailshergill on github.
  • I am shergill (https://keybase.io/shergill) on keybase.
  • I have a public key whose fingerprint is 623E 49E5 27D5 5D95 AA69 CE52 8956 DBE3 13DA 7380

To claim this, I am signing this object:

@suhailshergill
suhailshergill / MonadImpliesFunctor.scala
Created April 16, 2014 17:04 — forked from jdegoes/MonadImpliesFunctor.scala
scala: monad implies functor
import scala.language.higherKinds
trait Monad[M[_]] {
implicit def `Monad ~> Functor`[M[_]: Monad]: Functor[M] = new Functor[M]{}
}
trait Functor[F[_]] {
}
object Functor {
@suhailshergill
suhailshergill / scratch.hs
Created May 14, 2014 08:52
haskell: (free) applicative + monad
-- [[file:~/Dropbox/Public/papers/pl/haskell/free/free-applicative-functors_capriotti-kaposi.org::*%5B%5Bhttp://hackage.haskell.org/package/free-4.7.1/docs/Control-Monad-Free.html%5D%5BFree%20monad%5D%5D][su/haskell/free/FreeAL/modulo]]
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
(defun su/monkeypatch/nil-fun (&rest args))
(defvar su/monkeypatch/nil-var nil)
(defun su/monkeypatch/mangle-name (symbol prefix)
(concat "su/monkeypatches/" prefix (symbol-name symbol))
)
(defun su/monkeypatch/copy-values (source-symbol dest-symbol)
"This function copies values from source to dest. It does not keep any
backups. I f you want that you want to use 'su/monkeypatch' instead"
(ignore-errors
@suhailshergill
suhailshergill / TTFI.scala
Last active April 27, 2016 14:40
scala: TTFI
object TTFI {
object Initial {
// {{{ OOP
object OOP {
// extending language is easy, adding more functions is hard since it
// involves having to modify each case class
trait Exp[A] {
def eval: A
@suhailshergill
suhailshergill / BB_ADT.hs
Last active August 29, 2015 14:06
haskell: TTFI
-- The illustration of the Boehm-Berarducci encoding
-- This file is the baseline: using ordinary algebraic
-- data type and operations of constructions, deconstructions
-- and transformation.
-- We use the running example of the Exp data type from
-- tagless-final lectures
module BB_ADT where
@suhailshergill
suhailshergill / Deserialization.scala
Last active February 24, 2019 16:08 — forked from ramn/Deserialization.scala
scala: java.io.Serialization
import java.io._
@SerialVersionUID(15L)
class Animal(name: String, age: Int) extends Serializable {
override def toString = s"Animal($name, $age)"
}
case class Person(name: String)
// or fork := true in sbt
@suhailshergill
suhailshergill / emailme.py
Last active February 24, 2019 16:06 — forked from alexalemi/emailme.py
#! /usr/bin/env python
""" Email Me.
Usage:
emailme <message>
emailme [-s] <message>
emailme [-s] <subject> <message>
emailme <toaddr> <subject> <message>
emailme <toaddr> <fromaddr> <subject> <message>
emailme -h | --help
from itertools import imap
def foo(x): return iter(x) # function which returns an iter
bar = ["bar", "baz"]
list(foo("bar"))
#[Out]# ['b', 'a', 'r']
baz = iter(bar) # iterator of inputs
qu = (item for sublist in imap(foo, baz) for item in sublist)
list(qu) # demonstration of chaining things together
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
/**
* I am trying to narrow down on an Exception thrown by Spark when using "Factories".
* The factories have parameters that are used in the classes' functions.
*
* To run this code: copy-paste this whole content in a Spark-Shell. Execute Test.theMain(sc)
*
*/