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
fs = require 'fs' | |
class MyClass | |
# Trying to create middleware with access to class members. | |
withData: (cb) -> | |
return cb @__data if @__data? | |
fs.readFile 'datafile.json', (err, json) => | |
throw err if err? | |
@__data = JSON.parse json |
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
web: node server.js |
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
findRoots 0 b c = Nothing | |
findRoots a b c = Just ((-b + d) / 2*a, (-b - d) / 2*a) | |
where d = sqrt (b^2 - 4*a*c) | |
main = print (findRoots 1 6 8) |
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
-- findRoots is a function that takes 3 Doubles and maybe returns a tuple of doubles. | |
-- Here's its signature, which can be omitted because Haskell infers it: | |
findRoots :: Double -> Double -> Double -> Maybe (Double, Double) | |
-- In a C-like language with parameterized types, the type signature might look like: | |
-- | |
-- static Maybe<Tuple<double,double>> findRoots(double a, double b, double c); | |
-- | |
-- Maybe is Haskell's 'nullable type'; values of type Maybe t can be thought of as lists | |
-- containing exactly zero or one value of type t. So, a Maybe Double is either zero or |
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
// Register an API key in your AppDelegate's FinsihedLaunching method: | |
// GMSServices.ProvideAPIKey ("Your API key."); | |
GMSMapView mapView; | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// Create the map view, framing Xamarin headquarters |
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
// Demo: | |
// | |
// let files = sh "ls -a /Users/david" |> lines | |
// let install = sh "cp -r %s /Applications" | |
// install "/Volumes/Awareness/Awareness.app" | |
// | |
module Campari.Shell | |
open System |
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
// I see this a lot in F# code: | |
control.OnClick.Add (fun _ -> | |
printfn "%A was clicked" control | |
) | |
// The entire lamda is parenthesized so it can be | |
// passed to Add, resulting in an ugly, dangling ')'. | |
// F# has a reverse pipeline operator called <| that's |
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 FizzBuzz = | |
FizzBuzz | Fizz | Buzz | Nat of int | |
let (|DivisibleBy|_|) by n = | |
if n % by = 0 then Some () else None | |
let fizzbuzz n = match n with | |
| DivisibleBy 3 & DivisibleBy 5 -> FizzBuzz | |
| DivisibleBy 3 -> Fizz | |
| DivisibleBy 5 -> Buzz |
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
public static class RectangleExtensions | |
{ | |
public static RectangleF With (this RectangleF self, | |
float? X = null, float? Y = null, | |
float? Width = null, float? Height = null) | |
{ | |
return new RectangleF (X ?? self.X, Y ?? self.Y, Width ?? self.Width, Height ?? self.Height); | |
} | |
static T Id<T> (T t) { return t; } |
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
#r "Volare.dll" | |
open Volare | |
get "/" <| fun req res -> | |
"Hello, world!" | |
get "/:name" <| fun req res -> | |
html <| fun _ -> | |
body <| fun _ -> |