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
# Using MigLayout as frankly Javax Swing without a decent GUI | |
# tool is really a nightmare | |
# One has to download the MigLayout jar from its site | |
# then put it inside the jruby/lib folder | |
require 'java' | |
# For rvm users => allow to just run jruby frontend.rb | |
# provided that a .rvmrc has been created in the directory where | |
# frontend.rb is located. |
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
# jruby01.rb | |
require 'java' | |
java_import('java.util.Date') { |pkg, name| 'JDate' } | |
# To get the locales | |
java_import('java.util.Locale') { |pkg, name| 'JLocale'} | |
java_import('java.text.DateFormat') | |
# Get the date in local format |
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
# Alpha.txt is supposed to be a text file with multiple lines | |
# my_sort_file.rb | |
class MySortFile | |
def call(env) | |
req = Rack::Request.new(env) | |
initial_file = req.params['file'] | |
Rack::Response.new.finish do |res| | |
res['Content-Type'] = 'text/plain' |
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
# my_app_ter.ru | |
use Rack::MethodOverride | |
map '/' do | |
form = <<-HERE | |
<form action="/reverse_word" method="post"> | |
<input name="_method" type="hidden" value="put" /> | |
<input name="sentence" type="text" value="" /> | |
<input type="submit" value="Reverse the words order"> |
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
# config.ru | |
require './my_app_bis.rb' | |
run MyAppBis.new | |
# my_app_bis.rb | |
class MyAppBis | |
def initialize() | |
@str = "Is not rackup fun, is it?" | |
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
#my_rack_mtd1.rb | |
# Revisited version | |
require 'rack' | |
def reverse_word_order(env) | |
if (ARGV.length < 1 || ARGV.length > 1 || ARGV[0].split(" ").size < 2) | |
[400, {}, ["Enter one sentence with at least two words to reverse the sentence"]] | |
else | |
[200, {}, [ARGV[0].split(" ").reverse.join(" ")]] |
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
#my_rack_mtd.rb | |
require 'rack' | |
error = false | |
def check_argument | |
if (ARGV.length < 1 || ARGV.length > 1 || ARGV[0].split(" ").size < 2) | |
error = true | |
end | |
return error |
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
# input_number.rb | |
def input_response(n) | |
answer = "" | |
if n > 0 | |
answer = "positive" | |
elsif n < 0 | |
answer = "negative" | |
else n == 0 | |
answer = "zero" | |
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
# Main file string_reverse.rb | |
require 'sinatra' | |
helpers do | |
def concatenate_strings(string1, string2) | |
string1 + string2 | |
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
# Main file string_reverse.rb | |
require 'sinatra' | |
helpers do | |
def concatenate_strings(string1, string2) | |
string1 + string2 | |
end |
NewerOlder