问:
Python from csv file analyze data in columns and cells
I am trying to create a code for the following data:

I have imported the data using the code:

```<code>import csv
import itertools
import pandas as pd

input_file="computation.csv"
cmd=pd.read_csv(input_file)
subset = cmd[['Carbon A', 'Carbon B']]
carbon_pairs = [tuple(y) for y in subset.values]
c_pairs = carbon_pairs
</code>```

I want to create a code that has the output:

```<code>1 is connected to
  2
  4
  6
  7
  8
2 is connected to
  1
  4
  5
</code>```

Note that for 'carbon' 2, I would like it to repeat that it is connected to carbon 1.  I was thinking that some permutation would be able to show this, but I am very unsure where to start.  Basically, the code needs to output:

```<code>for every cell with the same value, print adjacent cell
</code>```

答:
You can get your desired output without the pandas dependency with the following function (Python 2), which will allow you to pass in any filename you want, and control with indices (zero-based) you're trying to query.  This solution assumes that the data is sorted as in the example you provided.

```<code>import csv

def printAdjacentNums(filename, firstIdx, secondIdx):
    with open(filename, 'rb') as csvfile:
        # handle header line
        header = next(csvfile)
        reader = csv.reader(csvfile)
        current_val = ''
        current_adj = []
        # dict of lists for lookback
        lookback = {}
        for row in reader:
            if current_val == '':
                current_val = row[firstIdx]
            if row[firstIdx] == current_val:
                current_adj.append(row[secondIdx])
            else:
                # check lookback
                for k, v in lookback.items():
                    if current_val in v:
                        current_adj.append(k)

                # print what we need to
                print current_val + ' is connected to'
                for i in current_adj:
                    print i

                # append current vals to lookback
                lookback[current_val] = current_adj

                # reassign
                current_val = row[firstIdx]
                current_adj = [row[secondIdx]]

     # print final set
    for k, v in lookback.items():
        if current_val in v:
            current_adj.append(k)
    print current_val + ' is connected to'
    for i in current_adj:
        print i
</code>```

Then call it like so, based on your example:

```<code>printAdjacentNums('computation.csv', 0, 1)
</code>```

Body:
I am trying to create a code for the following data:

I have imported the data using the code:

import csv
import itertools
import pandas as pd

input_file="computation.csv"
cmd=pd.read_csv(input_file)
subset = cmd[['Carbon A', 'Carbon B']]
carbon_pairs = [tuple(y) for y in subset.values]
c_pairs = carbon_pairs

I want to create a code that has the output:

1 is connected to
  2
  4
  6
  7
  8
2 is connected to
  1
  4
  5

Note that for 'carbon' 2, I would like it to repeat that it is connected to carbon 1.  I was thinking that some permutation would be able to show this, but I am very unsure where to start.  Basically, the code needs to output:

for every cell with the same value, print adjacent cell

Body:
You can get your desired output without the pandas dependency with the following function (Python 2), which will allow you to pass in any filename you want, and control with indices (zero-based) you're trying to query.  This solution assumes that the data is sorted as in the example you provided.

import csv

def printAdjacentNums(filename, firstIdx, secondIdx):
    with open(filename, 'rb') as csvfile:
        # handle header line
        header = next(csvfile)
        reader = csv.reader(csvfile)
        current_val = ''
        current_adj = []
        # dict of lists for lookback
        lookback = {}
        for row in reader:
            if current_val == '':
                current_val = row[firstIdx]
            if row[firstIdx] == current_val:
                current_adj.append(row[secondIdx])
            else:
                # check lookback
                for k, v in lookback.items():
                    if current_val in v:
                        current_adj.append(k)

                # print what we need to
                print current_val + ' is connected to'
                for i in current_adj:
                    print i

                # append current vals to lookback
                lookback[current_val] = current_adj

                # reassign
                current_val = row[firstIdx]
                current_adj = [row[secondIdx]]

     # print final set
    for k, v in lookback.items():
        if current_val in v:
            current_adj.append(k)
    print current_val + ' is connected to'
    for i in current_adj:
        print i

Then call it like so, based on your example:

printAdjacentNums('computation.csv', 0, 1)


来源: stackexchange

问:
Mask based on two different Pandas Dataframes?
Suppose I have two pandas dataframes:

```<code>In [1]: dates = pd.date_range('20170101',periods=6)
df1 = pd.DataFrame(np.empty([len(dates),2]),index=dates,columns=['foo','bar'])
df1['foo'].loc[0:2] = 'A'
df1['bar'].loc[0:3] = 'A'
df1['foo'].loc[2:6] = 'B'
df1['bar'].loc[3:6] = 'B'
df2 = pd.DataFrame(np.random.randint(10,size=(6,2)),index=dates,columns=df1.columns)
print(df1)
print(df2)

Out [1]:
           foo bar
2017-01-01   A   A
2017-01-02   A   A
2017-01-03   B   A
2017-01-04   B   B
2017-01-05   B   B
2017-01-06   B   B

            foo  bar
2017-01-01    5    3
2017-01-02    6    9
2017-01-03    5    9
2017-01-04    7    5
2017-01-05    0    2
2017-01-06    0    0
</code>```

I'm interested in a creating a 3rd df populated with the max of df2 based on df1.  For example, the output would look something like this:

```<code>            foo  bar
2017-01-01    6    9
2017-01-02    6    9
2017-01-03    7    9
2017-01-04    7    5
2017-01-05    7    5
2017-01-06    7    5
</code>```

Surely there's a succinct way to do this, right?

答:
You can add the column values of df1 to df1 to get unique groups for which to groupby

```<code>df2.stack().groupby(
    df1.add(df1.columns.to_series()).stack()
).transform('max').unstack()

            foo  bar
2017-01-01    6    9
2017-01-02    6    9
2017-01-03    7    9
2017-01-04    7    5
2017-01-05    7    5
2017-01-06    7    5
</code>```

To account for non strings

```<code>df2.stack().groupby(
    df1.astype(str).add(df1.columns.to_series().astype(str)).stack()
).transform('max').unstack()
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Suppose I have two pandas dataframes:

In [1]: dates = pd.date_range('20170101',periods=6)
df1 = pd.DataFrame(np.empty([len(dates),2]),index=dates,columns=['foo','bar'])
df1['foo'].loc[0:2] = 'A'
df1['bar'].loc[0:3] = 'A'
df1['foo'].loc[2:6] = 'B'
df1['bar'].loc[3:6] = 'B'
df2 = pd.DataFrame(np.random.randint(10,size=(6,2)),index=dates,columns=df1.columns)
print(df1)
print(df2)

Out [1]:
           foo bar
2017-01-01   A   A
2017-01-02   A   A
2017-01-03   B   A
2017-01-04   B   B
2017-01-05   B   B
2017-01-06   B   B

            foo  bar
2017-01-01    5    3
2017-01-02    6    9
2017-01-03    5    9
2017-01-04    7    5
2017-01-05    0    2
2017-01-06    0    0

I'm interested in a creating a 3rd df populated with the max of df2 based on df1.  For example, the output would look something like this:

            foo  bar
2017-01-01    6    9
2017-01-02    6    9
2017-01-03    7    9
2017-01-04    7    5
2017-01-05    7    5
2017-01-06    7    5

Surely there's a succinct way to do this, right?

Body:
You can add the column values of df1 to df1 to get unique groups for which to groupby

df2.stack().groupby(
    df1.add(df1.columns.to_series()).stack()
).transform('max').unstack()

            foo  bar
2017-01-01    6    9
2017-01-02    6    9
2017-01-03    7    9
2017-01-04    7    5
2017-01-05    7    5
2017-01-06    7    5

To account for non strings

df2.stack().groupby(
    df1.astype(str).add(df1.columns.to_series().astype(str)).stack()
).transform('max').unstack()


问:
Synchronized unordered_map in C++
I am using unordered_map from Boost. Are there any synchronized version of unordered_map? This is because I have quite a large number of unordered_map and manually synchronizing it using lock would be very messy.

Thanks.

答: It's impossible to usefully encapsulate containers offering STL-like interfaces (which unordered_map also does) with automatic locking because there are race conditions associated with retrieving iterators and positions inside the string then trying to use them in later operations.  If you can find some less flexible interface that suits your needs, perhaps putting any complex operations into single locked function calls, then you can easily wrap a thread-safe class around the container to simplify your usage.</p>

ContentLicense: CC BY-SA 2.5

Title: Synchronized unordered_map in C++


问:
wordpress external js not loading in my theme
I am making my first wordpress theme but when i tried to load external js in my theme its not loading in my page instead of that it load in wp-admin page

functions.php

```<code>wp_enqueue_script('jquery');
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'1.0', true );
</code>```

my script.js

```<code>(function($) {

    alert("it workd!!");
})(jQuery);
</code>```

答:
Try this

add_action('wp_enqueue_scripts', 'your_func');

function your_func(){
wp_enqueue_script('jquery');
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'1.0', true );
}

I'm on a phone, so the formatting sucks, but that should work.

Body:
I am making my first wordpress theme but when i tried to load external js in my theme its not loading in my page instead of that it load in wp-admin page

functions.php

wp_enqueue_script('jquery');
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'1.0', true );

my script.js

(function($) {

    alert("it workd!!");
})(jQuery);


问:
Image Recognition with Tensorflow
I'm currently following tensorflow tutorials.

If I would have a dataset, where each class contains a single image. Would TensorFlow be the best option?

Or should I copy & damage each image a little bit, so that I have multiple images in the same class? Similar to how they did number recognition..

Thanks

答:
You can use neural network implemented in tensorflow for image recognition. However, having enough training data is essential to achieve good performance. Of course it is not always easy to get more data, but one image per class sounds like far from being enough. So you should definitely try to achieve more data.

By the way, if you are talking about MNIST dataset (with regards to number recognition), it consists of digits written by high school students and employees of the United States Census Bureau (see here).

One way to increase the amount of training data may be by modifying existing training data a little bit, but it is also worthwhile to try and to get more data in other ways. Otherwise, all your training examples per class end up too similar to each other.

Title: Image Recognition with Tensorflow


问:
Python matplotlib error: "maximum recursion depth exceeded"
I am using Python and the matplotlib library.

I run through a very long code creating multiple figures along the way.

I do something like this, many many times:

```<code>plt.figure()
plt.plot(x, y)
plt.grid('on')
plt.close()
</code>```

Then, at some point, I get the error:

More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory.

The error is clear to me, but: I do call "plt.close()".

Now that I am writing this I am realizing that maybe plt.close() has to take a specific qualifier for what figure to close? Like plt.close(1) etc. I guess I can use plt.close('all'), but what if I just want to close the most recent figure?

答:
The code from the question should work fine. Since you close the figure in every loop step, there will only ever be one single figure open.

Minimal example, which does not produce any error:

```<code>import matplotlib.pyplot as plt

