Skip to content

Instantly share code, notes, and snippets.

next' n x = (x + n / x) / 2
-- [a0, f a0, f(f a0), f(f(f a0)), …]
repeat' f a = a : repeat' f (f a)
-- get approximations for square root of n by repeat' (next' n) a0
within' (eps a1:a2:rest)
| abs(a1 – a2) < eps = a2
| otherwise = within' eps (a2:rest)
@ryanivandsouza
ryanivandsouza / whyfp-higher-order.clj
Last active December 25, 2020 05:16
Why FP Matters - Part 2 🎈 - Higher-order Functions
;; Clojure
;; fold' f a [] = a
;; fold' f a (x:xs) = f x (fold' f a xs)
(defn fold' [f a xs]
(if (empty? xs)
a
(f (first xs) (fold' f a (rest xs)))))
;; sum'' = fold' (+) 0
labelsTree' numberNodes
-----------------------------------------------------------------
labelsTree' (Node 1 [Node 2 [Node 4 []], Node 5 []])
-----------------------------------------------------------------
foldtree' (:) (++) [] (Node 1 [Node 2 [Node 4 []], Node 5 []])
-----------------------------------------------------------------
foldnode' (:) (++) [] (Node 1 [Node 2 [Node 4 []], Node 5 []])
-----------------------------------------------------------------
(+) 1 (foldnodes' (:) (++) [] [Node 2 [Node 4 []], Node 5 []])
-----------------------------------------------------------------
func (host *Host) acceptRequest(philosopher *Philosopher, requestID int, wg *sync.WaitGroup) {
go func() {
<-host.servingAvailable
philosopher.eat()
}()
go func() {
<-philosopher.eatingEnded
host.servingAvailable <- "serving available"
wg.Done()
@ryanivandsouza
ryanivandsouza / cloudSettings
Last active June 9, 2018 07:11
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-06-09T06:57:16.462Z","extensionVersion":"v2.9.2"}
choco install -y googlechrome
choco install -y firefox
choco install -y 7zip.install
choco install -y notepadplusplus.install
choco install -y vlc
choco install -y autohotkey.portable
choco install -y nodejs.install
choco install -y git.install
choco install -y skype
choco install -y jdk8
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/5.0.5/react-redux.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/expect/umd/expect.min.js"></script>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>