问:
jqGrid show a large column as a row
We are using struts 2 jquery grid 3.7.0 plugin which uses jqGrid 4.6.0

The grid has one column which has very large data, is it possible to show this large column as a row.

Like below

Although it seems like grouping but it is not.

I wonder if it is possible?!

I try formatter but all returned data from a formatter is keep in a cell.

答:
The formatter allows to set innerHTML of the cells only. You should use cellattr instead of formatter to set colspan attribute on  elements of the first column and the attribute style="display:none;" on  elements of the next three column. I recommend you to look at the old answer for more details.

One more alternative option, which you can consider, is changing the CSS rules applied on the cells. You can use white-space: pre-wrap (or white-space: normal) to wrap the information inside of one cell.

Title: jqGrid show a large column as a row

Body:
The formatter allows to set innerHTML of the cells only. You should use cellattr instead of formatter to set colspan attribute on <td> elements of the first column and the attribute style="display:none;" on <td> elements of the next three column. I recommend you to look at the old answer for more details.

One more alternative option, which you can consider, is changing the CSS rules applied on the cells. You can use white-space: pre-wrap (or white-space: normal) to wrap the information inside of one cell.


来源: stackexchange

问:
Why use this construct - PropertyChangedEventHandler handler = this.PropertyChanged?
The article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx has the following code sample:

```<code>public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
    PropertyChangedEventHandler handler = this.PropertyChanged;
    if (handler != null)
    {
        var e = new PropertyChangedEventArgs(propertyName);
        handler(this, e);
    }
}
</code>```

My question is what is gained by introducing the variable 'handler' - the following code seems to work fine:

```<code>public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
    if (PropertyChanged!= null)
    {
        var e = new PropertyChangedEventArgs(propertyName);
        PropertyChanged(this, e);
    }
}
</code>```

答: This is to ensure that the OnPropertyChanged method is thread safe.  See Use of null check in event handler for another discussion. </p>

ContentLicense: CC BY-SA 2.5

Body:
The article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx has the following code sample:

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
    PropertyChangedEventHandler handler = this.PropertyChanged;
    if (handler != null)
    {
        var e = new PropertyChangedEventArgs(propertyName);
        handler(this, e);
    }
}

My question is what is gained by introducing the variable 'handler' - the following code seems to work fine:

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
    if (PropertyChanged!= null)
    {
        var e = new PropertyChangedEventArgs(propertyName);
        PropertyChanged(this, e);
    }
}


问:
Workaround for Android QCMediaPlayer not present
My LogCat gives me this error

```<code>E/MediaPlayer-JNI﹕ QCMediaPlayer mediaplayer NOT present
</code>```

So I searched for it and I found out that it looks like the device doesn't support the QCMediaPlayer. What else can I do to play Audio Files and how can I check if the QCMediaPlayer is supported?

答:
Mine Got solved by using static create method of MediaPlayer:

```<code>MediaPlayer player= MediaPlayer.create(cntx, Uri.parse(this.path));
</code>```

for resource files:

```<code>MediaPlayer player = MediaPlayer.create(cntx, sound_resource_id, loop);
</code>```

ContentLicense: CC BY-SA 4.0

Body:
My LogCat gives me this error

E/MediaPlayer-JNI﹕ QCMediaPlayer mediaplayer NOT present

So I searched for it and I found out that it looks like the device doesn't support the QCMediaPlayer. What else can I do to play Audio Files and how can I check if the QCMediaPlayer is supported?

Body:
Mine Got solved by using static create method of MediaPlayer:

MediaPlayer player= MediaPlayer.create(cntx, Uri.parse(this.path));

for resource files:

MediaPlayer player = MediaPlayer.create(cntx, sound_resource_id, loop);

ContentLicense: CC BY-SA 3.0


问:
Get a String out of Try-Catch
I have a little issue with try-catch.

My Target is to get the test and test2 values out of the try block that I can use it later.

How to handle it?

```<code>public class MyApplication {
    public static void main(String[] args) {
        try {
            int test = Integer.parseInt("123");
            String test2 = "ABCD";
        } catch (NumberFormatException ex) {
            System.out.print(ex.getMessage());
        }
    }
}
</code>```

答:
As others have pointed out, you have scope issues meaning your variable Test and Test 2 are declared within the try-catch block. Because of these you cannot access this variable outside the try-catch block. There are couple of ways to overcome this, the easiest way out is to declare just after your main function declaration or your class declaration.</p>

```<code>public class MyApplication {

    public static void main(String[] args) {
        int TEST = 0;
        String TEST2 = "";

        try {
            TEST = Integer.parseInt("123");
            TEST2 = "ABCD";
        } catch (NumberFormatException ex) {
            System.out.print(ex.getMessage());
        }
    }
}
</code>```

Title: Get a String out of Try-Catch

Body:
I have a little issue with try-catch.

My Target is to get the test and test2 values out of the try block that I can use it later.

How to handle it?

public class MyApplication {
    public static void main(String[] args) {
        try {
            int test = Integer.parseInt("123");
            String test2 = "ABCD";
        } catch (NumberFormatException ex) {
            System.out.print(ex.getMessage());
        }
    }
}

Body:
As others have pointed out, you have scope issues meaning your variable Test and Test 2 are declared within the try-catch block. Because of these you cannot access this variable outside the try-catch block. There are couple of ways to overcome this, the easiest way out is to declare just after your main function declaration or your class declaration.

public class MyApplication {

    public static void main(String[] args) {
        int TEST = 0;
        String TEST2 = "";

        try {
            TEST = Integer.parseInt("123");
            TEST2 = "ABCD";
        } catch (NumberFormatException ex) {
            System.out.print(ex.getMessage());
        }
    }
}


问:
Simple js framework, DOM. (module style,like jQuery) Issue with adding methods
The task is to code simple framework in jQuery style, to solve this i've written code:

```<code>(function(window) {
window.smp=function smpSelector(selector) {
    return new smpObj(selector);
    }

function smpObj(selector) {
    this.length = 0;
    if (!selector ) {
        this.el = [];
        return this;
        }
    if(typeof selector == 'string'){
        if(selector[0]==='#'){
            this.el = [document.getElementById(selector.slice(1, selector.length))];
            this.length = 1;
            return this;
        } else if(selector[0]==='.'){
            this.el = document.getElementsByClassName(selector.slice(1, selector.length));
            this.length = this.el.length;
            return this;
        } else {
            this.el = document.getElementsByTagName(selector);
            this.length = this.el.length;
            return this;
        }
    }
    else return null;
}
window.smp.changeColor=function smpColor(color) {
    for (var i = 0; i < this.length; i++)
            this.el[i].style.color = color;
    }
})(window);
</code>```

And it's working OK. I can call like:

```<code>smp('div')
</code>```

But then i've tried to add method:

```<code>window.smp.changeColor=function smpColor(color) {
    for (var i = 0; i < this.length; i++)
            this.el[i].style.color = color;
    }
</code>```

And it's not working properly.

```<code>  smp('div').changeColor('color')
</code>```