for i in range(30):
    plt.figure()
    plt.plot(range(i+3), range(i+3))
    plt.grid('on')
    plt.close()

plt.show() # doesn't show anything since no figure is open
</code>```

So the reason for the error must be somewhere else in the code.

Body:
I am using Python and the matplotlib library.

I run through a very long code creating multiple figures along the way.

I do something like this, many many times:

plt.figure()
plt.plot(x, y)
plt.grid('on')
plt.close()

Then, at some point, I get the error:

More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory.

The error is clear to me, but: I do call "plt.close()".

Now that I am writing this I am realizing that maybe plt.close() has to take a specific qualifier for what figure to close? Like plt.close(1) etc. I guess I can use plt.close('all'), but what if I just want to close the most recent figure?

Body:
The code from the question should work fine. Since you close the figure in every loop step, there will only ever be one single figure open.

Minimal example, which does not produce any error:

import matplotlib.pyplot as plt

for i in range(30):
    plt.figure()
    plt.plot(range(i+3), range(i+3))
    plt.grid('on')
    plt.close()

plt.show() # doesn't show anything since no figure is open

So the reason for the error must be somewhere else in the code.


问:
Why use monkeypatch.setenv instead of os.putenv
pytest's monkeypatch module provides a setenv function which will Set environment variable name to value. Why does monkeypatch provide this? It sounds the same as os.putenv? It provides prepend argument as a convenience, but that seems like a weak reason to have a new function for setting an environment variable.

答:
This is about tearing down the changes that the test makes in the environment.  If you only use os.putenv, or modify the os.environ directly, then your modifications will stay in place even after the end of the test.  That means the next test that runs will have the change applied, too!  Since the tests are not necessarily ordered, it means you no longer have a repeatable and reliable test execution.

It's undesirable for a individual tests to change some global mutable state, therefore either use a context manager or the fixture provided when you need to configure environment variables during tests.

ContentLicense: CC BY-SA 4.0


问:
Connect to MySQL server from php with Docker
I am new to Docker. I am developing a PHP application in Docker environment, and I need to use a MySql Server/database to persist data. Following documentation, I run this command to create the MySql server image:

docker run -v /var/lib/mysql mariadb

It downloaded it, but I also go this error with it:

error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

How do I set the MYSQL_ALLOW_EMPTY_PASSWORD option?

And then how would I create a database on this image, and then read/write to it from my PHP code (which is on a different image)?

答:
Create container

Run this command: docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=mysecretpw -v mysql:/var/lib/mysql -d mariadb:latest

With this, you are creating your docker container with mariadb, and storing data on mysql folder. In the command, you have -e MYSQL_ROOT_PASSWORD=my-secret-pw. This set your root password as my-secret-pw. When you connect to it, your user is root, and password is my-secret-pw.

Find out the address

docker inspect some-mariadb - With this command, you will find all information about your container. You need your IP address.

Hint: docker inspect some-mariadb | grep IPAddress you make easier to find your IP Address.

Connecting

Now, it is the PHP part. Run the PHP below, but check your host address, that in my case was 172.17.0.2 (from PHP documentation.):

```<code><?php
$link = mysqli_connect("172.17.0.2", "root", "my-secret-pw");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made!" . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);
</code>```

And if works fine, you will read:

```<code>A proper connection to MySQL was made!
Host information: 172.17.0.2 via TCP/IP
</code>```

Ps.: For database creation, run the required commands as you would make in a database without the docker. It is the same (CREATE DATABASE mydb).

This is just for starting. I recommend you to study docker compose. When you get it, will you learn a lot about docker advantages.

Body:
Create container

Run this command: docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=mysecretpw -v mysql:/var/lib/mysql -d mariadb:latest

With this, you are creating your docker container with mariadb, and storing data on mysql folder. In the command, you have -e MYSQL_ROOT_PASSWORD=my-secret-pw. This set your root password as my-secret-pw. When you connect to it, your user is root, and password is my-secret-pw.

Find out the address

docker inspect some-mariadb - With this command, you will find all information about your container. You need your IP address.

Hint: docker inspect some-mariadb | grep IPAddress you make easier to find your IP Address.

Connecting

Now, it is the PHP part. Run the PHP below, but check your host address, that in my case was 172.17.0.2 (from PHP documentation.):

<?php
$link = mysqli_connect("172.17.0.2", "root", "my-secret-pw");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made!" . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);

And if works fine, you will read:

A proper connection to MySQL was made!
Host information: 172.17.0.2 via TCP/IP

Ps.: For database creation, run the required commands as you would make in a database without the docker. It is the same (CREATE DATABASE mydb).

This is just for starting. I recommend you to study docker compose. When you get it, will you learn a lot about docker advantages.


问:
CAAffineTransformationMakeRotation problem
I have a problem with CAAffineTransformationMakeRotation. M trying to rotate a UIView with 22.5 degrees in ViewDidLoad, and after a delay of 1 sec,the View flyin to the screen.

the code is:

```<code>-(void)ViewDidiLoad{

imgView1 = [[UIView alloc] initWithFrame:CGRectMake(20,150,.1,400)];
    [imgView1 setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:imgView1];
CGAffineTransform trans = CGAffineTransformMakeRotation(3.14159/8);
imgView1.transform = trans;

[self performSelector:@selector(img1_enter) withObject:nil afterDelay:1];
 }

 -(void)img1_enter{
CGRect frame = [imgView1 frame];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
frame.origin.x = 550;
[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
[imgView1 setFrame :frame];
[UIView commitAnimations];
}
</code>```

The problem is that when this view fly's in..its width and height changes. I've tried without rotating the View(i.e without AffineTransformation), it works properly.

Is there any other method to rotate the View??

答:
You could incorporate the already existing transform to preserve the current size respectively aspect ratio:

```<code>imgView1.transform = CGAffineTransformConcat(trans, imgView1.transform);
</code>```

Also the documentation of the UIView class says that the frame property is undefined if the transform is not the identity transform, so you must not use it after you applied a rotation.

Body:
I have a problem with CAAffineTransformationMakeRotation. M trying to rotate a UIView with 22.5 degrees in ViewDidLoad, and after a delay of 1 sec,the View flyin to the screen.

the code is:

-(void)ViewDidiLoad{

imgView1 = [[UIView alloc] initWithFrame:CGRectMake(20,150,.1,400)];
    [imgView1 setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:imgView1];
CGAffineTransform trans = CGAffineTransformMakeRotation(3.14159/8);
imgView1.transform = trans;

[self performSelector:@selector(img1_enter) withObject:nil afterDelay:1];
 }

 -(void)img1_enter{
CGRect frame = [imgView1 frame];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
frame.origin.x = 550;
[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
[imgView1 setFrame :frame];
[UIView commitAnimations];
}

The problem is that when this view fly's in..its width and height changes. I've tried without rotating the View(i.e without AffineTransformation), it works properly.

Is there any other method to rotate the View??

Body:
You could incorporate the already existing transform to preserve the current size respectively aspect ratio:

imgView1.transform = CGAffineTransformConcat(trans, imgView1.transform);

Also the documentation of the UIView class says that the frame property is undefined if the transform is not the identity transform, so you must not use it after you applied a rotation.


问:
Can a PDF-1.3 be a PDF/A?
I have a PDF document which is supposed to be PDF/A conform, but the metadata states that it is a PDF-1.3 document. Can a PDF-1.3 document be conform with the rules of PDF/A?

Note that the first version of PDF/A is based on PDF-1.4 - hence my confusion.

Thanks in advance!

答:
The PDF/A-1 specification (ISO 19005 part 1) states

5.1 General

This part of ISO 19005 defines a file format for representing electronic documents known as “PDF/A-1.”
Conforming PDF/A-1 files shall adhere to all requirements of PDF Reference as modified by this part of
ISO 19005.

"PDF Reference" previously is defined as

4 Notation

...

For the purposes of this part of ISO 19005, references to the “PDF Reference” are to PDF Reference: Adobe
Portable Document Format, version 1.4, 3rd ed., as amended by Errata for PDF Reference, 3rd ed. [...]

Section 5.1 continues:

Neither the version number in the header of a PDF file nor the value of the Version key in the document catalog dictionary shall be used in determining whether a file is
in accordance with this part of ISO 19005.

As these are the only metadata that can state that it is a PDF-1.3 document, this statement of version MUST NOT be used in determining whether a file is PDF/A-1.

Thus, concerning your question:

stijndg> Can a PDF-1.3 document be conform with the rules of PDF/A?

Yes, it can.

It merely has to

adhere to all requirements of PDF Reference, version 1.4 and

adhere to the requirements of ISO 19005 part 1 of Level A conformance or Level B conformance.

Furthermore Section 5.1 recommends:

Features described in PDF specifications prior to Version 1.4 which are not explicitly
described in PDF Reference should not be used.

But "should" indicates that this is a recommendation, so if for some reason the use of such features cannot be prevented, this does not keep a PDF from being PDF/A conform.

Title: Can a PDF-1.3 be a PDF/A?


问:
Change Action Bar Overflow Icon in an app
I am trying to change the Action Bar Overflow Icon in an app.  I have seen some info on this site but it's not clear to me.  Does anyone know what code I should enter and in what files?  </p>

答:
Try this may be helpful to you</p>

```<code>private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setIcon(R.mipmap.ic_title);
......
}
</code>```

Body:
Try this may be helpful to you

private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setIcon(R.mipmap.ic_title);
......
}


问:
Xcode: ld: library not found for -lAFNetworking
Because of this one reason, build always fails...Any ideas about what I could try?

EDIT: the solution is to open the xcworkspace instead of the xcproject!

答:
I had this issue while using fastlane with a ReactNative project. I had added a dependency that required cocoapods.

My Fastfile looked like this:

```<code>...
gym(
  scheme: "AppName",
  project: "./ios/AppName.xcodeproj"
)
....
</code>```

And had to change it to the workspace like this:

```<code>...
gym(
  scheme: "AppName",
  workspace: "./ios/AppName.xcworkspace"
)
...
</code>```

Body:
I had this issue while using fastlane with a ReactNative project. I had added a dependency that required cocoapods.

My Fastfile looked like this:

...
gym(
  scheme: "AppName",
  project: "./ios/AppName.xcodeproj"
)
....

And had to change it to the workspace like this:

...
gym(
  scheme: "AppName",
  workspace: "./ios/AppName.xcworkspace"
)
...


问:
curl delete in codeigniter
I am a newbie and I am stuck to do delete in curl using Codeigniter.
It is my very first question and I am sorry if I am missing anything.
The followings are my codes and only edit is working (so I left out the codes) but my delete curl isn't working and I am kind of stuck.
Thanks in advance.

The problem is it isn't deleting at all and I think my curl is wrong.

```<code>    public function function3($data, $hostURL) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $hostURL.'..............');

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 90);
    curl_exec($ch);

    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if($http_code =! 200) {
        throw new Exception(curl_error($ch), curl_errno($ch));
    } else {
        return "Deleted";
    }
    curl_close($ch);
}
</code>```

答:
There is nothing wrong with your code.
Your function works well (I've tested it). There are only three possible problems:

the script on the page you are calling ($hostURL) is broken,

your input data ($data) has wrong format,

you are not reading the right post data on your $hostURL page.

What does the $data you are passing to function3 looks like? It should be something like this:

```<code>$data = 'param=value&anotherparam=anothervalue';
</code>```

You can use http_build_query function.

In the file that is handling your DELETE request, you have to use this code to read post data:

```<code>$post_data = file_get_contents("php://input");
</code>```

Title: curl delete in codeigniter

Body:
I am a newbie and I am stuck to do delete in curl using Codeigniter.
It is my very first question and I am sorry if I am missing anything.
The followings are my codes and only edit is working (so I left out the codes) but my delete curl isn't working and I am kind of stuck.
Thanks in advance.

The problem is it isn't deleting at all and I think my curl is wrong.

    public function function3($data, $hostURL) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $hostURL.'..............');

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 90);
    curl_exec($ch);

    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if($http_code =! 200) {
        throw new Exception(curl_error($ch), curl_errno($ch));
    } else {
        return "Deleted";
    }
    curl_close($ch);
}

Body:
There is nothing wrong with your code.
Your function works well (I've tested it). There are only three possible problems:

the script on the page you are calling ($hostURL) is broken,

your input data ($data) has wrong format,

you are not reading the right post data on your $hostURL page.

What does the $data you are passing to function3 looks like? It should be something like this:

$data = 'param=value&anotherparam=anothervalue';

You can use http_build_query function.

In the file that is handling your DELETE request, you have to use this code to read post data:

$post_data = file_get_contents("php://input");


问:
Need to reset fields in PHP edit form somehow
I have a DB-based AMCharts form/page that graphs figures that are entered in a separate edit form accessed from that main page. This latter php edit form is set up to always bring up the present set of entries in every field. This edit form serves two purposes: one is to be able to correct earlier mistakes, and the other is to enter a whole set of new ones. The new figures are entered in this edit page and then submitted. A series of four sets of previous generations are saved in identical tables, which are also graphed on the same main page. A JS div slider script allows the user to compare among 5 generations of separate graphs in the same space. A trigger built into MySql allows each new set to be passed on to older sets, 5 gen deep. Without getting into too many details, the trigger is written so that it is activated if two specific fields in the form are different from the previous. Thus allowing mistakes to be corrected without activating the trigger. With me so far? My question does not concern the structure of the thing, it works fine, but just one problem that does not seem to be available on SO or any other google search result. Specifically, in the case that the edit form is used to enter a brand new set of numbers, how could you use a reset button that activates  a script that clears all the old figures from the inputs? I've found numerous answers on SO that use either pure JS or JQuery, but they are not used on PHP forms, rather HMTL forms. Some posters point out that this is anyhow not possible, as edit forms contain DB values cannot be replaced unless the SUBMIT button is used. This simple device is to make entry of new figures easier when they are empty, but I haven't found any scripts so far that succeed in clearing them. The simple reset code that works in HTML forms but in my php one:

```<code>   <script>function resetform() {
   document.getElementById("myform").reset();}</script>

   <form action="" method="post" id="myform">

   <input value="RESET" onclick="resetform()">
