问:
Can xcodebuild manage automatic signing?
SUMMARY:

If you open a project in Xcode 8 with "Automatically manage signing" enabled and a new bundle ID, it will automatically create and download a provisioning profile for it. But how can I make the same thing happen with xcodebuild, so I can use it on a remote build server?

DETAILS:

I'm trying to build a Cordova app on a Mac. Cordova configures the Xcode project to use "Automatically manage signing", so I'm trying to use that.

I change the bundle ID often, so I want Cordova to be able to build it with a new bundle ID, that hasn't been used before.

But when I run cordova build ios --release --device --buildConfig build.json, I get a return code 65 and the following error:

```<code>Check dependencies
No profiles for 'com.my.bundle.id' were found:  Xcode couldn't find a provisioning profile matching 'com.my.bundle.id'.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'

** ARCHIVE FAILED **

The following build commands failed:
    Check dependencies
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/cordova-project/platforms/ios/cordova/build-debug.xcconfig,-workspace,MyApp.xcworkspace,-scheme,MyApp,-configuration,Debug,-destination,generic/platform=iOS,-archivePath,MyApp.xcarchive,archive,CONFIGURATION_BUILD_DIR=/cordova-project/platforms/ios/build/device,SHARED_PRECOMPS_DIR=/cordova-project/platforms/ios/build/sharedpch
</code>```

(I can manually run that xcodebuild command and get the same error, so it's probably not a Cordova issue.)

My build.json file looks like this:

```<code>{
    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "development"
        },
        "release": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "enterprise"
        }
    }
}
</code>```

I'm using cordova 7.0.1, cordova-ios 4.4.0, Xcode 8.3.3, and MacOS 10.12.5. I have an Apple Enterprise account.

WHAT I TRIED:

If I open the generated project in Xcode, it fixes the automatic signing, and from then on I can run cordova successfully with that bundle ID. But if I try to run it with a different bundle ID, it will fail again.

I tried using security unlock-keychain ~/Library/Keychains/login.keychain-db first, since that's worked in the past, but it didn't help.

I also tried opening my private signing key in Keychain Access and setting it to "Allow all applications to access this item", without any luck.

I get the same error regardless of whether I pass --debug or --release to cordova.

答:
This isn't directly supported in Xcode 8. In Xcode 9, however, you can pass -allowProvisioningUpdates to xcodebuild and automatic signing will work just as in the Xcode UI, without needing any additional tools.

e.g. cordova run ios --buildFlag="-allowProvisioningUpdates"

Body:
SUMMARY:

If you open a project in Xcode 8 with "Automatically manage signing" enabled and a new bundle ID, it will automatically create and download a provisioning profile for it. But how can I make the same thing happen with xcodebuild, so I can use it on a remote build server?

DETAILS:

I'm trying to build a Cordova app on a Mac. Cordova configures the Xcode project to use "Automatically manage signing", so I'm trying to use that.

I change the bundle ID often, so I want Cordova to be able to build it with a new bundle ID, that hasn't been used before.

But when I run cordova build ios --release --device --buildConfig build.json, I get a return code 65 and the following error:

Check dependencies
No profiles for 'com.my.bundle.id' were found:  Xcode couldn't find a provisioning profile matching 'com.my.bundle.id'.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'

** ARCHIVE FAILED **

The following build commands failed:
    Check dependencies
(1 failure)
Error: Error code 65 for command: xcodebuild with args: -xcconfig,/cordova-project/platforms/ios/cordova/build-debug.xcconfig,-workspace,MyApp.xcworkspace,-scheme,MyApp,-configuration,Debug,-destination,generic/platform=iOS,-archivePath,MyApp.xcarchive,archive,CONFIGURATION_BUILD_DIR=/cordova-project/platforms/ios/build/device,SHARED_PRECOMPS_DIR=/cordova-project/platforms/ios/build/sharedpch

(I can manually run that xcodebuild command and get the same error, so it's probably not a Cordova issue.)

My build.json file looks like this:

{
    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "development"
        },
        "release": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "MY_TEAM_ID",
            "packageType": "enterprise"
        }
    }
}

I'm using cordova 7.0.1, cordova-ios 4.4.0, Xcode 8.3.3, and MacOS 10.12.5. I have an Apple Enterprise account.

WHAT I TRIED:

If I open the generated project in Xcode, it fixes the automatic signing, and from then on I can run cordova successfully with that bundle ID. But if I try to run it with a different bundle ID, it will fail again.

I tried using security unlock-keychain ~/Library/Keychains/login.keychain-db first, since that's worked in the past, but it didn't help.

I also tried opening my private signing key in Keychain Access and setting it to "Allow all applications to access this item", without any luck.

I get the same error regardless of whether I pass --debug or --release to cordova.


来源: stackexchange

问:
How to setup Silverlight xap caching to work the same in all browsers
Basic Requirements

I have a SL app that can be run in-browser or out-of-browser. I want the browser to:

Cache the xap file

Load the xap from the cache if it has not changed or re-download it if it has changed.

More details

Setting a future expires header obviously solves the caching problem but then I cannot force the user to download the latest version. Normally I would just add a querystring to the url (eg url?v=1) but I cannot do this as this breaks the out-of-browser functionality. eg the app thinks it is not installed when in fact it is.

no cache

If I set Cache-Control to no-cache, Chrome and Firefox correctly send a request to the server for the xap but use the cache if a 304 is returned. IE8 just downloads the file again as does Safari.

must-revalidate

Setting Cache-Control to must-revalidate again works correctly in Chrome and Firefox but Safari always downloads the xap again while IE8 always uses the cache.

How do I set this up to work as described at the start of this question?

答:
I'm not sure that the Chrome/Firefox is strictly "correct", you have after all not told the browser that it should cache the content or even that the content is cacheable.

Instead of no-cache try "Cache-Control: max-age=15" instead.  See if that convinces IE that it ought cache the content despite its large size (which is why its not caching it originally).

For OOB install use the Application object's CheckAndDownloadUpdateAsync method.  Note you need to inform the user to restart the app once an update has been downloaded.

ContentLicense: CC BY-SA 2.5