(can't call like this )

I'll be grateful, if someone can show me mistake.

I've used this article article

答:
Since you return this in smpObj function, this is the instance of smpObj not window.smp and there's no changeColor method for smpObj.

To make it work, you can do like this:

```<code>(function(window) {
  window.smp = function smpSelector(selector) {
    return new smpObj(selector);
  };

  function smpObj(selector) {
    this.length = 0;
    this.changeColor = function smpColor(color) {
      for (var i = 0; i < this.length; i++) this.el[i].style.color = color;
    };
    if (!selector) {
      this.el = [];
      return this;
    }
    if (typeof selector == "string") {
      if (selector[0] === "#") {
        this.el = document.getElementById(selector.slice(1, selector.length));
        this.length = 1;
        return this;
      } else if (selector[0] === ".") {
        this.el = document.getElementsByClassName(
          selector.slice(1, selector.length)
        );
        this.length = this.el.length;
        return this;
      } else {
        this.el = document.getElementsByTagName(selector);
        this.length = this.el.length;
        return this;
      }
    } else return null;
  }
})(window);
</code>```

then try

```<code> smp('div').changeColor('red')
</code>```

Body:
The task is to code simple framework in jQuery style, to solve this i've written code:

(function(window) {
window.smp=function smpSelector(selector) {
    return new smpObj(selector);
    }

function smpObj(selector) {
    this.length = 0;
    if (!selector ) {
        this.el = [];
        return this;
        }
    if(typeof selector == 'string'){
        if(selector[0]==='#'){
            this.el = [document.getElementById(selector.slice(1, selector.length))];
            this.length = 1;
            return this;
        } else if(selector[0]==='.'){
            this.el = document.getElementsByClassName(selector.slice(1, selector.length));
            this.length = this.el.length;
            return this;
        } else {
            this.el = document.getElementsByTagName(selector);
            this.length = this.el.length;
            return this;
        }
    }
    else return null;
}
window.smp.changeColor=function smpColor(color) {
    for (var i = 0; i < this.length; i++)
            this.el[i].style.color = color;
    }
})(window);

And it's working OK. I can call like:

smp('div')

But then i've tried to add method:

window.smp.changeColor=function smpColor(color) {
    for (var i = 0; i < this.length; i++)
            this.el[i].style.color = color;
    }

And it's not working properly.

  smp('div').changeColor('color')

(can't call like this )

I'll be grateful, if someone can show me mistake.

I've used this article article

Body:
Since you return this in smpObj function, this is the instance of smpObj not window.smp and there's no changeColor method for smpObj.

To make it work, you can do like this:

(function(window) {
  window.smp = function smpSelector(selector) {
    return new smpObj(selector);
  };

  function smpObj(selector) {
    this.length = 0;
    this.changeColor = function smpColor(color) {
      for (var i = 0; i < this.length; i++) this.el[i].style.color = color;
    };
    if (!selector) {
      this.el = [];
      return this;
    }
    if (typeof selector == "string") {
      if (selector[0] === "#") {
        this.el = document.getElementById(selector.slice(1, selector.length));
        this.length = 1;
        return this;
      } else if (selector[0] === ".") {
        this.el = document.getElementsByClassName(
          selector.slice(1, selector.length)
        );
        this.length = this.el.length;
        return this;
      } else {
        this.el = document.getElementsByTagName(selector);
        this.length = this.el.length;
        return this;
      }
    } else return null;
  }
})(window);

then try

 smp('div').changeColor('red')


问:
How to return a viewEntryCollection in random order
I have the following code

```<code>var vec:ViewEntryCollection = database.getView("view").getAllEntriesByKey("Mykey",true)
</code>```

how can I make "vec" in random order using SSJS (or java) so that I get a new order every time?

答: How about having a secondary sort column on the view with a formula of @Unique.  Would need to refresh the view each time and performance may not be great if the view is big.

Body:
I have the following code

var vec:ViewEntryCollection = database.getView("view").getAllEntriesByKey("Mykey",true)

how can I make "vec" in random order using SSJS (or java) so that I get a new order every time?


问:
Difference between various AVAssetExportPreset
I am compressing video so i have come across following Export Presets

```<code>AVAssetExportPresetLowQuality
AVAssetExportPresetMediumQuality
AVAssetExportPresetHighestQuality

AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160
</code>```

I have read about all of them in apple documents and found that second list compressed in given fixed dimensions but found nothing about first list , i am confused that why it has 2 lists one with low, medium and high quality and other with fixed sizes and which one is better to use?

答:
The AVAssetExportPreset containing below available preset names.

1. Export Preset Names for Device-Appropriate QuickTime Files

```<code>AVAssetExportPresetLowQuality - Specifies a low quality QuickTime file.
AVAssetExportPresetMediumQuality - Specifies a medium quality QuickTime file.
AVAssetExportPresetHighestQuality - Specifies a high quality QuickTime file.
</code>```

You use these export options to produce QuickTime .mov files with
  video size appropriate to the current device.

2. Export Preset Names for QuickTime Files of a Given Size

```<code>AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160
</code>```

You use these export options to produce QuickTime .mov files with a specified video size.

3. Export Preset Name for iTunes Audio

```<code>AVAssetExportPresetAppleM4A
</code>```

You use this export option to produce an audio-only .m4a file with appropriate iTunes gapless playback data.

4. Export Preset Name for Pass-Through

```<code>AVAssetExportPresetPassthrough
</code>```

You use this export option to let all tracks pass through.This option does not show up in the
allExportPresets()
 and
exportPresets(compatibleWith:)
 methods.

Body:
I am compressing video so i have come across following Export Presets

AVAssetExportPresetLowQuality
AVAssetExportPresetMediumQuality
AVAssetExportPresetHighestQuality

AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160

I have read about all of them in apple documents and found that second list compressed in given fixed dimensions but found nothing about first list , i am confused that why it has 2 lists one with low, medium and high quality and other with fixed sizes and which one is better to use?

Body:
The AVAssetExportPreset containing below available preset names.

1. Export Preset Names for Device-Appropriate QuickTime Files

AVAssetExportPresetLowQuality - Specifies a low quality QuickTime file.
AVAssetExportPresetMediumQuality - Specifies a medium quality QuickTime file.
AVAssetExportPresetHighestQuality - Specifies a high quality QuickTime file.

You use these export options to produce QuickTime .mov files with
  video size appropriate to the current device.

2. Export Preset Names for QuickTime Files of a Given Size

AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160

You use these export options to produce QuickTime .mov files with a specified video size.

3. Export Preset Name for iTunes Audio

AVAssetExportPresetAppleM4A

You use this export option to produce an audio-only .m4a file with appropriate iTunes gapless playback data.

4. Export Preset Name for Pass-Through

AVAssetExportPresetPassthrough

You use this export option to let all tracks pass through.This option does not show up in the
allExportPresets()
 and
exportPresets(compatibleWith:)
 methods.


问:
Get the list of PNG files in File Storage excluding _processed_ folder
As topic says, I need to get only unprocessed PNG files.

My current approach is the following:

```<code>$fileExtensionFilter = $this->objectManager->get(FileExtensionFilter::class);
$fileExtensionFilter->setAllowedFileExtensions('png');

$storage->addFileAndFolderNameFilter([$fileExtensionFilter, 'filterFileList']);
$availablePngFiles = $storage->getFileIdentifiersInFolder($storage->getRootLevelFolder(false)->getIdentifier(), true, true);

foreach ($availablePngFiles as $pngFile) {
    if(!$storage->isWithinProcessingFolder($pngFile)) {
        $pngFileObject = $storage->getFile($pngFile);
    }
}
</code>```

So, it works, but I'd like to avoid the unnecessary isWithinProcessingFolder() lookup and get only the original unprocessed files, which will significantly reduce the number of loops.

答:
TYPO3 core 7.6.19 does only ship with two filters: FileExtensionFilter and FileNameFilter, which actually is a "hidden file filter".

You could write your own file filter and filter in there, but that's way more work than keeping those two lines of code.

Body:
As topic says, I need to get only unprocessed PNG files.

My current approach is the following:

$fileExtensionFilter = $this->objectManager->get(FileExtensionFilter::class);
$fileExtensionFilter->setAllowedFileExtensions('png');

$storage->addFileAndFolderNameFilter([$fileExtensionFilter, 'filterFileList']);
$availablePngFiles = $storage->getFileIdentifiersInFolder($storage->getRootLevelFolder(false)->getIdentifier(), true, true);

foreach ($availablePngFiles as $pngFile) {
    if(!$storage->isWithinProcessingFolder($pngFile)) {
        $pngFileObject = $storage->getFile($pngFile);
    }
}

So, it works, but I'd like to avoid the unnecessary isWithinProcessingFolder() lookup and get only the original unprocessed files, which will significantly reduce the number of loops.


问:
PHP and MySQL - how to update single row from single table using order by desc and limit 1
Hello guys actually i am trying to maintain user logs with ip, last login time and last logout time of users, working in php and mysql. successfully stored ip and login time while user logs in but while updating logout time at the time of logout it updated all logout time for the same user id and i want to update only last logout time of the user id whether he logged in any no of times. can any one help me for the same.

my code is  -

```<code>if (isset($_SESSION['userId']) && !empty($_SESSION['userId'])) {
    include "connection.php";
    $userId = $_SESSION['userId'];

    $sqluserlogs = "UPDATE userlogs SET LastLogout = now()
    WHERE uid = '$userId' ORDER BY uid DESC LIMIT 1";

    if (mysql_query($sqluserlogs, $conn)) {
        //echo 'success';
    } else {
        //echo 'failed';
    }
}
</code>```

updated query -

```<code>  $sqluserlogs = "UPDATE userlogs SET LastLogout = now() WHERE
   uid = '$userId' ORDER BY ulogID DESC LIMIT 1";
</code>```

Thanks in advance

答:
Try a join:</p>

```<code> "UPDATE userlogs AS UpdateTable
     INNER JOIN (
         SELECT JoinTable.id
         FROM userlogs AS JoinTable
         WHERE JoinTable.uid = '$userId'
         ORDER BY uid DESC
         LIMIT 1)
                 AS source ON source.id = UpdateTable.id
    SET LastLogout = now()";
</code>```

Body:
Hello guys actually i am trying to maintain user logs with ip, last login time and last logout time of users, working in php and mysql. successfully stored ip and login time while user logs in but while updating logout time at the time of logout it updated all logout time for the same user id and i want to update only last logout time of the user id whether he logged in any no of times. can any one help me for the same.

my code is  -

if (isset($_SESSION['userId']) && !empty($_SESSION['userId'])) {
    include "connection.php";
    $userId = $_SESSION['userId'];

    $sqluserlogs = "UPDATE userlogs SET LastLogout = now()
    WHERE uid = '$userId' ORDER BY uid DESC LIMIT 1";

    if (mysql_query($sqluserlogs, $conn)) {
        //echo 'success';
    } else {
        //echo 'failed';
    }
}

updated query -

  $sqluserlogs = "UPDATE userlogs SET LastLogout = now() WHERE
   uid = '$userId' ORDER BY ulogID DESC LIMIT 1";

Thanks in advance

Body:
Try a join:

 "UPDATE userlogs AS UpdateTable
     INNER JOIN (
         SELECT JoinTable.id
         FROM userlogs AS JoinTable
         WHERE JoinTable.uid = '$userId'
         ORDER BY uid DESC
         LIMIT 1)
                 AS source ON source.id = UpdateTable.id
    SET LastLogout = now()";


问:
UseSqlServer method missing MVC 6
I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do

```<code>services.AddEntityFramework()
    .AddSqlServer()
    .AddDbContext<MusicStoreContext>(options =>
                        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
</code>```

But for me, the UseSqlServer method isn't visible?  Anyone know how to make it visible?  Or is this an old way of configuring entity framework?

My startup.cs file looks like this

```<code>using FluentValidation;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;

namespace me.namespace.project
{
    public class Startup
    {
        public static IConfiguration Configuration { get; set; }

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            Configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // entity framework
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<DataContext>();

        }
    }
}
</code>```

答:
It's a NuGet Packages Problem

Install the following Packages  and with its Proper Versions

```<code> 1.  Microsoft.EntityFrameworkCore(Latest Version)
 2.  Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)
</code>```

Title: UseSqlServer method missing MVC 6

Body:
I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do

services.AddEntityFramework()
    .AddSqlServer()
    .AddDbContext<MusicStoreContext>(options =>
                        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

But for me, the UseSqlServer method isn't visible?  Anyone know how to make it visible?  Or is this an old way of configuring entity framework?

My startup.cs file looks like this

using FluentValidation;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;

namespace me.namespace.project
{
    public class Startup
    {
        public static IConfiguration Configuration { get; set; }

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            Configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // entity framework
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<DataContext>();

        }
    }
}

Body:
It's a NuGet Packages Problem

Install the following Packages  and with its Proper Versions

 1.  Microsoft.EntityFrameworkCore(Latest Version)
 2.  Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)


问:
Content not fitting in IPad screen When Change in Iphone Screens
Made a form in iphone 4s screen and at bottom i have submit button, when i use constraints on submit button to reside button at bottom in all screen , but when i check in IPad screen the submit button is not shown , I have to readjust the form again and bring that button bit up which look odd,i want button at bottom in all screen of iphone and ipad.How can this be achieve?

答:
Do something like below.

Select 4s view from storyboard

add dummy view 300x400

add your component in that dummy view textfields, submit buttons whatever you want to add in center.

add constraints to dummy view only

done

Note: any issue to view gif, download and separate frame.


问:
Using Thymeleaf when the value is null
I have some values in my database which can be null if they have not already been entered.

But when I use Thymeleaf in my html, it gives an error when parsing null values.

Is there any way to handle this?

答:
You can use 'th:if' together with 'th:text'</p>

```<code><span th:if="${someObject.someProperty != null}" th:text="${someObject.someProperty}">someValue</span>
</code>```

Title: Using Thymeleaf when the value is null

Body:
You can use 'th:if' together with 'th:text'

<span th:if="${someObject.someProperty != null}" th:text="${someObject.someProperty}">someValue</span>


问:
Sort RDD according to an Array() content
I have RDD[(Int , Array[Double])]
eg:

```<code>1, Array(2.0,5.0,6.3)
5, Array(1.0,3.3,9.5)
1, Array(5.0,4.2,3.1)
2, Array(9.6,6.3,2.3)
1, Array(8.5,2.5,1.2)
5, Array(6.0,2.4,7.8)
2, Array(7.8,9.1,4.2)
</code>```

I have to collect the distinct value of the 1st column and arrange the whole RDD according to that array.

```<code>val label_array = rdd.map(_._1).collect.distinct
</code>```

Output: Array(1,5,2) and now I have to arrange data according to label_array.

Required Output

```<code>1, Array(2.0,5.0,6.3)
1, Array(5.0,4.2,3.1)
1, Array(8.5,2.5,1.2)
5, Array(1.0,3.3,9.5)
5, Array(6.0,2.4,7.8)
2, Array(9.6,6.3,2.3)
2, Array(7.8,9.1,4.2)
</code>```

I have tried

```<code>val ordering = (1,5,2).productIterator.toList.zipWithIndex.toMap
rdd.sortBy{case (k,v) => ordering(k)}
</code>```

But how to get the required output as the Array will be varying(elements and size difference). How can I sort RDD according to array format?

答:
Just zipWithIndex your label_array and you should be fine

```<code>val ordering = label_array.zipWithIndex.map(x => (x._1, x._2)).toMap
</code>```

And you should have your ordering map

```<code>scala.collection.immutable.Map[Int,Int] = Map(1 -> 0, 5 -> 1, 2 -> 2)
</code>```

Body:
I have RDD[(Int , Array[Double])]
eg:

1, Array(2.0,5.0,6.3)
5, Array(1.0,3.3,9.5)
1, Array(5.0,4.2,3.1)
2, Array(9.6,6.3,2.3)
1, Array(8.5,2.5,1.2)
5, Array(6.0,2.4,7.8)
2, Array(7.8,9.1,4.2)

I have to collect the distinct value of the 1st column and arrange the whole RDD according to that array.

val label_array = rdd.map(_._1).collect.distinct

Output: Array(1,5,2) and now I have to arrange data according to label_array.

Required Output

1, Array(2.0,5.0,6.3)
1, Array(5.0,4.2,3.1)
1, Array(8.5,2.5,1.2)
5, Array(1.0,3.3,9.5)
5, Array(6.0,2.4,7.8)
2, Array(9.6,6.3,2.3)
2, Array(7.8,9.1,4.2)

I have tried

val ordering = (1,5,2).productIterator.toList.zipWithIndex.toMap
rdd.sortBy{case (k,v) => ordering(k)}

But how to get the required output as the Array will be varying(elements and size difference). How can I sort RDD according to array format?

Body:
Just zipWithIndex your label_array and you should be fine

val ordering = label_array.zipWithIndex.map(x => (x._1, x._2)).toMap

And you should have your ordering map

scala.collection.immutable.Map[Int,Int] = Map(1 -> 0, 5 -> 1, 2 -> 2)


问:
XML Schema: Multiple indicators within a complexType
The xsd snippet below states the XML element 'Warrior' should have three attributes, 'Strength', 'Sword' and 'Axe'.

```<code><complexType name="Warrior">
  <complexContent>
    <extension base="Character">
      <sequence>
        <attribute name="Strength" type="integer"/>
        <attribute name="Sword" type="weapon"/>
        <attribute name="Axe" type="weapon"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>
</code>```

How do I define a 'Warrior' to have a 'Strength' attribute, and EITHER a 'Sword' attribute or an 'Axe' attribute, but not both?

I'm assuming the use of the 'choice' indicator, but I don't know how to structure the complexType to use both the 'choice' and the 'sequence' indicator.

Thanks in advance.

答:
Try to define a simpleType for weapon like below code:</p>

```<code>    <xs:simpleType name="weapon">
      <xs:restriction base="xs:string">
        <xs:enumeration value="axe" />
        <xs:enumeration value="sword" />
      </xs:restriction>
    </xs:simpleType>
</code>```

Body:
The xsd snippet below states the XML element 'Warrior' should have three attributes, 'Strength', 'Sword' and 'Axe'.

<complexType name="Warrior">
  <complexContent>
    <extension base="Character">
      <sequence>
        <attribute name="Strength" type="integer"/>
        <attribute name="Sword" type="weapon"/>
        <attribute name="Axe" type="weapon"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>

How do I define a 'Warrior' to have a 'Strength' attribute, and EITHER a 'Sword' attribute or an 'Axe' attribute, but not both?

I'm assuming the use of the 'choice' indicator, but I don't know how to structure the complexType to use both the 'choice' and the 'sequence' indicator.

Thanks in advance.

Body:
Try to define a simpleType for weapon like below code:

    <xs:simpleType name="weapon">
      <xs:restriction base="xs:string">
        <xs:enumeration value="axe" />
        <xs:enumeration value="sword" />
      </xs:restriction>
    </xs:simpleType>


问:
Has reCaptcha been cracked / hacked / OCR'd / defeated / broken?
Have any programming methods have been used to defeat reCAPTCHA?

I'm interested in seeing evidence and potentially demonstrations that reCAPTCHA in particular has been made obsolete by completely automated, humanless methods.

To clarify, not looking for reCAPTCHA-cheating solutions that involve humans in any way, whether teams tasked with filling out CAPCHAs, porn-seekers, or Mechanical Turk.

I'm also not looking for alternatives to reCAPTCHA, like picking the type of animal, or background fields or javascript trickery.

答:
My favorite captcha is from Microsoft: http://research.microsoft.com/en-us/um/redmond/projects/asirra/

Asirra (Animal Species Image
  Recognition for Restricting Access)
  is a HIP that works by asking users to identify photographs of cats
  and dogs. This task is difficult for computers, but our user studies
  have shown that people can accomplish it quickly and accurately.
  Many even think it's fun!

It is a free service and they have example code to get you started.

I wonder how long it will be before it is cracked.

OwnerDisplayName: davebug

OwnerDisplayName: BoltBait

LastEditorDisplayName: Patrick McElhaney


问:
GWT and Search Engines
Does GWT app are indexed by search engines???? if yes, how to accomplish that?

Thanks.

答: GWT apps and more generally ajax can't be fully indexed by search engines... yet. But work is being done to make ajax applications crawlable. The most common alternative used by developers to get their gwt app referenced is to publish an html version.</p>

Title: GWT and Search Engines


问:
how to store id or any value in session variable and call session in all pages using ci?
controller: test.php

```<code><?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class Test extends CI_Controller
    {
        function __construct()
        {
            parent :: __construct();
            $this->load->helper(array('form', 'url', 'captcha', 'email'));
            $this->load->model('Fetch_data');
        }
        public function student()
        {
            $this->load->view('student-dashboard/index');
        }
    }
</code>```

view: login.php

```<code><?php
    if($this->input->post('login'))
    {
        $email2 = $this->input->post('email2');
        $password2 = $this->input->post('password2');

        $this->db->select('email,password');
        $this->db->from('students');
        $where = "email='$email2' and password = '$password2'";
        $this->db->where($where);
        $query = $this->db->get();
        $result = $query->result_array();
        $num = $query->num_rows();
        if($num >'0')
        {
            $this->db->select('email,password,student_id');
            $this->db->from('students');
            $where = "email='$email2' and password = '$password2'";
            $this->db->where($where);
            $query = $this->db->get();
            $result = $query->result_array();

            $data['student_id'] = $this->session->set_userdata('student_id',$result);
            if($result == true)
            {
                redirect('/test/student', $data);
            }
        }
        else
        {
            echo "<p style='color: red;font-weight: bold;'>Wrong email id or password! </p>";
        }
    }
?>
<form method="post">
    <div class="form-group">
        <input type="text" name="email2" id="email2" placeholder="Enter Your Email" class="text-line"/>
    </div>
    <div class="form-group">
        <input type="password" name="password2" id="password2" placeholder="Enter Your Password" class="text-line"/>
    </div>
    <div class="form-group">
        <input type="submit" name="login" id="login" value="Login" class="btn btn-warning"/>
    </div>
</form>
</code>```

I am new in codeigniter. In this code I am creating login form and it work perfectly. Now, I want to store student_id into session variable through which I can give welcome message on my all pages. So, How can I do this ? please help me.

Thank You

答:
Change this line

```<code>$data['student_id'] = $this->session->set_userdata('student_id',$result['student_id']);
</code>```

to this one:

```<code>$this->session->set_userdata('student_id',$result['student_id']);
$data['student_id'] = $this->session->userdata('student_id');
</code>```

You have to load session also

```<code>$this->load->library('session');
</code>```

Body:
controller: test.php

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class Test extends CI_Controller
    {
        function __construct()
        {
            parent :: __construct();
            $this->load->helper(array('form', 'url', 'captcha', 'email'));
            $this->load->model('Fetch_data');
        }
        public function student()
        {
            $this->load->view('student-dashboard/index');
        }
    }

view: login.php

<?php
    if($this->input->post('login'))
    {
        $email2 = $this->input->post('email2');
        $password2 = $this->input->post('password2');

        $this->db->select('email,password');
        $this->db->from('students');
        $where = "email='$email2' and password = '$password2'";
        $this->db->where($where);
        $query = $this->db->get();
        $result = $query->result_array();
        $num = $query->num_rows();
        if($num >'0')
        {
            $this->db->select('email,password,student_id');
            $this->db->from('students');
            $where = "email='$email2' and password = '$password2'";
            $this->db->where($where);
            $query = $this->db->get();
            $result = $query->result_array();

            $data['student_id'] = $this->session->set_userdata('student_id',$result);
            if($result == true)
            {
                redirect('/test/student', $data);
            }
        }
        else
        {
            echo "
Wrong email id or password!
";
        }
    }
?>
<form method="post">

        <input type="text" name="email2" id="email2" placeholder="Enter Your Email" class="text-line"/>

        <input type="password" name="password2" id="password2" placeholder="Enter Your Password" class="text-line"/>

        <input type="submit" name="login" id="login" value="Login" class="btn btn-warning"/>

</form>

I am new in codeigniter. In this code I am creating login form and it work perfectly. Now, I want to store student_id into session variable through which I can give welcome message on my all pages. So, How can I do this ? please help me.

Thank You

Body:
Change this line

$data['student_id'] = $this->session->set_userdata('student_id',$result['student_id']);

to this one:

$this->session->set_userdata('student_id',$result['student_id']);
$data['student_id'] = $this->session->userdata('student_id');

You have to load session also

$this->load->library('session');


问:
cl.exe' failed: No such file or directory when installing Scrapy
I'm trying to install Scrapy framework.
After installing all dependent libraries and start installing setup.py file, I get this error message: "cl.exe' failed: No such file or directory"
I'm working with python 3.6, Windows 7 64 bits.
Here is the full error message:

```<code>    copying src\twisted\trial\_dist\test\test_worker.py -> build\lib.win32-3.6\t
wisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\test_workerreporter.py -> build\lib.win
32-3.6\twisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\test_workertrial.py -> build\lib.win32-
3.6\twisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\__init__.py -> build\lib.win32-3.6\twis
ted\trial\_dist\test
    creating build\lib.win32-3.6\twisted\web\test
    copying src\twisted\web\test\requesthelper.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_agent.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_error.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_flatten.py -> build\lib.win32-3.6\twisted\
web\test
    copying src\twisted\web\test\test_http.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_http2.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_httpauth.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_http_headers.py -> build\lib.win32-3.6\twi
sted\web\test
    copying src\twisted\web\test\test_newclient.py -> build\lib.win32-3.6\twiste
d\web\test
    copying src\twisted\web\test\test_proxy.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_resource.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_script.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\test_stan.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_static.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\test_tap.py -> build\lib.win32-3.6\twisted\web\
test
    copying src\twisted\web\test\test_template.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_util.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_vhost.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_web.py -> build\lib.win32-3.6\twisted\web\
test
    copying src\twisted\web\test\test_webclient.py -> build\lib.win32-3.6\twiste
d\web\test
    copying src\twisted\web\test\test_web__responses.py -> build\lib.win32-3.6\t
wisted\web\test
    copying src\twisted\web\test\test_wsgi.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_xmlrpc.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\_util.py -> build\lib.win32-3.6\twisted\web\tes
t
    copying src\twisted\web\test\__init__.py -> build\lib.win32-3.6\twisted\web\
test
    creating build\lib.win32-3.6\twisted\web\_auth
    copying src\twisted\web\_auth\basic.py -> build\lib.win32-3.6\twisted\web\_a
uth
    copying src\twisted\web\_auth\digest.py -> build\lib.win32-3.6\twisted\web\_
auth
    copying src\twisted\web\_auth\wrapper.py -> build\lib.win32-3.6\twisted\web\
_auth
    copying src\twisted\web\_auth\__init__.py -> build\lib.win32-3.6\twisted\web
\_auth
    creating build\lib.win32-3.6\twisted\words\im
    copying src\twisted\words\im\baseaccount.py -> build\lib.win32-3.6\twisted\w
ords\im
    copying src\twisted\words\im\basechat.py -> build\lib.win32-3.6\twisted\word
s\im
    copying src\twisted\words\im\basesupport.py -> build\lib.win32-3.6\twisted\w
ords\im
    copying src\twisted\words\im\interfaces.py -> build\lib.win32-3.6\twisted\wo
rds\im
    copying src\twisted\words\im\ircsupport.py -> build\lib.win32-3.6\twisted\wo
rds\im
    copying src\twisted\words\im\locals.py -> build\lib.win32-3.6\twisted\words\
im
    copying src\twisted\words\im\pbsupport.py -> build\lib.win32-3.6\twisted\wor
ds\im
    copying src\twisted\words\im\__init__.py -> build\lib.win32-3.6\twisted\word
s\im
    creating build\lib.win32-3.6\twisted\words\protocols
    copying src\twisted\words\protocols\irc.py -> build\lib.win32-3.6\twisted\wo
rds\protocols
    copying src\twisted\words\protocols\__init__.py -> build\lib.win32-3.6\twist
ed\words\protocols
    creating build\lib.win32-3.6\twisted\words\test
    copying src\twisted\words\test\test_basechat.py -> build\lib.win32-3.6\twist
ed\words\test
    copying src\twisted\words\test\test_basesupport.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_domish.py -> build\lib.win32-3.6\twisted
\words\test
    copying src\twisted\words\test\test_irc.py -> build\lib.win32-3.6\twisted\wo
rds\test
    copying src\twisted\words\test\test_ircsupport.py -> build\lib.win32-3.6\twi
sted\words\test
    copying src\twisted\words\test\test_irc_service.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_jabberclient.py -> build\lib.win32-3.6\t
wisted\words\test
    copying src\twisted\words\test\test_jabbercomponent.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabbererror.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_jabberjid.py -> build\lib.win32-3.6\twis
ted\words\test
    copying src\twisted\words\test\test_jabberjstrports.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabbersasl.py -> build\lib.win32-3.6\twi
sted\words\test
    copying src\twisted\words\test\test_jabbersaslmechanisms.py -> build\lib.win
32-3.6\twisted\words\test
    copying src\twisted\words\test\test_jabberxmlstream.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabberxmppstringprep.py -> build\lib.win
32-3.6\twisted\words\test
    copying src\twisted\words\test\test_service.py -> build\lib.win32-3.6\twiste
d\words\test
    copying src\twisted\words\test\test_xishutil.py -> build\lib.win32-3.6\twist
ed\words\test
    copying src\twisted\words\test\test_xmlstream.py -> build\lib.win32-3.6\twis
ted\words\test
    copying src\twisted\words\test\test_xmpproutertap.py -> build\lib.win32-3.6\
twisted\words\test
    copying src\twisted\words\test\test_xpath.py -> build\lib.win32-3.6\twisted\
words\test
    copying src\twisted\words\test\__init__.py -> build\lib.win32-3.6\twisted\wo
rds\test
    creating build\lib.win32-3.6\twisted\words\xish
    copying src\twisted\words\xish\domish.py -> build\lib.win32-3.6\twisted\word
s\xish
    copying src\twisted\words\xish\utility.py -> build\lib.win32-3.6\twisted\wor
ds\xish
    copying src\twisted\words\xish\xmlstream.py -> build\lib.win32-3.6\twisted\w
ords\xish
    copying src\twisted\words\xish\xpath.py -> build\lib.win32-3.6\twisted\words
\xish
    copying src\twisted\words\xish\xpathparser.py -> build\lib.win32-3.6\twisted
\words\xish
    copying src\twisted\words\xish\__init__.py -> build\lib.win32-3.6\twisted\wo
rds\xish
    creating build\lib.win32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\client.py -> build\lib.win32-3.6\
twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\component.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\error.py -> build\lib.win32-3.6\t
wisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\ijabber.py -> build\lib.win32-3.6
\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\jid.py -> build\lib.win32-3.6\twi
sted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\jstrports.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\sasl.py -> build\lib.win32-3.6\tw
isted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\sasl_mechanisms.py -> build\lib.w
in32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\xmlstream.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\xmpp_stringprep.py -> build\lib.w
in32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\__init__.py -> build\lib.win32-3.
6\twisted\words\protocols\jabber
    creating build\lib.win32-3.6\twisted\_threads\test
    copying src\twisted\_threads\test\test_convenience.py -> build\lib.win32-3.6
\twisted\_threads\test
    copying src\twisted\_threads\test\test_memory.py -> build\lib.win32-3.6\twis
ted\_threads\test
    copying src\twisted\_threads\test\test_team.py -> build\lib.win32-3.6\twiste
d\_threads\test
    copying src\twisted\_threads\test\test_threadworker.py -> build\lib.win32-3.
6\twisted\_threads\test
    copying src\twisted\_threads\test\__init__.py -> build\lib.win32-3.6\twisted
\_threads\test
    running egg_info
    writing src\Twisted.egg-info\PKG-INFO
    writing dependency_links to src\Twisted.egg-info\dependency_links.txt
    writing entry points to src\Twisted.egg-info\entry_points.txt
    writing requirements to src\Twisted.egg-info\requires.txt
    writing top-level names to src\Twisted.egg-info\top_level.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'src\Twisted.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files matching '*.misc' found under director
y 'src\twisted'
    warning: no previously-included files matching '*.bugfix' found under direct
ory 'src\twisted'
    warning: no previously-included files matching '*.doc' found under directory
 'src\twisted'
    warning: no previously-included files matching '*.feature' found under direc
tory 'src\twisted'
    warning: no previously-included files matching '*.removal' found under direc
tory 'src\twisted'
    warning: no previously-included files matching 'NEWS' found under directory
'src\twisted'
    warning: no previously-included files matching 'README' found under director
y 'src\twisted'
    warning: no previously-included files matching 'topfiles' found under direct
ory 'src\twisted'
    warning: no previously-included files found matching 'src\twisted\topfiles\C
REDITS'
    warning: no previously-included files found matching 'src\twisted\topfiles\C
hangeLog.Old'
    warning: no previously-included files found matching 'codecov.yml'
    warning: no previously-included files found matching 'appveyor.yml'
    no previously-included directories found matching 'bin'
    no previously-included directories found matching 'admin'
    no previously-included directories found matching '.travis'
    warning: no previously-included files found matching 'docs\historic\2003'
    warning: no previously-included files matching '*' found under directory 'do
cs\historic\2003'
    writing manifest file 'src\Twisted.egg-info\SOURCES.txt'
    copying src\twisted\python\_sendmsg.c -> build\lib.win32-3.6\twisted\python
    copying src\twisted\python\twisted-completion.zsh -> build\lib.win32-3.6\twi
sted\python
    creating build\lib.win32-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\common.html -> build\lib.win32
-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\index.html -> build\lib.win32-
3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\summary.html -> build\lib.win3
2-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\runner\portmap.c -> build\lib.win32-3.6\twisted\runner
    copying src\twisted\test\raiser.c -> build\lib.win32-3.6\twisted\test
    copying src\twisted\test\raiser.pyx -> build\lib.win32-3.6\twisted\test
    copying src\twisted\test\server.pem -> build\lib.win32-3.6\twisted\test
    copying src\twisted\internet\iocpreactor\build.bat -> build\lib.win32-3.6\tw
isted\internet\iocpreactor
    copying src\twisted\internet\iocpreactor\notes.txt -> build\lib.win32-3.6\tw
isted\internet\iocpreactor
    creating build\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi -> build\l
ib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\connectex.pxi -> build\
lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\iocpsupport.c -> build\
lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\iocpsupport.pyx -> buil
d\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\winsock_pointers.c -> b
uild\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\winsock_pointers.h -> b
uild\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi -> build\li
b.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi -> build\li
b.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\test\_awaittests.py.3only -> build\lib.win32-3.
6\twisted\internet\test
    copying src\twisted\internet\test\_yieldfromtests.py.3only -> build\lib.win3
2-3.6\twisted\internet\test
    creating build\lib.win32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\chain.pem -> build\lib.win32-3.6\
twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\not-a-certificate -> build\lib.wi
n32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing1.pem -> build\lib.win32-3.6
\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing2-duplicate.pem -> build\lib
.win32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing2.pem -> build\lib.win32-3.6
\twisted\internet\test\fake_CAs
    creating build\lib.win32-3.6\twisted\mail\test
    copying src\twisted\mail\test\rfc822.message -> build\lib.win32-3.6\twisted\
mail\test
    copying src\twisted\words\im\instancemessenger.glade -> build\lib.win32-3.6\
twisted\words\im
    copying src\twisted\words\xish\xpathparser.g -> build\lib.win32-3.6\twisted\
words\xish
    running build_ext
    building 'twisted.test.raiser' extension
    creating build\temp.win32-3.6
    creating build\temp.win32-3.6\Release
    creating build\temp.win32-3.6\Release\src
    creating build\temp.win32-3.6\Release\src\twisted
    creating build\temp.win32-3.6\Release\src\twisted\test
    cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWIN32=1 -Ic:\users\yassine\appd
ata\local\programs\python\python36-32\include -Ic:\users\yassine\appdata\local\p
rograms\python\python36-32\include /Tcsrc/twisted/test/raiser.c /Fobuild\temp.wi
n32-3.6\Release\src/twisted/test/raiser.obj
    error: command 'cl.exe' failed: No such file or directory
</code>```

Maybe the question is not well explained, But I'm here to respond to any question.

答:
I've met the same problem after I installed the latest version of Visual Studio. Here's the solution that worked out in the end:

Visit: http://www.lfd.uci.edu/~gohlke/pythonlibs/

Download the correct version of Twisted and Lxml accordingly (your python version system version).

pip install twisted and lxml before pip install scrapy

Body:
I'm trying to install Scrapy framework.
After installing all dependent libraries and start installing setup.py file, I get this error message: "cl.exe' failed: No such file or directory"
I'm working with python 3.6, Windows 7 64 bits.
Here is the full error message:

    copying src\twisted\trial\_dist\test\test_worker.py -> build\lib.win32-3.6\t
wisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\test_workerreporter.py -> build\lib.win
32-3.6\twisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\test_workertrial.py -> build\lib.win32-
3.6\twisted\trial\_dist\test
    copying src\twisted\trial\_dist\test\__init__.py -> build\lib.win32-3.6\twis
ted\trial\_dist\test
    creating build\lib.win32-3.6\twisted\web\test
    copying src\twisted\web\test\requesthelper.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_agent.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_error.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_flatten.py -> build\lib.win32-3.6\twisted\
web\test
    copying src\twisted\web\test\test_http.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_http2.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_httpauth.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_http_headers.py -> build\lib.win32-3.6\twi
sted\web\test
    copying src\twisted\web\test\test_newclient.py -> build\lib.win32-3.6\twiste
d\web\test
    copying src\twisted\web\test\test_proxy.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_resource.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_script.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\test_stan.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_static.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\test_tap.py -> build\lib.win32-3.6\twisted\web\
test
    copying src\twisted\web\test\test_template.py -> build\lib.win32-3.6\twisted
\web\test
    copying src\twisted\web\test\test_util.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_vhost.py -> build\lib.win32-3.6\twisted\we
b\test
    copying src\twisted\web\test\test_web.py -> build\lib.win32-3.6\twisted\web\
test
    copying src\twisted\web\test\test_webclient.py -> build\lib.win32-3.6\twiste
d\web\test
    copying src\twisted\web\test\test_web__responses.py -> build\lib.win32-3.6\t
wisted\web\test
    copying src\twisted\web\test\test_wsgi.py -> build\lib.win32-3.6\twisted\web
\test
    copying src\twisted\web\test\test_xmlrpc.py -> build\lib.win32-3.6\twisted\w
eb\test
    copying src\twisted\web\test\_util.py -> build\lib.win32-3.6\twisted\web\tes
t
    copying src\twisted\web\test\__init__.py -> build\lib.win32-3.6\twisted\web\
test
    creating build\lib.win32-3.6\twisted\web\_auth
    copying src\twisted\web\_auth\basic.py -> build\lib.win32-3.6\twisted\web\_a
uth
    copying src\twisted\web\_auth\digest.py -> build\lib.win32-3.6\twisted\web\_
auth
    copying src\twisted\web\_auth\wrapper.py -> build\lib.win32-3.6\twisted\web\
_auth
    copying src\twisted\web\_auth\__init__.py -> build\lib.win32-3.6\twisted\web
\_auth
    creating build\lib.win32-3.6\twisted\words\im
    copying src\twisted\words\im\baseaccount.py -> build\lib.win32-3.6\twisted\w
ords\im
    copying src\twisted\words\im\basechat.py -> build\lib.win32-3.6\twisted\word
s\im
    copying src\twisted\words\im\basesupport.py -> build\lib.win32-3.6\twisted\w
ords\im
    copying src\twisted\words\im\interfaces.py -> build\lib.win32-3.6\twisted\wo
rds\im
    copying src\twisted\words\im\ircsupport.py -> build\lib.win32-3.6\twisted\wo
rds\im
    copying src\twisted\words\im\locals.py -> build\lib.win32-3.6\twisted\words\
im
    copying src\twisted\words\im\pbsupport.py -> build\lib.win32-3.6\twisted\wor
ds\im
    copying src\twisted\words\im\__init__.py -> build\lib.win32-3.6\twisted\word
s\im
    creating build\lib.win32-3.6\twisted\words\protocols
    copying src\twisted\words\protocols\irc.py -> build\lib.win32-3.6\twisted\wo
rds\protocols
    copying src\twisted\words\protocols\__init__.py -> build\lib.win32-3.6\twist
ed\words\protocols
    creating build\lib.win32-3.6\twisted\words\test
    copying src\twisted\words\test\test_basechat.py -> build\lib.win32-3.6\twist
ed\words\test
    copying src\twisted\words\test\test_basesupport.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_domish.py -> build\lib.win32-3.6\twisted
\words\test
    copying src\twisted\words\test\test_irc.py -> build\lib.win32-3.6\twisted\wo
rds\test
    copying src\twisted\words\test\test_ircsupport.py -> build\lib.win32-3.6\twi
sted\words\test
    copying src\twisted\words\test\test_irc_service.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_jabberclient.py -> build\lib.win32-3.6\t
wisted\words\test
    copying src\twisted\words\test\test_jabbercomponent.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabbererror.py -> build\lib.win32-3.6\tw
isted\words\test
    copying src\twisted\words\test\test_jabberjid.py -> build\lib.win32-3.6\twis
ted\words\test
    copying src\twisted\words\test\test_jabberjstrports.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabbersasl.py -> build\lib.win32-3.6\twi
sted\words\test
    copying src\twisted\words\test\test_jabbersaslmechanisms.py -> build\lib.win
32-3.6\twisted\words\test
    copying src\twisted\words\test\test_jabberxmlstream.py -> build\lib.win32-3.
6\twisted\words\test
    copying src\twisted\words\test\test_jabberxmppstringprep.py -> build\lib.win
32-3.6\twisted\words\test
    copying src\twisted\words\test\test_service.py -> build\lib.win32-3.6\twiste
d\words\test
    copying src\twisted\words\test\test_xishutil.py -> build\lib.win32-3.6\twist
ed\words\test
    copying src\twisted\words\test\test_xmlstream.py -> build\lib.win32-3.6\twis
ted\words\test
    copying src\twisted\words\test\test_xmpproutertap.py -> build\lib.win32-3.6\
twisted\words\test
    copying src\twisted\words\test\test_xpath.py -> build\lib.win32-3.6\twisted\
words\test
    copying src\twisted\words\test\__init__.py -> build\lib.win32-3.6\twisted\wo
rds\test
    creating build\lib.win32-3.6\twisted\words\xish
    copying src\twisted\words\xish\domish.py -> build\lib.win32-3.6\twisted\word
s\xish
    copying src\twisted\words\xish\utility.py -> build\lib.win32-3.6\twisted\wor
ds\xish
    copying src\twisted\words\xish\xmlstream.py -> build\lib.win32-3.6\twisted\w
ords\xish
    copying src\twisted\words\xish\xpath.py -> build\lib.win32-3.6\twisted\words
\xish
    copying src\twisted\words\xish\xpathparser.py -> build\lib.win32-3.6\twisted
\words\xish
    copying src\twisted\words\xish\__init__.py -> build\lib.win32-3.6\twisted\wo
rds\xish
    creating build\lib.win32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\client.py -> build\lib.win32-3.6\
twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\component.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\error.py -> build\lib.win32-3.6\t
wisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\ijabber.py -> build\lib.win32-3.6
\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\jid.py -> build\lib.win32-3.6\twi
sted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\jstrports.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\sasl.py -> build\lib.win32-3.6\tw
isted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\sasl_mechanisms.py -> build\lib.w
in32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\xmlstream.py -> build\lib.win32-3
.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\xmpp_stringprep.py -> build\lib.w
in32-3.6\twisted\words\protocols\jabber
    copying src\twisted\words\protocols\jabber\__init__.py -> build\lib.win32-3.
6\twisted\words\protocols\jabber
    creating build\lib.win32-3.6\twisted\_threads\test
    copying src\twisted\_threads\test\test_convenience.py -> build\lib.win32-3.6
\twisted\_threads\test
    copying src\twisted\_threads\test\test_memory.py -> build\lib.win32-3.6\twis
ted\_threads\test
    copying src\twisted\_threads\test\test_team.py -> build\lib.win32-3.6\twiste
d\_threads\test
    copying src\twisted\_threads\test\test_threadworker.py -> build\lib.win32-3.
6\twisted\_threads\test
    copying src\twisted\_threads\test\__init__.py -> build\lib.win32-3.6\twisted
\_threads\test
    running egg_info
    writing src\Twisted.egg-info\PKG-INFO
    writing dependency_links to src\Twisted.egg-info\dependency_links.txt
    writing entry points to src\Twisted.egg-info\entry_points.txt
    writing requirements to src\Twisted.egg-info\requires.txt
    writing top-level names to src\Twisted.egg-info\top_level.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'src\Twisted.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files matching '*.misc' found under director
y 'src\twisted'
    warning: no previously-included files matching '*.bugfix' found under direct
ory 'src\twisted'
    warning: no previously-included files matching '*.doc' found under directory
 'src\twisted'
    warning: no previously-included files matching '*.feature' found under direc
tory 'src\twisted'
    warning: no previously-included files matching '*.removal' found under direc
tory 'src\twisted'
    warning: no previously-included files matching 'NEWS' found under directory
'src\twisted'
    warning: no previously-included files matching 'README' found under director
y 'src\twisted'
    warning: no previously-included files matching 'topfiles' found under direct
ory 'src\twisted'
    warning: no previously-included files found matching 'src\twisted\topfiles\C
REDITS'
    warning: no previously-included files found matching 'src\twisted\topfiles\C
hangeLog.Old'
    warning: no previously-included files found matching 'codecov.yml'
    warning: no previously-included files found matching 'appveyor.yml'
    no previously-included directories found matching 'bin'
    no previously-included directories found matching 'admin'
    no previously-included directories found matching '.travis'
    warning: no previously-included files found matching 'docs\historic\2003'
    warning: no previously-included files matching '*' found under directory 'do
cs\historic\2003'
    writing manifest file 'src\Twisted.egg-info\SOURCES.txt'
    copying src\twisted\python\_sendmsg.c -> build\lib.win32-3.6\twisted\python
    copying src\twisted\python\twisted-completion.zsh -> build\lib.win32-3.6\twi
sted\python
    creating build\lib.win32-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\common.html -> build\lib.win32
-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\index.html -> build\lib.win32-
3.6\twisted\python\_pydoctortemplates
    copying src\twisted\python\_pydoctortemplates\summary.html -> build\lib.win3
2-3.6\twisted\python\_pydoctortemplates
    copying src\twisted\runner\portmap.c -> build\lib.win32-3.6\twisted\runner
    copying src\twisted\test\raiser.c -> build\lib.win32-3.6\twisted\test
    copying src\twisted\test\raiser.pyx -> build\lib.win32-3.6\twisted\test
    copying src\twisted\test\server.pem -> build\lib.win32-3.6\twisted\test
    copying src\twisted\internet\iocpreactor\build.bat -> build\lib.win32-3.6\tw
isted\internet\iocpreactor
    copying src\twisted\internet\iocpreactor\notes.txt -> build\lib.win32-3.6\tw
isted\internet\iocpreactor
    creating build\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi -> build\l
ib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\connectex.pxi -> build\
lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\iocpsupport.c -> build\
lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\iocpsupport.pyx -> buil
d\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\winsock_pointers.c -> b
uild\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\winsock_pointers.h -> b
uild\lib.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi -> build\li
b.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi -> build\li
b.win32-3.6\twisted\internet\iocpreactor\iocpsupport
    copying src\twisted\internet\test\_awaittests.py.3only -> build\lib.win32-3.
6\twisted\internet\test
    copying src\twisted\internet\test\_yieldfromtests.py.3only -> build\lib.win3
2-3.6\twisted\internet\test
    creating build\lib.win32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\chain.pem -> build\lib.win32-3.6\
twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\not-a-certificate -> build\lib.wi
n32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing1.pem -> build\lib.win32-3.6
\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing2-duplicate.pem -> build\lib
.win32-3.6\twisted\internet\test\fake_CAs
    copying src\twisted\internet\test\fake_CAs\thing2.pem -> build\lib.win32-3.6
\twisted\internet\test\fake_CAs
    creating build\lib.win32-3.6\twisted\mail\test
    copying src\twisted\mail\test\rfc822.message -> build\lib.win32-3.6\twisted\
mail\test
    copying src\twisted\words\im\instancemessenger.glade -> build\lib.win32-3.6\
twisted\words\im
    copying src\twisted\words\xish\xpathparser.g -> build\lib.win32-3.6\twisted\
words\xish
    running build_ext
    building 'twisted.test.raiser' extension
    creating build\temp.win32-3.6
    creating build\temp.win32-3.6\Release
    creating build\temp.win32-3.6\Release\src
    creating build\temp.win32-3.6\Release\src\twisted
    creating build\temp.win32-3.6\Release\src\twisted\test
    cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWIN32=1 -Ic:\users\yassine\appd
ata\local\programs\python\python36-32\include -Ic:\users\yassine\appdata\local\p
rograms\python\python36-32\include /Tcsrc/twisted/test/raiser.c /Fobuild\temp.wi
n32-3.6\Release\src/twisted/test/raiser.obj
    error: command 'cl.exe' failed: No such file or directory

Maybe the question is not well explained, But I'm here to respond to any question.


问:
Two Sites or One Site When building a CMS Type Application
I'm building a site which mainly has articles and I'm using ASP.NET MVC 5 framework. I want to have an admin page where I can add, edit these article content.

I'm building one site for both content management(Add articles) and display content(Display articles).

Are there any disadvantages with this approach? (Do I have to build one site for content management and another site to display content?)

答: Creating a separate project for the administration portal is valid if you have a security policy implying that administration pages must be only accessible by operations team over VPN or from intranet (not exposed to the internet). Otherwise, it is valid to have them hosted on the same site.</p>


问:
Howto call a Function from another class in TypeScript
I'd like to call the method refreshMe () from the home.ts. But I get the message that it is not in the typeof.

Here is what i've tried:

=> settings.ts

```<code>import { HomePage } from '../home/home'
</code>```

[...]

```<code>HomePage.refreshMe();
</code>```

=> home.ts

```<code>refreshMe() {
      this.navCtrl.setRoot(this.navCtrl.getActive().component);
    }
</code>```

Here again the exact error message:

Property 'refreshMe' does not exist on type 'typeof HomePage'.

答:
UPDATED

Try something like this,

create a provider with ionic cli using the command,

```<code>ionic g provider providerName
</code>```

now put your refreshMe() function inside the provider so that you can import the provider and use the refreshMe function wherever you want like this

```<code>import { NewProvider } from '../home/home'

constructor(public myProvider: NewProvider ){
   myProvider.refreshMe();
}
</code>```

Body:
I'd like to call the method refreshMe () from the home.ts. But I get the message that it is not in the typeof.

Here is what i've tried:

=> settings.ts

import { HomePage } from '../home/home'

[...]

HomePage.refreshMe();

=> home.ts

refreshMe() {
      this.navCtrl.setRoot(this.navCtrl.getActive().component);
    }

Here again the exact error message:

Property 'refreshMe' does not exist on type 'typeof HomePage'.

Body:
UPDATED

Try something like this,

create a provider with ionic cli using the command,

ionic g provider providerName

now put your refreshMe() function inside the provider so that you can import the provider and use the refreshMe function wherever you want like this

import { NewProvider } from '../home/home'

constructor(public myProvider: NewProvider ){
   myProvider.refreshMe();
}


问:
Setting readonly using ng-readonly dynamically is not working
I am fetching some data from the database server and displaying the same in tabular format on my GUI. I want to achieve the following in my GUI design

(a) Any cell in the table should be editable except the first column in the table.
(b) The first row of the table, if added newly to the GUI for accepting new inputs from the user, should be exempted from the above rule i.e., all columns of the first row should be editable.

To achieve this I wrote the following code.

HTML Code

```<code>    <tbody>
           <tr ng-repeat="x in sensordata">
           <td>
             <input class="form-control" type="text" ng-model="x.name" placeholder="Sensor name" ng-readonly="namereadonly" ng-init="ctrl2.setReadOnly(x.name,$index)"/>
           </td>
           <td>
              <input class="form-control" type="text" ng-model="x.unit" placeholder="Measurement Unit" required/>
           </td>
           <td>
                <input class="form-control" type="text" ng-model="x.type" placeholder="Sensor Type" required/>
           </td>
           <td>
                <input class="form-control" type="text" ng-model="x.periodicity" placeholder="Periodicity" required/>
           </td>
           <td>
                <input class="form-control" type="text" ng-model="x.formula" placeholder="Formula" required/>
           </td>
           <td>
               <input class="form-control" type="email" ng-model="x.vendor" placeholder="Email Id" required/>
           </td>
           </tr>
   </tbody>
</code>```

Controller code is as follows.

```<code>this.setReadOnly = function(name,idx) {
        console.log('name ' + name + ' idx ' + idx);
        if (name === undefined || name === null || name === '') $scope.namereadonly = false;
        if (name !== '' || name !== undefined || name !== null) $scope.namereadonly = true;
    };
</code>```

When I am executing above code the first column of all the rows are getting uneditable as expected. But when I am adding new row to the (by adding new empty JSON object in the sensordata array in another function of the same controller) GUI, the first column of the row is getting uneditable which should not be the case as per the first if statement in the above method. I am unable to figure out why it is happening.

答:
you can put the condition directly in ng-readonly as below</p>

```<code>   <input class="form-control" type="text" ng-model="x.name" placeholder="Sensor name" ng-readonly="{{x.name !== '' && x.name !== undefined && x.name !== null}}" />
</code>```

Body:
I am fetching some data from the database server and displaying the same in tabular format on my GUI. I want to achieve the following in my GUI design

(a) Any cell in the table should be editable except the first column in the table.
(b) The first row of the table, if added newly to the GUI for accepting new inputs from the user, should be exempted from the above rule i.e., all columns of the first row should be editable.

To achieve this I wrote the following code.

HTML Code

             <input class="form-control" type="text" ng-model="x.name" placeholder="Sensor name" ng-readonly="namereadonly" ng-init="ctrl2.setReadOnly(x.name,$index)"/>

              <input class="form-control" type="text" ng-model="x.unit" placeholder="Measurement Unit" required/>

                <input class="form-control" type="text" ng-model="x.type" placeholder="Sensor Type" required/>

                <input class="form-control" type="text" ng-model="x.periodicity" placeholder="Periodicity" required/>

                <input class="form-control" type="text" ng-model="x.formula" placeholder="Formula" required/>

               <input class="form-control" type="email" ng-model="x.vendor" placeholder="Email Id" required/>

Controller code is as follows.

this.setReadOnly = function(name,idx) {
        console.log('name ' + name + ' idx ' + idx);
        if (name === undefined || name === null || name === '') $scope.namereadonly = false;
        if (name !== '' || name !== undefined || name !== null) $scope.namereadonly = true;
    };

When I am executing above code the first column of all the rows are getting uneditable as expected. But when I am adding new row to the (by adding new empty JSON object in the sensordata array in another function of the same controller) GUI, the first column of the row is getting uneditable which should not be the case as per the first if statement in the above method. I am unable to figure out why it is happening.

Body:
you can put the condition directly in ng-readonly as below

   <input class="form-control" type="text" ng-model="x.name" placeholder="Sensor name" ng-readonly="{{x.name !== '' && x.name !== undefined && x.name !== null}}" />


问:
Can I cancel the method "applicationDidEnterBackground?
I wanted to cancel the method, to request a confirmation from the user when he presses the button "HOME" where on iPhone would go into the execution in background.

If the user accepts, enters into the execution in background, if not accept, I do not do anything.

I looked in the FORUM, in the documentation from Apple and I found nothing.

Could anyone help me?

Thanks in advance!

答:
No, you can't override the operating system or the user's button press.

If the user presses the button to send the app into the background, the app goes into the background.


问:
How to set up admin-on-rest with couchDB?
Edit to the makers of AoR : Your framework suffers from horrid documentation. You should really focus on that, people would really adopt it then.

I cant for the life of me decipher how admin-on-rest does the 'rest' part. If there is a better framework with better documentation, Im open to that.

Im very new to react, so thats probably part of it.

What I can discern is that

1) The [Admin] tag takes a prop 'restClient', and this is a function that sets your base path to your JSON source, then returns a function with a specific signature (takes 3 arguments, returns a promise).