</code>```

答:
You want to reset all form values to their initial values? What's wrong with this:

```<code><button type="reset">Reset</button>
</code>```

Or, if you want to party like it's 1999:

```<code><input type="reset" value="Reset">
</code>```

Body:
I have a DB-based AMCharts form/page that graphs figures that are entered in a separate edit form accessed from that main page. This latter php edit form is set up to always bring up the present set of entries in every field. This edit form serves two purposes: one is to be able to correct earlier mistakes, and the other is to enter a whole set of new ones. The new figures are entered in this edit page and then submitted. A series of four sets of previous generations are saved in identical tables, which are also graphed on the same main page. A JS div slider script allows the user to compare among 5 generations of separate graphs in the same space. A trigger built into MySql allows each new set to be passed on to older sets, 5 gen deep. Without getting into too many details, the trigger is written so that it is activated if two specific fields in the form are different from the previous. Thus allowing mistakes to be corrected without activating the trigger. With me so far? My question does not concern the structure of the thing, it works fine, but just one problem that does not seem to be available on SO or any other google search result. Specifically, in the case that the edit form is used to enter a brand new set of numbers, how could you use a reset button that activates  a script that clears all the old figures from the inputs? I've found numerous answers on SO that use either pure JS or JQuery, but they are not used on PHP forms, rather HMTL forms. Some posters point out that this is anyhow not possible, as edit forms contain DB values cannot be replaced unless the SUBMIT button is used. This simple device is to make entry of new figures easier when they are empty, but I haven't found any scripts so far that succeed in clearing them. The simple reset code that works in HTML forms but in my php one:

   <form action="" method="post" id="myform">

   <input value="RESET" onclick="resetform()">

Body:
You want to reset all form values to their initial values? What's wrong with this:

<button type="reset">Reset</button>

Or, if you want to party like it's 1999:

<input type="reset" value="Reset">


问:
How to access nested object array Javascript
I know this has been asked before but I can't seem to find the answer.
I just want to know how to access the values in service_name array in a console.log

Below is the array and just a snip out of the data.

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]

console.log(JSON.stringify(a, 0, 4))```

