I bet this is super simple and easy but can't find a basic example online. How can I read data from a plist file in my project using MacRuby?
Solution:
Turns out there's a few different ways to do it, but the cleanest I've found (so far) is to use the MacRuby helper method load_plist (which turns a plist file's contents into a hash). Also, if you're using XCode, you will need to get the file path relative to your app bundle:
# there's an AppConfig.plist file in my app bundle
config_path = NSBundle.mainBundle.pathForResource('AppConfig', ofType: 'plist')
#config = load_plist File.read(config_path)
This slide deck about MacRuby has some example code for accessing plist files (slides 77-80), the gist of which is that you open the file with NSDictionary.dictionaryWithContentsOfFile and then manipulate it as you would a Ruby Hash, then write it again with writeToFile_atomically. The NSDictionary documentation might be useful to you; you can find it here.
Related
I'm trying to take advantage of Google Closure Compiler minification by writing a database script of my own and compiling it with the pre-compiled ydn. To get a basic first version working I'm trying to rewrite the todo list demo from the project. Unfortunately, I don't understand how to keep namespaces for ydn functions preserved in the compiled output file.
Here's what I've written so far: http://pastebin.com/6YhnRuD5
When the code compiles in advanced mode, the "ydn.db.Storage" from "db = new ydn.db.Storage(dbName, Schema)" gets munged into "ydn.db.c$" making it unusable. The goog.exportSymbol at the bottom of the file doesn't seem to save the function names either.
Does anyone know how to rewrite this with Google Closure Compiler? Should this be compiled directly with the ydn source code instead?
The goog.exportSymbol at the bottom of the file doesn't seem to save the function names either.
It should.
goog.exportSymbol("ydn.db.Storage");
should be
goog.exportSymbol('ydn.db.Storage', ydn.db.Storage);
I am a newbie in yaml but I have to work on as3yaml which I don't have any knowledge on it.
I already downloaded as3yaml and attached to my project which is Flex project and I already read about yaml syntax.
But I don't have any ideas how can I start to work on it. I don't know how to new .yaml file with eclipse. I can't find any .yaml new file.
For now I understand that I have to create .yaml file and have to write the function on Actionscript Class to encode/decode the .yaml file.
And I also need some get started websites which I can learn myself.
Pls help!
I've never used Yaml as well, however it seems pretty straightforward:
var yaml:YAML = new YAML();
var data:Object = YAML.decode(yourYamlString);
You should really try reading the docs. Also, I wouldn't recommend using YAML unless you really have to. If you can, use AMF (native, faster, parses directly into model) but if you want something a little more 'web standardized' you can use JSON with the as3core library to parse it.
A bit of a followup from a previous question.
As I mentioned in that question, my overall goal is to call a Ruby script after ImageCache does its magic with generating thumbnails and whatnot.
Sebi's suggestion from this question involved using hook_nodeapi.
Sadly, my Drupal knowledge of creating modules and/or hacking into existing modules is pretty limited.
So, for this question:
Should I create my own module or attempt to modify the ImageCache module?
How do I go about getting the generated thumbnail path (from ImageCache) to pass into my Ruby script?
edit
I found this question searching through SO...
Is it possible to do something similar in the _imagecache_cache function that would do what I want?
ie
function _imagecache_cache($presetname, $path) {
...
...
// check if deriv exists... (file was created between apaches request handler and reaching this code)
// otherwise try to create the derivative.
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
imagecache_transfer($dst);
// call ruby script here
call('MY RUBY SCRIPT');
}
Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)
You should create a module that invokes hook_nodeapi, look at the api documentation to find the correct entry point for your script, nodeapi works on various different levels of the node process so you have to pick the correct one for you (it should become clear when you check the link out) http://api.drupal.org/api/function/hook_nodeapi
You won't be able to call the function you've shown because it is private so you'll have to find another route.
You could try and build the path up manually, you should be able to pull out the filename of the uploaded file and then append it to the directory structure, ugly but it should work. e.g.
If the uploaded file is called test123.jpg then it should be in /files/imagecache/thumbnails/test123/jpg (or something similar).
Hope it helps.
I am getting comfortable with using plists for initializing my app. I now want to save app state back to the plist used to initialize the app and I find myself stuck. At application startup I ingest the plist into an NSDictionary which is immutable. I now want to update the NSDictionary by replacing old values with new values for existing keys and write to the plist via [NSDictionary writeToFile:atomically]. How do I get around the immutability of NSDictionary?
Thanks,
Doug
UPDATE - Not quite there yet
I followed zneak's suggestion and ingested my settings file into an NSMutableDictionary. Works fine. Prior to writing the plist out I confirm that new values now replace old values. Cool. Good to go.
Problem: when I write the file thusly:
if ([self.settings writeToFile:plistPath atomically:YES] == NO) {
NSLog(#"Unable to write plist");
}
The method happily completes properly - the conditional is YES rather then NO - but I see no file. Where has the file gone?
Shouldn't I see the new file in my directory tree?
Make it a NSMutableDictionary by calling -[myDict mutableCopy], then use this one for writing the file; or simply load the plist using [NSMutableDictionary dictionaryWithContentsOfFile:(NSString*)] to get a mutable instance to start with instead of an immutable one.
Use an NSMutableDictionary (you can use -[NSDictionary mutableCopy] to create it). You can then use writeToFile just as with an NSDictionary.
I am having trouble in storing the files in a string array from a directory in c++, using System::IO::Directory::GetFiles in c++
Also would like to know if we could copy an entire folder to a new destination/ in c++ like given in http://www.codeproject.com/KB/files/xdirectorycopy.aspx for c#
You can store the file names from a directory in a managed array like this:
System::String ^path = "c:\\";
cli::array<System::String ^>^ a = System::IO::Directory::GetFiles(path);
Console::WriteLine(a[0]);
Console::ReadKey();
As for how would you copy an entire folder... Simply recurse from a given root directory creating each directory and copying the files to the new location. If you are asking for code for this, then please say so, but at least try to figure it out for yourself first (i.e. show me what you have so far).
Check out the file listing program in Boost::FileSystem: http://www.boost.org/doc/libs/1_41_0/libs/filesystem/example/simple_ls.cpp. They iterate over all files, printing the paths, but it's trivial to store them instead.
Assuming you're on Win32, you're looking for the FindFirstFile and FindNextFile APIs.
C/C++ does not define a standard way to do this, though Boost::Filesystem provides a method if you need cross platform support.