How do I ungzip a string like this - kotlin

I have this string:
H4sIAAAAAAAA/6VRPQvCMBD9K+VmBxF0yNZV6KLiIiJnc4RgPkqSilL6371o0Yo4iFNy79679y7p4Gh8fYogdh1oCeJRw2Q4BdCZXOIag2IWkxLZTN/3jNVJe8ekpdcO+smXEY3BK4XDwP4c9bjdkSxPl+wnMWGGHFpisA3WW+jZNBqfQEzvbmPZ0RwSqpHSN0O6UsoiNlhT5G7mCNjQJRVbNC0VFQWlXRY+11mTkxXFiIq+rvGKMpv/kGVFqjUYnkFKo5Wz/MRF5SX9EWLRv/3IWM2dG7pEKD7oAQAA
And I want to decompress it using gzip.
I spent almost 2 hours on this now and can't seem to find out how to do this.
Does anyone know? I am new to Kotlin and I've never done that before.

Use java.util.Base64 to convert the Base-64 to binary. Then ungzip that.

Related

Chai.js - Check if string contains substring from a list

I'm using chai.js writing some automation tests. I have a string:
url(http://somewhere.com/images/myimage.png)
I want to do something like:
expect(thatSelectedItem).contains.any('jpg', 'png', 'gif')
However can't seem to find anything in chai.js
Any have any suggestions - read the page http://chaijs.com/api/bdd/ however no luck.
Any help appreciated.
Thanks.
With plain Chai (no additional plugins), you can use match:
expect(thatSelectedItem).to.match(/(?:jpg|png|gif)/)
expect(thatSelectedItem).to.contain.oneOf(['jpg', 'png', 'gif'])
This lands with v4.3.0 (docs). oneOf can be chained with contain, contains, include and includes, which will work with both arrays and strings. It's strongly recommended to use because the error messages you get with it are much cleaner.

How can I detect org.docx4j.wml.instrText when parsing DOCX with docx4j?

I want to pars a docx file with docx4j library.
I need to detect org.docx4j.wml.instrText objects but actually it returns org.docx4j.wml.Text instead of org.docx4j.wml.instrText.
I found a solution that was working with older version of this library here:
http://www.docx4java.org/forums/docx-java-f6/can-i-just-don-t-load-contents-of-w-instrtext-into-text-t193.html
Actually this solution:
((javax.xml.bind.JAXBElement)((org.docx4j.wml.Text) o).getParent()).getName().getLocalPart()
But with the latest update it does not work. Could you please tell me what changes I have to make on this code?
Actually it make a type casting error that can not convert org.docx4j.wml.R to JAXBElement.
Thanks in advance.
The parent of the Text object, given by:
((org.docx4j.wml.Text) o).getParent()
is, as the error says, a org.docx4j.wml.R, which you can't cast to JAXBElement.
To identify your object in this case, try:
((javax.xml.bind.JAXBElement)o).getName().getLocalPart()

Convert date to string in Sencha 2

I want to convert a date to a string, and sees that Sencha 2 has this class for the job. It has a lot of convertion, but I cant find anyone where I can customize how I want the string formatted. I want a date in 'dd-MM-yyyy'.
In java you have the SimpleDateFormat class where you give the pattern you want it formated in as parameter, I would except there was something like this in the Date class. If not, whats the best way to do this in pure javascript (no third part libraries), I know the trivial way (getFullYear(), getMonth() and such), but its error prone.
http://docs.sencha.com/touch/2-0/#!/api/Date-method-toDateString
have a look at http://docs-devel.sencha.com/touch/2-0/#!/api/Ext.Date
it contains a ton of the format options :)
Cheers, Oleg

IOS JSON escaping special characters

I'm working in IOS and trying to pass some content to a web server via an NSURLRequest. On the server I have a PHP script setup to accept the request string and convert it into an JSON object using the Zend_JSON framework. The issue I am having is whenever the character "ø" is in any part of the request parameters, then the request string is cut short by one character.
Request string before going to server.
[{"description":"Blah blah","type":"Russebuss","name":"Roscoe Simulator","appVersion":"1.0.20","osVersion":"IOS 5.1","phone":"5555555","country":"Østfold","udid":"bed164974ea0d436a43f3cdee0e005a1"}]
Request string on server before any parsing
[{"description":"Blah blah","type":"Russebuss","name":"Roscoe Simulator","appVersion":"1.0.20","osVersion":"IOS 5.1","phone":"5555555","country":"Nord-Trøndelag","udid":"bed164974ea0d436a43f3cdee0e005a1"}
Everything looks exactly the same except the final closing ] is missing. I'm thinking it's having an issue when converting the string to UTF-8, but not sure the correct way to fix this issue.
Does anyone have any ideas why this is happening?
first of all do not trust the xcode console in such cases. you never know which coding the console is actually using.
second, escape the invalid characters before you build you json string. easiest way would probably to make sure you are using the same unicode representation, like utf-8, all the time.
third, if there are still invalid characters use a json lib with a parser (does the encoding). validate the output by parsing back to e.g. NSString. or validate the output manually by using a web form like http://jsonformatter.curiousconcept.com/
the badest way is to replace the single characters in the string, build your json and convert back. one way to do this could be to replace e.g an german ä with its unicode representaion U+00E4 (http://www.utf8-chartable.de/).
Thats the way I do it. I am glad that I nerver needed to go further than step three and this is the step you should do anyway to keep your code simple.
Please try to use Zends internal json Encoding:
Zend_Json::$useBuiltinEncoderDecoder = true;
should fix your issue.

how can i change the pattern in php?

i got this pattern for searching purpose for mysql from third party javascript. im assuming its html pattern, which can be converted, anyone have any idea on this?
pattern A%5B%D9%8B-%D9%93%D9%B0%5D*L%5B%D9%8B-%D9%93%D9%B0%5D*L%5B%D9%8B-%D9%93%D9%B0%5D*
It looks urlencoded and has some unicode charecters in it.
A[ً-ٰٓ]*L[ً-ٰٓ]*L[ً-ٰٓ]*
It looks like a query string - where values are encoded.
See http://www.blooberry.com/indexdot/html/tagpages/text.htm for more information.