2) Then a [Resource] tag adds to the path with name="posts" and makes a list, which (heres where it turns to magic) basically does a wget to your database then iterates over the results.

What I want to do : hook up couchDB to admin-on-rest. I already have a few test docs made on localhost. The couchDB url looks like :

http://127.0.0.1:5984/myproject/_design/getclients/_view/getclient/

and this works in postman, giving me a json object like this :

```<code>{
"total_rows": 4,
"offset": 0,
"rows": [
    {
        "id": "afc3bb9218d1a5c1e81ab3cc9f004467",
        "key": {
            "status": "active",
            "rating": 9.1,
            "bio": {
                "fname": "Sam",
                "mname": "TestMName",
                "lname": "TestLName",
                "address": "712347 B Street",
                "state": "CA",
                "city": "Los Santos",
                "zip": "90211",
                "phone": "123-456-7890",
                "email": "sam@samsemail.com",
                "username": "TestSam",
                "password": "abc123"
            }
        },
        "value": null
    },
</code>```

At this point Im so confused I dont know where to look.

Heres my code now :

```<code>//App.js

import React from 'react';
import { jsonServerRestClient, Admin, Resource } from 'admin-on-rest';

import { PostList } from './Posts.js';

const App = () => (

    <Admin restClient={jsonServerRestClient('http://127.0.0.1:5984/myproject/')}>
        <Resource name="_design/getclients/_view/getclient" list={PostList} />
    </Admin>
);

export default App;
</code>```

