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
require "test/unit" | |
class Array | |
def fifo | |
verbrauch = inject(0) {|sum, el| sum+=el.abs if el < 0; sum } | |
res = select{|el| el > 0}.inject([]) do |result, el| | |
if el > verbrauch | |
result << (el - verbrauch) | |
verbrauch = 0 | |
else |
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
# --------------------------------- | |
# Simple LIFO, FIFO Functions | |
# written in CoffeeScript | |
# --------------------------------- | |
verbrauch = (arr, menge) -> | |
res= [] | |
for el in arr | |
if el >= 0 | |
if el > menge |
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
require "test/unit" | |
class Array | |
def fifo | |
verbrauch = inject(0) {|sum, el| sum+=el.abs if el < 0; sum } | |
res = select{|el| el > 0}.inject([]) do |result, el| | |
if el > verbrauch | |
result << (el - verbrauch) | |
verbrauch = 0 | |
else |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
gem 'rack', '=0.9.1' | |
gem 'thin', '=1.0.0' | |
require 'sinatra' | |
get '/' do | |
content_type 'text/plain' | |
"Hello, world" | |
end |
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
# by Matt Sears | |
# http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks | |
class Proc | |
def callback(callable, *args) | |
self === Class.new do | |
method_name = callable.to_sym | |
define_method(method_name) { |&block| block.nil? ? true : block.call(*args) } | |
define_method("#{method_name}?") { true } | |
def method_missing(method_name, *args, &block) false; end |