load yaml files from outside current directory - yaml

I want to load a yaml file from outside the working directory. I use c++. I used YAML::LoadFile("/home/example.yaml") and it complains YAML::BadFile. Please let me know if there is any way to do that.

YAML::LoadFile does nothing else than reading the file via std::ifstream. So your actual problem is that you cannot open the file at all in your application.
Check whether the file exists and has the proper permissions so that your application may open it. Try opening it directly with a std::ifstream and hand that over to YAML::Load so you can inspect the stream directly to see what error occurred.

Related

How to delete a cached file template in Intellij

I'm trying to work on a Ruby project in Intellij. I tried creating a new file using the Ruby Class Template file type. However, for some reason when I open the file it opens the file with the application that is associated with the .rb extension in my OS config, instead of opening it in Intellij.
EDIT:
Although I still have the issue described below I figured it was worth mentioning that I was able to get Ruby Class Template types working by creating a new empty Ruby project first then importing
my Ruby project as a new module in the Project Settings. See Importing a
module and configuring a separate SDK for it ~
source
END OF EDIT
I figured out that if I just create a file using the basic File type in Intellij and name it with the .rb extension then I can open it in Intellij.
So after I figured this out I tried deleting the original file I created with the Ruby Class Template type. This time I created it as a plain File type and gave it the .rb extension. But, Intellij still doesn't associate this as a Ruby file (it still has a ? mark symbol next to the file). I tried creating multiple variations of *.rb file names and they all work, which confirms the issue is only with this one particular file name.
So I can only think that Intellij has some cached reference of the file name and it's template file type.
I tried searching by %project_name% and deleting any results under
source SYSTEM DRIVE>\Users\<USER ACCOUNT NAME>\.<PRODUCT><VERSION>
But that didn't work. I also renamed the cache folder and restarted Intellij, to no avail.
Aside from a complete reinstall does anyone have any advice on if I'm going in the right direction, and if so, where I might find this hidden cache reference?
For those not able to access the link to the solution posted as a comment by #y.bedrov
The provided solution was to check the following
In Settings(Preferences) | Editor | File Types check all the
registered patterns for Files Opened in Associated Applications:
As I accessed this screen and scrolled to the bottom I found my file. I removed the file from the list and now my issue is solved. I can now create this file and have it open in Intellij!

Lazarus: How to check if file is in use?