And

```<code>//Posts.js
export const PostList = (props) => (
    <List {...props}>
        <Datagrid>
            <TextField source="status" />
            <TextField source="rating" />
        </Datagrid>
    </List>
);
</code>```

The page loads but a little pink box pops up at the bottom saying :

```<code>The X-Total-Count header is missing in the HTTP Response. The jsonServer REST client expects responses
</code>```

答:
The RestClient is a bit of a murky beast. Not perfectly documented for sure.

But it is in the end quite straightforward if you know how the whole thing works together.

1) Admin-On-Rest has defined some REST types (below). These are usually shot off by Redux actions (in their meta tag). The system scans for these rest types and if it sees them, then it calls the RestClient

GET_LIST

GET_ONE
CREATE

UPDATE

DELETE

GET_MANY
GET_MANY_REFERENCE

The REST client is called with these types and some other params. It is the job of the rest client to interpret the type and then use the params to make a request to your API. For this AOR uses the new Fetch API that is built into browsers.

You can access it by calling. You should also go into AOR source code and check out how it works.

```<code>import { fetchUtils } from 'admin-on-rest';
</code>```

2) The X total count is a header field that AOR needs for all responses to the GET_LIST type.
You can set this quite simply in your API. I use loopback and I set the X-Total-Count manually in a remote hook (don't worry about it if you don't know it)
It seems your api is still using the JSON server. JSON server is a dummy API. So your app is not connected to your couchDB right now.