答:
Just do:

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]
a.forEach((e)=>console.log(e.service_name));```
</div>
</div>
</p>

<p>if you need a result array:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]
var res = a.map((e)=>e.service_name);
console.log(res);</code>```

Body:
Just do:

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]
a.forEach((e)=>console.log(e.service_name));

if you need a result array:

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]
var res = a.map((e)=>e.service_name);
console.log(res);


答:
var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]

a.forEach(function(element) {
  console.log(element.service_name);
});```

Title: How to access nested object array Javascript

Body:
I know this has been asked before but I can't seem to find the answer.
I just want to know how to access the values in service_name array in a console.log

Below is the array and just a snip out of the data.

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]

console.log(JSON.stringify(a, 0, 4))


问:
refresh posts in blogengine.net
I have installed blogengine.net on a windows azure website. When I post new blogitem it takes a long time (couple of hours) until the post is displayed on the website. Is it possible to display blogs immediately?</p>

答:
With the latest version of BlogEngine.Net

This issue is much easier to set.

You just set the time zone in which your server is located in.

https://github.com/rxtur/BlogEngine.NET

Title: refresh posts in blogengine.net


问:
Keyboard shortcut to remove empty lines in a C# code file
Is there any keyboard shortcut to remove empty lines in C# code files (.cs)?

Similar to Ctrl + K , D which formats the whole .cs file.

Or is there a workaround?

答:
Use the Find and Replace dialog (Ctrl + H). Search for

```<code>\n\n
</code>```

and replace with

```<code>\n
</code>```

using regular expressions (expand the Find Options section to enable).

If you want to remove lines containing nothing but whitespace you could try searching for

```<code>\n\s*\n+
</code>```

Body:
Use the Find and Replace dialog (Ctrl + H). Search for

\n\n

and replace with

\n

using regular expressions (expand the Find Options section to enable).

If you want to remove lines containing nothing but whitespace you could try searching for

\n\s*\n+


问:
A flexbox grid of two flex items next to one
I am trying to have one div on the left and two on the right. The bottomright should always be below the topRight div. The topRight is the only div with a variable height.

I am currently trying to achieve this using flexbox als you can see in my code below.

I would like to have some directions.

.wrapper {
  display: flex;
  height: 100px;
}

.left {
  background-color: green
}

.topRight {
  background-color: yellow
}

.bottomright {
  background-color: red
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <div class="left">Left</div>
  <div class="topRight">TopRight</div>
  <div class="bottomright">Bottom</div>
  </div</code>```

答:
On html put a div with a class called right wrapping both topRight and bottomRight and use this css on css:

```<code>.wrapper {
  display: flex;
  height: 100px;
}

.right {
 display: flex-flow;
 }

.left {
     background-color: green
}

.topRight {
 background-color: yellow;
 height: 50px;
}

.bottomright {
  background-color: red;
  height: 50px;
}
</code>```

I hope that helps you :)

Body:
I am trying to have one div on the left and two on the right. The bottomright should always be below the topRight div. The topRight is the only div with a variable height.

I am currently trying to achieve this using flexbox als you can see in my code below.

I would like to have some directions.

.wrapper {
  display: flex;
  height: 100px;
}

.left {
  background-color: green
}

.topRight {
  background-color: yellow
}

.bottomright {
  background-color: red
}

Left

TopRight

Bottom

  </div

Body:
On html put a div with a class called right wrapping both topRight and bottomRight and use this css on css:

.wrapper {
  display: flex;
  height: 100px;
}

.right {
 display: flex-flow;
 }

.left {
     background-color: green
}

.topRight {
 background-color: yellow;
 height: 50px;
}

.bottomright {
  background-color: red;
  height: 50px;
}

I hope that helps you :)


问:
Can I generate incremental Build Name in an OpenShift Origin build?
I am building a image using a BuildConfig, in every build a new image with the tag latest is created because I am using this config

```<code>"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:latest"
   }
}
</code>```

Is it possible to create images with a tag incremental? something like:

```<code>"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:${buildNumber}"
   }
}
</code>```

if not, what is the best approach to build new images and store the versions in the openshift registry?

Thanks in advance

答:
I had the same requirement, and I used environment variables passed to the build config.</p>

```<code>"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:${buildNumber}"
   }
}

oc start-build buildconfig_name --env=buildnumber=value
</code>```

Body:
I am building a image using a BuildConfig, in every build a new image with the tag latest is created because I am using this config

"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:latest"
   }
}

Is it possible to create images with a tag incremental? something like:

"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:${buildNumber}"
   }
}

if not, what is the best approach to build new images and store the versions in the openshift registry?

Thanks in advance

Body:
I had the same requirement, and I used environment variables passed to the build config.

"output": {
 "to": {
    "kind": "ImageStreamTag"
    "name": "myImage:${buildNumber}"
   }
}

oc start-build buildconfig_name --env=buildnumber=value


问:
How do I prevent permission escalation in Django admin when granting "user change" permission?
I have a django site with a large customer base. I would like to give our customer service department the ability to alter normal user accounts, doing things like changing passwords, email addresses, etc. However, if I grant someone the built-in auth | user | Can change user permission, they gain the ability to set the is_superuser flag on any account, including their own. (!!!)

What's the best way to remove this option for non-superuser staff? I'm sure it involves subclassing django.contrib.auth.forms.UserChangeForm and hooking it into my already-custom UserAdmin object... somehow. But I can't find any documentation on how to do this, and I don't yet understand the internals well enough.

答:
The below part of the accepted answer has a race condition where if two staff users try to access the admin form at the same time, one of them may get the superuser form.

```<code>try:
    self.readonly_fields = self.staff_self_readonly_fields
    response = super(MyUserAdmin, self).change_view(request, object_id, form_url, extra_context, *args, **kwargs)
finally:
    # Reset fieldsets to its original value
    self.fieldsets = UserAdmin.fieldsets
</code>```

To avoid this race condition (and in my opinion improve the overall quality of the solution), we can override the get_fieldsets() and get_readonly_fields() methods directly:

```<code>class UserAdmin(BaseUserAdmin):
    staff_fieldsets = (
        (None, {'fields': ('username')}),
        ('Personal info', {'fields': ('first_name', 'last_name', 'email')}),
        # No permissions
        ('Important dates', {'fields': ('last_login', 'date_joined')}),
    )
    staff_readonly_fields = ('username', 'first_name', 'last_name', 'email', 'last_login', 'date_joined')

    def get_fieldsets(self, request, obj=None):
        if not request.user.is_superuser:
            return self.staff_fieldsets
        else:
            return super(UserAdmin, self).get_fieldsets(request, obj)

    def get_readonly_fields(self, request, obj=None):
        if not request.user.is_superuser:
            return self.staff_readonly_fields
        else:
            return super(UserAdmin, self).get_readonly_fields(request, obj)
</code>```