问:
convert letters into numbers (A=1; B=2...) c++
I was trying to make letters into numbers in c++. When I write in console  it should count modulo and type out if ship is coming (i did all, but can't make letters into numbers :/ )

This what should happen: ABC a = 1; b=2; c=3    1*2*3=6....

So I need to write a word and it should be separated into letters and converted into numbers like that.

I am just learning and I don't know much :)

My current code:

```<code>int shipnum, groupnum, moduleship, modulegroup;

cout << "type ship number "; cin >> shipnum;
cout << "type group number "; cin >> groupnum;

/*shipnum dabar 5... (5 mod 2)
groupnum dabar 3... (3 mod 2)
*/

moduleship = shipnum % 47;        //skaiciuojam moduli...
modulegroup = groupnum % 47;

if (moduleship == modulegroup) {
 cout << "YES ship is coming for you :)";
 }

else if (moduleship != modulegroup) {             //  "!=" reiskia "nelygu"
    cout << "SORRY, NO ship for you :(";
}

return 0;
</code>```

答:
Your question isn't precise, although I find it enough. Tip: Be precise with the information you provide, there's no need to show the rest of the code.

Lets say we have this char Ship[20]="ABCDEF";. If you encoding is as simple as A=1, B=2, etc, then you only need something like this:

```<code>char Ship[20]="ABCDEF";
int decoded=1;
for(int i=1; Ship[i]=!'/0'; ++i) {
    decoded = decoded * i
}
cout<<decoded;
</code>```

This loop will run till it encounters the '\0' (null character) at the end of the string. So, you would have a factorial on the fact that your codeing (A=1,B=2, etc) represents a factorial.

otherwise, you could use a switch case, or if statements to check for individual characters and decode appropriately.

```<code>char Ship[20]="ABCDEF";
int decoded=1;
for(int i=1; Ship[i]=!'/0'; ++i) {
    switch(Ship[i]){
        case 'A'  :   decoded = decoded * 1;
                      break;
        case 'B'  :   decoded = decoded *2;
                      break;
              //So on
        default   :   break;
    }
}
cout<<decoded;
</code>```

Output in both cases:

720

ContentLicense: CC BY-SA 3.0

Body:
I was trying to make letters into numbers in c++. When I write in console  it should count modulo and type out if ship is coming (i did all, but can't make letters into numbers :/ )

This what should happen: ABC a = 1; b=2; c=3    1*2*3=6....

So I need to write a word and it should be separated into letters and converted into numbers like that.

I am just learning and I don't know much :)

My current code:

int shipnum, groupnum, moduleship, modulegroup;

cout << "type ship number "; cin >> shipnum;
cout << "type group number "; cin >> groupnum;

/*shipnum dabar 5... (5 mod 2)
groupnum dabar 3... (3 mod 2)
*/

moduleship = shipnum % 47;        //skaiciuojam moduli...
modulegroup = groupnum % 47;

if (moduleship == modulegroup) {
 cout << "YES ship is coming for you :)";
 }

else if (moduleship != modulegroup) {             //  "!=" reiskia "nelygu"
    cout << "SORRY, NO ship for you :(";
}

return 0;

Body:
Your question isn't precise, although I find it enough. Tip: Be precise with the information you provide, there's no need to show the rest of the code.

Lets say we have this char Ship[20]="ABCDEF";. If you encoding is as simple as A=1, B=2, etc, then you only need something like this:

char Ship[20]="ABCDEF";
int decoded=1;
for(int i=1; Ship[i]=!'/0'; ++i) {
    decoded = decoded * i
}
cout<<decoded;

This loop will run till it encounters the '\0' (null character) at the end of the string. So, you would have a factorial on the fact that your codeing (A=1,B=2, etc) represents a factorial.

otherwise, you could use a switch case, or if statements to check for individual characters and decode appropriately.

char Ship[20]="ABCDEF";
int decoded=1;
for(int i=1; Ship[i]=!'/0'; ++i) {
    switch(Ship[i]){
        case 'A'  :   decoded = decoded * 1;
                      break;
        case 'B'  :   decoded = decoded *2;
                      break;
              //So on
        default   :   break;
    }
}
cout<<decoded;

Output in both cases:

720


问:
How to tweet multiple lines with Tweepy?
How can I tweet this...

```
List of fruits:
1. Apple
2. Banana
3. Orange
```

Instead of this?

```List of fruits: 1. Apple 2. Banana 3. Orange```

My code so far:

```<code>import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
api.update_status('List of fruits: \n1. Apple \n2. Banana \n3. Orange')
</code>```

As you can see, using '\n' didn't work. Tweepy just ignored it.

Thanks in advance.

答:
When you call an external API, it need not be written in Python on the server end. So maybe the '\n' is simply being caught as an exception. Or probably, the encoding is changed to ignore the escape characters.

What you can do is:

```<code>with open('temp.txt', 'w') as f:
   f.write('List of fruits: \n1. Apple \n2. Banana \n3. Orange')

import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
with open('temp.txt','r') as f:
   api.update_status(f.read())
</code>```

Body:
How can I tweet this...

List of fruits:
1. Apple
2. Banana
3. Orange

Instead of this?

List of fruits: 1. Apple 2. Banana 3. Orange

My code so far:

import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
api.update_status('List of fruits: \n1. Apple \n2. Banana \n3. Orange')

As you can see, using '\n' didn't work. Tweepy just ignored it.

Thanks in advance.

Body:
When you call an external API, it need not be written in Python on the server end. So maybe the '\n' is simply being caught as an exception. Or probably, the encoding is changed to ignore the escape characters.

What you can do is:

with open('temp.txt', 'w') as f:
   f.write('List of fruits: \n1. Apple \n2. Banana \n3. Orange')

import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
with open('temp.txt','r') as f:
   api.update_status(f.read())


问:
Accept header in ruby rest-client I believe causes return of an error code 404
I am passing the following request to ruby rest-client gem;

```<code>RestClient::Request.execute(method: :get,
                            url: Config['site_url'] + path,
                            verify_ssl: OpenSSL::SSL::VERIFY_NONE,
                            headers: { organisation: 'WEB',
                                       accept: 'application/vnd.xyz.v2+json' })
</code>```

Gem Versions
ruby version 2.3.3
rest-client 2.0.2

I have passed the same request to Postman and I get the response I expected.

I also have a v1 of the API that accepts just ":json" and this also responds as expected so my feeling is that it is something around the

```<code>accept: 'application/vnd.xyz.v2+json'
</code>```

That is causing the problem but I'm not sure what exactly. As my feeling is if there was something wrong with the response then postman would also complain.

The documentation here https://github.com/rest-client/rest-client
default request headers: rest-client sets

```<code>accept:*/*
</code>```

Just in case I passed / (although I am assuming * means enter what you need) but this returned the v1 response.

The method, url and verify_ssl are working in multiple other requests. So I don't think there is any issue there either.

Anyone, have any suggestions? Thx

答:
The problem wasn't the request, it was the API didn't recognise the user-agent from the ruby request. It also returned a 404 when I sent a curl request.

When passing a

```<code> User-Agent:
</code>```

with a browser/mobile device, the API responded as expected.

Body:
I am passing the following request to ruby rest-client gem;

RestClient::Request.execute(method: :get,
                            url: Config['site_url'] + path,
                            verify_ssl: OpenSSL::SSL::VERIFY_NONE,
                            headers: { organisation: 'WEB',
                                       accept: 'application/vnd.xyz.v2+json' })

Gem Versions
ruby version 2.3.3
rest-client 2.0.2

I have passed the same request to Postman and I get the response I expected.

I also have a v1 of the API that accepts just ":json" and this also responds as expected so my feeling is that it is something around the

accept: 'application/vnd.xyz.v2+json'

That is causing the problem but I'm not sure what exactly. As my feeling is if there was something wrong with the response then postman would also complain.

The documentation here https://github.com/rest-client/rest-client
default request headers: rest-client sets

accept:*/*

Just in case I passed / (although I am assuming * means enter what you need) but this returned the v1 response.

The method, url and verify_ssl are working in multiple other requests. So I don't think there is any issue there either.

Anyone, have any suggestions? Thx

Body:
The problem wasn't the request, it was the API didn't recognise the user-agent from the ruby request. It also returned a 404 when I sent a curl request.

When passing a

 User-Agent:

with a browser/mobile device, the API responded as expected.


问:
Azure WebJobs Log Files/Key
I found the following post and followed the Accepted Answer, but I could not find the Connection String: Error in Azure WebJobs

I have a feeling the answer might be for the older Azure Portal, or for Cloud Apps, not the newer Web Apps.

I am doing an Azure Web App with WebJobs and I need to know how to enable logging.  I get the error:

```<code>The configuration is not properly set for the Microsoft Azure WebJobs
Dashboard.

In your Microsoft Azure Website configuration you must set a connection
string named AzureWebJobsDashboard by using the following format
DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY pointing to
the Microsoft Azure Storage account where the Microsoft Azure WebJobs
Runtime logs are stored.
</code>```

I can't figure out how to get the AccountName/AccountKey.

Thank you very much,

Philip

答:
Did you already have or created a storage account that you can use? If not, you will need to do that first! It is a required manual step (or use an existing storage account of course). Then you can get the connection string. See the docs:

Create a connection string for an Azure storage account

To create a connection string for your Azure storage account, use the following format. Indicate whether you want to connect to the storage account through HTTPS (recommended) or HTTP, replace myAccountName with the name of your storage account, and replace myAccountKey with your account access key:

DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey

For example, your connection string might look similar to:

DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=

Tip

You can find your storage account's connection strings in the Azure portal. Navigate to SETTINGS > Access keys in your storage account's menu blade to see connection strings for both primary and secondary access keys.

Now, easiest way is to open the app.config file of your webjob project and add the connection string like this:

```<code><?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
    <!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
    <!-- For local execution, the value can be set either in this config file or through environment variables -->
    <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
    <add name="AzureWebJobsStorage" connectionString="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
  </connectionStrings>
  ...
</configuration>
</code>```

Then deploy your web job.

Title: Azure WebJobs Log Files/Key

Body:
I found the following post and followed the Accepted Answer, but I could not find the Connection String: Error in Azure WebJobs

I have a feeling the answer might be for the older Azure Portal, or for Cloud Apps, not the newer Web Apps.

I am doing an Azure Web App with WebJobs and I need to know how to enable logging.  I get the error:

The configuration is not properly set for the Microsoft Azure WebJobs
Dashboard.

In your Microsoft Azure Website configuration you must set a connection
string named AzureWebJobsDashboard by using the following format
DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY pointing to
the Microsoft Azure Storage account where the Microsoft Azure WebJobs
Runtime logs are stored.

I can't figure out how to get the AccountName/AccountKey.

Thank you very much,

Philip

Body:
Did you already have or created a storage account that you can use? If not, you will need to do that first! It is a required manual step (or use an existing storage account of course). Then you can get the connection string. See the docs:

Create a connection string for an Azure storage account

To create a connection string for your Azure storage account, use the following format. Indicate whether you want to connect to the storage account through HTTPS (recommended) or HTTP, replace myAccountName with the name of your storage account, and replace myAccountKey with your account access key:

DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey

For example, your connection string might look similar to:

DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=

Tip

You can find your storage account's connection strings in the Azure portal. Navigate to SETTINGS > Access keys in your storage account's menu blade to see connection strings for both primary and secondary access keys.

Now, easiest way is to open the app.config file of your webjob project and add the connection string like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
    <!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
    <!-- For local execution, the value can be set either in this config file or through environment variables -->
    <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
    <add name="AzureWebJobsStorage" connectionString="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
  </connectionStrings>
  ...
</configuration>

Then deploy your web job.


问:
Can a piece of code, if reusable and applicable to different contexts be classified a pattern?
What constitutes a pattern ? If i have a template/code that is reusable and can be applied to other similar situations, can it be called a pattern ?

The following is what i have created. It is a binary approach to handling conditional constructs. I have a field in a table that is composite i.e. it comprises of 3 or more other sub-fields each of which have a true or false value.

Now, i have the sub-fields representing true/false values as 0 and 1. These fields are presented as drop downs to the user in the web based application. These fields are combined to form a byte value comprising 8 bits with the first 3 bits have values of 0 or 1 which the user chooses as false or true. If the user chooses all fields as true the main field would have a value 7 and if he chooses all fields as false, the main field would have a value 0 and like wise.

The main field represents one of the columns in an existing table. The advantage of this code is that, as new sub-fields are required, there is no need to add new columns in the table. The user interface would have an additional drop down for each new sub-field.

This code is reusable and can be applied to different contexts. Could this be classified as a pattern ?

答: Well, design patterns are typically more abstract than this. There is, no doubt, an underlying pattern here. However, the details of how you are storing become more implementation detail rather than part of a pattern. Now, you could probably think deeply and discern the underlying patten that you're using. It's a bit late for me to think that deeply about it right now, though. :) But, you are taking a sort of meta data approach and that has some relationship to things like Entity Attribue Value (though, this isn't a case of EAV).</p>

OwnerDisplayName: Subramanian

LastEditorDisplayName: Binary Worrier

OwnerDisplayName: BobbyShaftoe


问:
Using C#, how can I read the content of dynamic created textboxes?
Hy,

I have created some dynamic textboxes with standard content.

Does anyone know how can I read the content of these textboxes (assuming that user modified the standard content) when I press one button?

Thanks a lot.

Jeff

Update

This is how I am creating the textboxes:

```<code>foreach (string name in listOfNames)
{
   TextBox tb = new TextBox();
   tb.Text = name;
   tb.BorderStyle = BorderStyle.None;
   tb.BorderWidth = 0;
   tb.Font.Name = "Arial";
   tb.Font.Size = 8;
}
</code>```

答:
You should be able to access them as you would a normal control, you just need to get a reference to the control.
Remember to re-create all controls on each postback.

this is a useful article on dynamic controls in asp.net

Body:
Hy,

I have created some dynamic textboxes with standard content.

Does anyone know how can I read the content of these textboxes (assuming that user modified the standard content) when I press one button?

Thanks a lot.

Jeff

Update

This is how I am creating the textboxes:

foreach (string name in listOfNames)
{
   TextBox tb = new TextBox();
   tb.Text = name;
   tb.BorderStyle = BorderStyle.None;
   tb.BorderWidth = 0;
   tb.Font.Name = "Arial";
   tb.Font.Size = 8;
}


问:
Jquery ,css animation on page load start one animation after another
there are one main div contains image banner and textbanner as per in the code. right now both image and textbanner are show one by one. after last image and textbanner i want t stop animation but it is again start showing from first image and textbanner. i want to stop animation  after showing to third textbanner and image.after image and textbanner animation done , i want to cover the div  on  right now onload it starts overlapping here is my code:
not perfect. you can refer here https://codepen.io/anon/pen/RgeYQL
HTML

```<code><!DOCTYPE html>
<html>
<head>
    <title>Bolierplate banner</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="bolierplate banner">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/main.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

<body >
    <div class="imagecontainer" id="pot">
        <img src="img/product1.png" class="img1" >
        <img src="img/product2.png" class="img2">
        <img src="img/product3.png" class="img3">

    </div>
    <div id="mainContent">
    <h2 >SONY</h2>
        <div >
         <img src="img/img1.jpg" class="imagebanner">
         <img src="img/img2.jpg" class="imagebanner">
         <img src="img/img3.jpg" class="imagebanner">
        <div>

        <div class="textbanner">
        <!--  <p class="thenew"></p> -->
            <h2 class="quotes">THE NEW <p class="greet">ERGONIMICS</p> </h2>
            <h2 class="quotes">THE NEW <p class="greet">WORKFLOW</p></h2>
            <h2 class="quotes">THE NEW <p class="greet">VERSATALITY</p></h2>
        <!--    <h2 class="lastquotes">DISCOVER <p class="greet">THE NEW WORLD OF DOCUMENTARIES</p></h2> -->
        <div>
    </div>

     <script src="js/animation.js" type="text/javascript" charset="utf-8" async defer></script>
</body>

</html>
</code>```

CSS

```<code>@font-face {
  font-family: 'MyWebFont';

  src:  url('fonts/SSTPro-Light.ttf') format('ttf'), /* Pretty Modern Browsers */
       url('fonts/SSTPro-Light.woff')  format('woff');  }

html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent; }

