Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
thatrubylove / lispy-ruby-example-1.rb
Created April 30, 2014 04:35
LISPy code as data in ruby
# 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!
@marcusoftnet
marcusoftnet / url.sh
Created March 29, 2014 12:36
Adding users with CURL
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
@marcusoftnet
marcusoftnet / koaStorePostedData.js
Created March 29, 2014 12:35
Post and get data from Mongo via Koa
// 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');
@tj
tj / coros.rb
Last active August 29, 2015 13:55
def receive(co)
let status, val = coroutine.resume(co)
return val
end
def send(x)
coroutine.yield(x)
end
'use strict'
koa = require 'koa'
app = koa()
router = require 'koa-router'
logger = (format = ':method :url') ->
return (next) ->*
str = format
.replace(':method', @method)
@mrb
mrb / constraint.lisp
Created January 8, 2014 03:53
"Logic Programming in Lisp" from Luger and Stubblefield
;;; 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.
# 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
############
#############
#### #####
#####
####
#### Functional Programming
#####
####### in Ruby
#########
##########
class Shoot
def initialize
@kick = 1 + rand(6)
end
def result
@kick * 0.2
end
def goal?
class FizzBuzz
def fizz
loop do
["", "", "Fizz"].each{|s| yield s}
end
end
def buzz
loop do
["", "", "", "", "Buzz"].each{|s| yield s}