Parsintg UUID using sscanf - c++11

I'm tring to parse a UUID string to an std::array via sscanf, but something is wrong and I can'T seam to idetify the problem:
std::array<uint8_t, 16> arr{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
sscanf("00112233-4455-6677-8899-AABBCCDDEEFF",
"%hhx%hhx%hhx%hhx-%hhx%hhx-%hhx%hhx-%hhx%hhx-%hhx%hhx%hhx%hhx%hhx%hhx",
&arr[0], &arr[1], &arr[2], &arr[3], &arr[4], &arr[5], &arr[6], &arr[7],
&arr[8], &arr[9], &arr[10], &arr[11], &arr[12], &arr[13], &arr[14], &arr[15]
);
The array contains 0x33,0xab,0x89,0x67,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 afterwards.
Any idea what's wrong?

You need to specify the width 2 too:
std::sscanf("00112233-4455-6677-8899-AABBCCDDEEFF",
"%2hhx%2hhx%2hhx%2hhx-%2hhx%hhx-%2hhx%2hhx-%2hhx%2hhx-"
"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
&arr[0], &arr[1], &arr[2], &arr[3], &arr[4], &arr[5], &arr[6], &arr[7],
&arr[8], &arr[9], &arr[10], &arr[11], &arr[12], &arr[13], &arr[14], &arr[15]
);

Related

cypress check color of css background

I have this assertion :
cy.get('.myelement').should('have.css', 'background-color','rgb(75, 221, 51)')
I want to replace it with hexadecimal representation as following:
cy.get('.myelement').should('have.css', 'background-color','#4BDD33')
but I get this error from cypress :
expected <.myelement> to have CSS property background-color with the value #4BDD33, but the value was rgb(75, 221, 51)
any help
You can do something like this:
Install the rgb-hex package
npm install rgb-hex
In your test suite file import the package
import rgbHex from 'rgb-hex';
In your test write:
cy.get('.myelement')
.invoke('css', 'background-color')
.then((bgcolor) => {
expect(rgbHex(bgcolor)).to.eq('4bdd33')
})
I'd take the reverse approach of Alapan -- I prefer to modify my expected and leave my actual values alone. To do this, you'd need a way to turn your expected Hex value into the rgb() format.
const hexToRgb = (hex) => {
const rValue = ParseInt(hex.substring(0, 2), 16);
const gValue = ParseInt(hex.substring(2, 4), 16);
const bValue = ParseInt(hex.substring(4), 16);
return `rgb(${rValue}, ${gValue}, ${bValue})`;
}
cy.get('.myelement').should('have.css', 'background-color', hexToRgb('4BDD33'));
If you wanted to include the # in the hex string, you would just need to ignore it in setting the values, most likely by increasing every number in the substring() functions by one.
Overall, I think that Alapan's solution is easier, but this is just something to consider.

sort_values() got multiple values for argument 'axis'

sort_values() got multiple values for argument 'axis'
I am trying to sort this series using sort_values
Item Per Capita GSDP (Rs.)
Andhra_avg 102803
Arunachal_avg 100745
Assam_avg 55650.6
Bihar_avg 30030.6
Chattisgarh_avg 82046.7
Gujrat_avg 128755
Himachal_avg 126650
Jharkhand_avg 56385
Jammu_avg 73422.8
Karnataka_avg 128959
Kerala_avg 139140
MP_avg 61122.2
Maharashtra_avg 133512
my code:
dfGDP_percapita.sort_values("Item", axis = 0, ascending = True, inplace = True, na_position ='first')
Expected result should give "Per Capita GSDP (Rs.)" in the decreasing order with Nan on top
Try changing your code to
dfGDP_percapita.sort_values("Item", inplace=True, na_position ='first')
Some of the arguments are by default - I'm not sure why the error occurs, but my code works like this.

DateTimeFormatterBuilder parsing days below 31 SMART not STRICT if appendValueReduced is used

Playing in groovyConsole with DateTimeFormatter and DateTimeFormatterBuilder
String inputDateString = "31.2.58" // german date format
dtfIn = DateTimeFormatter
.ofPattern ( "d.M.uu" )
.withResolverStyle ( ResolverStyle.STRICT )
dtfIn.parse(inputDateString) // ERROR as expected
...but
// with base range 1937-2034
dtfIn = new DateTimeFormatterBuilder()
.appendPattern("d.M.")
.appendValueReduced(ChronoField.YEAR, 2, 2, Year.now().getValue() - 80)
.parseStrict()
.toFormatter()
dtfIn.parse(inputDateString) // Result: 1958-02-28
So DateTimeFormatterBuilder with .parseStrict() would parse rather SMART, which DateTimeFormatterBuilder shouldn't do at all but either STRICT or LENIENT (?)'
With day numbers over 31 I'll get an error.
The problem seem to be .appendValueReduced(). Without it I'd become an error as expected.
What do I do wrong?
Thanks
Rawi
DateTimeFormatter from DateTimeFormatterBuilder.toFormatter() is indeed SMART as documented:
The resolver style will be SMART
To obtain STRICT one has to use DateFormatter.withResolverStyle(ResolverStyle)
in this case as follows:
.toFormatter().withResolverStyle(ResolverStyle.STRICT);

Extract fields out of a ruby hash with special chars

I'm working to turn a pdf signature visible, using origami.pdf, and meanwhile I noticed that my signature is an hash, and so I try to capture fields like "Location", "Reason", "Date", "ContactInfo".
{/Type=>/Sig, /Contents=>"0\x82\a\xAE\x06\t*\x86H\x86\xF7\r\x01\a\x02\xA0\x82\a\
x9F0\x82\a\x9B\x02\x01\x011\v0\t\x06\x05+\x0E\x03\x02\x1A\x05\x000#\x06\t*\x86H\
x86\xF7\r\x01\a\x01\xA0\x16\x04\x14\xEF8uEn1#\x11M\x95\xE4\xD7\x9C\xFE(\xCF\xB7\
x92\x01\xC2\xA0\x82\x05\x970\x82\x05\x930\x82\x04{\xA0\x03\x02\x01\x02\x02\x04Bo
\x93\x8C0\r\x06\t*\x86H\x86\xF7\r\x01\x01\x05\x05\x000>1\v0\t\x06\x03U\x04\x06\x
13\x02pt1\x150\x13\x06\x03U\x04\n\x13\fMULTICERT-CA1\x180\x16\x06\x03U\x04\x03\x
13\x0FMULTICERT-CA 020\x1E\x17\r130320170147Z\x17\r140320164736Z0\x81\xA51\v0\t\
x06\x03U\x04\x06\x13\x02PT1\x150\x13\x06\x03U\x04\n\x13\fMULTICERT-CA1\x160\x14\
x06\x03U\x04\v\x13\rCERTIPOR - RA1\x120\x10\x06\x03U\x04\v\x13\tCorporate1 0\x1E
\x06\x03U\x04\v\x13\x17ESCRITA INTELIGENTE LDA1\x180\x16\x06\x03U\x04\v\x13\x0FW
eb Application1\x170\x15\x06\x03U\x04\x03\x13\x0ERECIBOS ONLINE0\x81\x9F0\r\x06\
t*\x86H\x86\xF7\r\x01\x01\x01\x05\x00\x03\x81\x8D\x000\x81\x89\x02\x81\x81\x00\x
AC\xCE\xA4\x06\x901\xB5x\x89lE\rw\xC8<\x13\xDDu\xC6h\xBF'b6\x8D\xB0\xA0\xB1Y\e\x
18\x00\xE5\x8C\x1A\xCD\xBB%\xDA\x15P\x1A\xF91\xF9\xF6\xBA\xE0\xF8\xF6LH\x16\x86\
xE9Y\xDE\x00Z\xEC\x82\xB3=\r2fP7\xD1\x8B\xF3k\xF7|MVb\fB\xFB\xBA\x92\xD3\xFF9\x7
F\x9D\x83w\xFE\xAB\xBA\x93G\x8F\xCE\xF0\t!d\x83\xD3F\xAC\xCCv\xCA\x10\xC9\xB8e;\
x80\xB8\xF6\xEBI\xBD\x93\x89zC\xDF\x06-\r\x9E\xD3\x02\x03\x01\x00\x01\xA3\x82\x0
2\xB30\x82\x02\xAF0\v\x06\x03U\x1D\x0F\x04\x04\x03\x02\x03\xF808\x06\b+\x06\x01\
x05\x05\a\x01\x01\x04,0*0(\x06\b+\x06\x01\x05\x05\a0\x01\x86\x1Chttp://ocsp.mult
icert.com/ca0\x81\xE0\x06\x03U\x1D \x04\x81\xD80\x81\xD50M\x06\t+\x06\x01\x04\x0
1\xB0<\n\x020#0>\x06\b+\x06\x01\x05\x05\a\x02\x01\x162http://www.multicert.com/c
ps/multicert-ca-cps.html0\x81\x83\x06\v+\x06\x01\x04\x01\xB0<\n\x02\x88\x060t0r\
x06\b+\x06\x01\x05\x05\a\x02\x020f\x1Ed\x00h\x00t\x00t\x00p\x00:\x00/\x00/\x00w\
x00w\x00w\x00.\x00m\x00u\x00l\x00t\x00i\x00c\x00e\x00r\x00t\x00.\x00c\x00o\x00m\
x00/\x00c\x00p\x00/\x00m\x00u\x00l\x00t\x00i\x00c\x00e\x00r\x00t\x00-\x00c\x00a\
x00-\x001\x000\x003\x000\x00.\x00h\x00t\x00m\x00l0\x11\x06\t`\x86H\x01\x86\xF8B\
x01\x01\x04\x04\x03\x02\x04\xB00 \x06\x03U\x1D\x11\x04\x190\x17\x81\x15info#reci
bosonline.pt0\x82\x01\x01\x06\x03U\x1D\x1F\x04\x81\xF90\x81\xF60\x81\x9A\xA0\x81
\x97\xA0\x81\x94\x86/http://www.multicert.com/ca/multicert-ca-02.crl\x86aldap://
ldap.multicert.com/cn=MULTICERT-CA%2002,o=MULTICERT-CA,c=PT?certificateRevocatio
nList?base0W\xA0U\xA0S\xA4Q0O1\v0\t\x06\x03U\x04\x06\x13\x02pt1\x150\x13\x06\x03
U\x04\n\x13\fMULTICERT-CA1\x180\x16\x06\x03U\x04\x03\x13\x0FMULTICERT-CA 021\x0F
0\r\x06\x03U\x04\x03\x13\x06CRL2950\x1F\x06\x03U\x1D#\x04\x180\x16\x80\x14\x1D\x
C3\xB9\x88\xA5\x18\xBE`\xA7,\xA6c\xCAf*\xFC\f'\xC1\xBD0\x1D\x06\x03U\x1D\x0E\x04
\x16\x04\x14\x06\xD8\x1Fr6a\x9E\xEB\x176\x9C)\x9E-t\xFF\xD080\x190\t\x06\x03U\x1
D\x13\x04\x020\x000\r\x06\t*\x86H\x86\xF7\r\x01\x01\x05\x05\x00\x03\x82\x01\x01\
x00AQ\x1F\xCD\\ua\x98\e\rT2kW\xF7\xB8|CZ\xAC\xB7\xA2\x96(\bv\x83\x13\x89*\xB1#r7
\xE9WW{\x87T\x14\xDE\x81\nA2?\x9E\nv\x8E\x9A\xC4\\\x0Ff\xAE\t<2\xC1\x14S\xC6F?\x
85o\xEFb\xE2x!\x13M\xD0\x9Fu \x80\x00\x04\x0E\x89\xA8\x14\xE60\x96#\xC5\xD0Ac\xC
0<\xFD\xE31S\x90\x8A\xC3\xDF\xCA[\x1Cf\xC3\xDC\xB8\x96D\xA3\x03\x0F\xE7\x94\xD5\
v\xD2U\xD3\x96SZz\xF2g\xC3\xA58\x14{\x93q\xD0_#\xD8\xCAH\x1A\xEB\xC7\xD7\xA7\xD9
|.\x7F\xB5\xABI\xC4\xE4UNH\x00d\x8B\xC7k\x1A\xF5a*\x1D\x93a\xD1r\bNpi\t(\xA9\x11
\xFC \x983\xC5\x06!\x9C\xF1\x86\xB6P{Y\x9EL\x0FB\xF3\xBF#\xC2\xB8\xF0\xA0x\xD0\x
1D\x9B\xF5\xFDGF\xD9rS\xEEO\xE8\xF4rH\x9B=\xC2opr\xC6Xr\x18\x82[\xB3\x06\x10t\xB
9\xC2#\xF8\x92\x8D6\xFE\xFC\x0Fp\x88\x97u,\xD9F1\x82\x01\xC70\x82\x01\xC3\x02\x0
1\x010F0>1\v0\t\x06\x03U\x04\x06\x13\x02pt1\x150\x13\x06\x03U\x04\n\x13\fMULTICE
RT-CA1\x180\x16\x06\x03U\x04\x03\x13\x0FMULTICERT-CA 02\x02\x04Bo\x93\x8C0\t\x06
\x05+\x0E\x03\x02\x1A\x05\x00\xA0\x81\xD80\x18\x06\t*\x86H\x86\xF7\r\x01\t\x031\
v\x06\t*\x86H\x86\xF7\r\x01\a\x010\x1C\x06\t*\x86H\x86\xF7\r\x01\t\x051\x0F\x17\
r130329223127Z0#\x06\t*\x86H\x86\xF7\r\x01\t\x041\x16\x04\x14\x93\xD9l\xBD68\xDB
*M\xADY\xF8\x8F<\x8E\x94m\xACS\xAE0y\x06\t*\x86H\x86\xF7\r\x01\t\x0F1l0j0\v\x06\
t`\x86H\x01e\x03\x04\x01*0\v\x06\t`\x86H\x01e\x03\x04\x01\x160\v\x06\t`\x86H\x01
e\x03\x04\x01\x020\n\x06\b*\x86H\x86\xF7\r\x03\a0\x0E\x06\b*\x86H\x86\xF7\r\x03\
x02\x02\x02\x00\x800\r\x06\b*\x86H\x86\xF7\r\x03\x02\x02\x01#0\a\x06\x05+\x0E\x0
3\x02\a0\r\x06\b*\x86H\x86\xF7\r\x03\x02\x02\x01(0\r\x06\t*\x86H\x86\xF7\r\x01\x
01\x01\x05\x00\x04\x81\x803]\xBC\xA2\xC5\x0F&\r\x94\x96\xD5\xBD\xF2\x96\xB3\x86\
x9D\x01\xA3{5\xEC\xA5\xEC\x8B=\r\xD7%w0o\x9C\x7F\v\x17YX\x80\xAF\x1A\x8F\x1E\xBB
e\xBCp4\xF7\x80\x89b&?\xCE<\xCC\x8D\xFE\xEFK\x86\x0F\xD8Q\xFFU\x04\x11E\t\xED\xC
9=WF\x93\x10w\xC6g\xD4\e`\xE5\xB5{Ax~%\xE9\x92\xF5\x01\x19\xCDS\xE1|%\"\xB2\xC6\
x107\xE9\xF7M\xD7\xA3\x11MJ\xAF\x03\x0F\xFF\x8D:s\x84g\xB6\xD5o\xAF\xB0\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00", /Filter=>/Adobe.PPKMS, /SubFilter=>/adbe.pkcs7.sha1, /
ByteRange=>[0, 12883, 17081, 1098], /Location=>"Portugal", /ContactInfo=>"email#email.com", /Reason=>"Proof of Concept", /M=>"D:20130329223127Z00'00", /P
rop_Build=>{/Filter=>{/Name=>/Adobe.PPKMS, /R=>131101, /Date=>"2013-03-29 22:31:
27 +0000"}, /SigQ=>{/Preview=>false, /R=>131101}, /PubSec=>{/NonEFontNoWarn=>fal
se, /Date=>"2013-03-29 22:31:27 +0000", /R=>131101}, /App=>{/TrustedMode=>false,
/OS=>[/Win], /R=>458752, /Name=>/Exchange-Pro}}}
If i extract the keys (pdf.signature.keys) i get
/Type
/Contents
/Filter
/SubFilter
/ByteRange
/Location
/ContactInfo
/Reason
/M
/Prop_Build
Now, how do I reach the contents of these keys ?
I cannot simply do pdf.signature[/Location] , because ruby says it is a syntax error...
Any ideas?
I took a look at the source for origami-pdf, and it seems that the / prepending every key in that output is generated on-the-fly from Origami::Name.to_s. Also looking at its eql? definition it seems like it just compares it to the underlying string value. So this should work, have you tried it?
signature[Origami::Name.new('Location')]
As generating an Origami::Name object with /Location seems to be so hard, I solved this with a different approach :
location = pdf.signature[pdf.signature.keys[5]]
The Output returns Portugal, and this is the approach I will take, since the array's keys position are supposed to be static.
I would appreciate a more elegant solution though

help with LibSVM input data

I am using the LibSVM tool for my support vector classification implementation:-
The first line in my input data file looks as so:-
+1 15752:47 6279:45 475:40 5231:30 515:29 7529:28 11623:24 274:24 15431:21 7342:20 4819:20 7598:18 8853:17 11134:16 501:16 911:15 4656:15 5875:14 10725:13 7334:13 13762:13 8295:12 9314:12 317:12 10641:12 2690:12 8771:12 4698:11 11519:10 10069:9 10019:8 1120:8 15017:8 254:8 7900:8 5395:8 486:8 1763:8 11183:7 9163:7 9219:7 1827:7 11901:7 4068:6 15592:6 9925:6 3464:5 8408:5 15348:5 8432:5 10064:5 6319:4 5729:4 8334:4 11817:4 6238:4 4521:4 11761:4 328:4 15876:4 6494:4 280:4 14628:4 5514:4 6383:4 9149:4 2456:4 6741:4 482:4 2773:4 10873:3 8715:3 8802:3 11478:3 11848:3 12269:3 10592:3 12911:3 11051:3 10798:3 8412:3 232:3 7654:3 1210:3 502:3 12687:3 14459:2 2725:2 9851:2 5799:2 16046:2 3612:2 1440:2 8503:2 245:2 9780:2 322:2 11902:2 8977:2 14949:2 5710:2 6423:2 9896:2 5507:2 10646:2 9932:2 14894:2 3997:2 13429:2 9845:2 8547:2 2720:2 861:2 2830:2 5703:2 6994:2 13973:2 3086:2 262:2 7793:2 208:2 3221:2 13229:2 13350:2 372:2 10384:2 3970:2 13506:2 9720:2 8981:2 9296:1 10276:1 15098:1 6631:1 383:1 6510:1 13304:1 9646:1 8233:1 1080:1 8537:1 12129:1 10711:1 14569:1 2969:1 1215:1 12435:1 7689:1 12626:1 14609:1 13474:1 4488:1 103:1 621:1 12430:1 617:1 514:1 11673:1 215:1 8817:1 10968:1 4717:1 1807:1 5737:1 3156:1 14320:1 13457:1 12411:1 9596:1 15028:1 10531:1 4301:1 4799:1 6013:1 7619:1 6717:1 9344:1 1817:1 15868:1 11307:1 9632:1 6945:1 9916:1 11899:1 883:1 11696:1 14503:1 316:1 4012:1 9994:1 8501:1 1847:1 12534:1 14966:1 11800:1 8093:1 13403:1 7309:1 5957:1 6538:1 2535:1 7042:1 13792:1 15001:1 4894:1 4921:1 13739:1 15875:1 15802:1 14253:1 10376:1 974:1 1882:1 2397:1 8105:1 4725:1 7707:1 7506:1 9749:1 8640:1 12566:1
The name of my input data file is --> a1a
I tried to run the program on my windows command prompt as
svm-train a1a
I get the following error
Wrong input format at line 1
Could somebody help me out here? I can't seem to figure out what's wrong.
Thanks.
The feature numbers (14253, 10376, etc) have to be listed in increasing order. Once you do that, svm-train will take that data. So, for example, your file needs to begin:
+1 103:1 208:2 215:1 232:3 245:2 254:8 262:2 274:24 280:4 316:1 317:12 322:2 328:4 372:2 383:1 475:40 482:4 486:8 501:16 502:3 514:1 515:29 617:1 621:1 861:2 883:1 911:15 974:1 1080:1 1120:8 1210:3 1215:1 1440:2 1763:8 1807:1 1817:1 1827:7 1847:1 1882:1 2397:1 2456:4 2535:1 2690:12 2720:2 2725:2 2773:4 2830:2 2969:1 3086:2 3156:1 3221:2 3464:5 3612:2 3970:2 3997:2 4012:1 4068:6 4301:1 4488:1 4521:4 4656:15 4698:11 4717:1 4725:1 4799:1 4819:20 4894:1 4921:1 5231:30 5395:8 5507:2 5514:4 5703:2 5710:2 5729:4 5737:1 5799:2 5875:14 5957:1 6013:1 6238:4 6279:45 6319:4 6383:4 6423:2 6494:4 6510:1 6538:1 6631:1 6717:1 6741:4 6945:1 6994:2 7042:1 7309:1 7334:13 7342:20 7506:1 7529:28 7598:18 7619:1 7654:3 7689:1 7707:1 7793:2 7900:8 8093:1 8105:1 8233:1 8295:12 8334:4 8408:5 8412:3 8432:5 8501:1 8503:2 8537:1 8547:2 8640:1 8715:3 8771:12 8802:3 8817:1 8853:17 8977:2 8981:2 9149:4 9163:7 9219:7 9296:1 9314:12 9344:1 9596:1 9632:1 9646:1 9720:2 9749:1 9780:2 9845:2 9851:2 9896:2 9916:1 9925:6 9932:2 9994:1 10019:8 10064:5 10069:9 10276:1 10376:1 10384:2 10531:1 10592:3 10641:12 10646:2 10711:1 10725:13 10798:3 10873:3 10968:1 11051:3 11134:16 11183:7 11307:1 11478:3 11519:10 11623:24 11673:1 11696:1 11761:4 11800:1 11817:4 11848:3 11899:1 11901:7 11902:2 12129:1 12269:3 12411:1 12430:1 12435:1 12534:1 12566:1 12626:1 12687:3 12911:3 13229:2 13304:1 13350:2 13403:1 13429:2 13457:1 13474:1 13506:2 13739:1 13762:13 13792:1 13973:2 14253:1 14320:1 14459:2 14503:1 14569:1 14609:1 14628:4 14894:2 14949:2 14966:1 15001:1 15017:8 15028:1 15098:1 15348:5 15431:21 15592:6 15752:47 15802:1 15868:1 15875:1 15876:4 16046:2

Resources