body {
  line-height: 1; }

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
  display: block; }

nav ul {
  list-style: none; }

blockquote, q {
  quotes: none; }

blockquote:before, blockquote:after, q:before, q:after {
  content: none; }

a {
  margin: 0;
  padding: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent; }

@font-face {}
html {
  box-sizing: border-box; }

*,
*:before,
*:after {
  box-sizing: inherit; }

body {
  font: normal 24px/1.5 Univers;
  color: #fff;
  -webkit-font-smoothing: antialiased;
  -moz-font-smoothing: antialiased; }

#mainContent {
  position: relative;
  overflow: hidden;
  width: 300px;
  height: 660px;
  border: 1px solid black;
  left: 40%;
  background-color: #DAA520; }
/*  #mainContent div {
position: absolute;*/
    }

h2{margin-left: 10px;

}

.quotes{ font-family: 'MyWebFont';  font-size: 60px;    margin: 2px; display: none;}
.imagebanner{display: none;}

.greet{ font-family: 'MyWebFont';   font-size: 45px;    margin: 2px; line-height: 5px;}

.imagecontainer {
    position: absolute;
    display: grid;
    top: 10px;
    right: 250px;
}

.img2{margin-top:15px;margin-bottom: 100px;}

#pot{
position:absolute;
animation:linear;
animation-name: run;
animation-duration: 5s;
z-index: 1;
animation-fill-mode: forwards;
}

@-webkit-keyframes run {
    0% { right: 0;}
   /* 50%{ right : 50%;}*/
    100%{ right: 41%;}
}
</code>```

JS

```<code>(function() {

    var img = $(".imagebanner");
    var imgIndex = -1;

    function showNextImage() {
        imgIndex++;
        img.eq(imgIndex % img.length)
            .fadeIn(400)
            .delay(2000)
            .fadeOut(400, showNextImage);

          //   if(img)
          // $(this).stop();
    }

    showNextImage();

})();

