Skip to content

Instantly share code, notes, and snippets.

View robotlolita's full-sized avatar
🐴
everything happens so much oh no

Quil robotlolita

🐴
everything happens so much oh no
View GitHub Profile
@robotlolita
robotlolita / 0-instructions.md
Last active August 29, 2015 14:00
BECAUSE TYPE SYSTEMS ARE SUPPOSED TO RUN COMPUTATIONS!!1!1!

Write a program in your favourite programming language to compute the sum of the first N even numbers in the Fibonacci sequence, then display the sum of its digits.

E.g.: Where N = 5, the answer is 17, since:

  1. The Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...;
  2. The first 5 even numbers are 0, 2, 8, 34, and 144;
  3. The sum of these numbers is 188;
  4. The sum of the digits of this answer is 17 (1 + 8 + 8).
@robotlolita
robotlolita / sum-digits.hm.hs
Last active August 29, 2015 14:00
sum digits in Harmonia
module Fib using: Platform where
open Platform Prelude expose [+, parse, as-string, ~]
open Platform List expose [zip:using:, map:, take:, filter:, sum]
open Platform IO expose [read-line, print]
-- Typing things is currently cumbersome, but the type inference algorithm should catch 90% of this
let (Num a) => String -> a ::
x as-number = x parse
@robotlolita
robotlolita / index.js
Last active August 29, 2015 14:00
Monadic wrapper for Express API
var express = require('express')
var app = require('./wrapper')(express())
require('./routes')(app)
app.listen(8080)
console.log('Listening on http://localhost:8080')
@robotlolita
robotlolita / web.java
Last active August 29, 2015 13:59
Java web vs Phemme
package something;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
@WebServlet("/")
@robotlolita
robotlolita / pressed.elm
Created February 11, 2014 00:48
Shows different text than what was pressed
import Char
import Keyboard
import String
toString char = String.cons (Char.fromCode char) ""
typed text = plainText "You typed: " `beside` asText text
transformed text = plainText "I'll show you: " `beside` (asText . String.reverse <| text)
data Maybe a = Nothing | Just: a
Nothing map: transform => Nothing
(Just: a) map: transform => Just: a transform
type Named a = {a | name: String }
{- { name: String, age: Int } -}
function flatMap(f, xs) {
return xs.reduce(function(ys, x){ return ys.concat(f(x)) }, [])
}
function ap(fs, ys) {
return flatMap(function(f){ return ys.map(f) }, fs)
}
function inverses(a){
return [a, -a]
// Frees the `[].slice` method to accept `this` as the first actual argument,
// rather than a special argument.
var toArray = Function.call.bind([].slice)
// To make searching efficient (O(1)), we switch the
// list of things to a HashMap, which allows we to
// retrieve an item by its name in constant time.
function indexBy(field, list) {
return list.reduce(function(result, item) {
result[item[field]] = item
function evaluate(ast){
return ast.reduce(function(result, a){ return compute(a, result) }, [])
}
function parse(input){
return input.trim().split(/\s+/)
}
function compute(a, stack) {
return a === '+'? concat(stack, pop(stack) + pop(stack))
var poly = require('polygamous')
var processSite = poly(function(data){ return normalise(data.url) })
processSite.when('http://...', function(data) {
return 'Wow'
})
processSite.when('http://blah', function(data) {
return 'Amaze'