Skip to content

Instantly share code, notes, and snippets.

View quelgar's full-sized avatar
🇦🇺

Lachlan O'Dea quelgar

🇦🇺
View GitHub Profile
@quelgar
quelgar / iodemo.html
Last active August 29, 2015 13:56
Basic demonstration of purely functional I/O in Javascript. This is just a demonstration of the concept, I doubt it's suitable for real-world use!
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Functional I/O Demo</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>

Lachlan C++ Style Guide

Google also have their own C++ Style Guide that you may find more useful.

C++

I do not use C++.

Pros:

Keybase proof

I hereby claim:

  • I am quelgar on github.
  • I am quelgar (https://keybase.io/quelgar) on keybase.
  • I have a public key whose fingerprint is 943B 4775 C45A 895B DEB2 B425 2DCC 6D93 44B3 8C1B

To claim this, I am signing this object:

@quelgar
quelgar / tagged.scala
Created July 16, 2015 06:27
Tagged types experiment
bject Tag {
type Tagged[T] = {
type Tag = T
}
type @@[A, T] = A with Tagged[T]
@quelgar
quelgar / exceptiontoeither.scala
Last active August 29, 2015 14:25
Generically convert thrown exceptions to an Either
/**
* Catch exceptions to create an `Either` value.
*
* Useful when you want to deal an API that reports failure conditions using
* exceptions. This method allows catching exceptions and converting them to
* `Left` values.
*
* An advantage vs using `scala.util.Try` is that you have full control over
* which exceptions are caught.
*
@quelgar
quelgar / gist:2497604
Created April 26, 2012 08:24
sbt setting to not check scala-tools
externalResolvers <<= resolvers map { rs =>
Resolver.withDefaultResolvers(rs, scalaTools = false)
}
@quelgar
quelgar / LensURI.scala
Last active December 18, 2015 17:39
Using Lenses with java.net.URI.
import java.net.URI
/**
* State co-monad.
*
* `Store[F, _]` is the co-monad.
*/
final case class Store[F, R](get: F, set: F => R) {
def map[S](f: R => S): Store[F, S] = Store(get, f compose set)
@quelgar
quelgar / most.hs
Created September 26, 2013 01:35
Find the most frequently occurring item that occurs more than once. Idea from http://skipoleschris.blogspot.com.au/2010/11/functional-programming-challenge-most.html
import qualified Data.Map as Map
-- Find the most frequently occurring item that occurs more than once
-- Idea from http://skipoleschris.blogspot.com.au/2010/11/functional-programming-challenge-most.html
most :: Ord a => [a] -> Maybe a
most xs = fst $ foldl most' (Nothing, Map.empty) xs where
most' (winning, seen) x = (winning', seen') where
winning' = if count > winningCount then Just x else winning
import java.util.*;
import java.util.stream.Stream;
/**
* Find the most frequently occurring item that occurs more than once.
* Idea from http://skipoleschris.blogspot.com.au/2010/11/functional-programming-challenge-most.html
*/
public final class Most {
@quelgar
quelgar / gist:8515708
Created January 20, 2014 06:11
The unconstructable Scala class. If you can figure out how to successfully construct an instance of the class Outer, please let me know how.
final case class Outer(inner: Outer#Inner) {
final case class Inner(a: String)
}