I need to check if a file is in use before I try to get access to it. Is there way to do it in Lazarus environment?
Open the file with FileOpen(FileName, fmOpenReadWrite or fmShareExclusive) and check the result.
Update (thanks to Ken White's comment). This is not the direct answer to your question as FileOpen actually gets access to the file, but you shouldn't perform the check and then open the file, otherwise you'll get a race condition. You should open the file and then check if the open succeeded.
Opening a file with FileOpen and accessing the file through its handle may seem unfamiliar. You can achieve the same goal when opening a file with e.g. Rewrite inside a try-except block. I am not sure about Lazarus, but in Delphi using try-except with high-level file routines requires explicit resetting IOResult in case of exception (put SetInOutRes(0) into except section), otherwise the following file operation fails.
You don't. You try to open it, and handle the exception if and when you can't.
Checking to see if it's in use first serves no purpose.
Your code to see if it's in use says it's not
--->>> Another app opens the file, locking it
Your code to open file fails
Instead, use a normal try..except block:
try
FS := TFileStream.Create(YourFileName, fmOpenReadWrite, fmShareExclusive);
// Code to use file here
except
// Handle failure to access file
end;

Accessing an external file from MacRuby

I have done several small scripting/automation projects before but this is my first time using MacRuby and I couldn't find out at all why my project is not working.
This task would have been easy to fix if it was just a plain Ruby script. However, it needs a Mac GUI so I decided to use MacRuby for its Cocoa bindings.
The app itself is a simple form that will perform a calculation based from some data from an external CSV and some text fields and then show the results of the calculation.
My problem is that this code does NOT seem to work:
#arr_from_csv = CSV.read("data.csv")
Upon building the file, I get the following error:
[...]/ruby/1.9.2/CSV.rb:1335:in `open': No such file or directory - open() failed (Errno::ENOENT)
At first, I thought that I must have put the CSV file into the wrong directory inside XCode project's folder structure. I tried putting on the same folder as the script itself (app_delegate.rb). Didn't work. I tried putting it in the Resources folder, still didn't work.
Then, I decided to just use an absolute file path. So, I changed to code into:
#arr_from_csv = CSV.read("~/data.csv")
and copied the file into my home directory. It still can't read the CSV file.
Am I missing something? I'm sorry, this is my first time using MacRuby.
Thanks.
You should change the code to "/Users/xxx/data.csv".
Ruby does not expand "~" to "/Users/xxx".
Notice: xxx represents your login id.
I was able to solve my problem by using:
#arr_from_csv = CSV.read(File.expand_path("~/data.csv"))

Can VS_VERSION_INFO be added to non-exe files?

My windows co-workers were asking me if I could modify my non-windows binary files such that when their "Properties" are examined under Windows, they could see a "Version" tab like that which would show for a Visual Studio compiled exe.
Specifically, I have some gzipped binary files and was wondering if I could modify them to satisfy this demand. If there's a better way, that would be fine, too.
Is there a way I could make my binaries appear to be exe files?
I tried simply appending the VS_VERSION_INFO block from notepad.exe to the end of one of my binaries in the hope that Windows scans for the block, but it didn't work.
I tried editing the other information regarding Author, Subject, Revision, etc. That doesn't modify the file, it just creates another data fork(what's the windows term?) for the file in NTFS.
It is not supported by windows, since each file type has their own file format. But that doesn't mean you can't accomplish it. The resources stored inside dlls and exes are part of the file format.
Display to the user:
If you wanted this information to be displayed to the user, this would probably be best accomplished with using a property page shell extension. You would create a similar looking page, but it wouldn't be using the exact same page. There is a really good multi part tutorial on shell extensions, including property pages starting with that link.
Where to actually store the resource:
Instead of appending a block to the file, you could store the resource into a separate alternate data stream on the same file. This would leave the original file stream non corrupted on disk and not cause its primary file size to change.
Alternate data streams allow more than one data stream to be associated with a filename. Each stream is identified by a colon : at the end of the filename and an identifier.
You can create them for example by doing:
notepad test.txt:adsname1
notepad test.txt:adsname2
notepad test.txt
Getting the normal Win32 APIs working:
If you wanted the normal API to work, you'd have to intercept the Win32 APIs: LoadLibraryEx, FindResource, LoadResource and LockResource. This is probably not worth the trouble though since you are already creating your own property page.
Can't think of any way to do this short of a shell extension. The approach I've taken in the past is a separate "census" program that knows how to read version information from any kind of file.
Zip files can be converted into exe files by using a program that turns a zip file into a self-extracting zip (I know that WinZip does this, there are most likely free utilities for this also; here's one that came up on a search but I haven't actually tried it). Once you've got an exe, you should be able to use a tool like Resource Hacker to change the version information.
It won't work. Either Windows would have to know every file format or no file format would be disturbed if version information were appended to it.
No, resource section is only expected inside PE (portable executable; exe, dll, sys).
It is more then just putting the data inside the file, you have a table that points to the data in the file header.
What you can do if you have NTFS drive, is to use NTFS stream to store custom properties this way the contact of the binary file will remain the same, but you will need to use a custom shell extension to show the content of the stream.

How to know in Ruby if a file is completely downloaded

Our issue is that our project has files being downloaded using wget to the file system. We are using ruby to read the downloaded files for data.
How is it possible to tell if the file is completely downloaded so we don't read a half complete file?
I asked a very similar question and got some good answers... in summary, use some combination of one or more of the following:
download the file to a holding area and finally copy to your input directory;
use a marker file, created once the download completes, to signal readiness;
poll the file twice and see if its size has stopped increasing;
check the file's permissions (some download processes block reads during download);
use another method like in-thread download by the Ruby process.
To quote Martin Cowie, "This is a middleware problem as old as the hills"...
The typical approach to this is to download the file to a temporary location and when finished 'move' it to the final destination for processing.

Resources