I have a plist in my document folder of the app with one string, an int value. An another plist is on my server with also a string, an int value.
How can i compare the two int value and then do something if one is bigger than the other thanks to all
How about sending along that int value as part of your download url (in a query parameter), and then only download the file if the number is different? Otherwise return a HTTP 304 (content unmodified) response. This is pretty simple to do in PHP at least...
You need to download the contents of the remote plist and compare it to the local one. Then you can 'do something' if it meets the criteria (e.g. if it's bigger).
Use NSURLConnection to download the data.
You can't compare without downloading.
Related
I have a variable in one of the scenario of a feature file which I need to use in the request body of second feature file.
For Example:
A.feature
Scenario: Test
Given url 'abc'
* def number = 12345
And request {tyu:'#(number)',dhd:'lkj'}
When method put
Then status 200
B.feature
Scenario: Test2
Given url 'pqr'
And request {tyu:'#(number)'}
When method put
Then status 200
Note: Number variable in A.feature is a 6 digit number which is randomly generated everytime and the same should be passed in B.feature file.
Normally if you have two Scenario-s that depend on one another you have to combine them into one. Refer the docs here: https://github.com/intuit/karate#script-structure
But if you are really looking for how to initialize something and re-use it across all feature files, maybe you are looking for karate.callSingle(): https://github.com/intuit/karate#hooks
var result = karate.callSingle('get-token.feature');
Basically, I am facing the following issue:
I have a TAR container (no compression) of a large size (4GB). This TAR encloses several files:
file 1
file 2
file 3 - the one THAT I NEED (also very large 3 GB)
other files (it doesn't matter how many.).
I should mention that I do know where the file 3 starts (start index) and how large it is(file length) because the TAR format is relatively easy to parse.
What I need to do is upload file 3 by using PHP Curl to a REST API.THE API endpoint is HTTP PUT and the headers are correctly set (it works if I'm uploading the entire TAR file).
So, INFILE = TAR Container.
File 3 starts at the Xth Byte and has a length of Y bytes. I already know the X and Y value.
I need the curl to start sending data from X to Y.
What I did until now was:
$fileHandle = fopen($filePath, "rb"); //File path is the one of the TAR archive
fseek($fileHandle, $fileStartIndex, SEEK_CUR);
And the settings of the curl are.
curl_setopt($curlHandle, CURLOPT_PUT, 1);
curl_setopt($curlHandle, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curlHandle, CURLOPT_INFILE, $fileHandle);
curl_setopt($curlHandle, CURLOPT_INFILESIZE, $fileSize);
I must mention that extracting file 3 to disk is not an option at this moment as the disk space is the main purpose of the task.
My first idea was to look at the CURLOPT_READFUNCTION, but the callback of this option should return a string (in my case very large one :3 GB, and it breaks the PHP variable size limit).
Has anyone succeeded in handling this kind of upload? Any other tips and trick about CURLOPT_READFUNCTION are also best appreciated.
Thank you!
According to the PHP curl doc:
CURLOPT_READFUNCTION
A callback accepting three parameters. The
first is the cURL resource, the second is a stream resource provided
to cURL through the option CURLOPT_INFILE, and the third is the
maximum amount of data to be read. The callback must return a string
with a length equal or smaller than the amount of data requested,
typically by reading it from the passed stream resource. It should
return an empty string to signal EOF.
So a combination of CURLOPT_INFILE to give curl the file handle, CURLOPT_INFILESIZE to tell curl how big the final file will be and CURLOPT_READFUNCTION to allow curl to read from the file looks like it should do what you need.
Although curl will call your CURLOPT_READFUNCTION with a $length parameter, you're free to return what you want, within the rules:
The callback must return a string with a length equal or smaller than
the amount of data requested
so if you return less than $length, curl will keep calling your CURLOPT_READFUNCTION until it returns EOF (an empty string). So you need to keep track of where you are in your file when reading in CURLOPT_READFUNCTION and start from the last read position on each call.
I'm new to Swift developing. I made tableView with 16 rows - there are names and prices of every items.
When the user clicks on a row, a new tableView (with static cell) is shown. The user can edit price (I only need price to be mutable) and save it. Then, the original tableView with the new price is shown.
BUT when I stop and load app again there is the original prices.
I found out that I have to use Core Data to storage data permanently. BUT I need the database to be filled with these 16 rows (with the first load after installing) and then let user to change price permanently (or until change it again).
It is possible? And how? Should I use Core Data or is there an easier option?
Pretty much everything suggested to you so far is more complex than it needs to be. You're talking about local data, and a very small amount of it.
The simplest option is to use a plist.
Xcode can help if you create a new file, select Resource as the type and then Property List. Once created it'll contain a dictionary by default, but you can convert that to an array. Add your data, so you have an array of dictionaries with your values for price etc.
Now, this file will be part of the bundle when you run the app, so you can't edit it. You should copy the file by finding it with NSBundle and copying it with NSFileManager into the documents folder.
Once it's there you can use NSArray init?(contentsOfFile path: String) to load the data. Use mutableCopy to create a version you can edit. You can use this array to drive your table view and you can edit the values it contains. Note that with this simple technique the dictionaries in the array will be immutable, so you're probably better off using NSPropertyListSerialization class func propertyListWithData(_ data: NSData, options opt: NSPropertyListReadOptions, format format: UnsafeMutablePointer<NSPropertyListFormat>) throws -> AnyObject with an option of MutableContainersAndLeaves instead.
Once you've edited the array contents you can write it back to disk for next run (with class func dataWithPropertyList(_ plist: AnyObject, format format: NSPropertyListFormat, options opt: NSPropertyListWriteOptions) throws -> NSData)
I am trying to find the max changestamp so I can start using it. I tried the following:
URL url = "https://docs.google.com/feeds/default/private/changes?v=3"
ChangelogFeed foo = service.getFeed(url, ChangelogFeed.class);
LargestChangestamp stamp = foo.getLargestChangestamp();
stamp is always null.
Is this the way to get the largest changestamp, or do I need to set it first in order to use it?
The largest changestamp is also available in the user metadata feed. See the "docs:largestChangestamp" element within the response protocol tab here,
I'm not sure the java api exposes the largestChangestamp property directly yet - last time I checked it was hidden in the xmlBlob property, and I had to do an xml parse to grab it out.
This seems to be a bug in the API. I got the changestamps by getting the ChangelogEntrys from the ChangelogFeed:
List<ChangelogEntry> entries = foo.getEntries();
for (ChangelogEntry entry: entries) {
String blob = entry.getXmlBlob().getBlob();
System.out.println("Blob: " + blob);
}
The changestamp for an entry is contained in its blob.
I have an application that generates Open XML documents with Content Controls.
To create a new Content Control I use Interop and the method ContentControls.Add. This method returns an instance of the added Content Control.
I have some logic that saves the id of the Content Control to reference it later, but in some computers I've been having a weird problem.
When I access the ID property of the Content Control I just created, it returns a string with the numeric id, the problem is that when this value is too big, after I save the document, if I look through the document.xml in the generated document, the <w:id/> element of the <w:sdtPr/> element has a negative value, that is the signed equivalent of the value I got from the Id property of the generated control.
For example:
var contentControl = ContentControls.Add(...);
var contentControlId = contentControl.ID;
// the value of contentControlId is "3440157266"
If I save the document and open it in the Package Explorer, the Id of the Content Control is "-854810030" instead of "3440157266".
What have I figured out is this:
((int)uint.Parse("3440157266")).ToString() returns "-854810030"
Any idea of why this happens? This issue is hard to replicate because I don't control the Id of the generated controls, the Id is automatically generated by the Interop libraries.
When displayed in 32-bit binary format, -854810030 and 3440157266 are just the same!
This problem is mentioned in the MSDN documentation of the ContentControl.ID Property:
When you get the ID property value at runtime, it is returned as an unsigned value. However, when saved into the Office Open XML file format, it is saved as a signed value. If your solution attempts to map programmatically returned values to values saved in the file format, you must check for both the unsigned and signed version of the value obtained from this property.
As Claude Martel mentioned, -854810030 and 3440157266 are ident. You can easily check this by casting the signed Int32 to a unsigned UInt32:
var id = Convert.ToInt32("-854810030 ");
UInt32 uId = (uint) id;
Assert.AreEqual(3440157266, uId);
I've had the very same type of issue in the past. The ID is unreliable as it doesn't seem to perpeturate. What I did instead is stored a name of the Content Control's .Tag so I could access it later.