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
let fibonacci n = | |
let rec loop current a b = | |
if current == n | |
then a + b | |
else loop (current+1) b (a+b) | |
match n with | |
| 0 -> 0 | |
| 1 -> 1 | |
| _ -> loop 2 0 1 |
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
let fibonacci n = | |
let rec fib_cps n cont = | |
match n with | |
| 0 -> (cont 0) // <-- even the base cases need to keep the promise | |
| 1 -> (cont 1) | |
| _ -> (fib_cps (n-1) (fun a -> fib_cps (n-2) (fun b -> cont(a+b)) ) ) | |
fib_cps n (fun x -> x) // <- this anon function is our base continuation |
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
-- Socket based network library | |
-- http://www.haskell.org/ghc/docs/6.10.4/html/libraries/network/Network-Socket.html | |
import Network.Socket | |
-- System io calls. Posix based | |
-- http://lambda.haskell.org/hp-tmp/docs/2011.2.0.0/ghc-doc/libraries/haskell2010-1.0.0.0/System-IO.html | |
import System.IO |
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
def using(object, message, *args) | |
begin | |
yield if block_given? | |
ensure | |
object.send(message, *args) | |
end | |
obj = SomthingToClose.connect |
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
// Adapted from http://igstan.ro/posts/2011-05-02-understanding-monads-with-javascript.html | |
type StackResult = {value: int; stack: int list} | |
let push element stack = | |
{value= element; stack = element :: stack} | |
let pop stack = | |
{value= (List.head stack); stack = (List.tail stack)} | |
let bind operation continuation stack = | |
let r = operation stack |
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 Fizzable = Plain of int | |
| Fizzy | |
| Buzzy | |
| FizzyBuzzy | |
let toFizzable n :Fizzable = | |
match n with | |
| _ when (n % 3) = 0 && n % 5 = 0 -> FizzyBuzzy | |
| _ when n % 3 = 0 -> Fizzy | |
| _ when 0 = n % 5 -> Buzzy |
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 Frame = StandardFrame of int * int | |
| SpareFrame of int * int | |
| StrikeFrame | |
type Game = Frame list | |
let score game = | |
let nextRoll frames = | |
match frames with | |
| [] -> 0 | |
| StandardFrame(a,_)::_ -> a |
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
namespace MyApplication { | |
public partial class MainWindow | |
{ | |
private readonly ViewModel _vm; | |
private bool _close; | |
public MainWindow() | |
{ | |
InitializeComponent(); |
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
(defn zero-pad [n number-string] | |
(->> | |
(concat (reverse number-string) (repeat \0)) | |
(take n) | |
reverse | |
(apply str))) | |
(defn prefix [file-name] | |
(str "ns" (clojure.string/replace file-name #"^\d+" #(pad 3 %)))) |
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
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script> | |
<script type="application/javascript"> | |
$(document).ready(function(e){ | |
$("button.delete").click(function(){ | |
var org_name = $(this).parents("tr") | |
.children("td:first-child").html(); | |
alert(org_name); | |
}); |