Body:
The below part of the accepted answer has a race condition where if two staff users try to access the admin form at the same time, one of them may get the superuser form.

try:
    self.readonly_fields = self.staff_self_readonly_fields
    response = super(MyUserAdmin, self).change_view(request, object_id, form_url, extra_context, *args, **kwargs)
finally:
    # Reset fieldsets to its original value
    self.fieldsets = UserAdmin.fieldsets

To avoid this race condition (and in my opinion improve the overall quality of the solution), we can override the get_fieldsets() and get_readonly_fields() methods directly:

class UserAdmin(BaseUserAdmin):
    staff_fieldsets = (
        (None, {'fields': ('username')}),
        ('Personal info', {'fields': ('first_name', 'last_name', 'email')}),
        # No permissions
        ('Important dates', {'fields': ('last_login', 'date_joined')}),
    )
    staff_readonly_fields = ('username', 'first_name', 'last_name', 'email', 'last_login', 'date_joined')

    def get_fieldsets(self, request, obj=None):
        if not request.user.is_superuser:
            return self.staff_fieldsets
        else:
            return super(UserAdmin, self).get_fieldsets(request, obj)

    def get_readonly_fields(self, request, obj=None):
        if not request.user.is_superuser:
            return self.staff_readonly_fields
        else:
            return super(UserAdmin, self).get_readonly_fields(request, obj)


问:
How does the microservice API gateway pattern work with auto Horizontal scaling?
If I would like to have a high available solution. So, I would have two API gateways in different data center.

Each API gateway is connected to three microservices like billing, users, and account services. Each one has three replica.

So is that true to have 6 copies for one microservice, and if not. How does it work?

答:
In this scenario you'd want to deploy a single Kong cluster across multiple data centers - have a look at https://getkong.org/docs/0.10.x/clustering/

Kong supports two datastores (Postgres and Cassandra) you'd probably want to pick Cassandra, but you could make Postgres work - have a look at https://getkong.org/docs/0.10.x/configuration/#datastore-section


答:
you can access it like an array, this is how you would access the service_name values in the 4th item in the array

var a = [{"ID":102254,"Name":"obj 1","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":226619,"Name":"DIDE","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":224522,"Name":"CAT","service_name":["Open  Ticket","Escalation Ticket"]},{"ID":122533,"Name":"Mirror","service_name":["Open  Ticket","Escalation Ticket"]}]

console.log(JSON.stringify(a[3].service_name[0]))
console.log(JSON.stringify(a[3].service_name[1]))```


问:
easiest way to generate base 3 numbers
I am trying to solve a mathematical problem programatically. Having a way to generate base 3 numbers would make it very easy to solve the problem. Do you know of any language that has in-built support for working with numbers of non-trivial base? It would be equally great if you could point me to some tool that can help me generate a sequence of base 3 numbers</p>

答: python can convert from base 3 using int('012',3) which is 5 and Python elegant inverse function of int(string,base) has the reverse of that

Title: easiest way to generate base 3 numbers


问:
Set JSON values dynamically?
Can I do something like this:

```<code>var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

      this.setState({
          values[number]: evt.target.value
      });
</code>```

instead of writing out:

```<code>      this.setState({
        my_component_state_0: evt.target.value
      });
</code>```

?

I need to iterate through some things and something like this would be useful. But it seems too hacky, and it also doesn't seem to work - or does it? (or something like this)

答:
Option 1:

```<code>var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

var newState = {};
newState[values[number]] = evt.target.value;

this.setState(newState);
</code>```

Option 2:
New notation in ECMAScript 2015(Computed property names) - but IE doesn't support this syntax.

```<code>var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

this.setState({
   [values[number]]: evt.target.value
});
</code>```

Title: Set JSON values dynamically?

Body:
Can I do something like this:

var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

      this.setState({
          values[number]: evt.target.value
      });

instead of writing out:

      this.setState({
        my_component_state_0: evt.target.value
      });

?

I need to iterate through some things and something like this would be useful. But it seems too hacky, and it also doesn't seem to work - or does it? (or something like this)

Body:
Option 1:

var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

var newState = {};
newState[values[number]] = evt.target.value;

this.setState(newState);

Option 2:
New notation in ECMAScript 2015(Computed property names) - but IE doesn't support this syntax.

var number = 0;
var values = ["my_component_state_0", "my_component_state_1"];

this.setState({
   [values[number]]: evt.target.value
});


问:
Multiple constructors on an immutable (data) class
I'm trying to implement an immutable data class with more than one constructor. I felt that something like this should be possible:

```<code>data class Color(val r: Int, val g: Int, val b: Int) {
   constructor(hex: String) {
        assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
        val r = hex.substring(1..2).toInt(16)
        val g = hex.substring(3..4).toInt(16)
        val b = hex.substring(5..6).toInt(16)
        this(r,g,b)
    }
}
</code>```

Of course, it isn't: Kotlin expects the call to the main constructor be declared at the top:

```<code>constructor(hex: String): this(r,g,b) {
    assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
    val r = hex.substring(1..2).toInt(16)
    val g = hex.substring(3..4).toInt(16)
    val b = hex.substring(5..6).toInt(16)
}
</code>```

That's no good either, as the call is executed before the constructor body and can not access the local variables.

I can do this, of course:

```<code>constructor(hex: String): this(hex.substring(1..2).toInt(16),
                               hex.substring(3..4).toInt(16),
                               hex.substring(5..6).toInt(16)) {
    assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
}
</code>```

But this will check the assertion too late, and does not scale very well.

The only way I see to get close to the desired behaviour is this using a  helper function (which can't be defined non-static on Color):

```<code>constructor(hex: String): this(hexExtract(hex, 1..2),
                               hexExtract(hex, 3..4),
                               hexExtract(hex, 5..6))
</code>```

This does not strike me as a very elegant pattern, so I'm guessing I'm missing something here.

Is there an elegant, idiomatic way to have (complex) secondary constructors on immutable data classes in Kotlin?

答:
As explained here, using the operator function invoke on the companion object (just like Scala's apply) one can achieve not really a constructor, but a factory that looks like a constructor usage-site:

```<code>companion object {
    operator fun invoke(hex: String) : Color {
        assert(Regex("#[a-fA-F0-6]{6}").matches(hex),
               {"$hex is not a hex color"})
        val r = hex.substring(1..2).toInt(16)
        val g = hex.substring(3..4).toInt(16)
        val b = hex.substring(5..6).toInt(16)
        return Color(r, g, b)
    }
}
</code>```

Now, Color("#FF00FF") will to the expected thing.

Body:
I'm trying to implement an immutable data class with more than one constructor. I felt that something like this should be possible:

data class Color(val r: Int, val g: Int, val b: Int) {
   constructor(hex: String) {
        assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
        val r = hex.substring(1..2).toInt(16)
        val g = hex.substring(3..4).toInt(16)
        val b = hex.substring(5..6).toInt(16)
        this(r,g,b)
    }
}

Of course, it isn't: Kotlin expects the call to the main constructor be declared at the top:

constructor(hex: String): this(r,g,b) {
    assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
    val r = hex.substring(1..2).toInt(16)
    val g = hex.substring(3..4).toInt(16)
    val b = hex.substring(5..6).toInt(16)
}

That's no good either, as the call is executed before the constructor body and can not access the local variables.

I can do this, of course:

constructor(hex: String): this(hex.substring(1..2).toInt(16),
                               hex.substring(3..4).toInt(16),
                               hex.substring(5..6).toInt(16)) {
    assert(Regex("#[a-fA-F0-6]{6}").matches(hex), { "$hex is not a hex color" } )
}

But this will check the assertion too late, and does not scale very well.

The only way I see to get close to the desired behaviour is this using a  helper function (which can't be defined non-static on Color):

constructor(hex: String): this(hexExtract(hex, 1..2),
                               hexExtract(hex, 3..4),
                               hexExtract(hex, 5..6))

This does not strike me as a very elegant pattern, so I'm guessing I'm missing something here.

Is there an elegant, idiomatic way to have (complex) secondary constructors on immutable data classes in Kotlin?

Body:
As explained here, using the operator function invoke on the companion object (just like Scala's apply) one can achieve not really a constructor, but a factory that looks like a constructor usage-site:

companion object {
    operator fun invoke(hex: String) : Color {
        assert(Regex("#[a-fA-F0-6]{6}").matches(hex),
               {"$hex is not a hex color"})
        val r = hex.substring(1..2).toInt(16)
        val g = hex.substring(3..4).toInt(16)
        val b = hex.substring(5..6).toInt(16)
        return Color(r, g, b)
    }
}

Now, Color("#FF00FF") will to the expected thing.


问:
Remove the first line from my directory
how can i remove the first line from my list of file , this is my code,

open my directory:

```<code>use strict;
use warnings;

