This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var store *datastore.Client | |
| func init() { | |
| projectId := os.Getenv("GCP_PROJECT") | |
| client, err := datastore.NewClient(context.Background(), projectId) | |
| if err != nil { | |
| log.Fatalf("Could not create datastore client: %v", err) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Kind = "DMT" | |
| type DeadMansTrigger struct { | |
| Id string `json:"id" datastore:",noindex"` | |
| DueToFire time.Time `json:"due"` | |
| HoursBetweenFire int `json:"hoursBetweenFire" datastore:",noindex"` | |
| Checkins []time.Time `json:"checkins" datastore:",noindex"` | |
| FireURL string `json:"fireURL" datastore:",noindex"` | |
| FirePayload string `json:"firePayload" datastore:",noindex"` | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var baseURL string | |
| func init() { | |
| // unfortunately, there seems to be no simple env property reporting the unmangled invocations URL, so | |
| // we build it from its parts | |
| projectId := os.Getenv("GCP_PROJECT") | |
| region := os.Getenv("FUNCTION_REGION") | |
| name := os.Getenv("FUNCTION_NAME") | |
| baseURL = fmt.Sprint("https://", region, "-", projectId, ".cloudfunctions.net/", name) |
OlderNewer