Skip to content

Instantly share code, notes, and snippets.

View balajisivaraman's full-sized avatar

Balaji Sivaraman balajisivaraman

View GitHub Profile
@balajisivaraman
balajisivaraman / rust_1_25.rs
Created May 13, 2018 15:03
Rust 1.25 Sample
trait Animal {
fn walk(&self);
}
struct Dog {
name: String
}
impl Animal for Dog {
fn walk(&self) {
@balajisivaraman
balajisivaraman / rust_1_26.rs
Created May 13, 2018 15:02
Rust 1.26 Sample
trait Animal {
fn walk(&self);
}
struct Dog {
pub name: String
}
impl Animal for Dog {
fn walk(&self) {
@balajisivaraman
balajisivaraman / HiveImportUsingFS2.scala
Last active November 10, 2019 14:42
Creating a wrapper for Hive ORC API using FS2
import java.sql.Timestamp
import java.time.{Instant, ZonedDateTime}
import cats.effect.IO
import cats.implicits._
import doobie._
import doobie.implicits._
import fs2.Stream
import scodec.bits.ByteVector
@balajisivaraman
balajisivaraman / reader-resources.scala
Created November 26, 2016 15:33
Reader Monad Resource Management
val getJDBCConnection: Reader[JDBCConf, Connection] = ???
val getStatement: Reader[Connection, PreparedStatement] = ???
val executeQuery: Reader[PreparedStatement, ResultSet] = ???
val queryExecutor: Reader[JDBCConf, ResultSet] = getJDBCConnection.andThen(getStatement).andThen(executeQuery)

Keybase proof

I hereby claim:

  • I am balajisivaraman on github.
  • I am balajisivaraman (https://keybase.io/balajisivaraman) on keybase.
  • I have a public key ASCkCKxKL9ESMggKqg0xNChjorBW4iAXWTk-a_jZzmI91Ao

To claim this, I am signing this object:

READ THIS

Have you read all the documentation at Ensime Emacs? Please do, we put a lot of effort into it. Most problems can be resolved easily by following a simple process, follow through our Troubleshooting guide and share the debugging information below as a gist if you need to escalate. Do not paste this directly into the gitter chat room as it is very verbose.


System Information - Ensime troubleshoot report

The goal is to write an API for the tic-tac-toe game. An API user, should be able to play a game of tic-tac-toe using this API, but importantly, it should be impossible for the API user to break the rules of the game. Specifically, if an attempt is made to break a rule, the API should reject the program. This is often done by way of a compile-time type error.

The following API functions should exist:

  • move: takes a tic-tac-toe board and position and moves to that position (if not occupied) returning a new board. This function can only be called on a board that is empty or in-play. Calling move on a game board that is finished is a compile-time type error.

  • whoWon: takes a tic-tac-toe board and returns the player that won the game (or none if neither has won). This function can only be called on a board that is finished. Calling whoWon on a game board that is empty or in-play is a compile-time type error.

  • playerAt: takes a tic-tac-toe board and position and returns the (possible) player at a given posi

sealed trait List[+T]
case object Nil extends List[Nothing]
case class Cons[+T](head: T, tail: List[T]) extends List[T]
object List {
def head[T](list: List[T]): T = list match {
case Nil => throw new RuntimeException("Empty List")
case Cons(x, _) => x
}
@balajisivaraman
balajisivaraman / Wk3Golf.hs
Created October 12, 2014 15:22
Doctest Testing
-- >>> skips "ABCD"
-- ["ABCD","BD","C","D"] -- This passes.
-- >>> skips "ABCD"
-- ["ABCD", "BD", "C", "D"] -- This doesn't pass. I assume because of the whitespace. Why?
-- But both are equal according to GHCi.
skips :: [a] -> [[a]]
skips l = map (getItems l) [1..length l]
where
getItems :: [a] -> Int -> [a]
getItems l n = map (l !!) [n-1,2*n-1..length l - 1]