I've got a Ruby program that keeps telling me that various files do not exist when it runs.
The paths are absolute, and the files do exist at the time the program runs. When the program is runĀ again, everything works fine. There is absolutely nothing special about the code, and it works for thousands of other files at the same time, just not certain files at certain times, apparently.
It's Ruby 1.8.7 on latest stable Cygwin on Windows 2003.
What could possibly be going on here?
If you're on cygwin, maybe you're using the wrong type of slashes? (forward vs. back)
Try something simple to experiment. Make a test file somewhere and try a bunch of ways to get to it.
File.exists?('c:/test.txt')
File.exists?('c:\test.txt')
File.exists?('/test.txt')
File.exists?('\test.txt')
(I don't know windows/cygwin so I don't know what the full space of things to try would be)
Related
For some reason, I cannot read csv files in Scilab anymore, which weren't written by Scilab itself. First, I thought it might be wrong with my files (although I have previously read them), but I also tried csv files from the internet and still not possible. For example, I used the first csv file listed on this website.
The error message I get is csvRead: XXXX.csv does not exist. One week ago, everything was working just fine with the same files. And I am using Scilab on Mac, in case that makes a difference.
Has anyone a clue how to solve this?
Can I make a ruby file (e.g script.rb) unreadable to a user?
The file is on an Ubuntu (offline) machine. The user will use a local Sinatra app that will use some ruby files. I don't want the user to see the code in some of those files.
How can I do it?
EDIT:
Can I setup the project in a way that the user will be able to start the app but won't have access to specific files in it?
Thanks
Does that correspond to what you are searching for ?
chmod yourfile.rb 711
As I said in my comment it is literally almost impossible to hide the content of your ruby source file, many people try this in many different ways but it is almost always trivial to reverse engineer. There are some "suggestions" for making your code hidden but they never really work still, here are a few;
Obfuscation - The process of making your code executable but unreadable, using a tool like ProGuard for Java (there are ones for most major languages) will try to make your code a mess, and as unreadable as possible while still maintaining execution speed. Normally this consists of renaming variables, using strange characters and generally hiding, moving or wrapping functions in complicated structures.
Package the interpreter - You can use a tool like ocra to package the script up inside an executable with the interpreter and standard library, but anyone with even a tiny bit of experience in reverse engineering will be able to easily tear out the source code given a small amount of time
Write a custom interpreter - Now we are getting somewhere with making it harder. Writing a custom interpreter will allow you to compile your script to a "bytecode" that can then be executed. This is of course a very time consuming, expensive and incompatible solution when it comes to working with other code bases.
Write most of your code in C and then call out to it via extensions - Again this mostly moves the problem but its still there. It will take more time but anyone can easily pull apart the machine code of the C library you load in and bob is your uncle they have the source code.
Many more alternatives - This isn't a comprehensive list, I am probably missing a few ideas or suggestions.
As far as it goes making code unreadable is hard a better solution might just to be consider providing a licence agreement with your code. That way, someone reads or modifies the source file you can take them to court for a legal settlement.
Extract your code and its functionality to an external API. And then provide it as a service. This way you don't have to expose your source code to your 'users'.
I've been writing less, and using Codekit to compile locally.
Everything compiles to the correct destination as it should.. but
Every time I save a less file, it creates an empty CSS file in the same location on my hard disk. This happens when Codekit is closed, so it doesn't seem to be an issue with the program itself.
I have no idea what is causing this behaviour, I have no other services running.
thanks
For others that get this problem, it's usually a missing or duplicate semicolon on a property or something simple that causes this particular issue. The hard part is tracking down the specific error, so your best bet is to try a couple of different compilers and hope for an error log that tells you at least which .less file is causing the problem. Try node.js with lessc, less.app, winless or whatever else is available to you on your OS. This is a common issues, so it's worthwhile to have another "backup" compiler handy to debug.
I have written a short program in a ruby file that runs correctly on my PC. However I need to find a way to give this to my colleagues to use. They have no knowledge of ruby. The program requires various non standard gems. What is the best way to provide them with a one click installer for my program, including all the gems and ruby itself.
Try OCRA - it packages everything into a single executable (no installation required).
When you run the executable, it extracts everything into a temporary directory (including the ruby interpreter) and runs your script from this directory.
I havn't use it (so I don't know if it works), but you can try to use RubyScript2Exe
I would like to upload documents to GoogleDocs every time the OS hears that a file was added/dragged/saved in a designated folder, just the way DropBox uploads a file when you save it in the DropBox folder.
What would this take in Ruby, what are the parts?
How do you listen for when a File is Saved?
How do you listen for when a File is added to a Folder?
I understand how to use the GoogleDocs API and upload things once I get these events, but I'm not sure how this would work.
Update
While I still don't know how to check if a file is added to a directory, listening for when a file is saved is now dirt simple, thanks to Guard for ruby.
If I were faced with this, I would use something like git or bzr to handle the version checking and just call add then commit from your script and monitor which files have changed (and therefore need to be uploaded).
This adds the benefit of full version control over files and it's mostly cross platform (if you include binaries for each platform).
Note this doesn't handle your listening problem, just what you do when you know something has changed. You could schedule the task (via various routes) but I still like the idea of a proper VCS under the hood.
I just found this: http://www.codeforpeople.com/lib/ruby/dirwatch/
You'd need to read over it as I can't vouch for its efficiency or reliability. It appears to use SQLite, so it might be better just to manually check once every 10 seconds (or something along those lines).
Ruby doesn't include a built-in way to "listen" for updates to files. If you want to stick to pure Ruby, your best bet would be to perform the upload on a fixed schedule (say every 5 minutes) regardless of when the file is saved.
If this isn't an acceptable alternative, you could try writing the app (or at least certain parts of it) in Java, which does support this type of thing. Take a look at JRuby for integrating the Ruby and Java portions of your app.
Here is a pure ruby gem:
http://github.com/TwP/directory_watcher
I don't know the correct way of doing this, but a simple hack would be to have a script running in the background which checks the contents of a bunch of folders every n minutes and uses the associated timestamps to determine if the file was modified in that span of time
You would definitely need some native OS code here, to write the monitoring service/client. I'd select C++ if you want it to be cross platform. If you decide to go with .Net, for example, you can use the FileSystemWatcher class to achieve what you need (documentation and here's a related article).
Kind of an old thread, but I am faced with doing something similar and wanted to throw in my thoughts. The route I'm going is to have a ruby script that watches a given directory and checks the timestamps. Once all files have been uploaded, the script saves the latest timestamp and then polls the directory again, checking if any files/folders have been added. If files are found, then the script uploads them and updates the global timestamp, etc...
The downside is that setting up a ruby script to run continually (or as a service) is somewhat painful. But it's not an overwhelming task, just needs to be thought out properly.
Also depends on if your users are competent enough to have ruby installed or if you have to package everything up into a one-click installer as well. That, to me, is the hardest part to figure out.