This file contains 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
-- Haskell Types | |
type Id = Int | |
type Title = String | |
type Author = String | |
data Book = Book Id Title Author | |
deriving (Eq, Show) | |
bookID :: Book -> Int |
This file contains 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
# A Binary Search Tree implementation in Ruby | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
# ======================================== | |
# | |
# 1 | |
# / \ | |
# / \ |
This file contains 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
# Returns new hash and leaves original as is | |
def select_from_param(hash, *args) | |
{}.tap do |result| | |
hash.each {|k, v| result[k] = v if args.include?(k)} | |
end | |
end | |
@model.update_attributes(select_from_param(params, :id, :email)) |
This file contains 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 BinaryTree | |
where | |
-- Haskell Binary Tree Examples | |
-- A binary tree can either be empty or a node with a left and right branch | |
data Tree a = EmptyTree | Node a (Tree a) (Tree a) | |
deriving ( Show, Read, Eq ) |
This file contains 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
(ns forward.lib.validation | |
(:refer-clojure :exclude [])) | |
;; Generic map validation library | |
(def m | |
{:first_name "jack" | |
:last_name "dorsey" | |
:password "twitter" | |
:age 25}) |
This file contains 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
(* Unbalanced Binary Tree *) | |
type 'a tree = | |
Node of 'a * 'a tree * 'a tree | |
| Leaf;; | |
(* e.g Node (5, Leaf, Leaf) *) | |
(* val insert : ’a -> ’a btree -> ’a btree = <fun> *) | |
let insert x s = Node (x, Leaf, s);; |
This file contains 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
(ns forward.views.helpers) | |
;; View helper functions | |
(defn flash-messages | |
"Show flash messages if they exist in a request" | |
[req] | |
(declare flash-message) | |
(if-let [flash-message (:flash req)] | |
[:div {:id "error_explanation"} |
This file contains 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 following implementation of rb-tree is based on http://www.cs.kent.ac.uk/people/staff/smk/redblack/. | |
(defun change-to-black (tree) | |
(pattern-match tree | |
((:pattern (_ . rest) :variable rest :ignore _) `(:B . ,rest)) | |
(:otherwise nil))) | |
(defun rb-insert (tree obj cmp) | |
(change-to-black (rb-insert% tree obj cmp))) |
This file contains 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
import qualified Data.Map as M | |
import Control.Applicative | |
import Data.Maybe (mapMaybe) | |
-- A BK-Tree is has a root word and more trees connected to it with branches of | |
-- lengths equal to the Levenshtein distance between their root words (i.e. an | |
-- n-ary tree). | |
data BKTree s = BKTree s (M.Map Int (BKTree s)) | Empty deriving (Show) | |
-- Inserting a word is done by inserting it along a branch of lenght |
This file contains 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
(*************************************** | |
Binary Search Trees | |
***************************************) | |
(* insert delete inorder search min max *) | |
type 'a binary_tree = | |
(* A root node and a left and right sub tree *) |