(function() {

    var quotes = $(".quotes");
    var quoteIndex = -1;

    function showNextQuote() {
        quoteIndex++;
        quotes.eq(quoteIndex % quotes.length)
            .fadeIn(400)
            .delay(2000)
            .fadeOut(400, showNextQuote);
    }

    showNextQuote();

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

答:
I wasn't exactly sure of what you are asking, but it seems like this may be close to it. Hope this helps!

var images = $(".imagebanner"),
  quotes = $(".quotes");

// Look up 'jquery queue' for more info
function oneByOne(elements) {
  elements.each(function() {

    var self = $(this);
    self.parent().queue(function (n) {

     //Do the animations
    self.fadeIn(400) // does nothing b/c opacity is already 1
      .delay(2000)
      .fadeOut(400, n);
    });

  });
}

// This will make the 1st img and 1st quote dissappear at the same time (likewise for 2nd img  and 2nd quote, etc.)
oneByOne(images);
oneByOne(quotes);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>

<div id="mainContent">
  <h1>Images</h1>
  <div>
    <img src="https://placehold.it/200x200" class="imagebanner">
    <img src="https://placehold.it/200x200" class="imagebanner">
    <img src="https://placehold.it/200x200" class="imagebanner">
  <div>

  <div class="textbanner">
    <h1>Quotes</h1>
    <h2 class="quotes">
      Quote 1
    </h2>
    <h2 class="quotes">
      Quote 2
    </h2>
    <h2 class="quotes">
      Quote 3
    </h2>
   </div></code>```

Body:
there are one main div contains image banner and textbanner as per in the code. right now both image and textbanner are show one by one. after last image and textbanner i want t stop animation but it is again start showing from first image and textbanner. i want to stop animation  after showing to third textbanner and image.after image and textbanner animation done , i want to cover the div  on  right now onload it starts overlapping here is my code:
not perfect. you can refer here https://codepen.io/anon/pen/RgeYQL
HTML

<!DOCTYPE html>

    <title>Bolierplate banner</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="bolierplate banner">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/main.css">

SONY

THE NEW
ERGONIMICS

THE NEW
WORKFLOW

THE NEW
VERSATALITY

CSS

@font-face {
  font-family: 'MyWebFont';

  src:  url('fonts/SSTPro-Light.ttf') format('ttf'), /* Pretty Modern Browsers */
       url('fonts/SSTPro-Light.woff')  format('woff');  }

html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent; }

body {
  line-height: 1; }

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
  display: block; }

nav ul {
  list-style: none; }

blockquote, q {
  quotes: none; }

blockquote:before, blockquote:after, q:before, q:after {
  content: none; }

a {
  margin: 0;
  padding: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent; }

@font-face {}
html {
  box-sizing: border-box; }

*,
*:before,
*:after {
  box-sizing: inherit; }

body {
  font: normal 24px/1.5 Univers;
  color: #fff;
  -webkit-font-smoothing: antialiased;
  -moz-font-smoothing: antialiased; }

#mainContent {
  position: relative;
  overflow: hidden;
  width: 300px;
  height: 660px;
  border: 1px solid black;
  left: 40%;
  background-color: #DAA520; }
/*  #mainContent div {
position: absolute;*/
    }

h2{margin-left: 10px;

}

.quotes{ font-family: 'MyWebFont';  font-size: 60px;    margin: 2px; display: none;}
.imagebanner{display: none;}

.greet{ font-family: 'MyWebFont';   font-size: 45px;    margin: 2px; line-height: 5px;}

.imagecontainer {
    position: absolute;
    display: grid;
    top: 10px;
    right: 250px;
}

.img2{margin-top:15px;margin-bottom: 100px;}

#pot{
position:absolute;
animation:linear;
animation-name: run;
animation-duration: 5s;
z-index: 1;
animation-fill-mode: forwards;
}

@-webkit-keyframes run {
    0% { right: 0;}
   /* 50%{ right : 50%;}*/
    100%{ right: 41%;}
}

JS

(function() {

    var img = $(".imagebanner");
    var imgIndex = -1;

    function showNextImage() {
        imgIndex++;
        img.eq(imgIndex % img.length)
            .fadeIn(400)
            .delay(2000)
            .fadeOut(400, showNextImage);

          //   if(img)
          // $(this).stop();
    }

    showNextImage();

})();

(function() {

    var quotes = $(".quotes");
    var quoteIndex = -1;

    function showNextQuote() {
        quoteIndex++;
        quotes.eq(quoteIndex % quotes.length)
            .fadeIn(400)
            .delay(2000)
            .fadeOut(400, showNextQuote);
    }

    showNextQuote();

})();

Body:
I wasn't exactly sure of what you are asking, but it seems like this may be close to it. Hope this helps!

var images = $(".imagebanner"),
  quotes = $(".quotes");

// Look up 'jquery queue' for more info
function oneByOne(elements) {
  elements.each(function() {

    var self = $(this);
    self.parent().queue(function (n) {

     //Do the animations
    self.fadeIn(400) // does nothing b/c opacity is already 1
      .delay(2000)
      .fadeOut(400, n);
    });

  });
}

// This will make the 1st img and 1st quote dissappear at the same time (likewise for 2nd img  and 2nd quote, etc.)
oneByOne(images);
oneByOne(quotes);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>

<div id="mainContent">
  <h1>Images</h1>
  <div>
    <img src="https://placehold.it/200x200" class="imagebanner">
    <img src="https://placehold.it/200x200" class="imagebanner">
    <img src="https://placehold.it/200x200" class="imagebanner">
  <div>

  <div class="textbanner">
    <h1>Quotes</h1>
    <h2 class="quotes">
      Quote 1
    </h2>
    <h2 class="quotes">
      Quote 2
    </h2>
    <h2 class="quotes">
      Quote 3
    </h2>
   </div>


问:
Android Volley app with local nodejs server
I'm testing the volley app to fetch a JSON data. My test succeeded from fetching it from an online site.But when I connect it to my localhost node js server it didn't fetch it and no exceptions fired in the console,there is just no response at all.Even I tested to send get request by the browser and it worked and returned the JSON data and yes I've putted the actual address of my machine not "localhost".
Thats my Nodejs server code:

```<code>var express=require('express');

var mongoose=require('mongoose');

//making the connections
mongoose.connect('mongodb://127.0.0.1:27017/db',function (error) {
if(error){console.log("error");}
else{

    console.log("connected!!");

 }

});

 //using the exported function to create the server
 var app=express();
// Port to be listened tos
var port=process.env.PORT || 3000;

app.get('/api',function(req,res){

res.json({firstname:'George',lastname:'Cloney'});
});

app.listen(port);
</code>```

AppController.java:

```<code>public class AppController  extends Application{

public static final String TAG = AppController.class
        .getSimpleName();

private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;

private static AppController mInstance;

@Override
public void onCreate() {

    super.onCreate();

    mInstance = this;
}

public static synchronized AppController getInstance() {
    return mInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}

public ImageLoader getImageLoader() {
    getRequestQueue();
    if (mImageLoader == null) {
        mImageLoader = new ImageLoader(this.mRequestQueue,
                new LruBitmapCache());
    }
    return this.mImageLoader;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(tag);
    }
}
}
</code>```

MainActivity.java:

```<code> public class MainActivity extends AppCompatActivity {

TextView text;
private String url = "http://192.168.43.214:3000/api";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    text=(TextView)findViewById(R.id.text);

    JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            //trying to test the response length but no results also
            text.setText(" "+response.length());
            for (int i = 0; i < response.length(); i++) {

                try {
                    JSONObject jsonObject = response.getJSONObject(i);

                    String fullname=jsonObject.getString("firstname");

                    text.setText(jsonObject.toString());

                                Toast.makeText(getApplicationContext(),fullname,Toast.LENGTH_LONG).show();

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            //Log.v("Data from the web: " , response.toString());

        }
    }, new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error) {

            VolleyLog.d("Mainactivity", error.getMessage());

        }
    });

    AppController.getInstance().addToRequestQueue(request);

}

   }
