How to sum row by row using app scripts? - google-sheets

I am trying to sum row by row and have values in grand total cell for respective rows.
I tried looping in the app scripts. But couldn't. Can anyone help me with this?
I have this data from b3:f16 and I need grand total in h3:h16
1906 904 106 221 1640
1771 842 97 188 1338
3221 1005 252 260 6323
3239 1141 317 287 7828
3556 1409 352 337 8890
3417 1307 303 382 7143
3264 1824 358 444 9288
2724 1916 196 395 3462
2641 1829 151 430 3255
4076 1858 398 471 12844
3986 2098 468 426 13411
4829 2504 422 514 14449
4462 4876 452 507 13285
5017 6654 423 410 7765
Code:
function adder() {
var sheet = SpreadsheetApp.getActiveSheet().getSheetByName("sheet1");
var data = sheet.getRange("B3:F16").getValues();
var range = sheet.getRange("H3:H16");
for(var i = 0; i < data.length; i++) {
var sum = 0;
for(var j = 0; j < data[i].length ; j++) {
sum += data[i][j];
}
range.setValue(sum);
Logger.log(sum);
}
}

this could be done with MMULT..
In G3, try:
=ArrayFormula(mmult(B3:F16, transpose(column(B3:F3)^0)))
If you want to use script, see if this works:
function adder() {
var sheet = SpreadsheetApp.getActive()
.getSheetByName("sheet1"),
res = [];
sheet.getRange("B3:F16")
.getValues()
.forEach(function (r) {
res.push([r.reduce(function (a, b) {
return a + b;
})])
});
sheet.getRange("H3:H16")
.setValues(res);
}
or with 'classic' for loops:
function adder2() {
var sheet = SpreadsheetApp.getActive()
.getSheetByName("Test"),
res = [],
sum,
data = sheet.getRange("B3:F16")
.getValues();
for (var i = 0, rlen = data.length; i < rlen; i++) {
sum = 0;
for (var j = 0, clen = data[0].length; j < clen; j++) {
sum += Number(data[i][j])
}
res.push([sum])
}
sheet.getRange("H3:H16")
.setValues(res);
}

Related

icinga2 - where to change client monitoring commands?

system ubuntu 16.04
On master node where icinga2 is installed
#ls /etc/icinga2/repository.d/hosts/WIN-U52321E0BAK/
disk C%3A.conf disk.conf icinga.conf load.conf ping4.conf
ping6.conf procs.conf swap.conf users.conf
All conf files have save "dummy" check_command on them for example
#cat load.conf
object Service "load" {
import "satellite-service"
check_command = "dummy"
host_name = "WIN-U52321E0BAK"
zone = "WIN-U52321E0BAK"
}
I cant understand from where dummy command is called and how to customize the checks for warning and critical threshold
The dummy command is defined in /usr/share/icinga2/include/command-plugins.conf, like so:
144 object CheckCommand "dummy" {
145 import "plugin-check-command"
146
147 command = [
148 PluginDir + "/check_dummy",
149 "$dummy_state$",
150 "$dummy_text$"
151 ]
152
153 vars.dummy_state = 0
154 vars.dummy_text = "Check was successful."
155 }
In order to modify the warn and crit levels, you set the custom variable at the host or service level. Using the example of ping, we see the default configuration in that same file:
36 template CheckCommand "ping-common" {
37 import "plugin-check-command"
38
39 command = [ PluginDir + "/check_ping" ]
40
41 arguments = {
42 "-H" = "$ping_address$"
43 "-w" = "$ping_wrta$,$ping_wpl$%"
44 "-c" = "$ping_crta$,$ping_cpl$%"
45 "-p" = "$ping_packets$"
46 "-t" = "$ping_timeout$"
47 }
48
49 vars.ping_wrta = 100
50 vars.ping_wpl = 5
51 vars.ping_crta = 200
52 vars.ping_cpl = 15
53 }
Here's the important bit:
49 vars.ping_wrta = 100
50 vars.ping_wpl = 5
51 vars.ping_crta = 200
52 vars.ping_cpl = 15
So: we go to our host or service definition, thusly (using /etc/icinga2/conf.d/host.conf and the NodeName/localhost definition which everybody has; comments removed):
18 object Host NodeName {
20 import "generic-host"
21
23 address = "127.0.0.1"
24 address6 = "::1"
25
27 vars.os = "Linux"
30 vars.http_vhosts["http"] = {
31 http_uri = "/"
32 }
37
39 vars.disks["disk"] = {
41 }
42 vars.disks["disk /"] = {
43 disk_partitions = "/"
44 }
45 }
And we insert before line 45 above to produce:
18 object Host NodeName {
20 import "generic-host"
21
23 address = "127.0.0.1"
24 address6 = "::1"
25
27 vars.os = "Linux"
30 vars.http_vhosts["http"] = {
31 http_uri = "/"
32 }
37
39 vars.disks["disk"] = {
41 }
42 vars.disks["disk /"] = {
43 disk_partitions = "/"
44 }
45 vars.ping_wrta = 50
46 vars.ping_wpl = 3
47 vars.ping_crta = 10
48 vars.ping_cpl = 2
49 }
...and you have successfully customized the check threshold. You can add those variables to a template or even a hostgroup (I think; better test that, I may be wrong).