https://github.com/typicode/json-server

If you are not using an api server like express or loopback, then you can also configure your restClient do all request and response handling. You have to construct the URL. Read the below link so you can follow my example code further down.

https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload

so something like this.

```<code>    if (type === 'GET_LIST' && resource === 'posts') {
const url = http://127.0.0.1:5984/myproject/_design/getclients/_view/getclient/
        options.method = 'GET';
        return fetchUtils.fetchJson(url, options)
          .then((response) => {
            const {headers, json} = response;
            //admin on rest needs the {data} key
            return {data: json,
                    total: parseInt(headers.get('x-total-count').split('/').pop(), 10)}

    })
</code>```

You can also write a function like this to handle the request and response.

```<code>function handleRequestAndResponse(url, options={}) {
  return fetchUtils.fetchJson(url, options)
    .then((response) => {
      const {headers, json} = response;
      //admin on rest needs the {data} key
      const data = {data: json}
      if (headers.get('x-total-count')) {
        data.total = parseInt(headers.get('x-total-count').split('/').pop(), 10)
      } else {
        data.total = json.length // this is why the X-Total-Count is needed by Aor

}
}
      }
      // handle get_list responses
        return {data: json,
                total: } else {
        return data
      }
  })
}
</code>```

The above code has been formatted in the window and so might not work straight out of the box. But I hope you get the idea.

