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
# treating a function as data | |
putter = ->(message) { puts message } | |
def deliver_message(message, handler) | |
handler.(message) | |
end | |
deliver_message("Hello, code as data!", putter) | |
# => Hello, code as data! |
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
curl -X POST -H "Content-Type: application/json" -d '{"username":"marcusoft.net@gmail.com","password":"xyz"}' http://localhost:3000/user -v | |
curl -X POST -H "Content-Type: application/json" -d '{"username":"hugo@gmail.com","password":"xyz^2"}' http://localhost:3000/user -v | |
curl -X POST -H "Content-Type: application/json" -d '{"username":"abbe@gmail.com","password":"zyx"}' http://localhost:3000/user -v |
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
// Create the application | |
var koa = require('koa'); | |
var route = require('koa-route'); | |
var parse = require('co-body'); | |
var app = module.exports = koa(); | |
// Get monk up an running | |
var monk = require('monk'); | |
var wrap = require('co-monk'); | |
var db = monk('localhost/koausers'); |
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
def receive(co) | |
let status, val = coroutine.resume(co) | |
return val | |
end | |
def send(x) | |
coroutine.yield(x) | |
end |
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' | |
koa = require 'koa' | |
app = koa() | |
router = require 'koa-router' | |
logger = (format = ':method :url') -> | |
return (next) ->* | |
str = format | |
.replace(':method', @method) |
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 is one of the example programs from the textbook: | |
;;; | |
;;; Artificial Intelligence: | |
;;; Structures and strategies for complex problem solving | |
;;; | |
;;; by George F. Luger and William A. Stubblefield | |
;;; | |
;;; These programs are copyrighted by Benjamin/Cummings Publishers. | |
;;; | |
;;; We offer them for use, free of charge, for educational purposes only. |
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
# pnodes => path | |
# ppath => parent | |
class Zipper | |
attr_reader :parent, :path, :node, :lefts, :rights, :at_end | |
def initialize(branch, children, make_node, node, lefts = nil, path = nil, parent = nil, rights = nil, changed = false, at_end = false) | |
@branch = branch | |
@children = children | |
@make_node = make_node |
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
############ | |
############# | |
#### ##### | |
##### | |
#### | |
#### Functional Programming | |
##### | |
####### in Ruby | |
######### | |
########## |
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
class Shoot | |
def initialize | |
@kick = 1 + rand(6) | |
end | |
def result | |
@kick * 0.2 | |
end | |
def goal? |
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
class FizzBuzz | |
def fizz | |
loop do | |
["", "", "Fizz"].each{|s| yield s} | |
end | |
end | |
def buzz | |
loop do | |
["", "", "", "", "Buzz"].each{|s| yield s} |
NewerOlder