Obj-C: Application crashing while converting NSDictionary to JSON

I am reading safari's Bookmarks.plist and storing it in an NSDictionary then trying to convert the NSDictionary into JSON
Problem
Bookmarks data is getting into dictionary but when I am converting the data into JSON the application is crashing.
NSString* path = #"path of the plist file";
NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:path];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:plistDict
options:NSJSONWritingPrettyPrinted error:&error];
NSString* result = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
Reason
The NSDictonary made of the Plist file contains some fields that are the type of NSData. Is there a way to convert all NSData fields to Base64 string in order clean the NSDictionary? Note that it is not possible to be aware of what fields and how many fields are type of NSData beforehand.
ErrorLog
2016-04-12 14:44:13.560 plistTOjosn[4228:68289] An uncaught exception was raised
2016-04-12 14:44:13.560 plistTOjosn[4228:68289] Invalid type in JSON write (__NSCFData)
2016-04-12 14:44:13.561 plistTOjosn[4228:68289] (
0 CoreFoundation 0x00007fff92d9b03c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff914e176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92d9aeed +[NSException raise:format:] + 205
3 Foundation 0x00007fff91174b9a _writeJSONValue + 715
4 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
5 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
6 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
7 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
8 Foundation 0x00007fff91175b1f _writeJSONObject + 439
9 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
10 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
11 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
12 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
13 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
14 Foundation 0x00007fff91175b1f _writeJSONObject + 439
15 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
16 Foundation 0x00007fff9117489a -[_NSJSONWriter dataWithRootObject:options:error:] + 137
17 Foundation 0x00007fff91174765 +[NSJSONSerialization dataWithJSONObject:options:error:] + 345
18 Utilities 0x00000001000c7d0b -[BrowserJunkUtilities readPlistFileFromSafariProfiles:] + 331
19 Utilities 0x00000001000c7e4b -[BrowserJunkUtilities safariBookmarksJson] + 59
20 Utilities 0x00000001000bbd5c -[BrowserJunkUtilities LogInBigData] + 252
21 Utilities 0x00000001000c1af2 -[BrowserJunkUtilities init] + 5970
22 plistTOjosn 0x00000001000299e5 -[DashBoardView init] + 261
23 plistTOjosn 0x0000000100016e45 -[AppController changeViewController:RunFix:] + 757
24 plistTOjosn 0x0000000100018fe5 -[AppController showIntroView:tag:] + 181
25 plistTOjosn 0x0000000100016a7f -[AppController awakeFromNib] + 1103
26 CoreFoundation 0x00007fff92ca7bdf -[NSSet makeObjectsPerformSelector:] + 223
27 AppKit 0x00007fff9329e03d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
28 AppKit 0x00007fff9327d0e5 loadNib + 384
29 AppKit 0x00007fff9327c60b +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 313
30 AppKit 0x00007fff9327c3c7 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 201
31 AppKit 0x00007fff9327c193 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 344
32 AppKit 0x00007fff93274d79 NSApplicationMain + 605
33 plistTOjosn 0x0000000100007542 main + 34
34 plistTOjosn 0x00000001000016d4 start + 52
35 ??? 0x0000000000000003 0x0 + 3
)
2016-04-12 14:44:13.690 plistTOjosn[4228:68289] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSCFData)'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff92d9b03c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff914e176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92d9aeed +[NSException raise:format:] + 205
3 Foundation 0x00007fff91174b9a _writeJSONValue + 715
4 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
5 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
6 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
7 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
8 Foundation 0x00007fff91175b1f _writeJSONObject + 439
9 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
10 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
11 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
12 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
13 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
14 Foundation 0x00007fff91175b1f _writeJSONObject + 439
15 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
16 Foundation 0x00007fff9117489a -[_NSJSONWriter dataWithRootObject:options:error:] + 137
17 Foundation 0x00007fff91174765 +[NSJSONSerialization dataWithJSONObject:options:error:] + 345
18 Utilities 0x00000001000c7d0b -[BrowserJunkUtilities readPlistFileFromSafariProfiles:] + 331
19 Utilities 0x00000001000c7e4b -[BrowserJunkUtilities safariBookmarksJson] + 59
20 Utilities 0x00000001000bbd5c -[BrowserJunkUtilities LogInBigData] + 252
21 Utilities 0x00000001000c1af2 -[BrowserJunkUtilities init] + 5970
22 plistTOjosn 0x00000001000299e5 -[DashBoardView init] + 261
23 plistTOjosn 0x0000000100016e45 -[AppController changeViewController:RunFix:] + 757
24 plistTOjosn 0x0000000100018fe5 -[AppController showIntroView:tag:] + 181
25 plistTOjosn 0x0000000100016a7f -[AppController awakeFromNib] + 1103
26 CoreFoundation 0x00007fff92ca7bdf -[NSSet makeObjectsPerformSelector:] + 223
27 AppKit 0x00007fff9329e03d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
28 AppKit 0x00007fff9327d0e5 loadNib + 384
29 AppKit 0x00007fff9327c60b +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 313
30 AppKit 0x00007fff9327c3c7 -[NSBundle(NSNibLoadin
g) loadNibNamed:owner:topLevelObjects:] + 201
31 AppKit 0x00007fff9327c193 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 344
32 AppKit 0x00007fff93274d79 NSApplicationMain + 605
33 plistTOjosn 0x0000000100007542 main + 34
34 plistTOjosn 0x00000001000016d4 start + 52
35 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
PLIST DATA
{
Children = (
{
Title = History;
WebBookmarkIdentifier = History;
WebBookmarkType = WebBookmarkTypeProxy;
WebBookmarkUUID = "019DBF83-1882-46AA-A8A7-669CCD3D5AB8";
},
{
Children = (
{
Sync = {
Key = "\"C=32#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/63582BD8-0400-40C4-9CA7-8942391957B8.xbel";
};
URIDictionary = {
title = "vikas Technologies Pvt. Ltd Mail";
};
URLString = "https://mail.google.com/mail/u/0/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "AFDCB7C0-10CE-4273-BDF8-E2FC40D83A3A";
},
{
Sync = {
Key = "\"C=6#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/474F816C-BB3E-4F42-89B4-666F5E323840.xbel";
};
URIDictionary = {
title = Apple;
};
URLString = "https://www.apple.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "4468D8F5-6A99-4B0A-85AD-E1E49B58546D";
},
{
Sync = {
Key = "\"C=8#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/89401E9C-92BB-4935-91D1-F968FD90239B.xbel";
};
URIDictionary = {
title = iCloud;
};
URLString = "https://www.icloud.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "2E4E8D77-D2C4-4B79-A563-5FF5FED0D553";
},
{
Sync = {
Key = "\"C=10#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/6B14FBB9-DA11-4F5B-BF85-4E997D73C720.xbel";
};
URIDictionary = {
title = Yahoo;
};
URLString = "https://www.yahoo.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "9CFD581F-2404-4BDF-8795-5D4DCC9A7CF0";
},
{
Sync = {
Key = "\"C=12#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/0F0130B7-2F0C-4BD5-9173-E91C210F845C.xbel";
};
URIDictionary = {
title = Bing;
};
URLString = "https://www.bing.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "89FEEC32-AC16-4A80-8875-68BE4A191862";
},
{
Sync = {
Key = "\"C=14#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/9554C3E5-61CD-40BE-BFB2-7FBEB22807C0.xbel";
};
URIDictionary = {
title = Google;
};
URLString = "https://www.google.com/?client=safari&channel=mac_bm";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "5A013EF2-E017-41B3-8FAE-2DA718D35AC5";
},
{
Sync = {
Key = "\"C=16#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/56EA5315-E1B1-430B-A018-7326A247ECAA.xbel";
};
URIDictionary = {
title = Wikipedia;
};
URLString = "https://www.wikipedia.org/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "49CE5DC7-6ABD-4876-95E4-0C7A007DED0D";
},
{
Sync = {
Key = "\"C=18#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/FDF4AD0D-FD33-4EE2-9097-19CA5046AFB7.xbel";
};
URIDictionary = {
title = Facebook;
};
URLString = "https://www.facebook.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "530A47C6-D116-4081-9BED-3C469C7C7697";
},
{
Sync = {
Key = "\"C=20#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/3E61C9CF-7646-4475-AC89-FB157DA50181.xbel";
};
URIDictionary = {
title = Twitter;
};
URLString = "https://twitter.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "D3893EF3-A885-41F6-A128-BBAC37A2033B";
},
{
Sync = {
Key = "\"C=22#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/C8801D19-7A76-4290-8950-5DA9385F3415.xbel";
};
URIDictionary = {
title = LinkedIn;
};
URLString = "https://www.linkedin.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "47F6045D-4F9A-4856-916A-07CB8889B7E2";
},
{
Sync = {
Key = "\"C=24#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/DF10E9C3-01FA-4EC6-ADE2-4A0B1FECD9EF.xbel";
};
URIDictionary = {
title = "The Weather Channel";
};
URLString = "http://www.weather.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "0DDD3778-437A-4FAE-8529-D389A5122758";
},
{
Sync = {
Key = "\"C=26#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/79C2C180-430C-4092-A4CF-D2B8F4551B1E.xbel";
};
URIDictionary = {
title = Yelp;
};
URLString = "http://www.yelp.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "2FD1AB60-B3A0-44D5-A20D-68CF51A40584";
},
{
Sync = {
Key = "\"C=28#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/63EDC45D-3138-41CF-A617-4178097656F0.xbel";
};
URIDictionary = {
title = TripAdvisor;
};
URLString = "http://www.tripadvisor.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "A6DA8288-409E-4B03-84E4-ACEF9F2B624C";
},
{
Sync = {
Key = "\"C=30#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/40F8D2AF-4F2E-44BE-8250-41E1C7C0F1D9.xbel";
};
URIDictionary = {
title = "ADplus.aspx";
};
URLString = "http://dev.etelmar.net/ADEV_ADplus3-01/ADplus.aspx";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "C5D3ADD4-DB17-421D-BAF5-04927F713BCE";
}
);
Sync = {
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/";
};
Title = BookmarksBar;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "E2EC6281-F0F9-41FA-9C2C-2DC8745F547A";
},
{
Sync = {
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/C81C19F2-E6A6-46C7-9836-DC58A02B46AB/";
};
Title = BookmarksMenu;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "06621BC7-DAA3-4225-8BCB-A65A8E0D0916";
}
);
Sync = {
ServerData = <62706c69 73743030 de010203 04050607 08090a0b 0c0d0e0f 10111213 14151624 25303120 20545054 61675443 54616757 50757368 4b65795d 426f6f6b 6d61726b 42617249 645d486f 6d655552 4c537472 696e675e 426f6f6b 6d61726b 4d656e75 49645c41 63636f75 6e745072 7349645c 42756c6b 52657175 65737473 5953796e 63546f6b 656e5e50 75736854 72616e73 706f7274 735d436c 69656e74 56657273 696f6e5f 10125072 696e6369 70616c55 524c5374 72696e67 5f101653 7570706f 72747353 796e6343 6f6c6c65 6374696f 6e5f100f 496e6974 69616c53 796e6344 6f6e655f 10195365 72766572 446f6573 4e6f7453 7570706f 72745054 6167735f 10314654 3d2d4052 553d3139 30313633 30352d35 3663392d 34333763 2d393566 342d3933 35323162 61643262 65384053 3d33315a 38343032 36333033 36385f10 72687474 70733a2f 2f62616e 73616c76 6b732534 3069636c 6f75642e 636f6d40 7033352d 626f6f6b 6d61726b 732e6963 6c6f7564 2e636f6d 2f383430 32363330 3336382f 626f6f6b 6d61726b 732f3241 36363246 45412d33 3546392d 34344335 2d383742 392d3844 44454245 30453439 31322f5f 104d6874 7470733a 2f2f6261 6e73616c 766b7325 34306963 6c6f7564 2e636f6d 40703335 2d626f6f 6b6d6172 6b732e69 636c6f75 642e636f 6d2f3834 30323633 30333638 2f626f6f 6b6d6172 6b732f5f 10726874 7470733a 2f2f6261 6e73616c 766b7325 34306963 6c6f7564 2e636f6d 40703335 2d626f6f 6b6d6172 6b732e69 636c6f75 642e636f 6d2f3834 30323633 30333638 2f626f6f 6b6d6172 6b732f43 38314331 3946322d 45364136 2d343643 372d3938 33362d44 43353841 30324234 3641422f 5a383430 32363330 333638d2 17181922 54637275 64567369 6d706c65 d41a1b1c 1d1e1f20 20586d61 782d7369 7a655d6d 61782d72 65736f75 72636573 56757064 61746556 696e7365 72741200 a0000010 c80909d3 1b1d1a1f 201e095f 103e4441 5653542d 56312d70 33352d46 543d2d40 52553d31 39303136 3330352d 35366339 2d343337 632d3935 66342d39 33353231 62616432 62653840 533d3333 d1262754 41505344 d428292a 2b2c2d2e 2f5b6170 7362756e 646c6569 6453656e 765f1010 73756273 63726970 74696f6e 2d75726c 5f101072 65667265 73682d69 6e746572 76616c5f 1010636f 6d2e6d65 2e626f6f 6b6d6172 6b735a50 524f4455 4354494f 4e5f1053 68747470 733a2f2f 62616e73 616c766b 73253430 69636c6f 75642e63 6f6d4070 33352d62 6f6f6b6d 61726b73 2e69636c 6f75642e 636f6d2f 38343032 36333033 36382f6d 6d2f7075 73682f72 65676973 74657256 31323030 30301001 5f104d68 74747073 3a2f2f62 616e7361 6c766b73 25343069 636c6f75 642e636f 6d407033 352d626f 6f6b6d61 726b732e 69636c6f 75642e63 6f6d2f38 34303236 33303336 382f7072 696e6369 70616c2f 09090008 0025002a 002f0037 00450053 0062006f 007c0086 009500a3 00b800d1 00e300ff 0133013e 01b30203 02780283 0288028d 0294029d 02a602b4 02bb02c2 02c702c9 02ca02cb 02d202d3 03140317 031c0325 03310335 0348035b 036e0379 03cf03d6 03d80428 04290000 00000000 02010000 00000000 00340000 00000000 00000000 00000000 042a>;
};
Title = "";
WebBookmarkFileVersion = 1;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "FBAA875A-C10A-4744-98BD-DC5EC1D9A009"; }
Before converting any object into json, first check that given object is json convertible or not, you can use following code to check that
if ([NSJSONSerialization isValidJSONObject: plistDict])
{
....
}
Because a JSON Object must be of type NSArray or a NSDictionary while you are passing a NSString.
From the docs :
An object that may be converted to JSON must have the following
properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
Numbers are not NaN or infinity.
Your data structure can be successfully read into a NSDictionary instance. But when you serialize it to JSON it fails because it contains parts that cannot be represented as JSON.
My guess is that it's the data at $.Sync.ServerData. This seems to be binary data. JSON doesn't have an data type for binary data.
Remove this element before you serialize it. Or replace it with something else, e.g. a string with a Base-64 representation of the binary data.
The crucial information is
Invalid type in JSON write (__NSCFData)
JSON does not support NSData type (the value of ServerData), you might send the data as string Base64 encoded.
This is the key:
Invalid type in JSON write (__NSCFData)
You cannot serialise NSData to JSON. Try encoding it to string using base-64 (see this answer to do that).
Do this way may be it helps you
{ NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *str=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *dict6 = [self cleanJsonToObject:responseData];
self.handmadeEmbDict = [dict6 objectForKey:#"hemb_list"];
[handmadeEmbTable reloadData];
}
- (id)cleanJsonToObject:(id)data {
NSError* error;
if (data == (id)[NSNull null]){
return [[NSObject alloc] init];
}
id jsonObject;
if ([data isKindOfClass:[NSData class]]){
jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
} else {
jsonObject = data;
}
if ([jsonObject isKindOfClass:[NSArray class]]) {
NSMutableArray *array = [jsonObject mutableCopy];
for (int i = (int)array.count-1; i >= 0; i--) {
id a = array[i];
if (a == (id)[NSNull null]){
[array removeObjectAtIndex:i];
} else {
array[i] = [self cleanJsonToObject:a];
}
}
return array;
} else if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *dictionary = [jsonObject mutableCopy];
for(NSString *key in [dictionary allKeys]) {
id d = dictionary[key];
if (d == (id)[NSNull null]){
dictionary[key] = #"";
} else {
dictionary[key] = [self cleanJsonToObject:d];
}
}
return dictionary;
} else {
return jsonObject;
}
}
Swift 2
if let path = NSBundle.mainBundle().pathForResource("try", ofType: "json")
{
do {
let jsonData = try NSData(contentsOfFile:
path, options: NSDataReadingOptions.MappedRead)
let dict = try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableLeaves)
let rootDict = dict
Print(rootDict)
catch
{
}
}

