Skip to content

Instantly share code, notes, and snippets.

View noelmarkham's full-sized avatar

Noel Markham noelmarkham

  • 47 Degrees
View GitHub Profile
@helenwilliamson
helenwilliamson / gist:eacf7e87a9b9c7888f24
Created October 16, 2014 21:19
Scala Dojo on 16th October
import java.io.File
import scala.io.Source
object MarkovChainApp extends App {
val tokenisedText = Source.fromFile(new File(args(0))).mkString.split(" ").map(_.trim)
val wordMap : Map[String, List[String]] = tokenisedText.sliding(2).foldLeft(Map[String, List[String]]().withDefaultValue(List.empty[String])) {
(dict, words) => {
dict.updated(words(0), words(1) :: dict(words(0)) )
@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@seanparsons
seanparsons / gist:7005543
Created October 16, 2013 10:08
Stacking ReaderT and OptionT.
import scalaz._,Scalaz._,scalaz.effect._,OptionT._,Kleisli._
type OptionTIO[+X] = OptionT[IO, X]
val reader1: ReaderT[Option, Int, String] = kleisli[Option, Int, String](n => n.toString.some)
val reader2: ReaderT[IO, Int, String] = kleisli[IO, Int, String](n => IO((n * 2).toString))
val convertedReader1: ReaderT[OptionTIO, Int, String] = reader1.mapK[OptionTIO, String](opt => optionT(IO(opt)))
val convertedReader2: ReaderT[OptionTIO, Int, String] = reader2.mapK[OptionTIO, String](io => io.liftM[OptionT])
@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active July 10, 2024 14:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@markhibberd
markhibberd / characters.md
Last active January 14, 2021 18:32
Haskell Character Data

Overview

There are lots of representations for strings. In most languages they pick one set of tradeoffs and run with it. In haskell the "default" implementation (at least the one in the prelude) is a pretty bad choice, but unlike most other languages (really) good implementations exist for pretty much every way you can twist these things. This can be a good thing, but it also leads to confusion, and frustration to find the right types and how to convert them.

Types

@seanparsons
seanparsons / gist:3761731
Created September 21, 2012 14:23
Playing with lenses.
// Note this requires scalaz-core 7.0 added to the classpath.
import scalaz._
import Scalaz._
import Lens._
case class Address(street: String, country: String)
case class User(name: String, address: Address)
val address = Address("Monkey Street", "England")
val user = User("Sean", address)
@codahale
codahale / pom.xml
Last active April 20, 2024 01:38
Take this and save it as pom.xml in your project directory.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- none yet -->
@nazgob
nazgob / ctags.setup
Created January 6, 2012 13:44
ctags setup on mac
# you have ctags but it does not work...
$ ctags -R --exclude=.git --exclude=log *
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
#you need to get new ctags, i recommend homebrew but anything will work
$ brew install ctags
#alias ctags if you used homebrew
$ alias ctags="`brew --prefix`/bin/ctags"
@xuwei-k
xuwei-k / build.sbt
Created December 19, 2011 11:45
auto enable power mode sbt console
initialCommands in console := {
"""
scala.tools.nsc.interpreter.replProps.power.enable
scala.concurrent.ops.spawn{
Thread.sleep(5000)
scala.tools.nsc.interpreter.replProps.power.disable
print("\nreset\nscala> ")
}
"""
}