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 MyServer.Routes (route) where | |
import FictitiousRoutingLib | |
-- Can't decide if I'd rather embed this into do-notation or just use lists; seems like the type param | |
-- ends up being a phantom type in the end? | |
route :: HttpRouter x | |
route = do | |
-- one thing you always want is static serving of files: | |
dom "static.myapp.example.com" % staticServe "/var/www/staticAssets" | |
-- maybe also `(excludePatterns [] $ staticServe "...")` to specify "these things shall never be served from that dir." |
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
"use strict"; | |
/* This is mostly just an example workflow to illustrate how a combination of ES6 generators and promises | |
* fully allow you to write your asynchronous workflow in a single synchronous-looking block. | |
* | |
* Unlike most such workflows which give you a really short snippet that can hide all of the thornier | |
* problems, this one is approximated from some of my work at IntegriShield: this is all of the real | |
* stuff that an actual daemon might have to do: manage a queue or three of concurrent workloads; load | |
* each item of each queue in order; make a bunch of concurrent requests on each item; preprocess each | |
* of these requests; save preprocessed results to a cache in the database; if all of them have completed | |
* successfully, report success, or else report failure. |
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
This example comes from the Wikipedia article: | |
https://en.wikipedia.org/wiki/Visitor_pattern | |
Our first indication of complexity is the fact that the MyInterface[] array requires rank 2 types: | |
> {-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies #-} | |
The multiparam type class and functional dependency is not part of the Wikipedia article proper, | |
and instead come because I saw myself writing an expression like: |
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
Custom guards in Haskell | |
======================== | |
In 2007, people changed their programming interview questions from complicated IQ-style questions to the new "FizzBuzz" style: give them a task which should be absurdly easy if you have ever programmed anything, but with one or two essential complications to prove that they have thought through the idea. The canonical example is: | |
* Write a program which prints the numbers from 1 to 100 in order, except instead of any number divisible by 3 it prints "Fizz" and instead of any number divisible by 5 it prints "Buzz". (When a number is divisible by both, it should print "FizzBuzz".) | |
This query tests for familiarity with the environment (e.g. in JavaScript you'll have to "print" to the DOM) and basic mathematics (what does "divisible" mean?) and logic (since it's not immediately in an if / else if / else format), but we assume that if you can do these things then you can do anything. | |
Some of the cooler answers use fall-through: |
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
-- Golden pair data type; GP x y represents x + y phi where phi ** 2 = 1 - phi | |
data GoldenPair = GP { r :: Integer, phi :: Integer } deriving (Eq, Show) | |
-- (a + b phi) * (1 + 1 phi) = (a + b) + a phi so we have the Fibonacci relation directly. | |
instance Num GoldenPair where | |
(GP a b) + (GP c d) = GP (a + c) (b + d) | |
(GP a b) * (GP c d) = GP (k + b*d) (k - (a - b)*(c - d)) where k = a*c | |
fromInteger x = GP x 0 |
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
// ==UserScript== | |
// @name Hacker News Comment Hiding | |
// @namespace http://drostie.org/ | |
// @include https://news.ycombinator.com/item?id=* | |
// @include http://news.ycombinator.com/item?id=* | |
// ==/UserScript== | |
function repeat(element, selector, n) { | |
return n <= 0 ? element : repeat(element[selector], selector, n - 1); | |
} |
NewerOlder