Reach Child Key Without Knowing Parent's Key Objective-C - objective-c

I have this data returned from Firebase. In my app, I have a search part in which users can search other users by their nicknames. But I'm retrieving all users and I needed to pass all users to find a wanted nickname. As you can see I'm saving users with their uids which I don't store.
So I need to reach the nickname key without knowing the parent key.
7zsRWD4QraQVJiONdqKLhsn5xI73 = {
followed = (
7zsRWD4QraQVJiONdqKLhsn5xI73,
7zsRWD4QraQVJiONdqKLhsn5xI73,
7zsRWD4QraQVJiONdqKLhsn5xI73,
vexD00nIPsb6MHfuw2w8Wod9fNF3
);
icon = "man.png";
itiraf = (
{
description = Kgkgkkgk;
itirafId = 20191121144558916686058;
title = Mcnckckg;
},
);
nickName = Oykuycj;
};
oLajRgtaRIZktecSXzo4HcZlU252 = {
followed = (
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252
);
icon = "man-4.png";
in = 1;
itiraf = (
{
description = "M\U0131mu";
itirafId = 2019112813101124788975;
title = Kmkm;
}
);
nickName = 5678999;
};

I found the solution by using a for-each loop. I'm saving my data to userDic which is a NSDictionary. Here's my code search key is the wanted nickname and key taking all user ids one by one. So I can reach nicknames without knowing uids.
for (NSString* key in userDic) {
NSString *nick = [userDic[key] objectForKey:#"nickName"];
if([nick isEqualToString:searchKey]){
NSLog(#"user found");
break;
}
}

Related

For loop with If condition in Terraform

I'm writing a module to create multiple S3 Buckets with all the related resources. Currently, I'm a little bit stuck on the server side encryption as I need to parametrize the KMS key id for a key that is not still created.
The variables passed to the module are:
A list of S3 buckets
A map with the KMS created
The structure of the S3 buckets is
type = list(object({
bucket = string
acl = string
versioning = string
kms_description = string
logging = bool
loggingBucket = optional(string)
logPath = optional(string)
}))
}
The structure of the KMS map is similar to
kms_resources = {
0 = {
kms_arn = (known after apply)
kms_description = "my-kms"
kms_id = (known after apply)
}
}
This variable is an output from a previous module that creates all the KMS. The output is created this way
output "kms_resources" {
value = {
for kms, details in aws_kms_key.my-kms :
kms => ({
"kms_description" = details.description
"kms_id" = details.key_id
"kms_arn" = details.arn
})
}
}
As you can see the idea is that, on the S3 variable, the user can select his own KMS key, but I'm struggling to retrieve the value. At this moment, resource looks like this
resource "aws_s3_bucket_server_side_encryption_configuration" "my-s3-buckets" {
count = length(var.s3_buckets)
bucket = var.s3_buckets[count.index].bucket
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = [
for k in var.kms_keys : k.kms_id
if k.kms_description == var.s3_buckets[count.index].kms_description
]
sse_algorithm = "aws:kms"
}
}
}
I thought it was gonna work but once terraform is giving me Inappropriate value for attribute "kms_master_key_id": string required.. I would also like that if the value does not exist the kms_master_key_id is set by default to aws/s3
The problem seems to be that you try to give a list as kms_master_key_id instead of just a string. The fact that you alternatively want to use "aws/s3" actually makes the fix quite easy:
kms_master_key_id = concat([
for k in var.kms_keys : k.kms_id
if k.kms_description == var.s3_buckets[count.index].kms_description
], ["aws/s3"])[0]
That way you first get a list with keys / that key that matches the description and then append the default s3 key. Afterwards you simply pick the first element of the list, either the first actual key or if none matched you pick the default key.

Automatically register users

I have created my first kind of complex application.
Now I need to register around 200 accounts to the application for testing the performance. Is there some sort of tool/bot that can do this through the web or perhaps some solution to insert them directly in the database?
U can use FakeData library for that. If you search Nuget for this package u can easily find. Just run code like this when u want to insert users.
for (int i = 0; i < 200; i++)
{
string name = FakeData.NameData.GetFirstName();
string lastname = FakeData.NameData.GetSurname();
string email = FakeData.NetworkData.GetEmail();
string password = "Password!123";
//if you need you can get more data
Person p = new Person { Email = email, Name = name, Lastname = lastname ,Password=password};
//here is your registiration code
RegisterModelUser(p);
}

How can check history information for a certain customer by using scripting in NetSuite?

I want to create a Script in NetSuite which needs some history information from a customer. In fact the information I need is to know if the user has purchased an item.
For this, I would need in some way to access to the history of this customer.
Pablo.
Try including this function and passing customer's internalID and item internalID
function hasPurchasedBefore(customerInternalID, itemInternalID){
var results = [];
var filters = [];
var columns = [];
filters.push(new nlobjSearchFilter('internalidnumber', 'customermain', 'equalto', [customerInternalID]))
filters.push(new nlobjSearchFilter('anylineitem', null, 'anyof', [itemInternalID]));
filters.push(new nlobjSearchFilter('type', null, 'anyof', ['CustInvc']));
columns.push(new nlobjSearchColumn('internalid', null, 'GROUP'));
results = nlapiSearchRecord('transaction', null, filters, columns);
if (results && results.length){
return true;
}
return false;
}
Example:
var record = nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var customerInternalID = record.getFieldValue('entity');
var itemInternalID = record.getLineItemValue('item', 'item', 1); //Gets line 1 item Internal ID
if( hasPurchasedBefore(customerInternalID, itemInternalID) ) {
//Has bought something before
}
You could use a saved search nlapiLoadSearch or nlapiCreateSearch for invoices, filtered by customer, and also reporting invoice items (or just a particular item). Using nlapiCreateSearch can be tricky to use, so I'd recommend building the saved search using the UI, then load it using nlapiLoadSeach(type, id)
This will give you an array of invoices/customers that bought your item.

