I am working with the COBOL Enterprise 6.3 JSON-GENERATE, using the SUPPRESS phrase. I have the following COBOL data area:
05 contactInfo.
07 postalAddresses OCCURS 0 TO 10
DEPENDING ON WIMBCST-POSTAL-COUNT.
09 POSTAL-ID PIC X(40).
09 addressCategory PIC X(30).
09 startDate PIC X(10).
09 legalAddressStartDate PIC X(10).
09 endDate PIC X(10).
09 perpetualEndDate PIC X(10).
09 perpetualStartDate PIC X(10).
09 addressFormatName PIC X(10).
09 POSTAL-SEQ PIC 99.
09 postalAddressType PIC X(20).
09 addressLines OCCURS 10 TIMES.
11 addressLineType PIC X(20).
11 addressLineText PIC X(60).
09 locationLines OCCURS 10 TIMES.
11 locationType PIC X(20).
11 locationText PIC X(60).
The data is initially LOW-VALUES. When the JSON is generated, if any occurrence of addressLines or locationLines is eligible for suppression, the entire table is suppressed as follows:
{
"postalAddresses": [
{
"addressCategory": "Master",
"addressFormatName": "US",
"sequenceNumber": 1,
"postalAddressType": "Unknown"
}
]
}
Even though occurrence 1 of addressLines has data, and locationLines has 3 occurrences of data.
I am really expecting this:
{
"postalAddresses": [
{
"addressCategory": "Master",
"addressFormatName": "US",
"sequenceNumber": 1,
"postalAddressType": "Unknown",
"addressLines": [
{
"addressLineType": "A",
"addressLineText": "123 MAIN"
}
],
"locationLines": [
{
"locationType": "City",
"locationText": "TEST CITY"
},
{
"locationType": "State",
"locationText": "CA"
},
{
"locationType": "Postal Code",
"locationText": "99999"
}
]
}
]
}
Any tips/advice on how I can use the SUPPRESS phrase and get the addressLines and locationLines items generated?
this is a known problem that should be fixed by APAR PH40288
Related
I have some data in a table that looks like the following:
date apples pears oranges
1 3 2 0
2 1 5 0
3 0 2 1
4 0 0 1
5 0 1 1
I can plot the count of a fruit by date using:
<%= line_chart FruitCount.pluck(:date, :apples), xtitle: "Date", ytitle: "Count" %>
I can't workout how to plot apples, pears and oranges onto the same plot. I thought it might be something like the following:
<%= line_chart [
{ name: Apples, data: FruitCount.pluck(:date, :apples) },
{ name: Pears, data: FruitCount.pluck(:date, :pears) }
{ name: Oranges, data: FruitCount.pluck(:date, :oranges) }
], xtitle: "Date", ytitle: "Count" %>
All help greatly appreciated.
Edit:
The issue was a missed comma and the names not being strings. The code below works:
<%= line_chart [
{ name: "Apples", data: FruitCount.pluck(:date, :apples) },
{ name: "Pears", data: FruitCount.pluck(:date, :pears) },
{ name: "Oranges", data: FruitCount.pluck(:date, :oranges) },
], xtitle: "Date", ytitle: "Count" %>
I have a line chart showing items that are "expiring" on a given date grouped by month using line_chart. I like the built-in feature of clicking on the color keys to show/hide each line. I use a complicated query to get info in this format:
{["Footwear", Sat, 01 May 2021]=>0,
["Footwear", Tue, 01 Jun 2021]=>1,
["Footwear", Thu, 01 Jul 2021]=>0,
...
["Coat", Sun, 01 Aug 2021]=>0,
["Coat", Wed, 01 Sep 2021]=>0,
["Coat", Fri, 01 Oct 2021]=>0,
["Coat", Mon, 01 Nov 2021]=>0,
...
["Helmet", Wed, 01 Dec 2021]=>0,
["Helmet", Sat, 01 Jan 2022]=>0,
["Helmet", Tue, 01 Feb 2022]=>1,
["Helmet", Tue, 01 Mar 2022]=>2,
["Helmet", Fri, 01 Apr 2022]=>0...}
So just hand line_chart a hash with data like: ["Apple", <date>] => count] and chartkick will do the rest. I have a very limited view of your table structures but going on what you have given us I think you could do:
hash_for_chart = {}
FruitCount.pluck(:date, :apples, :pears, :oranges).each do |arr|
hash_for_chart['Apples', arr[0]] = arr[1]
hash_for_chart['Pears', arr[0]] = arr[2]
hash_for_chart['Oranges', arr[0]] = arr[3]
end
Here we are grabbing every FruitCount record, plucking the date and the three counts so we have an array of those values. Then we add a hash pair for each of the three values on that date to a hash that we will pass to line_chart
line_chart hash_for_chart
There may be a more complex AR query that could give you the same data but hard for me to say with such limited info about your DB.
I am downloading a thumbnail from dropbox using the following API:
https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail
This is part of my function from cloud code:
}).then(function(oauthToken){
/* Retrieve thumbnail image from dropbox */
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://content.dropboxapi.com/2/files/get_thumbnail',
headers: {
'Authorization': 'Bearer ' + oauthToken.get("accessToken"),
'Dropbox-API-Arg': JSON.stringify({"path": dropboxFileId})
}
});
}).then(function(imageResponse){
if (log) {console.log(imageResponse);}
var imageBuffer = imageResponse.buffer;
var image = imageBuffer.toString("base64");
response.success(image);
}, function(error){
response.error(error.text);
});
Following is my imageResponse:
{ status: 200,
headers:
{ server: 'nginx',
date: 'Wed, 16 Mar 2016 04:30:54 GMT',
'content-type': 'application/octet-stream',
'content-length': '906',
connection: 'close',
'accept-ranges': 'bytes',
pragma: 'no-cache',
'cache-control': 'no-cache',
'original-content-length': '906',
'dropbox-api-result': '{"name": "HTS-logo-low-res.png", "path_lower": "/hts-logo-low-res.png", "path_display": "/HTS-logo-low-res.png", "id": "id:hrkr_mV5FYAAAAAAAAAAHw", "client_modified": "2015-04-05T04:16:15Z", "server_modified": "2016-02-13T06:08:02Z", "rev": "2a043d0c726", "size": 10506}',
'x-server-response-time': '190',
'x-dropbox-request-id': '04bb8d6b45511f2b2d7a278e230ea572',
'x-robots-tag': 'noindex, nofollow, noimageindex' },
buffer: <Buffer ef bf bd ef bf bd ef bf bd ef bf bd 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ef bf bd ef bf bd 00 43 00 06 04 05 06 05 04 06 06 05 06 07 07 06 ... >,
cookies: undefined,
text: '����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000C\u0000\u0006\u0004\u0005\u0006\u0005\u0004\u0006\u0006\u0005\u0006\u0007\u0007\u0006\b\n\u0010\n\n\t\t\n\u0014\u000e\u000f\f\u0010\u0017\u0014\u0018\u0018\u0017\u0014\u0016\u0016\u001a\u001d%\u001f\u001a\u001b#\u001c\u0016\u0016 , #&\')*)\u0019\u001f-0-(0%()(��\u0000C\u0001\u0007\u0007\u0007\n\b\n\u0013\n\n\u0013(\u001a\u0016\u001a((((((((((((((((((((((((((((((((((((((((((((((((((��\u0000\u0011\b\u0000\u0010\u0000#\u0003\u0001"\u0000\u0002\u0011\u0001\u0003\u0011\u0001��\u0000\u001f\u0000\u0000\u0001\u0005\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0010\u0000\u0002\u0001\u0003\u0003\u0002\u0004\u0003\u0005\u0005\u0004\u0004\u0000\u0000\u0001}\u0001\u0002\u0003\u0000\u0004\u0011\u0005\u0012!1A\u0006\u0013Qa\u0007"q\u00142���\b#B��\u0015R��$3br�\t\n\u0016\u0017\u0018\u0019\u001a%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������\u0000\u001f\u0001\u0000\u0003\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0011\u0000\u0002\u0001\u0002\u0004\u0004\u0003\u0004\u0007\u0005\u0004\u0004\u0000\u0001\u0002w\u0000\u0001\u0002\u0003\u0011\u0004\u0005!1\u0006\u0012AQ\u0007aq\u0013"2�\b\u0014B����\t#3R�\u0015br�\n\u0016$4�%�\u0017\u0018\u0019\u001a&\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������\u0000\f\u0003\u0001\u0000\u0002\u0011\u0003\u0011\u0000?\u0000�;ŷ��鱘\'[s,�\u0013L�\n���{\f�g\u000f��I�\\.�w\u0013��H~̡���\u0002�\u001b���\u000f\u0001���#�%�&�O��\u0004z����6�Z:X�"G;�GB}M%N�3��ͧ]4��̪��9`�������0�֕�+\u000b�t \u0006P�\u0001%�z��\u0003�R=ި�G$.� �U��h]���d�\u001d9����u���*O����q��|�\u0007\u0005\\�N\u000e\u0017\u0003�\u0000C�q��;�K���1\u001e��HR��z��~�N+���uy��d�بS咕�0e��91�\u001fC�\u0014���}z����.u\u0019Y�I\u0012�T.�\u0019~�\u0007ߦ\b��+���ߝ��W���_q��'
}
My code in XCode:
if let imageInBase64 = response as? String {
print(imageInBase64)
let decodedImage = NSData(base64EncodedString: imageInBase64, options: NSDataBase64DecodingOptions())
imageView.image = UIImage(data: decodedImage!)
}
Following is the output for imageInBase64:
77+977+977+977+9ABBKRklGAAEBAAABAAEAAO+/ve+/vQBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSjvv73vv70AQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo77+977+9ABEIABAAQAMBIgACEQEDEQHvv73vv70AHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL77+977+9AO+/vRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDLvv73vv73vv70II0Lvv73vv70VUu+/ve+/vSQzYnLvv70JChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl677+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+977+9AB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC++/ve+/vQDvv70RAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjLvv70IFELvv73vv73vv73vv70JIzNS77+9FWJy77+9ChYkNO+/vSXvv70XGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eu+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/ve+/vQAMAwEAAhEDEQA/AO+/vTvFt++/ve+/vemxmCdbcyzvv70TTO+/vQrvv73vv73vv717DO+/vWfeuX8P77+977+9Se+/vVwu77+9dxPvv73vv71Ifsyh77+977+977+9Au+/vRvvv73vv73vv70PAe+/ve+/ve+/vUDvv70l77+9Ju+/vU/vv73vv70Eeu+/ve+/ve+/ve+/vTbvv71aOljvv70iRzvvv71HQn1NJU7vv70z77+977+9zaddNO+/ve+/vcyq77+977+9OWDvv73vv73vv73vv73vv73vv73vv70w77+91pXvv70rC++/vXQgBlDvv70BJe+/vXrvv73vv70D77+9Uj3eqO+/vUckLu+/vSDvv71V77+977+9aF3vv73vv73vv71k77+9HTnvv73vv73vv73vv71177+977+977+9Kk/vv73vv73vv73vv71x77+977+9fO+/vQcFXO+/vU4OFwPvv70AQ++/vXHvv73vv70777+9S++/ve+/ve+/vTEe77+977+9SFLvv73vv71677+977+9fu+/vU4r77+977+977+9dXnvv73vv71k77+92KhT5ZKV77+9MGXvv73vv705Me+/vR9D77+9FO+/ve+/ve+/vX1677+977+977+977+9LnUZWe+/vUkS77+9VC7vv70Zfu+/vQffpgjvv73vv70r77+977+977+9353vv73vv71X77+977+977+9X3Hvv73vv70=
When I run this, I do not get an image displayed. I suspect that I am not properly handling the response from Dropbox before converting it to base64 string. Dropbox state that their responses are raw image data.
Any help will be much appreciated. Thanks.
Figured it out & thanks for those who answered. The issue was with Parse.com module Parse.Cloud.httpRequest which works slightly different when you are self-hosting parse-server vs Parse.com. I just needed to include encoding: null as an option in the module and everything works fine. Code below:
}).then(function(oauthToken){
/* Retrieve thumbnail image from dropbox */
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://content.dropboxapi.com/2/files/get_thumbnail',
headers: {
'Authorization': 'Bearer ' + oauthToken.get("accessToken"),
'Dropbox-API-Arg': JSON.stringify({"path": dropboxFileId})
},
encoding: null
});
}).then(function(imageResponse){
if (log) {console.log(imageResponse);}
var imageBuffer = imageResponse.buffer;
var image = imageBuffer.toString("base64");
response.success(image);
}, function(error){
response.error(error.text);
});
I've a hardware which sends me a hex data and i need to convert it to byte array in swift. Here's example data;
01 01 02 0A 12 14 14 11 10 0D 0B 0A 09 09 08 08 08 07 06 06 06 06 06 06 05 05 06 05 05 04 04 04 04 03 03 03 04
03 03 02 03 02 03 02 02 03 02 02 02 01 02 01 01 01 01 01
Can you help me please?
If you got a bunch of hexes (UInt8), then you can create NSData like this:
NSData(bytes: [0xFF, 0xD9] as [UInt8], length: 2)
use this method it gives Byte Array
func getByte(data:NSData) -> Array<UInt8> {
let count = data.length / sizeof(Int8)
var array = [UInt8](count: count, repeatedValue: 0)
data.getBytes(&array, length:count * sizeof(UInt32))
return array
}
The following Ruby code gets me the first day of each month :
require 'active_support/all'
# get the date at the beginning of this month
date = Date.today.beginning_of_month
# get the first day of the next 5 months
5.times do |num|
date = date.next_month
p date
end
Which gives :
=> Fri, 01 Aug 2014
=> Mon, 01 Sep 2014
=> Wed, 01 Oct 2014
=> Sat, 01 Nov 2014
=> Mon, 01 Dec 2014
But how do I get the first Thursday of each month? i.e.
=> Thu, 07 Aug 2014
=> Thu, 04 Sep 2014
=> Thu, 02 Oct 2014
=> Thu, 06 Nov 2014
=> Thu, 04 Dec 2014
There's no need for iterations or conditions just get the so called delta of days till next thursday:
#4 is thursday because wday starts at 0 (sunday)
date = Date.today.beginning_of_month
date += (4 - date.wday) % 7
p date
=> Thu, 03 Jul 2014
That my opinion:
date_begin = Date.today.beginning_of_month
date_end = date_begin + 5.month
[*date_begin..date_end].select(&:thursday?).uniq(&:month)
=> [Thu, 03 Jul 2014, Thu, 07 Aug 2014, Thu, 04 Sep 2014, Thu, 02 Oct 2014, Thu, 06 Nov 2014]
Just for fun
class Date
def skip_to_thursday
# given current weekday, how many days we need to add for it to become thursday
# for example, for monday (weekday 1) it's 3 days
offset = lambda {|x| (4-x) % 7 }
self + offset[wday]
end
end
# get the date at the beginning of this month
date = Date.today.beginning_of_month
date.skip_to_thursday # => Thu, 03 Jul 2014
Here is my way :
def first_thursday
date = Date.today.beginning_of_month
date += 1 until date.wday == 4
date
end
first_thursday # => Thu, 03 Jul 2014
you can use something like this:
def first_thursday(months_ahead)
start_of_month = months_ahead.months.from_now.beginning_of_month.to_date
start_of_month += (4 - start_of_month.cwday) % 7
end
first_thursday 1
=> Thu, 07 Aug 2014
first_thursday 2
=> Thu, 04 Sep 2014
I ran into this problem for a recurring_events feature that I needed to build. I changed some of the variables to find the first Thursday but it also shows how you could evolve the answer to find the 2nd or 3rd Thursday (or any day of the week for that matter) if you had a week and day of the week count.
def find_thursday
start_of_month = DateTime.now.beginning_of_month
month_day = nil
loop do
month_day = start_of_month += 1.day
break if month_day.wday == find_weekday("Thu")
end
return month_day
end
def find_weekday
d = default_weekdays.find { |d| d[:day] == start_date.strftime("%a") }
d[:count]
end
def default_weekdays
return [
{ day: 'Sun', count: 0 },
{ day: 'Mon', count: 1 },
{ day: 'Tue', count: 2 },
{ day: 'Wed', count: 3 },
{ day: 'Thu', count: 4 },
{ day: 'Fri', count: 5 },
{ day: 'Sat', count: 6 },
]
end
I send snmp traps from borland c++ application using indy components, (thanks Remy Lebeau for working example Implementing SNMP SendTrap using Indy components) But I have problem with russian letters.
void __fastcall TMainForm::QuickSendTrap()
{
String myEnterprise = _D("1.5.5.5.5.5.5.5");
String eventType = myEnterprise + _D(".1");
String eventDistance = myEnterprise + _D(".2");
String eventTitle1 = myEnterprise + _D(".3");
String eventTitle2 = myEnterprise + _D(".4");
String eventTitle3 = myEnterprise + _D(".5");
TStringList *names = new TStringList;
names->Add(eventType);
names->Add(eventDistance);
names->Add(eventTitle1);
names->Add(eventTitle2);
names->Add(eventTitle3);
TStringList *values = new TStringList;
values->AddObject(_D("ftCritical"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("2.357"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("АБВГД"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("абвгд"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("ОПРСТ"), (TObject*)ASN1_OCTSTR);
TIdSNMP *idSnmp = new TIdSNMP(NULL);
idSnmp->QuickSendTrap(edHost->Text, myEnterprise, _D("public"), 162, 6, 1, names, values);
delete idSnmp;
delete names;
delete values;
}
Instead of russian symbols Wireshark see "?"
0000 30 81 8b 02 01 00 04 06 70 75 62 6c 69 63 a4 7e 0.......public.~
0010 06 07 2d 05 05 05 05 05 05 40 04 c0 a8 64 56 02 ..-......#...dV.
0020 01 06 02 01 01 43 01 00 30 64 30 16 06 08 2d 05 .....C..0d0...-.
0030 05 05 05 05 05 01 04 0a 66 74 43 72 69 74 69 63 ........ftCritic
0040 61 6c 30 11 06 08 2d 05 05 05 05 05 05 02 04 05 al0...-.........
0050 32 2e 33 35 37 30 11 06 08 2d 05 05 05 05 05 05 2.3570...-......
0060 03 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d 05 05 05 ...?????0...-...
0070 05 05 05 04 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d ......?????0...-
0080 05 05 05 05 05 05 05 04 05 3f 3f 3f 3f 3f .........?????
The question is how to encode russian string for snmp properly?
Unfortunately, TIdSNMP does not support non-ASCII data at this time. This is because:
Indy's ASN.1 encode/decode functions have not been made encoding-aware yet so that strings can be converted to/from byte arrays using charsets.
TSNMPInfo encodes PDU data to a String first and then encodes that String to bytes using Indy's 8bit encoding when sending. Thus, any Unicode codepoints greater than #255 will get converted to ?. The Russian characters you are trying to send all have Unicode codepoint values greater than #255. There is no option to specify a different encoding, even though ASN.1 octet strings can technically carry character data encoded in any 8bit charset as long as both parties agree to the charset used.
In order to send cyrillic symbols via Indy's Snmp component I implemented functions which "hide" message in different encoding inside UnicodeString that used by TIdSnmp.
UnicodeString TMainForm::Windows1251ForSnmp(AnsiString str)
{
UnicodeString ustr = "";
for (int i = 0; i < str.Length(); i++)
{
unsigned char cc = *(str.c_str()+i);
wchar_t buff = 0;
memcpy((char*)&buff, &cc, 1);
ustr = ustr + buff;
}
return ustr;
}
UnicodeString TMainForm::Utf8ForSnmp(UTF8String str)
{
UnicodeString ustr = "";
for (int i = 0; i < str.Length(); i++)
{
unsigned char cc = *(str.c_str()+i);
wchar_t buff = 0;
memcpy((char*)&buff, &cc, 1);
ustr = ustr + buff;
}
return ustr;
}
UnicodeString TMainForm::Utf16ForSnmp(UnicodeString str)
{
UnicodeString ustr = "";
for (int i = 0; i < str.Length(); i++)
{
unsigned int cc = *(str.c_str()+i);
byte a = cc / 256;
byte b = cc % 256;
ustr = ustr + char(a);
ustr = ustr + char(b);
}
return ustr;
}
After message conversion by one of these functions I gave result to Indy component TIdSnmp as usually and it will be send without problem.
UnicodeString ustr = Windows1251ForSnmp("Русский");
UTF8String param = _D("Русский");
UnicodeString ustr2 = Utf8ForSnmp(param);
UnicodeString ustr3 = Utf16ForSnmp("Русский");
values->AddObject(ustr, (TObject*)ASN1_OCTSTR);
values->AddObject(ustr2, (TObject*)ASN1_OCTSTR);
values->AddObject(ustr3, (TObject*)ASN1_OCTSTR);
So, on the "other side" I recieved russian messages in Windows1251, Utf8 and Utf16 encoding.