</code>```

答:
After a long analysis I found that the object called responding json array so the solution is to return a json array in node js code simply by responding with a json array rather than a json object:

```<code>res.json([{,}];
</code>```

instead of this

```<code>res.json({,});
</code>```

plus putting the object responding json array and its functionality inside a method and invoke it onCreate:

```<code>       void getJsonArray(url){
       //like before
       }
</code>```

Body:
I'm testing the volley app to fetch a JSON data. My test succeeded from fetching it from an online site.But when I connect it to my localhost node js server it didn't fetch it and no exceptions fired in the console,there is just no response at all.Even I tested to send get request by the browser and it worked and returned the JSON data and yes I've putted the actual address of my machine not "localhost".
Thats my Nodejs server code:

var express=require('express');

var mongoose=require('mongoose');

//making the connections
mongoose.connect('mongodb://127.0.0.1:27017/db',function (error) {
if(error){console.log("error");}
else{

    console.log("connected!!");

 }

});

 //using the exported function to create the server
 var app=express();
// Port to be listened tos
var port=process.env.PORT || 3000;

app.get('/api',function(req,res){

res.json({firstname:'George',lastname:'Cloney'});
});

app.listen(port);

AppController.java:

public class AppController  extends Application{

public static final String TAG = AppController.class
        .getSimpleName();

private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;

private static AppController mInstance;

@Override
public void onCreate() {

    super.onCreate();

    mInstance = this;
}

public static synchronized AppController getInstance() {
    return mInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}

public ImageLoader getImageLoader() {
    getRequestQueue();
    if (mImageLoader == null) {
        mImageLoader = new ImageLoader(this.mRequestQueue,
                new LruBitmapCache());
    }
    return this.mImageLoader;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(tag);
    }
}
}

MainActivity.java:

 public class MainActivity extends AppCompatActivity {

TextView text;
private String url = "http://192.168.43.214:3000/api";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    text=(TextView)findViewById(R.id.text);

    JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            //trying to test the response length but no results also
            text.setText(" "+response.length());
            for (int i = 0; i < response.length(); i++) {

                try {
                    JSONObject jsonObject = response.getJSONObject(i);

                    String fullname=jsonObject.getString("firstname");

                    text.setText(jsonObject.toString());

                                Toast.makeText(getApplicationContext(),fullname,Toast.LENGTH_LONG).show();

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            //Log.v("Data from the web: " , response.toString());

        }
    }, new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error) {

            VolleyLog.d("Mainactivity", error.getMessage());

        }
    });

    AppController.getInstance().addToRequestQueue(request);

}

   }

Body:
After a long analysis I found that the object called responding json array so the solution is to return a json array in node js code simply by responding with a json array rather than a json object:

res.json([{,}];

instead of this

res.json({,});

plus putting the object responding json array and its functionality inside a method and invoke it onCreate:

       void getJsonArray(url){
       //like before
       }


问:
Ruby paragraph mode vs Awk and Perl
Suppose you have a file with five blocks of data separated by two or more \n to separate the records (a common text format).

If you run awk with RS="" you set awk to separate the blocks into records. You can then set FS=\n to separate the lines of the blocks into fields.

Example:

```<code>$ cat lines
f1, r1
f2, r1 then 2 \n:

f1, r2 then 3 \n:

f1,r3
f2,r3 then 4 \n:

f1, r4
f2,r4 then 6 \n:

f1,r5
</code>```

The idiomatic way to separate the blocks into records and the lines into fields with awk is:

```<code>$ awk 'BEGIN{RS=""; FS="\n"; OFS="|"}
       {$1=$1; printf "NR: %d, NF: %d, record: \"%s\"\n", NR, NF, $0 }' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"
</code>```

No matter how many \n separate the blocks, as long as 2 or more, it's a record.

(With gawk exactly the same result can be obtained by setting RS="\n\n+" instead of RS="" since gawk supports a regex to separate records. Thanks Ed Morton for pointing out the difference between POSIX awk and gawk on that)

While perl does not support using a regex for the input record separator, there are two methods to set an equivalent paragraph mode. You can either use the -00 command line switch or set the input record separator, $/, to a null string:

```<code>$ perl  -00 -F"\n" -lane 'BEGIN{ $\=""; $,="|"}
                    printf "NR: %d, NF: %d, record: \"%s\"\n", $., scalar(@F), join($,,@F)' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"
</code>```

Or,

```<code>$ perl -F"\n" -lane 'BEGIN{ $\=""; $,="|"; $/=""}
                     printf "NR: %d, NF: %d, record: \"%s\"\n", $., scalar(@F), join($,,@F)' lines
</code>```

works too -- same output.

Ruby does has a paragraph mode, but unlike Perl and awk, it has a behavior difference that can matter. If there are more than 2 \n, then the runs of \n are not ignored. It is equivalent to the regex /\n\n/ in Ruby vs /\n\n+/ in awk and Perl. It screws up both the field count and record count on the same input.

Demo:

```<code>$ ruby -00 -F"\n" -lane 'BEGIN{$\=""; $,="|"};
                        printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 3, record: "|f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 0, record: ""
NR: 5, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 6, NF: 0, record: ""
NR: 7, NF: 0, record: ""
NR: 8, NF: 1, record: "f1,r5"
</code>```

So Ruby's -00 paragraph mode thinks the same content has 8 records with 9 total fields when Perl and Awk thinks it has 5 records and 8 total fields.

Is there a way to get the same result with Ruby as with Perl and Awk?

答:
Like Perl, Ruby only supports a single octal character for $/ to separate records. (Ruby and Perl share similar global variables.)

So these are three workarounds:

Set $/="". In Ruby the behavior of $/="" is the same as Perl where runs of \n are taken as a single record separator (contrast with ruby -00). (Thanks to Stefan for that)

'Slurp' the file and then use a regex to separate the text into records and fields. (This what you need to do for any break between records that is not a single octal character or \n\n+ in either perl, POSIX awk, or ruby.)

Feed the file through awk to remove the excess \n and redefine the break as \n\n.

Example of #1

```<code>$ ruby -F"\n" -lane 'BEGIN{$\=""; $/=""; $,="|"};
                       printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"
</code>```

Example of #2

```<code>$ ruby -e 'i=0
      $<.read.split(/\n\n+/)
        .map {|record| record.split(/\n/)}
        .map {|f| i+=1; printf "NR: %d, NF: %d, record: \"%s\"\n", i,f.length,f.join
                  }' lines
</code>```

Example of #3

```<code>$ ruby -00 -F"\n" -lane 'BEGIN{$/=""; $\=""; $,="|"; $i=1};
                     printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' <(awk 'BEGIN{RS=""} {print $0 ORS}' lines)
</code>```

All produce the same output as the first.

The behavior of ruby -00 is not the same as the perl equivalent; it is equivalent of breaking on the regex /\n\n/  Only use -00 if you know that the blocks of data are separated by two \n only.

(At least until the filed bug on -00 is fixed...)

(Note: ruby -0 is different than ruby -0[some octal value] The former sets the input record separator to the literal value of 0x00 for use with other Unix utilities that can feed a Nul terminated string, such as find . print0 | ruby -0 -lane 'puts $_')

Title: Ruby paragraph mode vs Awk and Perl

Body:
Suppose you have a file with five blocks of data separated by two or more \n to separate the records (a common text format).

If you run awk with RS="" you set awk to separate the blocks into records. You can then set FS=\n to separate the lines of the blocks into fields.

Example:

$ cat lines
f1, r1
f2, r1 then 2 \n:

f1, r2 then 3 \n:

f1,r3
f2,r3 then 4 \n:

f1, r4
f2,r4 then 6 \n:

f1,r5

The idiomatic way to separate the blocks into records and the lines into fields with awk is:

$ awk 'BEGIN{RS=""; FS="\n"; OFS="|"}
       {$1=$1; printf "NR: %d, NF: %d, record: \"%s\"\n", NR, NF, $0 }' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"

No matter how many \n separate the blocks, as long as 2 or more, it's a record.

(With gawk exactly the same result can be obtained by setting RS="\n\n+" instead of RS="" since gawk supports a regex to separate records. Thanks Ed Morton for pointing out the difference between POSIX awk and gawk on that)

While perl does not support using a regex for the input record separator, there are two methods to set an equivalent paragraph mode. You can either use the -00 command line switch or set the input record separator, $/, to a null string:

$ perl  -00 -F"\n" -lane 'BEGIN{ $\=""; $,="|"}
                    printf "NR: %d, NF: %d, record: \"%s\"\n", $., scalar(@F), join($,,@F)' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"

Or,

$ perl -F"\n" -lane 'BEGIN{ $\=""; $,="|"; $/=""}
                     printf "NR: %d, NF: %d, record: \"%s\"\n", $., scalar(@F), join($,,@F)' lines

works too -- same output.

Ruby does has a paragraph mode, but unlike Perl and awk, it has a behavior difference that can matter. If there are more than 2 \n, then the runs of \n are not ignored. It is equivalent to the regex /\n\n/ in Ruby vs /\n\n+/ in awk and Perl. It screws up both the field count and record count on the same input.

Demo:

$ ruby -00 -F"\n" -lane 'BEGIN{$\=""; $,="|"};
                        printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 3, record: "|f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 0, record: ""
NR: 5, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 6, NF: 0, record: ""
NR: 7, NF: 0, record: ""
NR: 8, NF: 1, record: "f1,r5"

So Ruby's -00 paragraph mode thinks the same content has 8 records with 9 total fields when Perl and Awk thinks it has 5 records and 8 total fields.

Is there a way to get the same result with Ruby as with Perl and Awk?

Body:
Like Perl, Ruby only supports a single octal character for $/ to separate records. (Ruby and Perl share similar global variables.)

So these are three workarounds:

Set $/="". In Ruby the behavior of $/="" is the same as Perl where runs of \n are taken as a single record separator (contrast with ruby -00). (Thanks to Stefan for that)

'Slurp' the file and then use a regex to separate the text into records and fields. (This what you need to do for any break between records that is not a single octal character or \n\n+ in either perl, POSIX awk, or ruby.)

Feed the file through awk to remove the excess \n and redefine the break as \n\n.

Example of #1

$ ruby -F"\n" -lane 'BEGIN{$\=""; $/=""; $,="|"};
                       printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' lines
NR: 1, NF: 2, record: "f1, r1|f2, r1 then 2 \n:"
NR: 2, NF: 1, record: "f1, r2 then 3 \n:"
NR: 3, NF: 2, record: "f1,r3|f2,r3 then 4 \n:"
NR: 4, NF: 2, record: "f1, r4|f2,r4 then 6 \n: "
NR: 5, NF: 1, record: "f1,r5"

Example of #2

$ ruby -e 'i=0
      $<.read.split(/\n\n+/)
        .map {|record| record.split(/\n/)}
        .map {|f| i+=1; printf "NR: %d, NF: %d, record: \"%s\"\n", i,f.length,f.join
                  }' lines

Example of #3

$ ruby -00 -F"\n" -lane 'BEGIN{$/=""; $\=""; $,="|"; $i=1};
                     printf "NR: %d, NF: %d, record: \"%s\"\n", $.,$F.length,$F.join' <(awk 'BEGIN{RS=""} {print $0 ORS}' lines)

All produce the same output as the first.

The behavior of ruby -00 is not the same as the perl equivalent; it is equivalent of breaking on the regex /\n\n/  Only use -00 if you know that the blocks of data are separated by two \n only.

(At least until the filed bug on -00 is fixed...)

(Note: ruby -0 is different than ruby -0[some octal value] The former sets the input record separator to the literal value of 0x00 for use with other Unix utilities that can feed a Nul terminated string, such as find . print0 | ruby -0 -lane 'puts $_')


问:
debugger for C/C++ and Java
I mainly use vim, but I really like the debuggers used in modern IDEs such as Netbeans, Visual C++, and Eclipse and I am wondering if there were any debuggers like those except in a standalone program? I tried using gdb, but it seems that debugging will take a lot longer using a command line. I also tried ddd, but it was a little frustrating to use since it would not display some complex structures with arrays. I really like how the debuggers in the modern IDEs allow me to just click on the down arrow to view what are in my arrays something which I do not know how to do in gdb or ddd.</p>

答: Use Eclipse.  You can easily create an Eclipse project around existing code, and still use VIM to edit your files while using Eclipse to debug.</p>

Title: debugger for C/C++ and Java


问:
Centered shear/skew in postscript
I'm trying to apply skewing to an image in postscript. I have successfully done it with:

```<code>[1 -0.5 -0.5 1 0 0] concat
</code>```

Where both -0.5 refers to a skew of 22.5 degrees on the vertical and horizontal axis. The problem is that the skewing is not centered, the center of the image is moved so my image doesn't stay on the same position after applying the skew.

How can I apply skewing while maintaining the position? I tried translating the image before/after skewing but I can't find how much I should translate the image so it always stays in the same position.

答:
Ok, I finally find the way to do it. First of all, position the element as usual with translate:

```<code>1135 568 translate
</code>```

Then, skew the only on one axis X or Y, not both at the same time. The number in the matrix is tan(skew_angle) so for example, for a 20 degree angle on the X axis:

```<code>[1 0 0.3639 1 0 0] concat
</code>```

After this, translate the image because now the width of the bounding box of the image is bigger, we can calculate this additional width as additional_width = abs(object_height * tan(skew_angle)). So now we translate half this width:

```<code>{additional_width/2} 0 translate
</code>```

Now we do the skew on Y on the same way:

```<code>[1 0.3639 0 1 0 0] concat
</code>```

And calculate the additional height as additional_height = abs(object_width * tan(skew_angle))

```<code>0 {additional_height/2} translate
</code>```

On this way, after applying the skew the object center stays in the same position.

Title: Centered shear/skew in postscript

Body:
I'm trying to apply skewing to an image in postscript. I have successfully done it with:

[1 -0.5 -0.5 1 0 0] concat

Where both -0.5 refers to a skew of 22.5 degrees on the vertical and horizontal axis. The problem is that the skewing is not centered, the center of the image is moved so my image doesn't stay on the same position after applying the skew.

How can I apply skewing while maintaining the position? I tried translating the image before/after skewing but I can't find how much I should translate the image so it always stays in the same position.

Body:
Ok, I finally find the way to do it. First of all, position the element as usual with translate:

1135 568 translate

Then, skew the only on one axis X or Y, not both at the same time. The number in the matrix is tan(skew_angle) so for example, for a 20 degree angle on the X axis:

[1 0 0.3639 1 0 0] concat

After this, translate the image because now the width of the bounding box of the image is bigger, we can calculate this additional width as additional_width = abs(object_height * tan(skew_angle)). So now we translate half this width:

{additional_width/2} 0 translate

Now we do the skew on Y on the same way:

[1 0.3639 0 1 0 0] concat

And calculate the additional height as additional_height = abs(object_width * tan(skew_angle))

0 {additional_height/2} translate

On this way, after applying the skew the object center stays in the same position.


问:
Gradle show content of compile configuration of a sub project
Try to show a configuration content of sub project foo:

```<code>task foo {

    project(':foo').configurations.compile.files.each {
        println it.name
    }

    project(':foo').configurations.compileClasspath.files.each {
        println it.name
    }

}
</code>```

Error

```<code>* What went wrong:
A problem occurred evaluating project ':foo'.
> Cannot change dependencies of configuration ':foo:compile' after it has been resolved.
</code>```

I am confused with configurations.compile and configurations.compileClasspath. Are they the same? both are FileCollection?

For current project (not :foo), they contain the same set of files.

答:
Your problem is based on the same technical detail as most of the Gradle problems at StackOverflow: the difference between the configuration phase and the execution phase.

If you define a task (like foo in your example), the code in the following closure does NOT define what the task will do on execution. Instead, it is executed right after the task definition and should be used to configure the task. This is why the code will be executed every time you run Gradle on the project (in the configuration phase). On the other hand, the task in your example will do absolutely nothing when its executed (in the execution phase). Only task actions (defined by the task type), doFirst and doLast closures are executed during execution phase. Also note, that (task) configuration will be done for every task, but only selected tasks (via command line or dependencies) will be executed.

Knowing the above, we can understand the problem in your code: It tries to print the contents of a configuration of a subproject during the configuration phase of the root project. The configuration phase of the subproject, where you add dependencies, comes after the configuration phase of the root project, where you resolve the configuration (which is necessary to show the contents). But you can't add dependencies to configurations that are already resolved.

This means, that your code gets executed, resolves the configuration and prints nothing, because at the moment of execution the configuration is empty. After that, in your subprojects dependencies closure, you are trying to add a dependency to the configuration that is already resolved, which causes the error. Comment out all (compile) dependencies in your subproject foo and the error should disappear.

However, this is not what you want. You want to list the files of the configuration after they have been added. To achieve this, you can easily move your task code to a doLast (or doFirst) closure:

```<code>task foo {
    doLast {
        project(':foo').configurations.compile.files.each {
            println it.name
        }
    }
}
</code>```

Now, your configuration is resolved in the execution phase of your root project, which comes after the configuration phase of the subproject, so there won't be any problems adding dependencies. Please note, that the task will only be executed if you specify it (e.g. calling gradle foo / gradle build foo or using dependsOn foo on another task which will be executed).

Regarding the difference between the compile and the compileClasspath configuration, you can take a look at the docs of the Gradle Java Plugin, which defines both configurations: Configurations can extend other configurations, which means that they will contain all dependencies the other configuration contains, but can also contain additional dependencies. If you only use compile dependencies, compile and compileClasspath will be the same, but e.g. a compileOnly dependency will only be listed under compileClasspath.

Body:
Try to show a configuration content of sub project foo:

task foo {

    project(':foo').configurations.compile.files.each {
        println it.name
    }

    project(':foo').configurations.compileClasspath.files.each {
        println it.name
    }

}

Error

* What went wrong:
A problem occurred evaluating project ':foo'.
> Cannot change dependencies of configuration ':foo:compile' after it has been resolved.

I am confused with configurations.compile and configurations.compileClasspath. Are they the same? both are FileCollection?

For current project (not :foo), they contain the same set of files.

Body:
Your problem is based on the same technical detail as most of the Gradle problems at StackOverflow: the difference between the configuration phase and the execution phase.

If you define a task (like foo in your example), the code in the following closure does NOT define what the task will do on execution. Instead, it is executed right after the task definition and should be used to configure the task. This is why the code will be executed every time you run Gradle on the project (in the configuration phase). On the other hand, the task in your example will do absolutely nothing when its executed (in the execution phase). Only task actions (defined by the task type), doFirst and doLast closures are executed during execution phase. Also note, that (task) configuration will be done for every task, but only selected tasks (via command line or dependencies) will be executed.

Knowing the above, we can understand the problem in your code: It tries to print the contents of a configuration of a subproject during the configuration phase of the root project. The configuration phase of the subproject, where you add dependencies, comes after the configuration phase of the root project, where you resolve the configuration (which is necessary to show the contents). But you can't add dependencies to configurations that are already resolved.

This means, that your code gets executed, resolves the configuration and prints nothing, because at the moment of execution the configuration is empty. After that, in your subprojects dependencies closure, you are trying to add a dependency to the configuration that is already resolved, which causes the error. Comment out all (compile) dependencies in your subproject foo and the error should disappear.

However, this is not what you want. You want to list the files of the configuration after they have been added. To achieve this, you can easily move your task code to a doLast (or doFirst) closure:

task foo {
    doLast {
        project(':foo').configurations.compile.files.each {
            println it.name
        }
    }
}

Now, your configuration is resolved in the execution phase of your root project, which comes after the configuration phase of the subproject, so there won't be any problems adding dependencies. Please note, that the task will only be executed if you specify it (e.g. calling gradle foo / gradle build foo or using dependsOn foo on another task which will be executed).

Regarding the difference between the compile and the compileClasspath configuration, you can take a look at the docs of the Gradle Java Plugin, which defines both configurations: Configurations can extend other configurations, which means that they will contain all dependencies the other configuration contains, but can also contain additional dependencies. If you only use compile dependencies, compile and compileClasspath will be the same, but e.g. a compileOnly dependency will only be listed under compileClasspath.


问:
Dropdown List is not Updating the Selected Value (SemanticUI)
I am using SemanticUI for a dropdown list

```<code><div class="ui dropdown">
  <input type="hidden" name="gender">
  <i class="dropdown icon"></i>
  <div class="default text">Gender</div>
  <div class="menu">
    <div class="item" data-value="male">Male</div>
    <div class="item" data-value="female">Female</div>
  </div>
</div>
</code>```

in the bottom of my page, I am initializing it as

```<code>jQuery(document).ready(function($) {
    $('.ui.dropdown')
  .dropdown()
;
});
</code>```

The problem is that when a user selects an item, it does not update and it keeps showing the default value as selected.
But when I go to Chrome Console and execute the above code JQuery(document)..., then it works fine.

I am assuming it is due to that the initialization needs to execute after page loads completely. So, What I did is the following instead of the above:

```<code>window.addEventListener("load", function(){
jQuery(document).ready(function($) {

    $('.ui.dropdown')
  .dropdown()
;
});
});;
</code>```

It worked. Dropdown list updates selection immediatly. However, when I click on Submit, I and page reloads, the selection is lost.
The drop down is being used as a filter to table. Having the selection gets lost on submit, makes filter unusable.

What is the best way to go around this.

答: Use AJAX to submit the form so the page doesn't refresh.</p>

Body:
I am using SemanticUI for a dropdown list

  <input type="hidden" name="gender">

Gender

Male

Female

in the bottom of my page, I am initializing it as

jQuery(document).ready(function($) {
    $('.ui.dropdown')
  .dropdown()
;
});

The problem is that when a user selects an item, it does not update and it keeps showing the default value as selected.
But when I go to Chrome Console and execute the above code JQuery(document)..., then it works fine.

I am assuming it is due to that the initialization needs to execute after page loads completely. So, What I did is the following instead of the above:

window.addEventListener("load", function(){
jQuery(document).ready(function($) {

    $('.ui.dropdown')
  .dropdown()
;
});
});;

It worked. Dropdown list updates selection immediatly. However, when I click on Submit, I and page reloads, the selection is lost.
The drop down is being used as a filter to table. Having the selection gets lost on submit, makes filter unusable.

What is the best way to go around this.


Title: Sequence of exponentially growing numbers in python

Body:
Given a number and a ratio, how do I create an exponentially growing list of numbers, whose sum equals the starting number?

>>> r = (1 + 5 ** 0.5) / 2
>>> l = makeSeq(42, r)
>>> l
[2.5725461188664465, 4.162467057952537, 6.735013176818984,
10.897480234771521, 17.63249341159051]
>>> sum(l)
42.0
>>> l[-1]/l[-2]
1.6180339887498953
>>> r
1.618033988749895

Body:
Based off of Alex Hall's answer, this is what I ended up using:

def geoProgress(n, r=(1 + 5 ** 0.5) / 2, size=5):
    """ Creates a Geometric Progression with the Geometric sum of <n>
    >>> l = geoProgress(42)
    >>> l
    [2.5725461188664465, 4.162467057952537, 6.735013176818984,
    10.897480234771521, 17.63249341159051]
    >>> sum(l)
    42.0
    >>> l[-1]/l[-2]
    1.6180339887498953
    """
    return [(n * (1 - r) / (1 - r ** size)) * r ** i for i in range(size)]


问:
CSS positioning and z-index on card
I'm trying to code this card design:

However, I need some help with the positioning and z-index. This is how far I've come:

.card {
  width: 450px;
  height: 400px;
  background: lightblue;
}

.card-hover-state {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(-180deg, #000000 0%, rgba(216,216,216,0.00) 100%);
  opacity: 0.6;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  max-width: 60%;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="card">
  <div class="card-hover-state"></div>
  <div class="information-container">
    <div class="card-hover-state-title">Brace yourself - A fancy Lorem Ipsum Title is comming</div>
    <div class="card-hover-state-button">READ MORE</div>
  </div>
</div></code>```

However, the text isn't showing. What am I missing?

答:
You can get it by using below approach.

I just added display:table to your .information-container and assigned width:100% to take full parent div width, after that I assigned .card-hover-state-title and .card-hover-state-button
 to position:relative so they don't use the parent div's opacity:0.6 and also added display:table-cell and width to get inline both.

I added CSS properties in the following classes:

.information-container {
  display: table;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  width: 50%;
  position: relative;
  display: table-cell;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
  position: relative;
  display: table-cell;
  text-align: right;
  vertical-align:middle;
}
```

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.card {
  width: 450px;
  height: 400px;
  background: lightblue;
  position: relative;
}

.card-hover-state {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(-180deg, #000000 0%, rgba(216, 216, 216, 0.00) 100%);
  opacity: 0.6;
}

.information-container {
  display: table;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  width: 50%;
  position: relative;
  display: table-cell;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
  position: relative;
  display: table-cell;
  text-align: right;
  vertical-align:middle;
}</code>```

Brace yourself - A fancy Lorem Ipsum Title is comming

READ MORE

```

Title: CSS positioning and z-index on card

Body:
I'm trying to code this card design:

However, I need some help with the positioning and z-index. This is how far I've come:

.card {
  width: 450px;
  height: 400px;
  background: lightblue;
}

.card-hover-state {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(-180deg, #000000 0%, rgba(216,216,216,0.00) 100%);
  opacity: 0.6;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  max-width: 60%;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
}

Brace yourself - A fancy Lorem Ipsum Title is comming

READ MORE

However, the text isn't showing. What am I missing?

Body:
You can get it by using below approach.

I just added display:table to your .information-container and assigned width:100% to take full parent div width, after that I assigned .card-hover-state-title and .card-hover-state-button
 to position:relative so they don't use the parent div's opacity:0.6 and also added display:table-cell and width to get inline both.

I added CSS properties in the following classes:

.information-container {
  display: table;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  width: 50%;
  position: relative;
  display: table-cell;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
  position: relative;
  display: table-cell;
  text-align: right;
  vertical-align:middle;
}

.card {
  width: 450px;
  height: 400px;
  background: lightblue;
  position: relative;
}

.card-hover-state {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(-180deg, #000000 0%, rgba(216, 216, 216, 0.00) 100%);
  opacity: 0.6;
}

.information-container {
  display: table;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.card-hover-state-title {
  font-size: 15px;
  color: #FFFFFF;
  width: 50%;
  position: relative;
  display: table-cell;
}

.card-hover-state-button {
  font-size: 11px;
  color: #FFFFFF;
  position: relative;
  display: table-cell;
  text-align: right;
  vertical-align:middle;
}

<div class="card">
  <div class="card-hover-state"></div>
  <div class="information-container">
    <div class="card-hover-state-title">Brace yourself - A fancy Lorem Ipsum Title is comming</div>
    <div class="card-hover-state-button">READ MORE</div>
  </div>
</div>


问:
Spring Jpa Specification Join table with like
I want use the spring JPA specification join function

This is my code for the tables:

Table InStudent

Table InParent

```<code>public static Specification<InStudent> filterByKeywordAndStatus(final String keyword) {
return (Root<InStudent> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
    List<Predicate> predicates = new ArrayList<>();

    if (StringUtils.hasText(keyword)) {

        predicates.add(
                cb.or(
                        cb.like(root.get(InStudent_.name), "%" + keyword + "%"),
                        cb.like(root.get(InStudent_.address), "%" + keyword + "%"),
                        cb.like(root.get(InStudent_.phone), "%" + keyword + "%")
                )
        );
    }

    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
</code>```

}

How can I join table inStudent and inParent within the specification?

答:
Try something like this (if I've understood you correctly): </p>

```<code>public static Specification<Student> filterByKeywordAndStatus(String keyword, String parentStatus) {

    return (student, query, cb) -> {

        Join<Student, Parent> joinParent = student.join("parent");

        return cb.and(
                cb.or(
                   cb.like(student.get("name"), "%" + keyword + "%"),
                   cb.like(student.get("address"), "%" + keyword + "%"),
                   cb.like(student.get("phone"), "%" + keyword + "%")
                ),
                cb.like(joinParent.get("status"), "%" + parentStatus + "%"));
    };
}
</code>```

Body:
I want use the spring JPA specification join function

This is my code for the tables:

Table InStudent

Table InParent

public static Specification<InStudent> filterByKeywordAndStatus(final String keyword) {
return (Root<InStudent> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
    List<Predicate> predicates = new ArrayList<>();

    if (StringUtils.hasText(keyword)) {

        predicates.add(
                cb.or(
                        cb.like(root.get(InStudent_.name), "%" + keyword + "%"),
                        cb.like(root.get(InStudent_.address), "%" + keyword + "%"),
                        cb.like(root.get(InStudent_.phone), "%" + keyword + "%")
                )
        );
    }

    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};

}

How can I join table inStudent and inParent within the specification?

Body:
Try something like this (if I've understood you correctly):

public static Specification<Student> filterByKeywordAndStatus(String keyword, String parentStatus) {

    return (student, query, cb) -> {

        Join<Student, Parent> joinParent = student.join("parent");

        return cb.and(
                cb.or(
                   cb.like(student.get("name"), "%" + keyword + "%"),
                   cb.like(student.get("address"), "%" + keyword + "%"),
                   cb.like(student.get("phone"), "%" + keyword + "%")
                ),
                cb.like(joinParent.get("status"), "%" + parentStatus + "%"));
    };
}


问:
How to get all possible 2 words combinations with their frequency without tm package
I have a text like this:

```<code>dat<-c("this is my farm this is my land")
</code>```

I would like to get all possible 2 words combinations with their frequency.
I can't use tm package so any other solution will be appreciated.
The output should be something like this:

```<code>two words freq
this is     2
is my       2
my farm     1
my land     1
</code>```

答:
The combinations could be generated by splitting the dat and then extracting the consecutive two word combinations. Then, gregexpr could be used to count the appearances.

```<code>temp = unlist(strsplit(dat, " "))
temp2 = unique(sapply(2:length(temp), function(i)
    paste(temp[(i-1):i], collapse = " ")))
sapply(temp2, function(x)
    length(unlist(gregexpr(pattern = x, text = dat))))
#  this is     is my   my farm farm this   my land
#        2         2         1         1         1
</code>```

Or for three word combinations

```<code>temp = unlist(strsplit(dat, " "))
temp2 = unique(sapply(3:length(temp), function(i)
    paste(temp[(i-2):i], collapse = " ")))
sapply(temp2, function(x)
    length(unlist(gregexpr(pattern = x, text = dat))))
#  this is my   is my farm my farm this farm this is   is my land
#           2            1            1            1            1
</code>```

Body:
I have a text like this:

dat<-c("this is my farm this is my land")

I would like to get all possible 2 words combinations with their frequency.
I can't use tm package so any other solution will be appreciated.
The output should be something like this:

two words freq
this is     2
is my       2
my farm     1
my land     1

Body:
The combinations could be generated by splitting the dat and then extracting the consecutive two word combinations. Then, gregexpr could be used to count the appearances.

temp = unlist(strsplit(dat, " "))
temp2 = unique(sapply(2:length(temp), function(i)
    paste(temp[(i-1):i], collapse = " ")))
sapply(temp2, function(x)
    length(unlist(gregexpr(pattern = x, text = dat))))
#  this is     is my   my farm farm this   my land
#        2         2         1         1         1

Or for three word combinations

temp = unlist(strsplit(dat, " "))
temp2 = unique(sapply(3:length(temp), function(i)
    paste(temp[(i-2):i], collapse = " ")))
sapply(temp2, function(x)
    length(unlist(gregexpr(pattern = x, text = dat))))
#  this is my   is my farm my farm this farm this is   is my land
#           2            1            1            1            1


问:
Vuejs - cannot ready property of undefined - (but it render on browser)
I have this strange behavior on Vue.
I'm trying to render a nested property of an object, named descrizione and it works! But in the console I have a warning from Vue:

TypeError: Cannot read property 'descrizione' of undefined"

Here is my code:

HTML

```<code><div id="input-container">
  {{modello.lineaGialla.descrizione}}
  <input
     class="styled-checkbox"
     type="checkbox"
     v-for="(servizio, index) in modello.lineaGialla.servizi"
     v-bind:style="{left:servizio.x+'px',top:servizio.y+'px'}"
     v-model="servizio.selected"
     v-on:click="AddServizi(servizio.selected,servizio.nomeServizio)"
     />
  <br/>
  {{modello.lineaBlu.descrizione}}
  <input
     class=""
     type="checkbox"
     v-for="(servizio, index) in modello.lineaBlu.servizi"
     v-model="servizio.selected"
     v-on:click="AddServizi(servizio.selected,servizio.nomeServizio)"
     />
</div>
</code>```

JSON

```<code>{
"lineaGialla": {
  "class":"gialla",
  "selected": false,
  "descrizione": "Questa è linea gialla",
  "descrizione_breve":"descrizione breve gialla",
  "descrizione_lunga":"descrizione lunga gialla",
  "servizi": [
      {"nomeServizio":"servizio_giallo1","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":534,"y":83,"selected": false},
      {"nomeServizio":"servizio_giallo2","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":399,"y":259,"selected": false},
      {"nomeServizio":"servizio_giallo3","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":224,"y":262,"selected": false},
      {"nomeServizio":"servizio_giallo4","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":150,"y":502,"selected": false}
  ]
},
"lineaBlu": {
  "class":"blu",
  "selected": false,
  "descrizione": "Questa è la linea blu",
  "descrizione_breve":"descrizione breve blu",
  "descrizione_lunga":"descrizione lunga blu",
  "servizi": [
      {"nomeServizio":"servizio_blu1","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":534,"y":83,"selected": false},
      {"nomeServizio":"servizio_blu2","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":399,"y":259,"selected": false},
      {"nomeServizio":"servizio_blu3","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":224,"y":262,"selected": false},
      {"nomeServizio":"servizio_blu4","descrizione":"qui desc <br/> breve","descrizione_lunga":"qui desc lunga","x":150,"y":502,"selected": false}
  ]
}
</code>```

JS
Here I use a self invoked function to make an ajax call:

```<code>var Callmodule = (function(){
var urljsonEntrata= "modello.json";

function getmodules(){
    var req = $.ajax({
        url: urljsonEntrata,
        dataType: 'json',
        type: 'GET'
    });

    req.done(function(data){
        console.log('ajax to '+urljsonEntrata+' DONE');
        console.log(data);
        console.log('-----------------------------');
    });

    req.fail(function( jqXHR, textStatus, errorThrown ) {
        console.log('ajax to '+urljsonEntrata+' FAIL');
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        console.log('-----------------------------');
    });
    return req;
}
return {
    callGetmodules : getmodules(),
}
})();

var modello = {};

var VueApp = (function(){

 //VUE JS
var Metromappa = new Vue({
 el: '#metromappa',
  data: {
    modello:modello
  },
  methods:{
    getModuleData : function(){
       var req = Callmodule.callGetmodules;
       var self = this;
       req.done(function(data){
         self.modello=data;
       });
       req.fail(function(jqXHR,textStatus,errorThrown){
        console.log('richiesta andata a male')
       });
   }
</code>```

I'm going crazy.

答:
The problem here is that you are retrieving your data asynchronously but you have defined the template in a way that it expects the data to be populated immediately.

For example in your template you have the following code.

```<code>modello.lineaGialla.descrizione
</code>```

However, when the template is first rendered, lineaGialla does not exist or is undefined. However, you are trying to access the descrizione property of that value and undefined has no properties. This results in your error.

In order to fix the problem, simply do not render the template until you have data,

```<code><div  v-if="modello.lineaGialla && modello.lineaBlu" id="input-container">
</code>```

or guard the access like this:

```<code>{{modello.lineaGialla && modello.lineaGialla.descrizione}}
</code>```

Body:
I have this strange behavior on Vue.
I'm trying to render a nested property of an object, named descrizione and it works! But in the console I have a warning from Vue:

TypeError: Cannot read property 'descrizione' of undefined"

Here is my code:

HTML

  {{modello.lineaGialla.descrizione}}
  <input
     class="styled-checkbox"
     type="checkbox"
     v-for="(servizio, index) in modello.lineaGialla.servizi"
     v-bind:style="{left:servizio.x+'px',top:servizio.y+'px'}"
     v-model="servizio.selected"
     v-on:click="AddServizi(servizio.selected,servizio.nomeServizio)"
     />

  {{modello.lineaBlu.descrizione}}
  <input
     class=""
     type="checkbox"
     v-for="(servizio, index) in modello.lineaBlu.servizi"
     v-model="servizio.selected"
     v-on:click="AddServizi(servizio.selected,servizio.nomeServizio)"
     />

JSON

{
"lineaGialla": {
  "class":"gialla",
  "selected": false,
  "descrizione": "Questa è linea gialla",
  "descrizione_breve":"descrizione breve gialla",
  "descrizione_lunga":"descrizione lunga gialla",
  "servizi": [
      {"nomeServizio":"servizio_giallo1","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":534,"y":83,"selected": false},
      {"nomeServizio":"servizio_giallo2","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":399,"y":259,"selected": false},
      {"nomeServizio":"servizio_giallo3","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":224,"y":262,"selected": false},
      {"nomeServizio":"servizio_giallo4","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":150,"y":502,"selected": false}
  ]
},
"lineaBlu": {
  "class":"blu",
  "selected": false,
  "descrizione": "Questa è la linea blu",
  "descrizione_breve":"descrizione breve blu",
  "descrizione_lunga":"descrizione lunga blu",
  "servizi": [
      {"nomeServizio":"servizio_blu1","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":534,"y":83,"selected": false},
      {"nomeServizio":"servizio_blu2","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":399,"y":259,"selected": false},
      {"nomeServizio":"servizio_blu3","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":224,"y":262,"selected": false},
      {"nomeServizio":"servizio_blu4","descrizione":"qui desc
 breve","descrizione_lunga":"qui desc lunga","x":150,"y":502,"selected": false}
  ]
}

JS
Here I use a self invoked function to make an ajax call:

var Callmodule = (function(){
var urljsonEntrata= "modello.json";

function getmodules(){
    var req = $.ajax({
        url: urljsonEntrata,
        dataType: 'json',
        type: 'GET'
    });

    req.done(function(data){
        console.log('ajax to '+urljsonEntrata+' DONE');
        console.log(data);
        console.log('-----------------------------');
    });

    req.fail(function( jqXHR, textStatus, errorThrown ) {
        console.log('ajax to '+urljsonEntrata+' FAIL');
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        console.log('-----------------------------');
    });
    return req;
}
return {
    callGetmodules : getmodules(),
}
})();

var modello = {};

var VueApp = (function(){

 //VUE JS
var Metromappa = new Vue({
 el: '#metromappa',
  data: {
    modello:modello
  },
  methods:{
    getModuleData : function(){
       var req = Callmodule.callGetmodules;
       var self = this;
       req.done(function(data){
         self.modello=data;
       });
       req.fail(function(jqXHR,textStatus,errorThrown){
        console.log('richiesta andata a male')
       });
   }

I'm going crazy.

Body:
The problem here is that you are retrieving your data asynchronously but you have defined the template in a way that it expects the data to be populated immediately.

For example in your template you have the following code.

modello.lineaGialla.descrizione

However, when the template is first rendered, lineaGialla does not exist or is undefined. However, you are trying to access the descrizione property of that value and undefined has no properties. This results in your error.

In order to fix the problem, simply do not render the template until you have data,

<div  v-if="modello.lineaGialla && modello.lineaBlu" id="input-container">

or guard the access like this:

{{modello.lineaGialla && modello.lineaGialla.descrizione}}


问:
MySQL error 1064 table creation
This seems a fairly trivial problem but I am having no luck in running the following query:

```<code>create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR(20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
</code>```

When I run this I get the following error message:

```<code>Error Code: 1064. You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '(20),  retweet_count INT,     favourite_count INT,
tweet_followers_count ' at line 3
</code>```

When I hover over the error tag on line 3 it says:

```<code>Syntax error : unexpected '(' (opening parenthesis)
</code>```

I'm sure this is a simple fix, any help would be great!

答:
```<code>create table if not exists  tweet_data (

created_at DATETIME,

user_name VARCHAR (20),

retweet_count INT,

favourite_count INT,

tweet_followers_count INT,

is_retweet BOOLEAN,

tweet_source VARCHAR(256),

user_location VARCHAR(256),

tweet_mentioned_count INT,

tweet_ID VARCHAR(256) NOT NULL,

tweet_text VARCHAR(140),

UNIQUE (tweet_ID) );
</code>```

Man this code is running perfectly.

go to this link and check it your self

http://rextester.com/l/mysql_online_compiler

Title: MySQL error 1064 table creation

Body:
This seems a fairly trivial problem but I am having no luck in running the following query:

create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR(20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );

When I run this I get the following error message:

Error Code: 1064. You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '(20),  retweet_count INT,     favourite_count INT,
tweet_followers_count ' at line 3

When I hover over the error tag on line 3 it says:

Syntax error : unexpected '(' (opening parenthesis)

I'm sure this is a simple fix, any help would be great!

Body:
create table if not exists  tweet_data (

created_at DATETIME,

user_name VARCHAR (20),

retweet_count INT,

favourite_count INT,

tweet_followers_count INT,

is_retweet BOOLEAN,

tweet_source VARCHAR(256),

user_location VARCHAR(256),

tweet_mentioned_count INT,

tweet_ID VARCHAR(256) NOT NULL,

tweet_text VARCHAR(140),

UNIQUE (tweet_ID) );

Man this code is running perfectly.

go to this link and check it your self

http://rextester.com/l/mysql_online_compiler

ContentLicense: CC BY-SA 4.0