CopyPastor

Detecting plagiarism made easy.

Score: 0.8740798830986023; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-04-13
by HockChai Lim

Original Post

Original - Posted on 2017-08-15
by user2804865



            
Present in both answers; Present only in the new answer; Present only in the old answer;

It works if I change my code to below. This new code creates a temporary myPlainData2 field, assigns its base pointer to the myPlainData field, and uses this temporary field to call the encoder.

* play variables D myPlainData s 200 ccsid(819) D myPlainDataLen... D s 10I 0 D myBase64Data s 65535A D myBase64DataLen... D s 10I 0 D myPlainData2 s 200 based(myPlainData2_p) * ibm base 64 encoder * note: apr_base64_* functions can be found in the QSYSDIR/QAXIS10HT service program D apr_base64_encode_binary... D pr 10i 0 extproc('apr_base64_encode_binary') D piBase64Data... D 65535A options(*varsize) D piPlainData... D 65535a options(*varsize) D piPlainDataLen... D 10i 0 value /free myPlainData = 'Hello'; // myPlainData is a ccsid(819) field (ascii field) myPlainDataLen = %len(%trimr(myPlainData)); myPlainData2_p = %addr(myPlainData); //encode the data myBase64DataLen = apr_base64_encode_binary(myBase64Data :myPlainData2 :myPlainDataLen); *inlr = *on; /end-free
Just to add some variety to the answer, [sci-kit learn](https://github.com/scikit-learn/scikit-learn/blob/ef5cb84a805efbe4bb06516670a9b8c690992bd7/sklearn/utils/__init__.py#L31) has this implemented as a `Bunch`:

class Bunch(dict): """ Scikit Learn's container object Dictionary-like object that exposes its keys as attributes. >>> b = Bunch(a=1, b=2) >>> b['b'] 2 >>> b.b 2 >>> b.c = 6 >>> b['c'] 6 """ def __init__(self, **kwargs): super(Bunch, self).__init__(kwargs) def __setattr__(self, key, value): self[key] = value def __dir__(self): return self.keys() def __getattr__(self, key): try: return self[key] except KeyError: raise AttributeError(key) def __setstate__(self, state): pass
All you need is to get the `setattr` and `getattr` methods - the `getattr` checks for dict keys and the moves on to checking for actual attributes. The `setstaet` is a fix for fix for pickling/unpickling "bunches" - if inerested check https://github.com/scikit-learn/scikit-learn/issues/6196

        
Present in both answers; Present only in the new answer; Present only in the old answer;