Body:
Edit to the makers of AoR : Your framework suffers from horrid documentation. You should really focus on that, people would really adopt it then.

I cant for the life of me decipher how admin-on-rest does the 'rest' part. If there is a better framework with better documentation, Im open to that.

Im very new to react, so thats probably part of it.

What I can discern is that

1) The [Admin] tag takes a prop 'restClient', and this is a function that sets your base path to your JSON source, then returns a function with a specific signature (takes 3 arguments, returns a promise).

2) Then a [Resource] tag adds to the path with name="posts" and makes a list, which (heres where it turns to magic) basically does a wget to your database then iterates over the results.

What I want to do : hook up couchDB to admin-on-rest. I already have a few test docs made on localhost. The couchDB url looks like :

http://127.0.0.1:5984/myproject/_design/getclients/_view/getclient/

and this works in postman, giving me a json object like this :

{
"total_rows": 4,
"offset": 0,
"rows": [
    {
        "id": "afc3bb9218d1a5c1e81ab3cc9f004467",
        "key": {
            "status": "active",
            "rating": 9.1,
            "bio": {
                "fname": "Sam",
                "mname": "TestMName",
                "lname": "TestLName",
                "address": "712347 B Street",
                "state": "CA",
                "city": "Los Santos",
                "zip": "90211",
                "phone": "123-456-7890",
                "email": "sam@samsemail.com",
                "username": "TestSam",
                "password": "abc123"
            }
        },
        "value": null
    },

At this point Im so confused I dont know where to look.

Heres my code now :

//App.js

import React from 'react';
import { jsonServerRestClient, Admin, Resource } from 'admin-on-rest';

import { PostList } from './Posts.js';

const App = () => (

    <Admin restClient={jsonServerRestClient('http://127.0.0.1:5984/myproject/')}>
        <Resource name="_design/getclients/_view/getclient" list={PostList} />
    </Admin>
);

export default App;

And

//Posts.js
export const PostList = (props) => (
    <List {...props}>
        <Datagrid>
            <TextField source="status" />
            <TextField source="rating" />
        </Datagrid>
    </List>
);

The page loads but a little pink box pops up at the bottom saying :

The X-Total-Count header is missing in the HTTP Response. The jsonServer REST client expects responses

Body:
The RestClient is a bit of a murky beast. Not perfectly documented for sure.

But it is in the end quite straightforward if you know how the whole thing works together.

1) Admin-On-Rest has defined some REST types (below). These are usually shot off by Redux actions (in their meta tag). The system scans for these rest types and if it sees them, then it calls the RestClient

GET_LIST

GET_ONE
CREATE

UPDATE

DELETE

GET_MANY
GET_MANY_REFERENCE

The REST client is called with these types and some other params. It is the job of the rest client to interpret the type and then use the params to make a request to your API. For this AOR uses the new Fetch API that is built into browsers.

You can access it by calling. You should also go into AOR source code and check out how it works.

import { fetchUtils } from 'admin-on-rest';

2) The X total count is a header field that AOR needs for all responses to the GET_LIST type.
You can set this quite simply in your API. I use loopback and I set the X-Total-Count manually in a remote hook (don't worry about it if you don't know it)
It seems your api is still using the JSON server. JSON server is a dummy API. So your app is not connected to your couchDB right now.