why is code not executing on return from Future in Dart program

Could someone please explain to me why in the following code (using r25630 Windows), the value of iInsertTot at line 241 is null, or more to the point, why is line 234 ("return iInsertTot;") not executed and therefore at line 241, iInsertTot is null. The value of iInsertTot at lines 231/232 is an integer. While I can and probably should code this differently, I thought that I would try and see if it worked, because my understanding of Futures and Chaining was that it would work. I have used “return” in a similar way before and it worked, but I was returning null in those cases (eg. line 201 below).
/// The problem lines are :
233 fUpdateTotalsTable().then((_) {
234 return iInsertTot;
235 });
While running in the debugger, it appears that line 234 “return iInsertTot;” is never actually executed. Running from command line has the same result.
The method being called on line 233 (fUpdateTotalsTable) is something I am just in the process of adding, and it consists basically of sync code at this stage. However, the debugger appears to go through it correctly.
I have included the method “fUpdateTotalsTable()” (line 1076) just in case that is causing a problem.
Lines 236 to 245 have just been added, however just in case that code is invalid I have commented those lines out and run with the same problem occurring.
218 /*
219 * Process Inserts
220 */
221 }).then((_) {
222 sCheckpoint = "fProcessMainInserts";
223 ogPrintLine.fPrintForce ("Processing database ......");
224 int iMaxInserts = int.parse(lsInput[I_MAX_INSERTS]);
225 print ("");
226 return fProcessMainInserts(iMaxInserts, oStopwatch);
227 /*
228 * Update the 'totals' table with the value of Inserts
229 */
230 }).then((int iReturnVal) {
231 int iInsertTot = iReturnVal;
232 sCheckpoint = "fUpdateTotalsTable (insert value)";
233 fUpdateTotalsTable().then((_) {
234 return iInsertTot;
235 });
236 /*
237 * Display totals for inserts
238 */
239 }).then((int iInsertTot) {
240 ogTotals.fPrintTotals(
241 "${iInsertTot} rows inserted - Inserts completed",
242 iInsertTot, oStopwatch.elapsedMilliseconds);
243
244 return null;
245 /*
192 /*
193 * Clear main table if selected
194 */
195 }).then((tReturnVal) {
196 if (tReturnVal)
197 ogPrintLine.fPrintForce("Random Keys Cleared");
198 sCheckpoint = "Clear Table ${S_TABLE_NAME}";
199 bool tClearTable = (lsInput[I_CLEAR_YN] == "y");
200 if (!tFirstInstance)
201 return null;
202 return fClearTable(tClearTable, S_TABLE_NAME);
203
204 /*
205 * Update control row to increment count of instances started
206 */
207 }).then((_) {
1073 /*
1074 * Update totals table with values from inserts and updates
1075 */
1076 async.Future<bool> fUpdateTotalsTable() {
1077 async.Completer<bool> oCompleter = new async.Completer<bool>();
1078
1079 String sCcyValue = ogCcy.fCcyIntToString(ogTotals.iTotAmt);
1080
1081 print ("\n********* Total = ${sCcyValue} \n");
1082
1083 oCompleter.complete(true);
1084 return oCompleter.future;
1085 }
Your function L230-235 does not return anything and that's why your iInsertTot is null L239. To make it work you have to add a return at line 233.
231 int iInsertTot = iReturnVal;
232 sCheckpoint = "fUpdateTotalsTable (insert value)";
233 return fUpdateTotalsTable().then((_) {
234 return iInsertTot;
235 });

Why my [UIScrollView removeFromSuperview] is crashing?

The crash log is below.
Do you know any particular reason why might [UIScrollView removeFromSuperview] can crash? The scrollview contains view hierarchy with different types of UIViews. I also finds that the ad hoc version crash often not the debug version. I could not find any reason for that.
Same viewcontroller is loaded in a different flow in iPhone that works fine. But in iPad it crashes.
In iPad, in a container view controller, only viewcontroler.view is loaded.
Incident Identifier: EE102239-34D1-4BE7-8B52-41F74AB26203
CrashReporter Key: 2b11ea2a01ac5618e199ffc5a1e1f321600bb6a9
Hardware Model: iPad3,4
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-06-18 15:19:16.132 +0200
OS Version: iOS 6.1.3 (10B329)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3bab7070 prepareForMethodLookup + 20
1 libobjc.A.dylib 0x3bab6fb2 lookUpMethod + 42
2 libobjc.A.dylib 0x3bab6f7e _class_lookupMethodAndLoadCache3 + 14
3 libobjc.A.dylib 0x3bab6638 objc_msgSend_uncached + 24
4 QuartzCore 0x357f2a72 CA::Layer::contents_visibility_changed(CA::Transaction*, bool) + 50
5 QuartzCore 0x357f29de CA::Layer::mark_visible(CA::Transaction*, bool) + 190
6 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
7 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
8 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
9 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
10 QuartzCore 0x357f28d2 CA::Layer::update_removed_sublayer(CA::Transaction*, unsigned int) + 18
11 QuartzCore 0x357f255a CA::Layer::remove_sublayer(CA::Transaction*, CALayer*) + 130
12 QuartzCore 0x357f246a CA::Layer::remove_from_superlayer() + 34
13 UIKit 0x35a6e92c -[UIView(Hierarchy) removeFromSuperview] + 144
14 UIKit 0x35b857bc -[UIScrollView removeFromSuperview] + 60
15 MyApp 0x000bde8a -[iPadNavigationController vcAnimationDone] (iPadNavigationController.m:400)
16 UIKit 0x35a55ab6 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 154
17 UIKit 0x35aca8f8 -[UIViewAnimationState animationDidStop:finished:] + 44
18 QuartzCore 0x35801304 CA::Layer::run_animation_callbacks(void*) + 204
19 libdispatch.dylib 0x3bed55d8 _dispatch_client_callout + 20
20 libdispatch.dylib 0x3bed8e40 _dispatch_main_queue_callback_4CF + 224
21 CoreFoundation 0x33c051ac __CFRunLoopRun + 1284
22 CoreFoundation 0x33b78238 CFRunLoopRunSpecific + 352
23 CoreFoundation 0x33b780c4 CFRunLoopRunInMode + 100
24 GraphicsServices 0x37733336 GSEventRunModal + 70
25 UIKit 0x35a942b4 UIApplicationMain + 1116
A few line from the code (as asked),
previous = showing;
showing = [ vc retain ];
showing.view.frame = startFrameIn;
[ container addSubview:showing.view ];
CGContextRef context = UIGraphicsGetCurrentContext();
[ UIView beginAnimations:nil context:context ];
[ UIView setAnimationDelegate:self ];
[ UIView setAnimationDidStopSelector:#selector(vcAnimationDone) ];
[ UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[ UIView setAnimationDuration:0.4 ];
previous.view.frame = endFrameOut;
showing.view.frame = detailFrame;
[ UIView commitAnimations ];
}
- (void) vcAnimationDone {
if ( previous != nil ) {
if (previous.view.superview != nil) {
[previous.view removeFromSuperview];
}
[ previous release ];
previous = nil;
}
A very probable reason is that you are overreleasing your scrollview or one of the views inside it.
Calling removeFromSuperview then deallocates the view instead of simply decreasing the retain count.
Actually, if you are still stuck with non-ARC project, Static Code Analysis is very useful for this kind of bug. Retain/release balancing issues are hard to pin down, and nearly impossible with incomplete method so I suggest you post the full method body if possible.
Thanks everyone for your answers, tips and tricks. However one thing I want share with you is the cause of the crash. I found that the crash was at different thread in different times. I had several views loaded with button pressing/menu in my iPad app. Some of the button pressing fetch data from web service. So I was bit confused to get the cuase of crash, animation, or url connection etc... I tried with enabled NSZombie objects, but it did not show any information.
Then I tried with Guard Malloc. This only runs in Simulator. And magically I found the code point of crash. I have function to convert a hex string into data. There I have line of code to make a C string null terminated. where I assigned 0 at the last index. and that makes the crash!
tmpCh[count] = 0;
I do not why, but probably it takes some time in the memory management procedure in iOS so it crash at different thread at different times. But with Guard malloc in Simulator, it always point out here and when I rewrite the code, the crash is gone.
/* Converts a hex string to bytes.
Precondition:
. The hex string can be separated by space or not.
. the string length without space or 0x, must be even. 2 symbols for one byte/char
. sample input: 23 3A F1 OR 233AF1
*/
+ (NSData *) dataFromHexString:(NSString*)hexString
{
if (hexString.length < 1) {
return nil;
}
char * tmpCh = (char *) malloc([hexString length] * sizeof(char));
int count = 0;
for (int k=0; k<hexString.length;k++) {
char c = [hexString characterAtIndex:k];
if (c == (char)0x20) { //skip space
continue;
}
if (c == '0') { // skip 0x
if(k+1 < hexString.length){
if ([hexString characterAtIndex:k+1] == 'x'
|| [hexString characterAtIndex:k+1] == 'X' )
{
k = k + 1;
continue;
}
}
}
tmpCh[count] = c;
count++;
}
tmpCh[count] = 0; // make null terminated string
if (count % 2) {
return nil;
}
NSString *temp = [[NSString alloc] initWithUTF8String:tmpCh];
free(tmpCh);
if ([temp length] % 2 != 0) {
return nil;
}
NSMutableData *result = [[NSMutableData alloc] init];
unsigned char byte;
char hexChars[3] = {0};
for (int i=0; i < (temp.length/2); i++) {
hexChars[0] = [temp characterAtIndex:i*2];
hexChars[1] = [temp characterAtIndex:i*2+1];
if (![Util isValidChar:hexChars[0]] || ![Util isValidChar:hexChars[1]]) {
return nil;
}
byte = strtol(hexChars, NULL, 16);
[result appendBytes:&byte length:1];
}
NSData * data = [NSData dataWithData:result];
[result release];
return data;
}

ios Right way to free 2 dimensional memory allocated via calloc

I have a iOS app. I allocate 2d memory and then deallocate using free function. Is this the right way to free? Recently I had crash pointing to free statement. Should I be releasing buf[i] in loop?
+(int**) initArr:(int) Nr:( int) Nc
{
int ** buf;
buf = calloc(Nr,sizeof(int*));
for(int i = 0; i < Nr; i++)
{
buf[i] = calloc(Nc,sizeof(int));
}
//Funny Processing
//Release
for(int i = 0; i < Nr; i++)
free(buf[i]);
free(buf);
}
Here is the error message
2 libsystem_c.dylib 0x328b87ec _sigtramp + 48
3 libsystem_c.dylib 0x328ae20e pthread_kill + 54
4 libsystem_c.dylib 0x328a729e abort + 94
5 libsystem_c.dylib 0x32862380 free + 380
6 MyApp 0x0009be52 +[clsGlobalHelper resizeImageAvg:::] (clsGlobalHelper.m:300)

Resources