Ruby shoes4 package over 1.5GB - ruby

I've made a small CLI script in ruby to manage a small shop for a friend, but then he wanted me to make a GUI for him, so I looked around and found shoes4.
So, I went and download it, created a small test, and run:
./bin/shoes -p swt:jar ./path/to/app.rb
and left it to create the package, then I got a warning from system that I'm running low on disc space, so I went to check the jar file, and it was over 1.5GB and still not done packaging... and the code is very small and basic:
require 'yaml'
Shoes.app do
button "Add client" do
filename = ask_open_file
para File.read(filename)
clients = YAML.load_file(filename)
id = clients[clients.length - 1][0].to_i + 1
name = ask("Enter the client's full name: ")
items = ask("Enter list of items.")
patients[id] = ["ID = "+ id.to_s,"Name = "+ pname,"list of items:\n"+ items]
File.open(filename, 'w') { |f| YAML.dump(clients, f) }
alert ("Added new patient.")
end
button "Exit" do
exit()
end
end
any idea why this small app is more than 1.5GB?? or did I try to package it wrong way??

The packager will include everything in the directory of your shoes script and below.

Related

Launching browser windows from Ruby command prompt

I've got this code below. What I'd like it to do is launch each of the search queries I've specified into browser windows, instead of listing the search results as it's currently written to do. But I'm a beginner and having a difficult time finding documentation on this. Is it possible?
The issue is the actual list of search_criteria I will be using is actually 40 terms long and I need to do it for dozens and dozens of cities - which is why I was looking to automate the search process.
If it's not possible to launch each query as a browser window (or better tabs in a browser window) is there a way to specify each URL that results in some systematic way so as to be called by Ruby from command prompt to launch as a browser window?
require "google-search"
search_criteria = ["makers", "makerspaces", "fablabs", "smartlabs"]
#City name
search_1 = search_criteria.map do |noun|
"#{noun} new york city"
end
#City acronym 1
search_2 = search_criteria.map do |noun|
"#{noun} new york"
end
#City acronym 2
search_3 = search_criteria.map do |noun|
"#{noun} nyc"
end
#Replace "search_1" for other acronyms
search_1.each do |query|
puts "Just one moment please! I am searching for #{query}"
Google::Search::Web.new do |search|
search.query = query
search.size = :large
end.each { |item| puts item.title }
end
search_criteria = ["makers", "makerspaces", "fablabs", "smartlabs"]
names = ["new+york+city", "new+york", "nyc"]
query_strings = names.map do |name|
"#{name}+#{search_criteria.join('+')}"
end
urls = query_strings.map do |q|
"google.com/search?q=" + q
end
cmd_line = urls.join(' ')
Then you pass cmd_line to the Google Chrom executable via the system() call. On Mac OS X it would be like this:
system("/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --url #{cmd_line}")
Chrome will then open each url in the string passed to it in it's own tab in a new window.
If you are using Windows you will have to find where the chrome.exe executable is buried, and in Linux you would just find the chrome binary to call it. Everything before the last part of ...Chrome --url #{cmd_line}") is just the path to the executable, which is buried inside the "Google Chrome.app" container on OS X.

Building a downloadable sitemap zip file in Heroku