use utf8;

use Encode;

use Encode::Guess;

use Devel::Peek;
my $new_directory = '/home/lenovo/corpus';
my $directory = '/home/lenovo/corpus';
open( my $FhResultat, '>:encoding(UTF-8)', $FichierResulat );
my $dir = '/home/corpus';
opendir (DIR, $directory) or die $!;
my @tab;
while (my $file = readdir(DIR)) {

 next if ($file eq "." or $file eq ".." );
    #print "$file\n";

my $filename_read = decode('utf8', $file);
        #print $FichierResulat "$file\n";

push @tab, "$filename_read";

}
 closedir(DIR);
</code>```

open my file:

```<code>foreach my $val(@tab){

utf8::encode($val);

my $filename = $val;

open(my $in, '<:utf8', $filename) or die "Unable to open '$filename' for read: $!";
</code>```

rename file

```<code>my $newfile = "$filename.new";

open(my $out, '>:utf8', $newfile) or die "Unable to open '$newfile' for write: $!";
</code>```

remove the first line

```<code>my @ins = <$in>; # read the contents into an array
chomp @ins;
shift @ins; # remove the first element from the array

print $out   @ins;
    close($in);
    close $out;
</code>```

the probem my new file is empty !
    rename $newfile,$filename or die "unable to rename '$newfile' to '$filename': $!";
    }

It seems true but the result is an empty file.

答:
The accepted pattern for doing this kind of thing is as follows:

```<code>use strict;
use warnings;

my $old_file = '/path/to/old/file.txt';
my $new_file = '/path/to/new/file.txt';

open(my $old, '<', $old_file) or die $!;
open(my $new, '>', $new_file) or die $!;

while (<$old>) {
    next if $. == 1;
    print $new $_;
}

close($old) or die $!;
close($new) or die $!;

rename($old_file, "$old_file.bak") or die $!;
rename($new_file, $old_file) or die $!;
</code>```

In your case, we're using $. (the input line number variable) to skip over the first line.

Title: Remove the first line from my directory

Body:
how can i remove the first line from my list of file , this is my code,

open my directory:

use strict;
use warnings;

use utf8;

use Encode;

use Encode::Guess;

use Devel::Peek;
my $new_directory = '/home/lenovo/corpus';
my $directory = '/home/lenovo/corpus';
open( my $FhResultat, '>:encoding(UTF-8)', $FichierResulat );
my $dir = '/home/corpus';
opendir (DIR, $directory) or die $!;
my @tab;
while (my $file = readdir(DIR)) {

 next if ($file eq "." or $file eq ".." );
    #print "$file\n";

my $filename_read = decode('utf8', $file);
        #print $FichierResulat "$file\n";

push @tab, "$filename_read";

}
 closedir(DIR);

open my file:

foreach my $val(@tab){

utf8::encode($val);

my $filename = $val;

open(my $in, '<:utf8', $filename) or die "Unable to open '$filename' for read: $!";

rename file

my $newfile = "$filename.new";

open(my $out, '>:utf8', $newfile) or die "Unable to open '$newfile' for write: $!";

remove the first line

my @ins = <$in>; # read the contents into an array
chomp @ins;
shift @ins; # remove the first element from the array

print $out   @ins;
    close($in);
    close $out;

the probem my new file is empty !
    rename $newfile,$filename or die "unable to rename '$newfile' to '$filename': $!";
    }

It seems true but the result is an empty file.

Body:
The accepted pattern for doing this kind of thing is as follows:

use strict;
use warnings;

my $old_file = '/path/to/old/file.txt';
my $new_file = '/path/to/new/file.txt';

open(my $old, '<', $old_file) or die $!;
open(my $new, '>', $new_file) or die $!;

while (<$old>) {
    next if $. == 1;
    print $new $_;
}

close($old) or die $!;
close($new) or die $!;

rename($old_file, "$old_file.bak") or die $!;
rename($new_file, $old_file) or die $!;

In your case, we're using $. (the input line number variable) to skip over the first line.


问:
Why doesn't Rails update its association cache when creating new records through the association?
```<code>class User < ActiveRecord::Base
  has_many :addresses, -> { order("created_at DESC") }
end

class Address < ActiveRecord::Base
  belongs_to :user
end

class UserTest < ActiveSupport::TestCase
  test 'should return the last address the user created' do
    user = User.create!
    user.addresses.create!(created_at: Date.today - 1.day)
    user.addresses.create!(created_at: Date.today)
    assert_equal Date.today, user.addresses.first.created_at # note that .first here should actually return the last record created, when hitting the DB, due to the ordering specified in the association scope block
  end
end
</code>```

This assertion would fail (user.addresses.first.created_at returns Date.today-1.day), while if I did user.reload or user.addresses.reset right before the assertion, it would succeed (user.addresses.first.created_at then returns Date.today).

Why doesn't Rails update its association cache when creating new records through the association?

I would have expected using user.addresses.create would actually have updated the cached association on the user object, as well as the DB record, since it is created through the association. As opposed to using Address.create, in which case I would expect the need to reload the user object.

答:
I assume because it would be too expensive and unnecessary in most situations. I usually write these specs as:</p>

```<code>assert_equal Date.today, user.addresses.reload.first.created_at
</code>```

Body:
class User < ActiveRecord::Base
  has_many :addresses, -> { order("created_at DESC") }
end

class Address < ActiveRecord::Base
  belongs_to :user
end

class UserTest < ActiveSupport::TestCase
  test 'should return the last address the user created' do
    user = User.create!
    user.addresses.create!(created_at: Date.today - 1.day)
    user.addresses.create!(created_at: Date.today)
    assert_equal Date.today, user.addresses.first.created_at # note that .first here should actually return the last record created, when hitting the DB, due to the ordering specified in the association scope block
  end
end

This assertion would fail (user.addresses.first.created_at returns Date.today-1.day), while if I did user.reload or user.addresses.reset right before the assertion, it would succeed (user.addresses.first.created_at then returns Date.today).

Why doesn't Rails update its association cache when creating new records through the association?

I would have expected using user.addresses.create would actually have updated the cached association on the user object, as well as the DB record, since it is created through the association. As opposed to using Address.create, in which case I would expect the need to reload the user object.

Body:
I assume because it would be too expensive and unnecessary in most situations. I usually write these specs as:

assert_equal Date.today, user.addresses.reload.first.created_at


问:
Face tracking using opencv arduino and python
I'm working on face tracking project. I sucessfully coded face detection on python . I need to track my face by webcam. I have arduino for motor control. I couldn't able to track my face, its hard to communicate with arduino. and what code should I use for tracking purpose I have no idea about the axis . please help</p>

答:
Face Detection in Python Using a Webcam

```<code>import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
</code>```

But you know that you can't use this on an arduino or any other OpenCV likes (image processing library) on any type of micro-controller
for that matter, since they have very low processor power that is just enough to handle some IO commands but also you may can use some more expensive camera module with built-in face detection on hardware.
to do the face detection ; But with a webcam you would need a raspberry pi or any other single board pc with enough CPU & GPU to do the job.

and for the communication with python you can go to arduino playground

Arduino and Python

After installing pySerial, reading data from Arduino is straightforward:

```<code>>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
>>> while True:
...     print ser.readline()
'1 Hello world!\r\n'
'2 Hello world!\r\n'
'3 Hello world!\r\n'
</code>```

Body:
Face Detection in Python Using a Webcam

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

But you know that you can't use this on an arduino or any other OpenCV likes (image processing library) on any type of micro-controller
for that matter, since they have very low processor power that is just enough to handle some IO commands but also you may can use some more expensive camera module with built-in face detection on hardware.
to do the face detection ; But with a webcam you would need a raspberry pi or any other single board pc with enough CPU & GPU to do the job.

and for the communication with python you can go to arduino playground

Arduino and Python

After installing pySerial, reading data from Arduino is straightforward:

>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
>>> while True:
...     print ser.readline()
'1 Hello world!\r\n'
'2 Hello world!\r\n'
'3 Hello world!\r\n'


问:
javax.jms.InvalidDestinationException: MQJMS2008: failed to open MQ queue ---- MQJE001: Completion Code 2, Reason 2085
I'm migrating an application from Websphere to JBoss EAP 6.4.

Jboss has been configured to comunincare with a MQ queue via a resource-adapter.
This is the configuration of Jboss:

```<code><resource-adapters>
<resource-adapter id="wmq.jmsra.rar">
    <archive>
        wmq.jmsra.rar
    </archive>
    <transaction-support>NoTransaction</transaction-support>
    <config-property name="logWriterEnabled">
        true
    </config-property>
    <config-property name="maxConnections">
        100
    </config-property>
    <config-property name="reconnectionRetryCount">
        1000
    </config-property>
    <config-property name="traceLevel">
        6
    </config-property>
    <config-property name="traceEnabled">
        true
    </config-property>
    <config-property name="reconnectionRetryInterval">
        30000
    </config-property>
    <config-property name="connectionConcurrency">
        1
    </config-property>
    <connection-definitions>
        <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/puc.ejb.factory" enabled="true" use-java-context="false" pool-name="puc.ejb.factory">
            <config-property name="port">
                ${wmq.port:1414}
            </config-property>
            <config-property name="hostName">
                ${wmq.host:xxx.xxx.xxx.xxx}
            </config-property>
            <config-property name="channel">
                ${wmq.queue.channel:CLT2SRV}
            </config-property>
            <config-property name="transportType">
                CLIENT
            </config-property>
            <config-property name="queueManager">
                ${wmq.queue.manager:MQEDFIDP}
            </config-property>
            <timeout>
                <allocation-retry>3</allocation-retry>
                <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
            </timeout>
        </connection-definition>
    </connection-definitions>
    <admin-objects>
        <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/puc.ejb.queue" enabled="true" use-java-context="false" pool-name="puc.ejb.queue">
            <config-property name="baseQueueName">
                DATAGRAM.GG9.INVIOSMS
            </config-property>
            <config-property name="baseQueueManagerName">
                MQEDFIDP
            </config-property>
        </admin-object>
    </admin-objects>
</resource-adapter>
</code>```

When publishing messages on the queue I get this exception:

mar 30, 2017 - 10:50:50,177 ERROR [stderr] (EJB default - 1) ERROR!
  javax.jms.InvalidDestinationException: MQJMS2008: impossibile aprire
  la coda MQ 'DATAGRAM.GG9.INVIOSMS'.

mar 30, 2017 - 10:50:50,180 ERROR [stderr] (EJB default - 1)
  javax.jms.InvalidDestinationException: MQJMS2008: impossibile aprire
  la coda MQ 'DATAGRAM.GG9.INVIOSMS'.

mar 30, 2017 - 10:50:50,181 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getQueueOpenException(MQQueueServices.java:860)

mar 30, 2017 - 10:50:50,182 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getOutputQueue(MQQueueServices.java:689)

mar 30, 2017 - 10:50:50,183 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.JMSServicesMgr.getOutputQueue(JMSServicesMgr.java:215)

mar 30, 2017 - 10:50:50,185 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createQProducer(MQSession.java:3082)

mar 30, 2017 - 10:50:50,186 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createProducer(MQSession.java:2820)

mar 30, 2017 - 10:50:50,187 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createProducer(MQSession.java:2876)

mar 30, 2017 - 10:50:50,188 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.jms.internal.JmsSessionImpl.createProducer(JmsSessionImpl.java:1232)

mar 30, 2017 - 10:50:50,189 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.jms.MQSession.createProducer(MQSession.java:687)

mar 30, 2017 - 10:50:50,191 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.connector.outbound.MessageProducerWrapper.(MessageProducerWrapper.java:104)

mar 30, 2017 - 10:50:50,192 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.connector.outbound.SessionWrapper.createProducer(SessionWrapper.java:375)

mar 30, 2017 - 10:50:50,193 ERROR [stderr] (EJB default - 1)  at
  com.fideuram.puc.ejb.AccodaSMS.inviaSMS(AccodaSMS.java:81)

mar 30, 2017 - 10:50:50,194 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

mar 30, 2017 - 10:50:50,195 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

mar 30, 2017 - 10:50:50,197 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

mar 30, 2017 - 10:50:50,198 ERROR [stderr] (EJB default - 1)  at
  java.lang.reflect.Method.invoke(Method.java:597)

mar 30, 2017 - 10:50:50,199 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

mar 30, 2017 - 10:50:50,200 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,201 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

mar 30, 2017 - 10:50:50,203 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

mar 30, 2017 - 10:50:50,204 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,205 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

mar 30, 2017 - 10:50:50,207 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

mar 30, 2017 - 10:50:50,208 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,209 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

mar 30, 2017 - 10:50:50,210 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,212 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

mar 30, 2017 - 10:50:50,213 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,214 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

mar 30, 2017 - 10:50:50,215 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,216 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

mar 30, 2017 - 10:50:50,218 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

mar 30, 2017 - 10:50:50,219 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,220 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

mar 30, 2017 - 10:50:50,221 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,223 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:279)

mar 30, 2017 - 10:50:50,224 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:331)

mar 30, 2017 - 10:50:50,225 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:243)

mar 30, 2017 - 10:50:50,226 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,227 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80)

mar 30, 2017 - 10:50:50,229 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,230 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

mar 30, 2017 - 10:50:50,231 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,232 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43)

mar 30, 2017 - 10:50:50,234 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,235 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:89)

mar 30, 2017 - 10:50:50,236 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,237 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)

mar 30, 2017 - 10:50:50,239 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,240 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)

mar 30, 2017 - 10:50:50,241 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,242 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

mar 30, 2017 - 10:50:50,243 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,245 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

mar 30, 2017 - 10:50:50,246 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,247 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)

mar 30, 2017 - 10:50:50,248 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,250 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

mar 30, 2017 - 10:50:50,251 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,252 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

mar 30, 2017 - 10:50:50,253 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:189)

mar 30, 2017 - 10:50:50,254 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:319)

mar 30, 2017 - 10:50:50,256 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$100(MethodInvocationMessageHandler.java:68)

mar 30, 2017 - 10:50:50,257 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:201)

mar 30, 2017 - 10:50:50,258 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

mar 30, 2017 - 10:50:50,260 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

mar 30, 2017 - 10:50:50,261 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.FutureTask.run(FutureTask.java:138)

mar 30, 2017 - 10:50:50,262 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

mar 30, 2017 - 10:50:50,263 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

mar 30, 2017 - 10:50:50,264 ERROR [stderr] (EJB default - 1)  at
  java.lang.Thread.run(Thread.java:662)

mar 30, 2017 - 10:50:50,266 ERROR [stderr] (EJB default - 1)  at
  org.jboss.threads.JBossThread.run(JBossThread.java:122)

mar 30, 2017 - 10:50:50,267 ERROR [stderr] (EJB default - 1) Caused
  by: com.ibm.mq.MQException: MQJE001: Codice di completamento '2',
  ragione '2085'.

mar 30, 2017 - 10:50:50,268 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.base.internal.MQQueueManager.accessQueue(MQQueueManager.java:751)

mar 30, 2017 - 10:50:50,269 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getOutputQueue(MQQueueServices.java:682)

mar 30, 2017 - 10:50:50,271 ERROR [stderr] (EJB default - 1)  ... 68
  more

In another discussion the error had been detected on the wrong configuration of the queue but does not specify what the error was (argh!).

This is the discussion

答:
com.ibm.mq.MQException: MQJE001: Codice di completamento '2', ragione
  '2085'.

Why don't you just look up the reason code in the IBM MQ Knowledge Center.  If you had done a simple search (i.e. Google), this page would have been at the top

Body:
I'm migrating an application from Websphere to JBoss EAP 6.4.

Jboss has been configured to comunincare with a MQ queue via a resource-adapter.
This is the configuration of Jboss:

<resource-adapters>
<resource-adapter id="wmq.jmsra.rar">
    <archive>
        wmq.jmsra.rar
    </archive>
    <transaction-support>NoTransaction</transaction-support>
    <config-property name="logWriterEnabled">
        true
    </config-property>
    <config-property name="maxConnections">
        100
    </config-property>
    <config-property name="reconnectionRetryCount">
        1000
    </config-property>
    <config-property name="traceLevel">
        6
    </config-property>
    <config-property name="traceEnabled">
        true
    </config-property>
    <config-property name="reconnectionRetryInterval">
        30000
    </config-property>
    <config-property name="connectionConcurrency">
        1
    </config-property>
    <connection-definitions>
        <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/puc.ejb.factory" enabled="true" use-java-context="false" pool-name="puc.ejb.factory">
            <config-property name="port">
                ${wmq.port:1414}
            </config-property>
            <config-property name="hostName">
                ${wmq.host:xxx.xxx.xxx.xxx}
            </config-property>
            <config-property name="channel">
                ${wmq.queue.channel:CLT2SRV}
            </config-property>
            <config-property name="transportType">
                CLIENT
            </config-property>
            <config-property name="queueManager">
                ${wmq.queue.manager:MQEDFIDP}
            </config-property>
            <timeout>
                <allocation-retry>3</allocation-retry>
                <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
            </timeout>
        </connection-definition>
    </connection-definitions>
    <admin-objects>
        <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/puc.ejb.queue" enabled="true" use-java-context="false" pool-name="puc.ejb.queue">
            <config-property name="baseQueueName">
                DATAGRAM.GG9.INVIOSMS
            </config-property>
            <config-property name="baseQueueManagerName">
                MQEDFIDP
            </config-property>
        </admin-object>
    </admin-objects>
</resource-adapter>

When publishing messages on the queue I get this exception:

mar 30, 2017 - 10:50:50,177 ERROR [stderr] (EJB default - 1) ERROR!
  javax.jms.InvalidDestinationException: MQJMS2008: impossibile aprire
  la coda MQ 'DATAGRAM.GG9.INVIOSMS'.

mar 30, 2017 - 10:50:50,180 ERROR [stderr] (EJB default - 1)
  javax.jms.InvalidDestinationException: MQJMS2008: impossibile aprire
  la coda MQ 'DATAGRAM.GG9.INVIOSMS'.

mar 30, 2017 - 10:50:50,181 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getQueueOpenException(MQQueueServices.java:860)

mar 30, 2017 - 10:50:50,182 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getOutputQueue(MQQueueServices.java:689)

mar 30, 2017 - 10:50:50,183 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.JMSServicesMgr.getOutputQueue(JMSServicesMgr.java:215)

mar 30, 2017 - 10:50:50,185 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createQProducer(MQSession.java:3082)

mar 30, 2017 - 10:50:50,186 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createProducer(MQSession.java:2820)

mar 30, 2017 - 10:50:50,187 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQSession.createProducer(MQSession.java:2876)

mar 30, 2017 - 10:50:50,188 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.jms.internal.JmsSessionImpl.createProducer(JmsSessionImpl.java:1232)

mar 30, 2017 - 10:50:50,189 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.jms.MQSession.createProducer(MQSession.java:687)

mar 30, 2017 - 10:50:50,191 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.connector.outbound.MessageProducerWrapper.(MessageProducerWrapper.java:104)

mar 30, 2017 - 10:50:50,192 ERROR [stderr] (EJB default - 1)  at
  com.ibm.mq.connector.outbound.SessionWrapper.createProducer(SessionWrapper.java:375)

mar 30, 2017 - 10:50:50,193 ERROR [stderr] (EJB default - 1)  at
  com.fideuram.puc.ejb.AccodaSMS.inviaSMS(AccodaSMS.java:81)

mar 30, 2017 - 10:50:50,194 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

mar 30, 2017 - 10:50:50,195 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

mar 30, 2017 - 10:50:50,197 ERROR [stderr] (EJB default - 1)  at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

mar 30, 2017 - 10:50:50,198 ERROR [stderr] (EJB default - 1)  at
  java.lang.reflect.Method.invoke(Method.java:597)

mar 30, 2017 - 10:50:50,199 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

mar 30, 2017 - 10:50:50,200 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,201 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

mar 30, 2017 - 10:50:50,203 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

mar 30, 2017 - 10:50:50,204 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,205 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

mar 30, 2017 - 10:50:50,207 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

mar 30, 2017 - 10:50:50,208 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,209 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

mar 30, 2017 - 10:50:50,210 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,212 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

mar 30, 2017 - 10:50:50,213 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,214 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

mar 30, 2017 - 10:50:50,215 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,216 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

mar 30, 2017 - 10:50:50,218 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

mar 30, 2017 - 10:50:50,219 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,220 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

mar 30, 2017 - 10:50:50,221 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,223 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:279)

mar 30, 2017 - 10:50:50,224 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:331)

mar 30, 2017 - 10:50:50,225 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:243)

mar 30, 2017 - 10:50:50,226 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,227 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80)

mar 30, 2017 - 10:50:50,229 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,230 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

mar 30, 2017 - 10:50:50,231 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,232 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43)

mar 30, 2017 - 10:50:50,234 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,235 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:89)

mar 30, 2017 - 10:50:50,236 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,237 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)

mar 30, 2017 - 10:50:50,239 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,240 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)

mar 30, 2017 - 10:50:50,241 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,242 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

mar 30, 2017 - 10:50:50,243 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,245 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

mar 30, 2017 - 10:50:50,246 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,247 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)

mar 30, 2017 - 10:50:50,248 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,250 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

mar 30, 2017 - 10:50:50,251 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

mar 30, 2017 - 10:50:50,252 ERROR [stderr] (EJB default - 1)  at
  org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

mar 30, 2017 - 10:50:50,253 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:189)

mar 30, 2017 - 10:50:50,254 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:319)

mar 30, 2017 - 10:50:50,256 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$100(MethodInvocationMessageHandler.java:68)

mar 30, 2017 - 10:50:50,257 ERROR [stderr] (EJB default - 1)  at
  org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:201)

mar 30, 2017 - 10:50:50,258 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

mar 30, 2017 - 10:50:50,260 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

mar 30, 2017 - 10:50:50,261 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.FutureTask.run(FutureTask.java:138)

mar 30, 2017 - 10:50:50,262 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

mar 30, 2017 - 10:50:50,263 ERROR [stderr] (EJB default - 1)  at
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

mar 30, 2017 - 10:50:50,264 ERROR [stderr] (EJB default - 1)  at
  java.lang.Thread.run(Thread.java:662)

mar 30, 2017 - 10:50:50,266 ERROR [stderr] (EJB default - 1)  at
  org.jboss.threads.JBossThread.run(JBossThread.java:122)

mar 30, 2017 - 10:50:50,267 ERROR [stderr] (EJB default - 1) Caused
  by: com.ibm.mq.MQException: MQJE001: Codice di completamento '2',
  ragione '2085'.

mar 30, 2017 - 10:50:50,268 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.base.internal.MQQueueManager.accessQueue(MQQueueManager.java:751)

mar 30, 2017 - 10:50:50,269 ERROR [stderr] (EJB default - 1)  at
  com.ibm.msg.client.wmq.v6.jms.internal.MQQueueServices.getOutputQueue(MQQueueServices.java:682)

mar 30, 2017 - 10:50:50,271 ERROR [stderr] (EJB default - 1)  ... 68
  more

In another discussion the error had been detected on the wrong configuration of the queue but does not specify what the error was (argh!).

This is the discussion


问:
Ruby 2.4 Split an Array of Hashes based on a list of acceptable key values
I have an array of IDs as listed below:

```<code>ids = [101153, 87218, 99589, 73109, 80660, 107784, 76392, 101501]
</code>```

I have an array of hashes.

```<code>[
  {"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>101501, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>107784, "key"=>"ABC-2453", "hidden"=>true, "done"=>false},
  {"id"=>107786, "key"=>"ABC-1345", "hidden"=>true, "done"=>false}
]
</code>```

How do I filter an array of hashes where the ID is present from the array ids?

Body:
I have an array of IDs as listed below:

ids = [101153, 87218, 99589, 73109, 80660, 107784, 76392, 101501]

I have an array of hashes.

[
  {"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>101501, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},
  {"id"=>107784, "key"=>"ABC-2453", "hidden"=>true, "done"=>false},
  {"id"=>107786, "key"=>"ABC-1345", "hidden"=>true, "done"=>false}
]

How do I filter an array of hashes where the ID is present from the array ids?

Body:
It isn't very hard. Iterate over hashes with select to see which ids are known. Use a Set for faster lookup.

require 'set'

ids = Set.new([101153, 87218, 99589, 73109, 80660, 107784, 76392, 101501])
hashes = [{"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},{"id"=>101501, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},{"id"=>107786, "key"=>"ABC-2002", "hidden"=>true, "done"=>false},{"id"=>107784, "key"=>"ABC-2453", "hidden"=>true, "done"=>false},{"id"=>107786, "key"=>"ABC-1345", "hidden"=>true, "done"=>false}]

p hashes.select{ |h| ids.include?(h['id']) }
# [{"id"=>101501, "key"=>"ABC-2002", "hidden"=>true, "done"=>false}, {"id"=>107784, "key"=>"ABC-2453", "hidden"=>true, "done"=>false}]