Skip to content

Instantly share code, notes, and snippets.

View Norwae's full-sized avatar

Norwae

View GitHub Profile
@Norwae
Norwae / go.mod
Created April 4, 2019 14:26
Basic go.mod file
module deadmod
go 1.11
require (
github.com/kr/pretty v0.1.0 // indirect
github.com/satori/go.uuid v1.2.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
@Norwae
Norwae / handler.go
Last active April 4, 2019 14:37
GCP Functions - HandleHTTP
type StatusCodeError struct {
StatusCode int
Message string
}
func (ue *StatusCodeError) Error() string {
return ue.Message
}
var notFound = StatusCodeError{http.StatusNotFound, "The requested URL could not be found"}
package experiment
import akka.actor.ActorSystem
import akka.util.Timeout
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import spray.http.HttpHeaders.Accept
import spray.http.MediaTypes._
import spray.http.{ContentType, HttpResponse}
import spray.httpx.marshalling.{ToResponseMarshaller, ToResponseMarshallingContext}
@Norwae
Norwae / Moo.scala
Last active August 29, 2015 14:25
Reusable bit of js code
package com.github.norwae.util
import javax.script.{Invocable, ScriptEngineManager}
object Moo extends App {
val script = "input.sub.structure <= 12"
val escaped = script.replace("'", "\\'")
val factory = new ScriptEngineManager()
@Norwae
Norwae / Roman.hs
Last active August 29, 2015 14:21
Roman numerals (how I wanted it to work...)
data PseudoDigit = PseudoDigit {
value :: Int,
display :: String
} deriving Show
digits = [ PseudoDigit 1000 "M", PseudoDigit 900 "CM", PseudoDigit 500 "D", PseudoDigit 400 "CD", PseudoDigit 100 "C", PseudoDigit 90 "XC",
PseudoDigit 50 "L", PseudoDigit 40 "XL", PseudoDigit 10 "X", PseudoDigit 9 "IX", PseudoDigit 5 "V", PseudoDigit 4 "IV", PseudoDigit 1 "I"]
highestDigit x = head $ filter (\p -> x >= value p) digits
The origin of the question is http://stackoverflow.com/q/25949977/3185992 where user Sri asked about a problem he had.
The problem is not that hard to solve, but the answers got me concerned that there must be a more elegant way of doing this.
I wanted something with meaningful intermediate results, which is composable and not some nested for loops which at the end will result in the right thing.
Problem description:
====================
Given two strings compute the count of characters which are not common in both of them.
However each character "counts of its own", that is if a character is included in the first string 2 times and a single time in the second one, the right answer for this character is: 1.
Example from the user:
module Attaxx (Coordinate, Move(..), CellState(..), Board, get, initial, moves, movesFor, applyMove, indices, neighbours) where
import Data.Array hiding (indices)
import Data.Maybe
import Data.Char
import Prelude
data Coordinate = Coordinate { x:: Int, y :: Int} deriving (Show, Eq, Ord, Ix)
data ShortDirection = ShortNW | ShortN | ShortNE | ShortW | ShortE | ShortSW | ShortS | ShortSE deriving (Enum, Show)
data LongDirection = LongNW | LongNNW | LongN | LongNNE | LongNE | LongWNW | LongENE | LongW | LongE | LongWSW | LongESE | LongSW | LongSSW | LongS | LongSSE | LongSE deriving (Enum, Show)