I'm building a web tool in Heroku / Ruby Sinatra that scrapes a web domain and downloads all specified filetypes (it should provide a zip file of the sitemap of the domain's filetypes to download).
I am trying to figure out how to build a ZipFile on Heroku. How do I set the home directory? Then once I have the ZipFile, how do I link to it so it's downloadable?
Here is some of the relavent code so far:
anemone.after_crawl do
puts "Crawl finished. Gathering files, preparing download..."
datasets.each do |url|
u = URI.parse(url.to_s)
Net::HTTP.start(u.host) { |http|
resp = http.get(u.path)
if u.path[0] == "/"
u.path[0] = ''
end
full_path = u.path.split("/")
i = 0
len = full_path.size
filename = full_path[-1]
Zip::ZipFile.open(u.host + ".zip", Zip::ZipFile::CREATE) {
|zipfile|
while i < (len-1) do
directory = full_path[i]
unless File.directory?(directory)
zipfile.mkdir(directory)
end
Dir.chdir directory
i+=1
end
zipfile.add(filename);
while (i > 0) do
Dir.chdir File.expand_path("..",Dir.pwd)
i-=1
end
}
}
end
end
The Heroku filesystem is mostly read-only, but you should be able to temporarily stash the zipfile on /tmp:
Zip::ZipFile.open("#{RAILS_ROOT}/tmp/" + u.host + ".zip", Zip::ZipFile::CREATE)
You'll probably want to use send_file in a "downloads" controller to allow users to download the file. You'll want to build in error handling in case the temporary file disappears before the user downloads it (e.g., if the dyno restarted between zipfile creation and download).
EDIT
The documentation I linked is apparently outdated. RAILS_ROOT is the Rails 2 way to refer to the directory root, but the Rails 3 way (Rails.root) doesn't work either--in Heroku it refers to the ./app folder.
However, you can use the Heroku base filesystem /tmp folder, like this:
Zip::ZipFile.open("/tmp/" + u.host + ".zip", Zip::ZipFile::CREATE)

AVCaptureMovieFileOutput - no active/enabled connections

In RubyMotion, I'm using AVFoundation for screencapture in an attempt to implement this gist from the Mac Developer Library. The program should capture video from the screen and write to a .mov file.
I don't quite understand why I'm getting this error:
* -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - no active/enabled
connections.
The simple code is:
# Setup recording pipeline
#session = AVCaptureSession.alloc.init
#session.sessionPreset = AVCaptureSessionPresetMedium
input = AVCaptureScreenInput.alloc.initWithDisplayID(KCGDirectMainDisplay)
#session.addInput(input)
movieFileOutput = AVCaptureMovieFileOutput.alloc.init
if #session.canAddOutput(movieFileOutput)
#session.addOutput(movieFileOutput)
else
Logger.error "Could not add ouput #{movieFileOutput}"
end
#session.startRunning()
# Delete exisiting file
fileManager = NSFileManager.defaultManager
path = "~/Desktop/video.mov"
if fileManager.fileExistsAtPath(path)
err = Pointer.new(:object)
unless fileManager.defaultManager.removeItemAtPath(path, error:err)
Logger.error "Can't delete existing movie"
end
end
# Start recording
movieFileOutput.startRecordingToOutputFileURL(NSURL.fileURLWithPath(path), recordingDelegate:self) # <--- Problem
What am I doing incorrect?
I used an incorrect constant for display id. This works:
input = AVCaptureScreenInput.alloc.initWithDisplayID(CGMainDisplayID())

Rally APIs: How to Move A Test Folder