https://github.com/typicode/json-server

If you are not using an api server like express or loopback, then you can also configure your restClient do all request and response handling. You have to construct the URL. Read the below link so you can follow my example code further down.

https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload

so something like this.

    if (type === 'GET_LIST' && resource === 'posts') {
const url = http://127.0.0.1:5984/myproject/_design/getclients/_view/getclient/
        options.method = 'GET';
        return fetchUtils.fetchJson(url, options)
          .then((response) => {
            const {headers, json} = response;
            //admin on rest needs the {data} key
            return {data: json,
                    total: parseInt(headers.get('x-total-count').split('/').pop(), 10)}

    })

You can also write a function like this to handle the request and response.

function handleRequestAndResponse(url, options={}) {
  return fetchUtils.fetchJson(url, options)
    .then((response) => {
      const {headers, json} = response;
      //admin on rest needs the {data} key
      const data = {data: json}
      if (headers.get('x-total-count')) {
        data.total = parseInt(headers.get('x-total-count').split('/').pop(), 10)
      } else {
        data.total = json.length // this is why the X-Total-Count is needed by Aor

}
}
      }
      // handle get_list responses
        return {data: json,
                total: } else {
        return data
      }
  })
}

The above code has been formatted in the window and so might not work straight out of the box. But I hope you get the idea.


