Skip to content

Instantly share code, notes, and snippets.

View davidkaste's full-sized avatar

David Castellà davidkaste

View GitHub Profile
@davidkaste
davidkaste / roll.hs
Created April 12, 2018 10:46
Dice roll utility made in Haskell
-- roll.hs a dice rolling shell utility
-- David Castellà 'kaste' <[email protected]>
import Data.List.Split
import Data.List
import Data.Char
import System.Random
import Control.Monad
import Control.Arrow
import Options.Applicative
module ExampleReader where
import Control.Monad.Reader
data Person = Pr { name :: String,
age :: Integer,
address :: String }
type PersonReader = Reader Person String
@davidkaste
davidkaste / BinTree.hs
Last active April 26, 2022 16:55
Haskell binary search tree
module BinTree where
data BinTree a = Leaf
| Node (BinTree a) a (BinTree a)
instance Show a => Show (Tree a) where
show Leaf = "Leaf"
show (Node lt x rt) = "(" ++ show lt ++ " " ++ show x ++ " " ++ show rt ++ ")"
-- Tree is a Functor
@davidkaste
davidkaste / fibonacci.clj
Last active March 2, 2016 09:01
Some examples of how to get the 15 first fibonacci numbers in Clojure
; Classic recursion
(defn fibo [n]
(if (or (= n 0) (= n 1))
n
(+ (fibo (dec n)) (fibo (- n 2)))))
(map fibo (range 15))
; Tail-call recursion
(defn fibo2 [n]
@davidkaste
davidkaste / tempServer.ino
Last active August 29, 2015 14:02
Web server to get temperature and id with Arduino
#include <SerialGraphicLCD.h>//inculde the Serial Graphic LCD library
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0x7F, 0xC2 };
IPAddress ip(192,168,1,177);
@davidkaste
davidkaste / btmon.ino
Last active August 29, 2015 14:01
Bluetooth temperature monitor
/*
* Author: David Castellà <d.castella.85 at gmail dot com>
* Sketch title: Bluetooth temperature monitor
* Sketch filename: btmon.ino
* Date: 2014/05/21
* Version: 0.1
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@davidkaste
davidkaste / rps.clj
Created March 15, 2012 16:11
RPS game based on nested vectors. Written in Clojure
(defn rpswinner
[match]
(if (= ((match 0) 1) ((match 1) 1))
(match 0)
(if (and (= ((match 0) 1) "R") (= ((match 1) 1) "P"))
(match 1)
(if (and (= ((match 0) 1) "P") (= ((match 1) 1) "S"))
(match 1)
(if (and (= ((match 0) 1) "S") (= ((match 1) 1) "R"))
(match 1)