I've worked with the script outlined in the following answer:
Rally APIs: How to copy Test Folder and member Test Cases
and it's handy, but what I really want to do is to move an entire Test Folder into a different project. This is next to impossible through the Rally User Interface. According to Rally Support, the only way to do this in the UI is:
Un-assign the Test Cases from their current Test Folder
Setup a Custom Grid app on your dashboard
Use the Custom Grid bulk edit to update the Project of the Test Cases
Lastly use the Custom Grid bulk edit to update the Test Folder - now that you're in the target Project, of the Test Cases
Even though the above process is clunky, it is easier now than it used to be before the advent of the bulk edit within the Custom Grids. Before you had to go through and edit each Test Case one-by-one which was very manual and slow.
However, we have several thousand Test Cases we need to move, and the Custom Grid has a fatal flaw for us. It will only show the first 200 records in a query. So we would have to manually change our grid query in a step wise manner to accomplish the move we need. This is barely better than editing Test Cases one-by-one. Is there a way to move a Test Folder with Test Cases from one Project to another, using a script? Please tell me there is.
The following script will perform this task - it will move all Test Cases from a Source Test Folder identified by FormattedID, to a Target Test Folder, also identified by FormattedID. The Source Test Folder and Target Test Folder can be in different Projects (although they must be within the same Workspace). Like the Copy script referenced in the question, the Target Test Folder must exist, i.e. the script will not create a Test Folder for you if the Target is not found.
For those needing to install and configure the Ruby REST Toolkit, links are here:
Developer Portal: Rally REST API for Ruby
Github
# Copyright 2002-2012 Rally Software Development Corp. All Rights Reserved.
require 'rally_api'
$my_base_url = "https://rally1.rallydev.com/slm"
$my_username = "user#company.com"
$my_password = "password"
$my_workspace = "My Workspace"
$my_project = "My Project"
$wsapi_version = "1.39"
# Test Folders
$source_test_folder_formatted_id = "TF8"
$target_test_folder_formatted_id = "TF11"
#==================== Make a connection to Rally ====================
config = {:base_url => $my_base_url}
config[:username] = $my_username
config[:password] = $my_password
config[:workspace] = $my_workspace
config[:project] = $my_project
config[:version] = $wsapi_version
#rally = RallyAPI::RallyRestJson.new(config)
begin
# Lookup source Test Folder
source_test_folder_query = RallyAPI::RallyQuery.new()
source_test_folder_query.type = :testfolder
source_test_folder_query.fetch = true
source_test_folder_query.query_string = "(FormattedID = \"" + $source_test_folder_formatted_id + "\")"
source_test_folder_result = #rally.find(source_test_folder_query)
# Lookup Target Test Folder
target_test_folder_query = RallyAPI::RallyQuery.new()
target_test_folder_query.type = :testfolder
target_test_folder_query.fetch = true
target_test_folder_query.query_string = "(FormattedID = \"" + $target_test_folder_formatted_id + "\")"
target_test_folder_result = #rally.find(target_test_folder_query)
if source_test_folder_result.total_result_count == 0
puts "Source Test Folder: " + $source_test_folder_formatted_id + "not found. Exiting."
exit
end
if target_test_folder_result.total_result_count == 0
puts "Target Test Folder: " + $target_test_folder_formatted_id + "not found. Target must exist before moving."
exit
end
source_test_folder = source_test_folder_result.first()
target_test_folder = target_test_folder_result.first()
# Populate full object for both Source and Target Test Folders
full_source_test_folder = source_test_folder.read
full_target_test_folder = target_test_folder.read
# Grab collection of Source Test Cases
source_test_cases = source_test_folder["TestCases"]
# Loop through Source Test Cases and Move to Target
source_test_cases.each do |source_test_case|
begin
test_case_to_update = source_test_case.read
source_test_case_formatted_id = test_case_to_update["FormattedID"]
target_project = full_target_test_folder["Project"]
target_project_full_object = target_project.read
target_project_name = target_project_full_object["Name"]
source_project = full_source_test_folder["Project"]
source_project_full_object = source_project.read
source_project_name = source_project_full_object["Name"]
puts "Source Project Name: #{source_project_name}"
puts "Target Project Name: #{target_project_name}"
# Test if the source project and target project are the same
source_target_proj_match = source_project_name.eql?(target_project_name)
# If the target Test Folder is in a different Project, we have to do some homework first:
# "un-Test Folder" the project
# Assign the Test Case to the Target Project
# Assign the Test Case to the Target Test Folder
if !source_target_proj_match then
fields = {}
fields["TestFolder"] = ""
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully dissociated from: #{$source_test_folder_formatted_id}"
# Get full object on Target Project and assign Test Case to Target Project
fields = {}
fields["Project"] = target_project_full_object
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully assigned to Project: #{target_project_name}"
end
# Change the Test Folder attribute on the Test Case
fields = {}
fields["TestFolder"] = target_test_folder
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully moved to #{$target_test_folder_formatted_id}"
rescue => ex
puts "Test Case #{source_test_case_formatted_id} not updated due to error"
puts ex
end
end
end

How can I measure the length of a long string in Ruby? SciTE and command prompt aren't working.

