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
solveRPN :: String -> Float | |
solveRPN = head . foldl ff [] . words | |
where ff (x:y:ys) "*" = (x * y):ys | |
ff (x:y:ys) "+" = (x + y):ys | |
ff (x:y:ys) "-" = (y - x):ys | |
ff (x:y:ys) "/" = (y / x):ys | |
ff (x:y:ys) "^" = (y ** x):ys | |
ff (x:y:ys) "log" = (logBase x y):ys | |
ff (x:xs) "ln" = log x:xs | |
ff xs "sum" = [sum xs] |
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
$ ruby duopaste.rb | |
== Sinatra/1.0 has taken the stage on 4567 for development with backup from Mongrel |
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
require 'duopaste' | |
run Sinatra::Application |
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
get '/' do | |
erb :new | |
end | |
post '/' do | |
@paste = Paste.new(:body => params[:paste]) | |
if @paste.save | |
redirect "#{@paste.id}" | |
else | |
redirect '/' |
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
<div class="snippet"> | |
<div><%= @snippet.body %></div> | |
<br/><a href="/">Ajouter un snippet</a> | |
</div> |
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
<div class="snippet"> | |
<form action="/" method="POST"> | |
<textarea name="paste" id="snippet_body" rows="20"></textarea> | |
<br/><input type="submit" value="Save"/> | |
</form> | |
</div> |
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
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/duopaste.sqlite3") | |
class Paste | |
include DataMapper::Resource | |
property :id, Serial | |
property :body, Text, :required => true | |
end | |
DataMapper.auto_upgrade! |
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
require 'dm-core' | |
require 'dm-validations' | |
require 'dm-migrations' |
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
get '/' do | |
erb :new | |
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
require 'rubygems' | |
require 'sinatra' |
NewerOlder