MapKit: How to retrieve apartment number from the return value of MKLocalSearchResponse

I searched thoroughly online but couldn't find any discussion about this:
The MKLocalSearchResponse object returned from a MapKit search is a collection of MKMapItem, which has the information of search results, e.g. City, state, country.
A single MKMapItem looks like this(from Xcode quick look of the object):
"Name: ADVANCED SOLUTIONS ADDICTION MANAGEMENT CurrentLocation: 0 Place: <GEOPlace: 0x9b2db90> {
address = {
formattedAddressLine = (
\"205 W Crestway Ave\",
\"Unit 200\",
\"Derby, KS 67037-1850\",
\"United States\"
);
structuredAddress = {
administrativeArea = Kansas;
administrativeAreaCode = KS;
country = \"United States\";
countryCode = US;
dependentLocality = (
Derby,
Rockford
);
fullThoroughfare = \"205 W Crestway Ave\";
geoId = (
);
locality = Derby;
postCode = 67037;
postCodeExtension = 1850;
postCodeFull = \"67037-1850\";
subAdministrativeArea = Sedgwick;
subLocality = Rockford;
subPremise = (
{
name = 200;
type = 0;
}
);
subThoroughfare = 205;
thoroughfare = \"W Crestway Ave\";
};
};
}"
I was able to retrieve all the information I needed, except the Apartment number. It's contained in the "subPremise" part, which I don't know how to retrieve.
You may suggest me to retrieve it from the "formattedAddressLines", which I have access to, but for some results, that property is empty, so I cannot rely on it.
I've also tried the "addressDictionary" property, it has all the necessary information except apartment number, which is very unthoughtful to me.
mapItem.placemark.subThoroughfare. Note that it may be empty

Recipe for adding Drupal node records

I am looking for a recipe for adding Drupal node records.
I have identified three tables.
node_revisions
nid=249 - vid + 1?
vid=248 - auto-increment
node:
nid=250 - vid + 1?
vid=249 - auto-increment
content_type_my_content
vid=248 - from node_revisions table?
nid=249 - from node table?
Am I on right track?
Is there some helper functions for this?
If you are looking to programatically create nodes, use the Drupal API.
Start by creating a $node object. Fill in title, type, status, body, plus any CCK fields. At the end, call node_save($node);.
node_save will save your node object and do the necessary database work.
Check this out:
http://api.drupal.org/api/function/node_save/6
http://mediumexposure.com/how-build-node-drupal-programmatically/
The easiest way to see what each type of content type has as fields is to create a node (for example, Page), then use var_dump() to see the node's contents. That will show you every field you will need to use in your node object creation script.
Some folks will say you should create a form array, and call drupal_execute() on it so validation is performed before it's saved to the database. Either way is fine.
Kevin - With your help I have made good progress.
Node and CCK fields are now being populated.
Location (long/lat) is populated but not showing up on View screen.
Checkboxes are not being populated.
global $user;
$newnode = new stdClass();
$newnode->title = 'New node title';
$newnode->body = "this is a new node, created by import function";
$newnode->uid = $user->uid;
$newnode->type = 'items';
$newnode->status = 1;
$newnode->promote = 0;
// CCK fields
$newnode->field_myfield1[0]['value'] = 'test 1';
$newnode->field_myfield2[0]['value'] = 'test 2';
$newnode->field_mycheckbox[0]['value'] = 1;
// longitude, lalitude
// $newnode->locations[0]['lid'] = ?;
$newnode->locations[0]['street'] = 'xx';
$newnode->locations[0]['city'] = 'xx';
$newnode->locations[0]['province'] = 'xx';
$newnode->locations[0]['postal_code'] = 'xx';
$newnode->locations[0]['latitude'] = 0;
$newnode->locations[0]['longitude'] = 0;
$newnode = node_submit($newnode);
node_save($newnode);
content_insert($newnode);
OK. here is the full recipe. Drupal does the rest automagically.
global $user;
// Node fields
$newnode = new stdClass();
$newnode->title = $data[0];
$newnode->body = $data[1];
$newnode->uid = $user->uid;
$newnode->type = 'mytype';
$newnode->status = 1;
$newnode->promote = 0;
// CCK fields
$newnode->field_myfield1[0]['value'] = $something;
$newnode->field_myfield2[0]['value'] = $something;
$newnode->field_my_checkbox[0]['value'] = $something;
// longitude, latitude
$newnode->field_loc_latitude[0]['street'] = $something;
$newnode->field_loc_latitude[0]['city'] = $something;
$newnode->field_loc_latitude[0]['province'] = $something;
$newnode->field_loc_latitude[0]['postal_code'] = $something;
$newnode->field_loc_latitude[0]['latitude'] = '';
$newnode->field_loc_latitude[0]['longitude'] = '';
$newnode = node_submit($newnode);
node_save($newnode);
content_insert($newnode);