I've written a program that measures my typing speed. As part of this, I need it to count how many characters I've typed. I did that with
text = gets.chomp
puts text.length.to_s
Unfortunately, I can't get this working for a long string.
In the SciTE editor, .length doesn't work properly, so instead of giving me the length of the string, it gives me the character count of everything I've typed, including corrected mistakes - if I typo "Hrello" and correct it to "Hello", it'll still return 6 instead of 5.
I googled this, and the suggested fix was to run the program from the command prompt instead. In the command prompt, .length works fine, but it turned out that I can't type in more than 264 characters.
So I tried to put a GUI on the program with Shoes:
Shoes.app :width => 300, :height => 300 do
button "Start." do
text = ask "Type here."
para text.length.to_s
end
end
and discovered that Shoes' input box has an even shorter character limit.
I'm running Windows 7, Ruby 1.9.2, SciTe version 2.29 and Shoes Policeman Revision 1514.
How can I run this program so it'll correctly measure the length of a really long string? I'd be happy with any solution that fixes the command prompt or Shoes character limit, the SciTE bug, or just a suggestion for a different way to execute ruby programs where this will work.
I'd be happy with [...] a suggestion for a different way to execute ruby programs where this will work.
What about a simple web app? Here is a simple Sinatra app that accomplishes exactly what you have asked with a very large character limit.
require 'sinatra'
get '/' do
%{<html>
<body>
<form method="post">
<textarea name="typed"></textarea>
<input type="submit">
</form>
</body>
</html>
}
end
post '/' do
"You typed #{params['typed'].length} characters."
end
To run the app you can use something as simple as ruby sinatra_example.rb to use a built-in web server. Or, you can deploy this app using any of several web servers.
If you need timers this should be easy to accomplish through javascript and include in the form submit.
Ok, your question is not accurately titled, but lets see:
There is a very broad number of options of using command prompt, and you should consider running a simple script in ruby on it.
On command line from windows, try typing ruby C:/path_to_folder_program/program.rb
If it won`t execute, you can find on ruby folder some executable called ruby and should, from command prompt on that path, run it like above.
But let me ask you, why ruby? Other more accessible and user-friendly programming languages, like javascript would behave better and would be easier to make your program accessible.
- EDIT -
Seems shoes can handle more chars, use edit_box instead of ask:
In Shoes:
Shoes.app do
#txt = edit_box
button("How many"){ alert(#txt.text.size) }
end
Anyway, before trying shoes I did the exercise with that I knew, here it is:
In javascript:
<script>
function start_stop(){
var txt = document.getElementById('txt');
var btn = document.getElementById('btn');
if( txt.disabled ){
txt.value = '';
txt.disabled = false;
btn.value = 'Stop';
txt.focus();
startTime = new Date().getSeconds();
} else {
txt.disabled = true;
btn.value = 'Start again';
timeNow = new Date().getSeconds();
alert(txt.value.length + " characters in " + (timeNow - startTime) + " seconds.");
}
}
</script>
<input type='button' id='btn' onclick='start_stop()' value='Start'>
<textarea id='txt' rows='8' cols='80' disabled></textarea>
In Ruby using Qt: (replicating the same idea as in the javascript one)
require 'Qt'
class MyWidget < Qt::Widget
slots :start_stop
def initialize
super
setFixedSize(400, 120)
#btn = Qt::PushButton.new("Start")
#txt = Qt::TextEdit.new ; #txt.readOnly = true
vbox = Qt::VBoxLayout.new
vbox.addWidget #btn
vbox.addWidget #txt
setLayout vbox
connect(#btn, SIGNAL("clicked()"), self, SLOT(:start_stop))
end
def start_stop
if #txt.readOnly
#txt.plainText = ''
#txt.readOnly = false
#btn.text = "Stop"
#txt.setFocus
#startTime = Time.now
else
#txt.readOnly = true
#btn.text = "Start again (#{#txt.plainText.size} chars #{(Time.now - #startTime).to_i} in seconds)"
end
end
end
app = Qt::Application.new(ARGV)
widget = MyWidget.new
widget.show
app.exec

Resources