Rubymotion Base64 - ios5

I am looking for a simple way to encode a string using base64. In ruby motion I can't just use the Base64encode of Ruby because I am not able to require it. So I thought I could use a build in function of Cocoa. But Cocoa does not seem to have a Base64encode function. I have found some categories on NSData, but don't know how to use them in a ruby motion project. Should I create a statics library for this?
I have got the feeling that I am looking in the wrong direction, there must be easy solution for this?

If you look at the source for Base64.encode64 method, you'll see that it just uses the pack method. So you can encode/decode like this (note that you need to put the thing you want to encode inside an array):
["my string"].pack("m")
# => "bXkgc3RyaW5n\n"
"bXkgc3RyaW5n\n".unpack("m").first
# => "my string"
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/base64/rdoc/Base64.html#method-i-encode64

Related

Is there a generally specification for references within a file?

I wanted writing an IDE plugin to simplify work with references to code in my documentation, but decided to first check the existence of a specification (like URI) so as not to reinvent the wheel.
I tried to find the answer to this on the internet but failed.
We know that such references work in different IDEs:
appRoot.folder.file.Class#method
appRoot.folder.file:35
appRoot/fodler/file.ext:35
But what if you need to get the path to the nested property JSON or XML?
I naively imagine that the sign # means the root and then for the JSON path I could use something like this:
appRoot/folder/jsonFile.json#oneLevelProp.twoLevelProp
But this of course does not work at the current moment in any IDE that I know of.

Find a replacement for JavaModelUtil.getResolvedTypeName

I've always used JavaModelUtil.getResolvedTypeName(ifield.getTypeSignature(), itype) in my plugincode. This is internal code of eclipse and I'm trying to replace this code with a "legal" variation. But I seem to be unable to find an alternative.
So what can I use instead of JavaModelUtil to get the qualified classname, if I have only the IField and the IType in which the IField exists.
Thanks for any help!
Looks like you can use org.eclipse.jdt.core.IType.resolveType(String). This is what getResolvedTypeName uses internally. You will have to do a bit more processing since resolveType expects a name and not a signature (in other words, you need to pass MyType instead of QMyType;. If you look at the signature and implementation of the resolveType method you should be able to figure out how to use it.

XML Parser on MonoTouch?

I want to parse XML formatted string. How to use XML parser on MonoTouch?
Exactly the same way you would in standard C#.
Your options include:
XmlSerializer - good if you want to translate a full document to a set of C# objects
XmlDocument - good if the document is custom beyond XmlSerializer can handle
XPath - good for pulling out small pieces of data, if you don't care about the whole doc.
Linq2XML - another option using Linq.
Depending on what exactly you need.
You can use LINQ to XML in MonoTouch.
So,
var element = XElement.Parse("<cat>dog</cat>");
Console.WriteLine(element.Value);
prints "dog".
You canĀ“t use System.Xml.Linq in full, there will be a JIT part that will blow up when testing in the device, see Xamarin Monotouch limitations:
link

How to write a string starting with '=' to a cell using Spreadsheet::WriteExcel

I'm using the Perl package Spreadsheet::WriteExcel to write an Excel file. I want to write a string that starts with the equal sign, "=ABC()", to a cell.
$ws->write('A1', '=ABC()');
But I got an error message of
Unknown function ABC() in formula
Can someone advise?
Use the write_string method directly instead of using write:
$ws->write_string('A1', '=ABC()');
Spreadsheet::WriteExcel's write method is a convenience method that guesses what kind of data you're trying to store. If it guesses wrong, you should use one of the type-specific methods.
#Cjm already provided the best answer. Still, I'd like to remember that's possible also to format any cell as text and type whatever you want, that won't be interpreted.

how can i replace json string?

i want to replace particular data's in json string
Parse it, make the changes you need, then serialize it back out. You didn't say what JSON library you're using, but it should be fairly easy.
Without knowing the specifics of your problem:
[jsonString stringByReplacingOccurrencesOfString:#"replaceme" withString:#"replacement"];
But you're probably far better of using a JSON library.