Skip to content

Instantly share code, notes, and snippets.

@adomokos
adomokos / keybase.md
Created April 9, 2019 20:22
Keybase Proof

Keybase proof

I hereby claim:

  • I am adomokos on github.
  • I am adomokos (https://keybase.io/adomokos) on keybase.
  • I have a public key ASA8JcfM-KoBRcr5g7J-bADE-azTB3JtbjP0B6yn84UXygo

To claim this, I am signing this object:

@adomokos
adomokos / RomanNumeralsSpec.hs
Created April 26, 2017 04:42
The Roman Numerals kata in Haskell
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import qualified Data.Map as Map
import Data.List
mapping :: Map.Map Int String
mapping = Map.fromList [
(1, "I"),
(4, "IV"),
@adomokos
adomokos / type_vs_data_constructors.md
Created April 5, 2017 02:18
Type vs Data Constructors in Haskell

Type vs Data Constructors

In a data declaration, a type constructor is the thing on the left hand side of the equals sign. The data constructor(s) are the things on the right hand side of the equals sign. You use type constructors where a type is expected, and you use data constructors where a value is expected.

Data constructors

To make things simple, we can start with an example of a type that represents a colour.

data Colour = Red | Green | Blue
@adomokos
adomokos / string_calculator_test.go
Created January 5, 2017 03:42
String Calculator in Go
package string_calculator
import (
"github.com/stretchr/testify/assert"
"strconv"
"strings"
"testing"
)
func Convert(params ...string) int {
@adomokos
adomokos / string_calculator.hs
Created July 14, 2016 17:44
String Calculator in Haskell
module StringCalculator where
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import Data.List.Split (splitOn)
calculator' :: String -> Char -> Integer
calculator' x c = sum $ coerceString x c
@adomokos
adomokos / Makefile
Last active February 18, 2020 00:21
Makefile template
DBUSER=db_user
DBPASSWD=db_password
DBNAME=some_db
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.DEFAULT_GOAL := help
build-db: ## Builds the DB
dropdb --if-exists --username $(DBUSER) $(DBNAME)
(ns change-maker.core-test
(:require [clojure.test :refer :all]))
(def ^:dynamic *denominations* [25 10 5 1])
(defn best-match [value]
(first (filter #(<= % value) *denominations*)))
(defn calculate-change [value product]
(let [reducer (best-match value)]
@adomokos
adomokos / core_test.clj
Created May 15, 2015 18:53
Solving the Roman Numeral Kata in Clojure
(ns roman-numerals.core-test
(:require [clojure.test :refer :all]))
(def mapping {
0 ""
1 "I"
4 "IV"
5 "V"
9 "IX"
10 "X"
@adomokos
adomokos / string_calculator_spec.rb
Last active August 29, 2015 14:12
String Calculator Kata in Ruby - using enumerable methods
# Solving the String Calculator Kata
# http://osherove.com/tdd-kata-1/
class StringCalculator
def self.add(numbers)
return 0 if numbers.empty?
numbers.split(",").map(&:to_i).reduce(:+)
#splitted_array = numbers.split(",")
@adomokos
adomokos / group_by_spec.rb
Created March 5, 2014 04:12
Recognizing Ruby's group_by in the imperative code
class Location
attr_reader :city, :user
def initialize(city, user)
@city = city
@user = user
end
end
class User
attr_reader :name