问:
RegEx for alphanumeric and some certain special characters
I am trying to allow English alphabets, numeric values  and the following characters only:

- # $ % & * ( ) [ ] , . / - _ +

I have managed to come up with the following code

```<code><form id="accountForm" action="">
   <input type="text" name="my_input">
</form>

$(function() {

    $.validator.addMethod("accept", function(value, element, param) {
        return value.match(new RegExp("." + param + "$"));
    }, 'Only English is allowed');

    $( "#accountForm" ).validate({
        rules: {
            my_input : {
                required: true,
                accept: '[a-zA-Z0-9@%#&()/+*$,._\\-]+$'
            }

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

But there are some problems :

If I try to add [ ] the code completely stops working

If I add other characters that or not in the list above, after any alphabets it does not show any error message. Example : ABC你好

If I enter just a letter it gives an error.

Here's a demo of my code: https://jsfiddle.net/w2p1rdbd/1/

Could you please show me how to fix this?

Thank you very much!

答:
First of all, note that JavaScript has a regular expression type, so regular expressions can be specified as a language element do not need to be specified as a string, which does save you a couple of escape sequences and also your syntax highlighting can help you better.

Then you are doing this_

"." + param + "$"
```

<p>This will change your regular expression. The dot means that an additional character of any class is matched at the beginning. Hence a single character won't match at all, you'll need to characters to match and the second charachter must be of the class you specified. Then you also append the <code>$</code> at the end. You also have that character in your original expression: <code>'[a-zA-Z0-9@%#&()/+*$,._\\-]+$'</code>, so now you got it twice. However one of them is ignored, so while this is not helpful, it is no harm. Probably you meant to use <code>"^" + param + "$"</code>, because that would mean "match from the beginning (<code>^</code>) to the end (<code>$</code>), but then you should not include these in both your variable expression and your function.</p>

<p>Then there is the issue of the <code>[]</code>. You simply need to escape them in the regex. But you ALSO need to escape them for the string, and then you need to escape the regex escape sequence for the string. So quite a lot of escapes. Note also that this applies to the dash, but the problem with the dash is ignores as long as it is the last part of the <code>[]</code> sequence. So finally your regex needs to be <code>"^[a-zA-Z0-9@%#&()/+*$,._\\-\\[\\]]+$"</code>. (The escape for the opening <code>[</code> is optional)</p>

<p>However if you use a literal, then you can just write <code>/^[a-zA-Z0-9@%#&()/+*$,._\-\[\]]+$/</code>, which is less escape sequences. In total that would be the result:</p>

<pre class="lang-javascript prettyprint-override"><code>$(function() {
    $.validator.addMethod("accept", function(value, element, param) {
        return param.test(value);
    }, 'Only English is allowed');

    $( "#accountForm" ).validate({
        rules: {
            my_input : {
                required: true,
                accept: /^[a-zA-Z0-9@%#&()/+*$,._\-\[\]]+$/
            }
        }
    });
});
</code>```

Body:
I am trying to allow English alphabets, numeric values  and the following characters only:

- # $ % & * ( ) [ ] , . / - _ +

I have managed to come up with the following code

<form id="accountForm" action="">
   <input type="text" name="my_input">
</form>

$(function() {

    $.validator.addMethod("accept", function(value, element, param) {
        return value.match(new RegExp("." + param + "$"));
    }, 'Only English is allowed');

    $( "#accountForm" ).validate({
        rules: {
            my_input : {
                required: true,
                accept: '[a-zA-Z0-9@%#&()/+*$,._\\-]+$'
            }

        }
    });
 });

But there are some problems :

If I try to add [ ] the code completely stops working

If I add other characters that or not in the list above, after any alphabets it does not show any error message. Example : ABC你好

If I enter just a letter it gives an error.

Here's a demo of my code: https://jsfiddle.net/w2p1rdbd/1/

Could you please show me how to fix this?

Thank you very much!

Body:
First of all, note that JavaScript has a regular expression type, so regular expressions can be specified as a language element do not need to be specified as a string, which does save you a couple of escape sequences and also your syntax highlighting can help you better.

Then you are doing this_

"." + param + "$"

This will change your regular expression. The dot means that an additional character of any class is matched at the beginning. Hence a single character won't match at all, you'll need to characters to match and the second charachter must be of the class you specified. Then you also append the $ at the end. You also have that character in your original expression: '[a-zA-Z0-9@%#&()/+*$,._\\-]+$', so now you got it twice. However one of them is ignored, so while this is not helpful, it is no harm. Probably you meant to use "^" + param + "$", because that would mean "match from the beginning (^) to the end ($), but then you should not include these in both your variable expression and your function.

Then there is the issue of the []. You simply need to escape them in the regex. But you ALSO need to escape them for the string, and then you need to escape the regex escape sequence for the string. So quite a lot of escapes. Note also that this applies to the dash, but the problem with the dash is ignores as long as it is the last part of the [] sequence. So finally your regex needs to be "^[a-zA-Z0-9@%#&()/+*$,._\\-\\[\\]]+$". (The escape for the opening [ is optional)

However if you use a literal, then you can just write /^[a-zA-Z0-9@%#&()/+*$,._\-\[\]]+$/, which is less escape sequences. In total that would be the result:

$(function() {
    $.validator.addMethod("accept", function(value, element, param) {
        return param.test(value);
    }, 'Only English is allowed');

    $( "#accountForm" ).validate({
        rules: {
            my_input : {
                required: true,
                accept: /^[a-zA-Z0-9@%#&()/+*$,._\-\[\]]+$/
            }
        }
    });
});