Skip to content

Instantly share code, notes, and snippets.

View shkesar's full-sized avatar

Shubham Keserwani shkesar

View GitHub Profile
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
}
// For lifting pure values into effects and to chain effects
trait Monad[F[_]] extends Functor[F] {
def pure(x: A): F[A]
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
// map can now be defined in terms of pure and flatten so Monad is a functor
}
@shkesar
shkesar / Nat.hs
Created June 5, 2019 08:04
Haskell Natural Numbers
-- Natural Numbers
data Nat = Zero | Succ Nat
instance Show Nat where
show Zero = "Zero"
show (Succ m) = printf "Succ (%s)" (show m)
nat2int :: Nat -> Int
nat2int Zero = 0
@shkesar
shkesar / Main.hs
Last active June 5, 2019 11:35
Learning Haskell - Programming in Haskell - Graham Hutton
module Main where
import Lib
import Data.Char
import Prelude
import Text.Printf
main :: IO ()
main = someFunc
@shkesar
shkesar / DependencyInjection.scala
Created November 10, 2018 01:28
Dependency Injection
trait Service {
def sendMessage(msg: String, recv: String): Unit
}
class SMSService extends Service {
def sendMessage(msg: String, recv: String) =
println(s"SMS sent to ${recv} containing ${msg}")
}
class EmailService extends Service {
def sendMessage(msg: String, recv: String) =
println(s"Email sent to ${recv} containing ${msg}")
sealed trait Direction
case object Horizontal extends Direction
case object Vertical extends Direction
object Direction {
def random(): Direction =
if (Math.random() < 0.5)
Horizontal
else
Vertical
@shkesar
shkesar / .vimrc
Last active June 19, 2019 00:00
set expandtab
set shiftwidth=2
set softtabstop=2
set hlsearch
set wildignore+=*/node_modules/*
set wildignore+=*/dist/*
set wildignore+=*/build/*
set listchars=tab:▸\ ,eol:¬,trail:▫
set encoding=utf-8
dashboard "Food":
- h1 text: Food
- h2 text: By caloric content
- 3 columns:
- rows:
- h3 text: Bananas
- pie chart: {
"columns": [
["Protein", 5], ["Sugar", 10], ["Other carbs", 40], ["Fat", 1]
]
@shkesar
shkesar / index.js
Last active January 26, 2018 10:48
#!/usr/bin/env node
console.log("Say hello");
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define MAX 100
#define EXIT_CHOICE 10
#define USERS_FILE "users.txt"
#define BOOKS_FILE "books.txt"
@shkesar
shkesar / library.c
Created January 24, 2017 12:05
Library
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define MAX 100
#define EXIT_CHOICE 10
#define USERS_FILE "users.txt"
#define BOOKS_FILE "books.txt"