问:
Java - Converting Defined Intergers to Name Value
Not sure how to phrase that but I have this:

In a

```<code>public class DefinedValues{
public static final int CommandGroupLength = 0x00000001;
}
</code>```

I want a way of getting the String "CommandGroupLength" from value 0x00000001;

Is that possible?

答:
do you want to access the name of the variable that has the value 0x00000001? than this is not possible:

```<code>public class DefinedValues {
  public static final int CommandGroupLength = 0x00000001;
}
</code>```

with Java8 it is technically possible to at least get the name of a variable via reflection, see Java Reflection: How to get the name of a variable?

you can achieve the same thing much easier with a Map, which contains Key-Value-Pairs.

```<code>Map<String,Integer> myMap= new HashMap<>();
myMap.put("CommandGroupLength", 0x00000001);
</code>```

then you write a function which searches in the entrySet of the Map for all keys that have that value, since it is not ensured there is only one, it'll need to return a Collection or Array or something similar.
here's my code:

```<code>public static void main(String[] args) {
  Map<String,Integer> myMap = new HashMap<>();
  myMap.put("CommandGroupLength", 0x00000001);
  myMap.put("testA", 5);
  myMap.put("testB", 12);
  myMap.put("testC", 42);

  System.out.println("Searching for value 0x00000001 in myMap");
  Set<String> searchResults = findKeyByValue(myMap, 0x00000001);
  System.out.println("I found the following keys:");
  boolean isFirst = true;
  for(String result : searchResults) {
    if(isFirst)
      isFirst = false;
    else
      System.out.printf(", ");

    System.out.printf("%s", result);
  }
}

public static Set<String> findKeyByValue(Map<String, Integer> map, Integer value) {
  Set<String> result = new HashSet<>();

  if(value != null) {
    Set<Entry<String, Integer>> entrySet = map.entrySet();

    for(Entry<String, Integer> entry : entrySet) {
      if(value.equals(entry.getValue())) {
        result.add(entry.getKey());
      }
    }
  }

  return result;
}
</code>```

Body:
Not sure how to phrase that but I have this:

In a

public class DefinedValues{
public static final int CommandGroupLength = 0x00000001;
}

I want a way of getting the String "CommandGroupLength" from value 0x00000001;

Is that possible?

Body:
do you want to access the name of the variable that has the value 0x00000001? than this is not possible:

public class DefinedValues {
  public static final int CommandGroupLength = 0x00000001;
}

with Java8 it is technically possible to at least get the name of a variable via reflection, see Java Reflection: How to get the name of a variable?

you can achieve the same thing much easier with a Map, which contains Key-Value-Pairs.

Map<String,Integer> myMap= new HashMap<>();
myMap.put("CommandGroupLength", 0x00000001);

then you write a function which searches in the entrySet of the Map for all keys that have that value, since it is not ensured there is only one, it'll need to return a Collection or Array or something similar.
here's my code:

public static void main(String[] args) {
  Map<String,Integer> myMap = new HashMap<>();
  myMap.put("CommandGroupLength", 0x00000001);
  myMap.put("testA", 5);
  myMap.put("testB", 12);
  myMap.put("testC", 42);

  System.out.println("Searching for value 0x00000001 in myMap");
  Set<String> searchResults = findKeyByValue(myMap, 0x00000001);
  System.out.println("I found the following keys:");
  boolean isFirst = true;
  for(String result : searchResults) {
    if(isFirst)
      isFirst = false;
    else
      System.out.printf(", ");

    System.out.printf("%s", result);
  }
}

public static Set<String> findKeyByValue(Map<String, Integer> map, Integer value) {
  Set<String> result = new HashSet<>();

  if(value != null) {
    Set<Entry<String, Integer>> entrySet = map.entrySet();

    for(Entry<String, Integer> entry : entrySet) {
      if(value.equals(entry.getValue())) {
        result.add(entry.getKey());
      }
    }
  }

  return result;
}


来源: stackexchange

问:
change active menu-items font on click
So, i've got this menu which is linked to some dynamically displayed content, I've been trying to write some js-code that changes the font of the currently active item. My problem is now that it never deselects that item if it isn't active anymore.

jsfiddle:

https://jsfiddle.net/z4uhL5wv/2/

jquery:

```<code>$(document).ready(function() {

  $("a.menu2").click(function(e) {
  $('.ShowClickedContent').html($($(this).attr('href')).html()); //dynamic content
  var clicks = 0;

      if(clicks % 2 == 0){
          $(this).css('font-family','gillsans');
      }else{
          $(this).css('font-family','gillsanslight');
      }
      ++clicks;

});

});
</code>```

Any help would be greatful. Note: i need to use that exact showClickedContent query in the final solution due to problems arising with margin otherwise.

答:
https://jsfiddle.net/ynrnt6xL/</p>

```<code>$(document).ready(function() {

  const buttons = $('.menu2');
  const clear = function() {
    $.each( buttons, function(index, btn) {
        $(btn).removeClass('selected');
    })
  }

    $.each( buttons, function(index, btn) {
    $(btn).click( function(e) {
        clear();
      $(this).addClass('selected');
    });
  });

});
</code>```

ContentLicense: CC BY-SA 3.0

Title: change active menu-items font on click

Body:
So, i've got this menu which is linked to some dynamically displayed content, I've been trying to write some js-code that changes the font of the currently active item. My problem is now that it never deselects that item if it isn't active anymore.

jsfiddle:

https://jsfiddle.net/z4uhL5wv/2/

jquery:

$(document).ready(function() {

  $("a.menu2").click(function(e) {
  $('.ShowClickedContent').html($($(this).attr('href')).html()); //dynamic content
  var clicks = 0;

      if(clicks % 2 == 0){
          $(this).css('font-family','gillsans');
      }else{
          $(this).css('font-family','gillsanslight');
      }
      ++clicks;

});

});

Any help would be greatful. Note: i need to use that exact showClickedContent query in the final solution due to problems arising with margin otherwise.

Body:
https://jsfiddle.net/ynrnt6xL/

$(document).ready(function() {

  const buttons = $('.menu2');
  const clear = function() {
    $.each( buttons, function(index, btn) {
        $(btn).removeClass('selected');
    })
  }

    $.each( buttons, function(index, btn) {
    $(btn).click( function(e) {
        clear();
      $(this).addClass('selected');
    });
  });

});


问:
Using ManagementObjectSearcher to get an exact BitLocker WMI value
Good Day All,
I am having an issue with ManagementObjectSearcher. I am trying to query the exact value that i want but cannot find any reference to the precise syntax requirements and I continually receive an error when trying to finish out the code to be what I need it to be.

the specific portion of code that is presenting the issue is when I check for the drives Encryption state(I know for a fact that my disk is not encrypted on this machine, which is why that is the only value i have if'd currently). Any assistance in getting this code to pull the correct value would be greatly appreciated.

I've tried both the "=" method and the "LIKE" method with no change in output.

```<code>using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Management;
using System.Windows.Forms;

    public Form1()
    {
        InitializeComponent();

        // Check for OS Version
        string OSVer = Convert.ToString(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", null));
        OSDialog.Text = OSVer;

        // Check Architecture
        if (Directory.Exists("C:\\Program Files (x86)"))
        {
            ArchitectureDialog.Text = "64 Bit";
        }
        else
        {
            ArchitectureDialog.Text = "32 Bit";
        }

        // Check Encryption
        ManagementObjectSearcher Collect = new ManagementObjectSearcher("SELECT ProtectionStatus FROM Win32_EncryptableVolume WHERE DriveLetter = 'C:'");

        string Encryption = Collect.ToString();

        if (Encryption == "0")
        {
            EncryptionDialog.Text = "Disk is not Encrypted";
            EncryptionDialog.ForeColor = Color.Green;
        }
    }

    private void Cancel_Click(object sender, EventArgs e)
    {
        Close();
    }
</code>```

答:
OK so I figured it out, thank you for all of the assistance provided. Code is below.</p>

```<code>ManagementObjectSearcher Encryption = new ManagementObjectSearcher(@"root\cimv2\Security\MicrosoftVolumeEncryption", "SELECT * FROM Win32_EncryptableVolume");

        foreach (ManagementObject QueryObj in Encryption.Get())
        {
            string EncryptionStatus = QueryObj.GetPropertyValue("ProtectionStatus").ToString();

            if (EncryptionStatus == "0")
            {
                EncryptionDialog.Text = "Unencrypted";
            }
            else if (EncryptionStatus == "1")
            {
                EncryptionDialog.Text = "Encrypted - SysPrep will not complete";
            }
            else if (EncryptionStatus == "2")
            {
                EncryptionDialog.Text = "Cannot Determine Encryption";
            }
        }
</code>```

Body:
Good Day All,
I am having an issue with ManagementObjectSearcher. I am trying to query the exact value that i want but cannot find any reference to the precise syntax requirements and I continually receive an error when trying to finish out the code to be what I need it to be.

the specific portion of code that is presenting the issue is when I check for the drives Encryption state(I know for a fact that my disk is not encrypted on this machine, which is why that is the only value i have if'd currently). Any assistance in getting this code to pull the correct value would be greatly appreciated.

I've tried both the "=" method and the "LIKE" method with no change in output.

using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Management;
using System.Windows.Forms;

    public Form1()
    {
        InitializeComponent();

        // Check for OS Version
        string OSVer = Convert.ToString(Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", null));
        OSDialog.Text = OSVer;

        // Check Architecture
        if (Directory.Exists("C:\\Program Files (x86)"))
        {
            ArchitectureDialog.Text = "64 Bit";
        }
        else
        {
            ArchitectureDialog.Text = "32 Bit";
        }

        // Check Encryption
        ManagementObjectSearcher Collect = new ManagementObjectSearcher("SELECT ProtectionStatus FROM Win32_EncryptableVolume WHERE DriveLetter = 'C:'");

        string Encryption = Collect.ToString();

        if (Encryption == "0")
        {
            EncryptionDialog.Text = "Disk is not Encrypted";
            EncryptionDialog.ForeColor = Color.Green;
        }
    }

    private void Cancel_Click(object sender, EventArgs e)
    {
        Close();
    }

Body:
OK so I figured it out, thank you for all of the assistance provided. Code is below.

ManagementObjectSearcher Encryption = new ManagementObjectSearcher(@"root\cimv2\Security\MicrosoftVolumeEncryption", "SELECT * FROM Win32_EncryptableVolume");

        foreach (ManagementObject QueryObj in Encryption.Get())
        {
            string EncryptionStatus = QueryObj.GetPropertyValue("ProtectionStatus").ToString();

            if (EncryptionStatus == "0")
            {
                EncryptionDialog.Text = "Unencrypted";
            }
            else if (EncryptionStatus == "1")
            {
                EncryptionDialog.Text = "Encrypted - SysPrep will not complete";
            }
            else if (EncryptionStatus == "2")
            {
                EncryptionDialog.Text = "Cannot Determine Encryption";
            }
        }


问:
unable find Provisioning Profiles in xcode due space
When I want Build, it shows me below error:

security: unable to open "/Users/antonio/Library/MobileDevice/Provisioning Profiles/.mobileprovision" for reading: No such file or directory

When cding into this directory using terminal, it show me this error:

```<code>$ cd /Users/antonio/Library/MobileDevice/Provisioning Profiles
-bash: cd: /Users/antonio/Library/MobileDevice/Provisioning: No such file or directory
</code>```

But it is available when I going to this directory using Finder.

I think due it have space in the name, it can't open,is there any way I change name of Provisioning Profiles?

答:
```<code>cd "/Users/antonio/Library/MobileDevice/Provisioning Profiles"
</code>```

or

```<code>cd /Users/antonio/Library/MobileDevice/Provisioning\ Profiles
</code>```

more on this: https://askubuntu.com/questions/398400/how-do-i-navigate-to-folders-with-spaces-in-their-names-i-get-no-such-file-or

Body:
When I want Build, it shows me below error:

security: unable to open "/Users/antonio/Library/MobileDevice/Provisioning Profiles/.mobileprovision" for reading: No such file or directory

When cding into this directory using terminal, it show me this error:

$ cd /Users/antonio/Library/MobileDevice/Provisioning Profiles
-bash: cd: /Users/antonio/Library/MobileDevice/Provisioning: No such file or directory

But it is available when I going to this directory using Finder.

I think due it have space in the name, it can't open,is there any way I change name of Provisioning Profiles?

Body:
cd "/Users/antonio/Library/MobileDevice/Provisioning Profiles"

or

cd /Users/antonio/Library/MobileDevice/Provisioning\ Profiles

more on this: https://askubuntu.com/questions/398400/how-do-i-navigate-to-folders-with-spaces-in-their-names-i-get-no-such-file-or


问:
Dynamically display fields in TCA
Servus,
Based on the previous question Display field in TCA of pages based on the previous field value, I am wondering how I can dynamically show the next field with displayCond because of my field shows, only when I hit the save and reload the page. So it is not dynamical. I would like to have when a user changes it than in next second will be displayed another field.

答:
I don‘t think there‘s an API for doing what you plan. You can improve the situation a bit if you set 'onChange' => 'reload' for question_field (directly in the array, not in config).

This will show a modal prompt asking for reload in order to apply changes in display conditions. Can get nasty, too :-(

Title: Dynamically display fields in TCA


问:
CSS ScaleY without stretch img children
I have to show a list of image, but since a lot of them have a portrait aspect ratio I want to be able to show the images with smaller heigth, but not stretched, and when the user click them they will expand... I was able to do it changing the max-height, but the transition on mobile are very bad, so I want to use transform and scaleY to improve performance. The problem is that the image get stretched.

For example if this is the image, normal:

I want to make it to look like this, stretched:

And when the user click it the image return to the initial state.

This is my current code:

CSS

.card img, .card video{
width: 100%;
vertical-align: middle;
border-radius:2px;
object-fit:cover;
will-change: max-height,height;
transition: max-height 0.4s ease;
}
```

<p>HTML</p>

<pre class="lang-html prettyprint-override"><code>   <div class="card">
        <div>
            <img src="image.jpg"/>
        </div>
   </div>
</code>```

And then in Javascript I simply set maxHeight of the img in onclick event.

Thank you!

答:
Here is my code</p>

```<code>.image_container img {
margin: 0 auto;
object-fit: cover;
position: absolute;
top: 54%;
left: 50%;
width: auto;
height: auto;
max-height: none;
max-width: none;
min-height: 100%;
min-width: 100%;
-webkit-transform: translate(-50%, -50%);
vertical-align: middle;
}
</code>```

Title: CSS ScaleY without stretch img children

Body:
I have to show a list of image, but since a lot of them have a portrait aspect ratio I want to be able to show the images with smaller heigth, but not stretched, and when the user click them they will expand... I was able to do it changing the max-height, but the transition on mobile are very bad, so I want to use transform and scaleY to improve performance. The problem is that the image get stretched.

For example if this is the image, normal:

I want to make it to look like this, stretched:

And when the user click it the image return to the initial state.

This is my current code:

CSS

.card img, .card video{
width: 100%;
vertical-align: middle;
border-radius:2px;
object-fit:cover;
will-change: max-height,height;
transition: max-height 0.4s ease;
}

HTML

And then in Javascript I simply set maxHeight of the img in onclick event.

Thank you!

Body:
Here is my code

.image_container img {
margin: 0 auto;
object-fit: cover;
position: absolute;
top: 54%;
left: 50%;
width: auto;
height: auto;
max-height: none;
max-width: none;
min-height: 100%;
min-width: 100%;
-webkit-transform: translate(-50%, -50%);
vertical-align: middle;
}


问:
how can I add Action to a texture packer in libgdx?
I'm trying to create eventListner on each image (playIcon,pauseIcon) but its not working using  touchUp and touchDown

here is my code:

```<code>TextureAtlas buttonsPlayPause = new TextureAtlas("uiii/uiii.pack");
skin.addRegions(buttonsPlayPause);
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("pauseIcon");
textButtonStyle.checked = skin.getDrawable("playIcon");
TextButton button = new TextButton("", textButtonStyle);
button.setY(pauseY);
button.setX(Gdx.graphics.getWidth()/6);
button.setSize(150,150);
stage.addActor(button);

//pause/playAction
button.addListener(new ClickListener() {
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {resume();
              }
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
         pause();
            return true;
        }
    });
</code>```

What happens now is that the button listener behaves as 'istouched()' rather than 'justtouched()'.  When I click the button, the game is paused but whenever I remove my finger, there's no pause, the game runs.

答:
If I understand correctly, you want this button to toggle between Play and Pause, calling either pause() or resume() based on current state.

The Button class already has a built-in internal InputListener, so all you need is a ChangeListener to react to button presses:

```<code>//pause/playAction
button.addListener(new ChangeListener() {
    @Override
    public void changed (ChangeEvent event, Actor actor) {
        if (button.isChecked())
            resume();
        else
            play();
    }
});
</code>```

Make sure you mark it final when you first declare it, so the listener can reference it:

```<code>//...
final TextButton button = new TextButton("", textButtonStyle);
//...
</code>```

Body:
I'm trying to create eventListner on each image (playIcon,pauseIcon) but its not working using  touchUp and touchDown

here is my code:

TextureAtlas buttonsPlayPause = new TextureAtlas("uiii/uiii.pack");
skin.addRegions(buttonsPlayPause);
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("pauseIcon");
textButtonStyle.checked = skin.getDrawable("playIcon");
TextButton button = new TextButton("", textButtonStyle);
button.setY(pauseY);
button.setX(Gdx.graphics.getWidth()/6);
button.setSize(150,150);
stage.addActor(button);

//pause/playAction
button.addListener(new ClickListener() {
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {resume();
              }
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
         pause();
            return true;
        }
    });

What happens now is that the button listener behaves as 'istouched()' rather than 'justtouched()'.  When I click the button, the game is paused but whenever I remove my finger, there's no pause, the game runs.

Body:
If I understand correctly, you want this button to toggle between Play and Pause, calling either pause() or resume() based on current state.

The Button class already has a built-in internal InputListener, so all you need is a ChangeListener to react to button presses:

//pause/playAction
button.addListener(new ChangeListener() {
    @Override
    public void changed (ChangeEvent event, Actor actor) {
        if (button.isChecked())
            resume();
        else
            play();
    }
});

Make sure you mark it final when you first declare it, so the listener can reference it:

//...
final TextButton button = new TextButton("", textButtonStyle);
//...


问:
Why nav-tabs cannot be used with nav-stacked?
Why this case is invalid ?</p>

```<code><ul class="nav nav-tabs nav-stacked" role="tablist">
 <li> ... </li>
 <li> ... </li>
</ul>
</code>```

答:
Only pills are stackable. Not tabs. See bootstrap docs:

http://getbootstrap.com/components/#nav-tabs

You can always achieve the same effect by styling the nav-pill and nav-stacked if you want stacked tabs. Although, stacked tabs sound counter-intuitive.

Body:
Why this case is invalid ?

 ...

 ...


问:
iOS design question: How should switching between days be implemented in a table view?
I've got a bad case of analysis paralysis on this one so I thought I'd open it up to SO:

I have a table view, the contents of which represent activities that took place on a given day.  When the app loads, today's data is downloaded, parsed (both by a central singleton), and displayed.  Simple enough, and it works great.

I'd like to add the ability to go forward/back between days, using some kind of control at the top.  An excellent example would be the day view of the iOS Calendar app.

Or, alternatively, I could init and push new views using a navigation bar and navigationItem.rightBarButtonItem & navigationItem.leftBarButtonItem.

What's the best approach here, and how should it be implemented (e.g., use another intermediary view or handle everything from the table view that actually displays the data)?

答:
I think Mike's answer is a good one.  I'd go one further to say that your view controller view might host two separate UITableViews (they can both use your view controller as a delegate...).  The reason for this would be to enhance your ability to transition between the two separate views on a day-change.

Your view hierarchy might be:

```<code>YourCustomViewController <UITableViewDelegate, UTableViewDataSource, CustomDatePickerDelegate>
    view
      date-picker-control-view
      tableview1
      tableview2
</code>```

With this arrangement you can use built-in view transition animations to switch between tableview1 and tableview2.

ContentLicense: CC BY-SA 2.5

Body:
I think Mike's answer is a good one.  I'd go one further to say that your view controller view might host two separate UITableViews (they can both use your view controller as a delegate...).  The reason for this would be to enhance your ability to transition between the two separate views on a day-change.

Your view hierarchy might be:

YourCustomViewController <UITableViewDelegate, UTableViewDataSource, CustomDatePickerDelegate>
    view
      date-picker-control-view
      tableview1
      tableview2

With this arrangement you can use built-in view transition animations to switch between tableview1 and tableview2.


问:
Angularjs way, conditionally to generate new form and append it to the page or state change
i am  new to angularjs,
and wonder What is the angularjs way to complete such a task as conditionally generating or showing the form ?
Lets say

```<code>$scope.counter = function(){
   if ($scope.years < 5){

    // what is here? append or should  return true and use ng-if directive in html?

    }}
</code>```

Thank you

答:
var myApp = angular.module('myApp',[]);

myApp.controller('ctrl', ['$scope', function($scope) {
  $scope.years = 10;
}]);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="ctrl">
<label>age :</label>
  <input type="number" ng-model="years">
  <div ng-if="years<5"> show if years < 5 </div>
  <div ng-if="years>5"> show if years > 5 </div>
</div></code>```

just like that

Body:
i am  new to angularjs,
and wonder What is the angularjs way to complete such a task as conditionally generating or showing the form ?
Lets say

$scope.counter = function(){
   if ($scope.years < 5){

    // what is here? append or should  return true and use ng-if directive in html?

    }}

Thank you

Body:
var myApp = angular.module('myApp',[]);

myApp.controller('ctrl', ['$scope', function($scope) {
  $scope.years = 10;
}]);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="ctrl">
<label>age :</label>
  <input type="number" ng-model="years">
  <div ng-if="years<5"> show if years < 5 </div>
  <div ng-if="years>5"> show if years > 5 </div>
</div>

just like that


问:
Search through methods in a class PhpStorm
I used to work in Eclipse and had this very neat hotkey (Ctrl + O) which is used to search through the methods within a class.

I mean, if you are in the editor viewing a source of a class, and if you hit Ctrl + O, a pop-up comes up with all the methods listed. The list will get filtered if you start typing in. If I type in get, I can see a list of getters..

This is very helpful. I moved to PHP and PhpStorm and I miss this feature here, or I do not know if PhpStorm has this.

Do you guys have any idea of such a key combo in PhpStorm?

答:
I have never used Eclipse .. so not 100% sure how that popup looks and works .. but here is the PhpStorm functionality:

Navigate | File Structure (Ctrl + F12 using Default keymap)

Alternatively just use Speed Search (just start typing) in actual Structure panel.


问:
Problems minifying javascript file (asp.net application)
I have the following javascript code:

```<code>class UrlParameters {

constructor() {
    this.initVariablesWithDefaultValues();
    var serverUrlData = HelperJSViewBag.getValue("UrlData", true);
    var urlVariables = serverUrlData ? serverUrlData : HLinks.getAllUrlVariables();
    var sessionID = this.convertToString(urlVariables["sessionID"]);
    var idSession = this.convertToString(urlVariables["idSession"]);
    var sessionid = this.convertToString(urlVariables["sessionid"]);

    if (idSession.length > 0)
        this.sessionID = idSession;
    else if (sessionid.length > 0)
        this.sessionID = sessionid;
    else
        this.sessionID = sessionID;

    var countryISO = this.convertToString(urlVariables["countryISO"]);
    var country = this.convertToString(urlVariables["country"]);
    this.countryISO = countryISO.length > 0 ? countryISO : country;

    var productRef = this.convertToString(urlVariables["productRef"]);
    var pRef = this.convertToString(urlVariables["ref"]);
    var refproduct = this.convertToString(urlVariables["refproduct"]);
    var productReference = this.convertToString(urlVariables["productReference"]);

    if (productRef.length > 0)
        this.productReference = productRef;
    else if (pRef.length > 0)
        this.productReference = pRef;
    else if (refproduct.length > 0)
        this.productReference = refproduct;
    else
        this.productReference = productReference;

    var PartnerCode = this.convertToString(urlVariables["PartnerCode"]);
    var partnerCode = this.convertToString(urlVariables["partnerCode"]);

    this.partnerCode = PartnerCode.length > 0 ? PartnerCode : partnerCode;

    var themeReference = this.convertToString(urlVariables["themeReference"]);
    var theme = this.convertToString(urlVariables["theme"]);
    this.themeReference = themeReference.length > 0 ? themeReference : theme;

    this.projectName = this.convertToString(urlVariables["projectName"]);

    var coverReference = this.convertToString(urlVariables["coverReference"]);
    var refCover = this.convertToString(urlVariables["refCover"]);
    this.coverReference = coverReference.length > 0 ? coverReference : refCover;

    this.themeFill = this.convertToInt(urlVariables["themeFill"], 0);  // 0 -> directly without autofill ; 1 -> not directly without autofill ; 2 -> not directly quick autofill ; 3 -> not directly smart autofill
    this.smartOpt = this.convertToInt(urlVariables["smartOpt"], 2);  //1->faces,colors,dimentions; 2-> colors and dimentions; 3-> dimentions

    var open = this.convertToString(urlVariables["open"]);
    var projectCode = this.convertToString(urlVariables["projectCode"]);

    this.projectCode = open.length > 0 ? open : projectCode;

    this.productCode = this.convertToString(urlVariables["productCode"]);

    this.projectID = this.convertToString(urlVariables["projectID"]);

    var categoryID = this.convertToInt(urlVariables["categoryID"]);
    var cat = this.convertToInt(urlVariables["cat"]);
    this.categoryID = categoryID > 0 ? categoryID : cat;

    var subCategoryReference = this.convertToString(urlVariables["subCategoryReference"]);
    var subCat = this.convertToString(urlVariables["subCat"]);
    this.subCategoryReference = subCategoryReference.length > 0 ? subCategoryReference : subCat;

    var typeFinishID = this.convertToInt(urlVariables["typeFinishID"]);
    var refProdutFinish = this.convertToInt(urlVariables["refProdutFinish"]);
    var productTypeFinishID = this.convertToInt(urlVariables["productTypeFinishID"]);

    if (typeFinishID > 0)
        this.productTypeFinishID = typeFinishID;
    else if (refProdutFinish > 0)
        this.productTypeFinishID = refProdutFinish;
    else
        this.productTypeFinishID = productTypeFinishID;

    var coverTypeFinishID = this.convertToInt(urlVariables["coverTypeFinishID"]);
    var coverFinishID = this.convertToInt(urlVariables["coverFinishID"]);
    var refCoverFinish = this.convertToInt(urlVariables["refCoverFinish"]);

    if (coverTypeFinishID > 0) this.coverTypeFinishID = coverTypeFinishID;
    else if (coverFinishID > 0) this.coverTypeFinishID = coverFinishID;
    else this.coverTypeFinishID = refCoverFinish;

    var numPages = this.convertToInt(urlVariables["numPages"]);
    var refPages = this.convertToInt(urlVariables["refPages"]);
    var numberOfPages = this.convertToInt(urlVariables["numberOfPages"]);

    if (numPages > 0)
        this.numberOfPages = numPages;
    else if (refPages > 0)
        this.numberOfPages = refPages;
    else
        this.numberOfPages = numberOfPages;

    this.coverType = this.convertToString(urlVariables["coverType"]);

    var textureID = this.convertToString(urlVariables["textureID"]);
    var textureReference = this.convertToString(urlVariables["textureReference"]);

    if (textureID.length > 0) this.textureReference = textureID;
    else this.textureReference = textureReference;

    var textureColorID = this.convertToString(urlVariables["textureColorID"]);
    var textureColorReference = this.convertToString(urlVariables["textureColorReference"]);
    var refColor = this.convertToString(urlVariables["refColor"]);

    if (textureColorID.length > 0) this.textureColorReference = textureColorID;
    else if (refColor.length > 0) this.textureColorReference = refColor;
    else this.textureColorReference = textureColorReference;

    var windowID = this.convertToString(urlVariables["windowID"]);
    var refWindow = this.convertToString(urlVariables["refWindow"]);
    var windowReference = this.convertToString(urlVariables["windowReference"]);

    if (windowID.length > 0)
        this.windowReference = windowID;
    else if (refWindow.length > 0)
        this.windowReference = refWindow;
    else
        this.windowReference = windowReference;

    this.savedProject = this.convertToBoolean(urlVariables["savedProject"]);

    this.startMonth = this.convertToInt(urlVariables["startMonth"]);
    this.startYear = this.convertToInt(urlVariables["startYear"]);
    this.wantHolidays = this.convertToBoolean(urlVariables["wantHolidays"]);

    var frameID = this.convertToString(urlVariables["frameID"]);
    var frameReference = this.convertToString(urlVariables["frameReference"]);
    var canvasRef = this.convertToString(urlVariables["canvasRef"]);

    if (frameID.length > 0)
        this.frameReference = frameID;
    else if (canvasRef.length > 0)
        this.frameReference = canvasRef;
    else
        this.frameReference = frameReference;

    this.frameReference = frameID.length > 0 ? frameID : frameReference;

    var colorFrameID = this.convertToString(urlVariables["colorFrameID"]);
    var frameColorReference = this.convertToString(urlVariables["frameColorReference"]);
    var canvasColor = this.convertToString(urlVariables["canvasColor"]);

    if (colorFrameID.length > 0)
        this.frameColorReference = colorFrameID;
    else if (canvasColor.length > 0)
        this.frameColorReference = canvasColor;
    else
        this.frameColorReference = frameColorReference;

    this.albumXML = this.convertToString(urlVariables["albumXML"]);
    this.pagesXML = this.convertToString(urlVariables["pagesXML"]);

    var languageISO = this.convertToString(urlVariables["languageISO"]);
    var lang = this.convertToString(urlVariables["lang"]);

    if (languageISO.length > 0)
        this.languageISO = languageISO;
    else if (lang.length > 0)
        this.languageISO = lang;

    this.openThemeAccordion = this.convertToBoolean(urlVariables["openThemeAccordion"]);

    var galleryID = this.convertToString(urlVariables["galleryID"]);
    var galleryReference = this.convertToString(urlVariables["galleryReference"]);
    this.galleryReference = galleryID.length > 0 ? galleryID : galleryReference;

    var login_page = this.convertToString(urlVariables["login_page"]);
    var Login_Page = this.convertToString(urlVariables["Login_Page"]);
    this.Login_Page = this.convertToBoolean(login_page.length > 0 ? login_page : Login_Page);
    this.forceMobile = this.convertToBoolean(urlVariables["forceMobile"]);
    this.clientApplication = this.convertToString(urlVariables["clientApplication"]);
    this.goToPreview = this.convertToInt(urlVariables["goToPreview"]);
    this.orderID = this.convertToInt(urlVariables["orderID"], -1);

    this.CID = this.convertToString(urlVariables["CID"]);
    this.unblock = this.convertToBoolean(urlVariables["unblock"]);

    var idPartner = this.convertToInt(urlVariables["idPartner"]);
    var partnerID = this.convertToInt(urlVariables["partnerID"]);
    var idEmp = this.convertToInt(urlVariables["idEmp"]);
    this.forceException = this.convertToBoolean(urlVariables["forceException"]);

    if (idPartner > 0)
        this.partnerID = idPartner;
    else if (partnerID > 0)
        this.partnerID = partnerID;
    else if (idEmp > 0)
        this.partnerID = idEmp;

    this.goDirectlyToEditor = this.convertToBoolean(urlVariables["goDirectlyToEditor"]);
}

static getInstance() {
    if (typeof UrlParameters.urlParameters === "undefined")
        UrlParameters.urlParameters = new UrlParameters();

    return UrlParameters.urlParameters;
}

getData() {
    return {
        sessionID : this.sessionID,
        countryISO: this.countryISO,
        productReference: this.productReference,
        partnerCode: this.partnerCode,
        themeReference: this.themeReference,
        projectName: this.projectName,
        coverReference: this.coverReference,
        themeFill: this.themeFill,
        smartOpt: this.smartOpt,
        projectCode: this.projectCode,
        productCode: this.productCode,
        projectID: this.projectID,
        categoryID: this.categoryID,
        subCategoryReference: this.subCategoryReference,
        productTypeFinishID: this.productTypeFinishID,
        coverTypeFinishID: this.coverTypeFinishID,
        numberOfPages: this.numberOfPages,
        coverType: this.coverType,
        textureReference: this.textureReference,
        textureColorReference: this.textureColorReference,
        windowReference: this.windowReference,
        savedProject: this.savedProject,
        startMonth: this.startMonth,
        startYear: this.startYear,
        wantHolidays: this.wantHolidays,
        frameReference: this.frameReference,
        frameColorReference: this.frameColorReference,
        albumXML: this.albumXML,
        pagesXML: this.pagesXML,
        languageISO: this.languageISO,
        openThemeAccordion: this.openThemeAccordion,
        galleryReference: this.galleryReference,
        Login_Page: this.Login_Page,
        forceMobile: this.forceMobile,
        clientApplication: this.clientApplication,
        goToPreview: this.goToPreview,
        orderID: this.orderID,
        CID: this.CID,
        unblock: this.unblock,
        partnerID: this.partnerID,
        forceException: this.forceException,
        goDirectlyToEditor: this.goDirectlyToEditor

    }
}

getVariableOnce(name) {
    if (!this.variableOnce) this.variableOnce = this.getData();

    var value = this.variableOnce[name];
    delete this.variableOnce[name];

    return value;
}

initVariablesWithDefaultValues() {
    this.projectName = "";
    this.productReference = "";
    this.coverReference = "";
    this.textureReference = "";
    this.colorReference = "";
    this.windowReference = "";
    this.numberOfPages = 0;
    this.productTypeFinishID = 0;
    this.coverTypeFinishID = 0;
    this.canvasColor = "";
    this.projectCode = "";
    this.sessionID = "";
    this.countryISO = "";
    this.themeReference = "";
    this.themeFill = 0;
    this.smartOpt = 2;
    this.projectID = "";
    this.productCode = "";
    this.categoryID = -1;
    this.savedProject = false;
    this.startMonth = 0;
    this.startYear = 0;
    this.wantHolidays = false;
    this.albumXML = "";
    this.pagesXML = "";
    this.languageISO = "";
    this.Login_Page = false;
    this.frameReference = "";
    this.frameColorReference = "";
    this.partnerCode = "";
    this.partnerID = "";
    this.coverType = "";
    this.textureColorReference = ""
    this.subCategoryReference = "";
    this.openThemeAccordion = false;
    this.galleryReference = "";
    this.clientApplication = "";
    this.forceMobile = false;
    this.idUpload = 0;
    this.orderID = -1;
    this.idControl = 0;
    this.goToPreview = 0;
    this.unblock = false;
    this.CID = "";
    this.forceException = false;
    this.goDirectlyToEditor = false;
}

convertToString(value, defaultValue) {
    if (typeof defaultValue !== "var") defaultValue = "";

    if (value)
        return value;
    else
        return defaultValue;
}

convertToInt(value, defaultValue) {
    if (typeof defaultValue !== "number") defaultValue = 0;

    if (value)
        return parseInt(value);
    else
        return defaultValue;
}

convertToBoolean(value, defaultValue) {
    if (typeof defaultValue !== "boolean") defaultValue = false;

    if (value)
        return value;
    else
        return defaultValue;
}
}
</code>```

When I run my application with the BundleTable.EnableOptimizations = true the asp.net does not minify this files. Istead, return a new file with the following errors:

```<code>/* Minification failed. Returning unminified contents.
(1,1-6): run-time error JS1195: Expected expression: class
(3,19-20): run-time error JS1004: Expected ';': {
(201,12-23): run-time error JS1004: Expected ';': getInstance
(201,26-27): run-time error JS1004: Expected ';': {
(208,15-16): run-time error JS1004: Expected ';': {
(256,27-28): run-time error JS1004: Expected ';': {
(265,38-39): run-time error JS1004: Expected ';': {
(314,42-43): run-time error JS1004: Expected ';': {
(323,39-40): run-time error JS1004: Expected ';': {
(332,43-44): run-time error JS1004: Expected ';': {
(341,1-2): run-time error JS1002: Syntax error: }
(336,13-25): run-time error JS1018: 'return' statement outside of function: return value
(338,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(327,13-35): run-time error JS1018: 'return' statement outside of function: return parseInt(value)
(329,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(318,13-25): run-time error JS1018: 'return' statement outside of function: return value
(320,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(262,9-21): run-time error JS1018: 'return' statement outside of function: return value
(209,9,253,10): run-time error JS1018: 'return' statement outside of function: return {
            sessionID : this.sessionID,
            countryISO: this.countryISO,
            productReference: this.productReference,
            partnerCode: this.partnerCode,
            themeReference: this.themeReference,
            projectName: this.projectName,
            coverReference: this.coverReference,
            themeFill: this.themeFill,
            smartOpt: this.smartOpt,
            projectCode: this.projectCode,
            productCode: this.productCode,
            projectID: this.projectID,
            categoryID: this.categoryID,
            subCategoryReference: this.subCategoryReference,
            productTypeFinishID: this.productTypeFinishID,
            coverTypeFinishID: this.coverTypeFinishID,
            numberOfPages: this.numberOfPages,
            coverType: this.coverType,
            textureReference: this.textureReference,
            textureColorReference: this.textureColorReference,
            windowReference: this.windowReference,
            savedProject: this.savedProject,
            startMonth: this.startMonth,
            startYear: this.startYear,
            wantHolidays: this.wantHolidays,
            frameReference: this.frameReference,
            frameColorReference: this.frameColorReference,
            albumXML: this.albumXML,
            pagesXML: this.pagesXML,
            languageISO: this.languageISO,
            openThemeAccordion: this.openThemeAccordion,
            galleryReference: this.galleryReference,
            Login_Page: this.Login_Page,
            forceMobile: this.forceMobile,
            clientApplication: this.clientApplication,
            goToPreview: this.goToPreview,
            orderID: this.orderID,
            CID: this.CID,
            unblock: this.unblock,
            partnerID: this.partnerID,
            forceException: this.forceException,
            goDirectlyToEditor: this.goDirectlyToEditor

        }
(205,9-43): run-time error JS1018: 'return' statement outside of function: return UrlParameters.urlParameters
 */
</code>```

I search a lot on the internet but I didn't find any solution for this case. Maybe, it's because I'm using the ES6 standard?

I'm using the 1.1.0.0 version of System.Web.Optimization.

答:
System.Web.Optimization doesn't support ES6 syntax

I suggest you to integrate gulp, grunt or webpack into your build process in order to minify your scripts

Body:
I have the following javascript code:

class UrlParameters {

constructor() {
    this.initVariablesWithDefaultValues();
    var serverUrlData = HelperJSViewBag.getValue("UrlData", true);
    var urlVariables = serverUrlData ? serverUrlData : HLinks.getAllUrlVariables();
    var sessionID = this.convertToString(urlVariables["sessionID"]);
    var idSession = this.convertToString(urlVariables["idSession"]);
    var sessionid = this.convertToString(urlVariables["sessionid"]);

    if (idSession.length > 0)
        this.sessionID = idSession;
    else if (sessionid.length > 0)
        this.sessionID = sessionid;
    else
        this.sessionID = sessionID;

    var countryISO = this.convertToString(urlVariables["countryISO"]);
    var country = this.convertToString(urlVariables["country"]);
    this.countryISO = countryISO.length > 0 ? countryISO : country;

    var productRef = this.convertToString(urlVariables["productRef"]);
    var pRef = this.convertToString(urlVariables["ref"]);
    var refproduct = this.convertToString(urlVariables["refproduct"]);
    var productReference = this.convertToString(urlVariables["productReference"]);

    if (productRef.length > 0)
        this.productReference = productRef;
    else if (pRef.length > 0)
        this.productReference = pRef;
    else if (refproduct.length > 0)
        this.productReference = refproduct;
    else
        this.productReference = productReference;

    var PartnerCode = this.convertToString(urlVariables["PartnerCode"]);
    var partnerCode = this.convertToString(urlVariables["partnerCode"]);

    this.partnerCode = PartnerCode.length > 0 ? PartnerCode : partnerCode;

    var themeReference = this.convertToString(urlVariables["themeReference"]);
    var theme = this.convertToString(urlVariables["theme"]);
    this.themeReference = themeReference.length > 0 ? themeReference : theme;

    this.projectName = this.convertToString(urlVariables["projectName"]);

    var coverReference = this.convertToString(urlVariables["coverReference"]);
    var refCover = this.convertToString(urlVariables["refCover"]);
    this.coverReference = coverReference.length > 0 ? coverReference : refCover;

    this.themeFill = this.convertToInt(urlVariables["themeFill"], 0);  // 0 -> directly without autofill ; 1 -> not directly without autofill ; 2 -> not directly quick autofill ; 3 -> not directly smart autofill
    this.smartOpt = this.convertToInt(urlVariables["smartOpt"], 2);  //1->faces,colors,dimentions; 2-> colors and dimentions; 3-> dimentions

    var open = this.convertToString(urlVariables["open"]);
    var projectCode = this.convertToString(urlVariables["projectCode"]);

    this.projectCode = open.length > 0 ? open : projectCode;

    this.productCode = this.convertToString(urlVariables["productCode"]);

    this.projectID = this.convertToString(urlVariables["projectID"]);

    var categoryID = this.convertToInt(urlVariables["categoryID"]);
    var cat = this.convertToInt(urlVariables["cat"]);
    this.categoryID = categoryID > 0 ? categoryID : cat;

    var subCategoryReference = this.convertToString(urlVariables["subCategoryReference"]);
    var subCat = this.convertToString(urlVariables["subCat"]);
    this.subCategoryReference = subCategoryReference.length > 0 ? subCategoryReference : subCat;

    var typeFinishID = this.convertToInt(urlVariables["typeFinishID"]);
    var refProdutFinish = this.convertToInt(urlVariables["refProdutFinish"]);
    var productTypeFinishID = this.convertToInt(urlVariables["productTypeFinishID"]);

    if (typeFinishID > 0)
        this.productTypeFinishID = typeFinishID;
    else if (refProdutFinish > 0)
        this.productTypeFinishID = refProdutFinish;
    else
        this.productTypeFinishID = productTypeFinishID;

    var coverTypeFinishID = this.convertToInt(urlVariables["coverTypeFinishID"]);
    var coverFinishID = this.convertToInt(urlVariables["coverFinishID"]);
    var refCoverFinish = this.convertToInt(urlVariables["refCoverFinish"]);

    if (coverTypeFinishID > 0) this.coverTypeFinishID = coverTypeFinishID;
    else if (coverFinishID > 0) this.coverTypeFinishID = coverFinishID;
    else this.coverTypeFinishID = refCoverFinish;

    var numPages = this.convertToInt(urlVariables["numPages"]);
    var refPages = this.convertToInt(urlVariables["refPages"]);
    var numberOfPages = this.convertToInt(urlVariables["numberOfPages"]);

    if (numPages > 0)
        this.numberOfPages = numPages;
    else if (refPages > 0)
        this.numberOfPages = refPages;
    else
        this.numberOfPages = numberOfPages;

    this.coverType = this.convertToString(urlVariables["coverType"]);

    var textureID = this.convertToString(urlVariables["textureID"]);
    var textureReference = this.convertToString(urlVariables["textureReference"]);

    if (textureID.length > 0) this.textureReference = textureID;
    else this.textureReference = textureReference;

    var textureColorID = this.convertToString(urlVariables["textureColorID"]);
    var textureColorReference = this.convertToString(urlVariables["textureColorReference"]);
    var refColor = this.convertToString(urlVariables["refColor"]);

    if (textureColorID.length > 0) this.textureColorReference = textureColorID;
    else if (refColor.length > 0) this.textureColorReference = refColor;
    else this.textureColorReference = textureColorReference;

    var windowID = this.convertToString(urlVariables["windowID"]);
    var refWindow = this.convertToString(urlVariables["refWindow"]);
    var windowReference = this.convertToString(urlVariables["windowReference"]);

    if (windowID.length > 0)
        this.windowReference = windowID;
    else if (refWindow.length > 0)
        this.windowReference = refWindow;
    else
        this.windowReference = windowReference;

    this.savedProject = this.convertToBoolean(urlVariables["savedProject"]);

    this.startMonth = this.convertToInt(urlVariables["startMonth"]);
    this.startYear = this.convertToInt(urlVariables["startYear"]);
    this.wantHolidays = this.convertToBoolean(urlVariables["wantHolidays"]);

    var frameID = this.convertToString(urlVariables["frameID"]);
    var frameReference = this.convertToString(urlVariables["frameReference"]);
    var canvasRef = this.convertToString(urlVariables["canvasRef"]);

    if (frameID.length > 0)
        this.frameReference = frameID;
    else if (canvasRef.length > 0)
        this.frameReference = canvasRef;
    else
        this.frameReference = frameReference;

    this.frameReference = frameID.length > 0 ? frameID : frameReference;

    var colorFrameID = this.convertToString(urlVariables["colorFrameID"]);
    var frameColorReference = this.convertToString(urlVariables["frameColorReference"]);
    var canvasColor = this.convertToString(urlVariables["canvasColor"]);

    if (colorFrameID.length > 0)
        this.frameColorReference = colorFrameID;
    else if (canvasColor.length > 0)
        this.frameColorReference = canvasColor;
    else
        this.frameColorReference = frameColorReference;

    this.albumXML = this.convertToString(urlVariables["albumXML"]);
    this.pagesXML = this.convertToString(urlVariables["pagesXML"]);

    var languageISO = this.convertToString(urlVariables["languageISO"]);
    var lang = this.convertToString(urlVariables["lang"]);

    if (languageISO.length > 0)
        this.languageISO = languageISO;
    else if (lang.length > 0)
        this.languageISO = lang;

    this.openThemeAccordion = this.convertToBoolean(urlVariables["openThemeAccordion"]);

    var galleryID = this.convertToString(urlVariables["galleryID"]);
    var galleryReference = this.convertToString(urlVariables["galleryReference"]);
    this.galleryReference = galleryID.length > 0 ? galleryID : galleryReference;

    var login_page = this.convertToString(urlVariables["login_page"]);
    var Login_Page = this.convertToString(urlVariables["Login_Page"]);
    this.Login_Page = this.convertToBoolean(login_page.length > 0 ? login_page : Login_Page);
    this.forceMobile = this.convertToBoolean(urlVariables["forceMobile"]);
    this.clientApplication = this.convertToString(urlVariables["clientApplication"]);
    this.goToPreview = this.convertToInt(urlVariables["goToPreview"]);
    this.orderID = this.convertToInt(urlVariables["orderID"], -1);

    this.CID = this.convertToString(urlVariables["CID"]);
    this.unblock = this.convertToBoolean(urlVariables["unblock"]);

    var idPartner = this.convertToInt(urlVariables["idPartner"]);
    var partnerID = this.convertToInt(urlVariables["partnerID"]);
    var idEmp = this.convertToInt(urlVariables["idEmp"]);
    this.forceException = this.convertToBoolean(urlVariables["forceException"]);

    if (idPartner > 0)
        this.partnerID = idPartner;
    else if (partnerID > 0)
        this.partnerID = partnerID;
    else if (idEmp > 0)
        this.partnerID = idEmp;

    this.goDirectlyToEditor = this.convertToBoolean(urlVariables["goDirectlyToEditor"]);
}

static getInstance() {
    if (typeof UrlParameters.urlParameters === "undefined")
        UrlParameters.urlParameters = new UrlParameters();

    return UrlParameters.urlParameters;
}

getData() {
    return {
        sessionID : this.sessionID,
        countryISO: this.countryISO,
        productReference: this.productReference,
        partnerCode: this.partnerCode,
        themeReference: this.themeReference,
        projectName: this.projectName,
        coverReference: this.coverReference,
        themeFill: this.themeFill,
        smartOpt: this.smartOpt,
        projectCode: this.projectCode,
        productCode: this.productCode,
        projectID: this.projectID,
        categoryID: this.categoryID,
        subCategoryReference: this.subCategoryReference,
        productTypeFinishID: this.productTypeFinishID,
        coverTypeFinishID: this.coverTypeFinishID,
        numberOfPages: this.numberOfPages,
        coverType: this.coverType,
        textureReference: this.textureReference,
        textureColorReference: this.textureColorReference,
        windowReference: this.windowReference,
        savedProject: this.savedProject,
        startMonth: this.startMonth,
        startYear: this.startYear,
        wantHolidays: this.wantHolidays,
        frameReference: this.frameReference,
        frameColorReference: this.frameColorReference,
        albumXML: this.albumXML,
        pagesXML: this.pagesXML,
        languageISO: this.languageISO,
        openThemeAccordion: this.openThemeAccordion,
        galleryReference: this.galleryReference,
        Login_Page: this.Login_Page,
        forceMobile: this.forceMobile,
        clientApplication: this.clientApplication,
        goToPreview: this.goToPreview,
        orderID: this.orderID,
        CID: this.CID,
        unblock: this.unblock,
        partnerID: this.partnerID,
        forceException: this.forceException,
        goDirectlyToEditor: this.goDirectlyToEditor

    }
}

getVariableOnce(name) {
    if (!this.variableOnce) this.variableOnce = this.getData();

    var value = this.variableOnce[name];
    delete this.variableOnce[name];

    return value;
}

initVariablesWithDefaultValues() {
    this.projectName = "";
    this.productReference = "";
    this.coverReference = "";
    this.textureReference = "";
    this.colorReference = "";
    this.windowReference = "";
    this.numberOfPages = 0;
    this.productTypeFinishID = 0;
    this.coverTypeFinishID = 0;
    this.canvasColor = "";
    this.projectCode = "";
    this.sessionID = "";
    this.countryISO = "";
    this.themeReference = "";
    this.themeFill = 0;
    this.smartOpt = 2;
    this.projectID = "";
    this.productCode = "";
    this.categoryID = -1;
    this.savedProject = false;
    this.startMonth = 0;
    this.startYear = 0;
    this.wantHolidays = false;
    this.albumXML = "";
    this.pagesXML = "";
    this.languageISO = "";
    this.Login_Page = false;
    this.frameReference = "";
    this.frameColorReference = "";
    this.partnerCode = "";
    this.partnerID = "";
    this.coverType = "";
    this.textureColorReference = ""
    this.subCategoryReference = "";
    this.openThemeAccordion = false;
    this.galleryReference = "";
    this.clientApplication = "";
    this.forceMobile = false;
    this.idUpload = 0;
    this.orderID = -1;
    this.idControl = 0;
    this.goToPreview = 0;
    this.unblock = false;
    this.CID = "";
    this.forceException = false;
    this.goDirectlyToEditor = false;
}

convertToString(value, defaultValue) {
    if (typeof defaultValue !== "var") defaultValue = "";

    if (value)
        return value;
    else
        return defaultValue;
}

convertToInt(value, defaultValue) {
    if (typeof defaultValue !== "number") defaultValue = 0;

    if (value)
        return parseInt(value);
    else
        return defaultValue;
}

convertToBoolean(value, defaultValue) {
    if (typeof defaultValue !== "boolean") defaultValue = false;

    if (value)
        return value;
    else
        return defaultValue;
}
}

When I run my application with the BundleTable.EnableOptimizations = true the asp.net does not minify this files. Istead, return a new file with the following errors:

/* Minification failed. Returning unminified contents.
(1,1-6): run-time error JS1195: Expected expression: class
(3,19-20): run-time error JS1004: Expected ';': {
(201,12-23): run-time error JS1004: Expected ';': getInstance
(201,26-27): run-time error JS1004: Expected ';': {
(208,15-16): run-time error JS1004: Expected ';': {
(256,27-28): run-time error JS1004: Expected ';': {
(265,38-39): run-time error JS1004: Expected ';': {
(314,42-43): run-time error JS1004: Expected ';': {
(323,39-40): run-time error JS1004: Expected ';': {
(332,43-44): run-time error JS1004: Expected ';': {
(341,1-2): run-time error JS1002: Syntax error: }
(336,13-25): run-time error JS1018: 'return' statement outside of function: return value
(338,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(327,13-35): run-time error JS1018: 'return' statement outside of function: return parseInt(value)
(329,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(318,13-25): run-time error JS1018: 'return' statement outside of function: return value
(320,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(262,9-21): run-time error JS1018: 'return' statement outside of function: return value
(209,9,253,10): run-time error JS1018: 'return' statement outside of function: return {
            sessionID : this.sessionID,
            countryISO: this.countryISO,
            productReference: this.productReference,
            partnerCode: this.partnerCode,
            themeReference: this.themeReference,
            projectName: this.projectName,
            coverReference: this.coverReference,
            themeFill: this.themeFill,
            smartOpt: this.smartOpt,
            projectCode: this.projectCode,
            productCode: this.productCode,
            projectID: this.projectID,
            categoryID: this.categoryID,
            subCategoryReference: this.subCategoryReference,
            productTypeFinishID: this.productTypeFinishID,
            coverTypeFinishID: this.coverTypeFinishID,
            numberOfPages: this.numberOfPages,
            coverType: this.coverType,
            textureReference: this.textureReference,
            textureColorReference: this.textureColorReference,
            windowReference: this.windowReference,
            savedProject: this.savedProject,
            startMonth: this.startMonth,
            startYear: this.startYear,
            wantHolidays: this.wantHolidays,
            frameReference: this.frameReference,
            frameColorReference: this.frameColorReference,
            albumXML: this.albumXML,
            pagesXML: this.pagesXML,
            languageISO: this.languageISO,
            openThemeAccordion: this.openThemeAccordion,
            galleryReference: this.galleryReference,
            Login_Page: this.Login_Page,
            forceMobile: this.forceMobile,
            clientApplication: this.clientApplication,
            goToPreview: this.goToPreview,
            orderID: this.orderID,
            CID: this.CID,
            unblock: this.unblock,
            partnerID: this.partnerID,
            forceException: this.forceException,
            goDirectlyToEditor: this.goDirectlyToEditor

        }
(205,9-43): run-time error JS1018: 'return' statement outside of function: return UrlParameters.urlParameters
 */

I search a lot on the internet but I didn't find any solution for this case. Maybe, it's because I'm using the ES6 standard?

I'm using the 1.1.0.0 version of System.Web.Optimization.


问:
phpexcel file download issue
I am using the 05featuredemo.php example of the phpexcel, which is downloaded from the codeplex Latest Built PHPExcel_1.8.0_doc  by MarkBaker (SO)

The point i need i look is

```<code>$objWriter->save(str_replace('.php', '.xls', __FILE__));
</code>```

Above is used for saving the file in the script location, But How can i make it as simple downloadable.

I tried with

```<code>$objWriter->save('php://output');
</code>```

But It didn't download the file that is generated. How can i do that, Is there any other thing i should do ?

答:
If you want to give name by yourself then you can specify as I have specified in $a.

I wanted to use a filename from where this function is being called so I concat that name to the excel filename and also attached current date to the filename.

Note: LogReport is a folder where my files will be downloaded.

```<code>self::$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_IOFactory::createWriter(self::$objPHPExcel, 'Excel2007');
        $a = 'Log' . self::$filename . date("Y-m-d") . '.xlsx';
        $objWriter->save(__DIR__ . '/LogReport/' . $a);
</code>```

Title: phpexcel file download issue

Body:
I am using the 05featuredemo.php example of the phpexcel, which is downloaded from the codeplex Latest Built PHPExcel_1.8.0_doc  by MarkBaker (SO)

The point i need i look is

$objWriter->save(str_replace('.php', '.xls', __FILE__));

Above is used for saving the file in the script location, But How can i make it as simple downloadable.

I tried with

$objWriter->save('php://output');

But It didn't download the file that is generated. How can i do that, Is there any other thing i should do ?

Body:
If you want to give name by yourself then you can specify as I have specified in $a.

I wanted to use a filename from where this function is being called so I concat that name to the excel filename and also attached current date to the filename.

Note: LogReport is a folder where my files will be downloaded.

self::$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_IOFactory::createWriter(self::$objPHPExcel, 'Excel2007');
        $a = 'Log' . self::$filename . date("Y-m-d") . '.xlsx';
        $objWriter->save(__DIR__ . '/LogReport/' . $a);


问:
Delete duplicates if they are together in a column excel
I am trying to delete entire row if duplicates are found together. If not found together I want to keep it without deleting.

```<code>For an example Column A:
Apple,
Apple,
Orange,
Orange,
Apple,
Apple,
</code>```

I need to have the output as;

```<code>Apple,
Orange,
Apple,
</code>```

I'm using the following code but have not achieved the desired output yet (only get Apple, Orange).

```<code>   Sub FindDuplicates()
   Dim LastRow, matchFoundIndex, iCntr As Long
   LastRow = Cells(Rows.Count, "A").End(xlUp).Row
   For iCntr = 1 To LastRow
   If Cells(iCntr, 1) <> "" Then
   matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" &      LastRow), 0)
   If iCntr <> matchFoundIndex Then
   Cells(iCntr, 10) = "Duplicate"
   End If
   End If
   Next

   last = Cells(Rows.Count, "J").End(xlUp).Row ' check results col for values
   For i = last To 2 Step -1
   If (Cells(i, "J").Value) = "" Then
   Else
   Cells(i, "J").EntireRow.Delete  ' if values then delete
   End If
   Next i
   End Sub
</code>```

答:
Doesn't something simple like

```<code>Dim LastRow As Long
Application.screenUpdating=False
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = LastRow To 2 Step -1
    If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
        Cells(i, 1).EntireRow.Delete
    End If
Next i
Application.screenUpdating=True
</code>```

solve this?

ContentLicense: CC BY-SA 4.0

Body:
I am trying to delete entire row if duplicates are found together. If not found together I want to keep it without deleting.

For an example Column A:
Apple,
Apple,
Orange,
Orange,
Apple,
Apple,

I need to have the output as;

Apple,
Orange,
Apple,

I'm using the following code but have not achieved the desired output yet (only get Apple, Orange).

   Sub FindDuplicates()
   Dim LastRow, matchFoundIndex, iCntr As Long
   LastRow = Cells(Rows.Count, "A").End(xlUp).Row
   For iCntr = 1 To LastRow
   If Cells(iCntr, 1) <> "" Then
   matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" &      LastRow), 0)
   If iCntr <> matchFoundIndex Then
   Cells(iCntr, 10) = "Duplicate"
   End If
   End If
   Next

   last = Cells(Rows.Count, "J").End(xlUp).Row ' check results col for values
   For i = last To 2 Step -1
   If (Cells(i, "J").Value) = "" Then
   Else
   Cells(i, "J").EntireRow.Delete  ' if values then delete
   End If
   Next i
   End Sub

Body:
Doesn't something simple like

Dim LastRow As Long
Application.screenUpdating=False
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = LastRow To 2 Step -1
    If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
        Cells(i, 1).EntireRow.Delete
    End If
Next i
Application.screenUpdating=True

solve this?


问:
JS Browser Update jQuery Plugin/Code Snippet
I'm looking for a code snippet or jQuery plugin that detects a user's browser and whether it's out of date and displays message.  Ideally, it would need to meet the following requirements:

Unobtrusive

Configurable text

Multiple browser support

Configurable minimum browser versions

Any help would be appreciated.

Thanks.

答:
I think this will get you pointed in the right direction: http://jquery.thewikies.com/browser/

EDIT

Here's a few more:

jReject: http://jreject.turnwheel.com/

sevenup: http://code.google.com/p/sevenup/


问:
Creating objects dynamically using a list of Strings?
I am trying to create objects by using a list of Strings that will populate their fields. For example I have the list of strings, Note that the values repeat after every 3. i.e. id, name , address.

```<code>List<String> myList = "Id1", "name1", "address1", "Id2", "name2", "address2";
</code>```

I would like to dynamically create a number of Person Objects (shown below) using this list

```<code>Person object:

public class Person {

    private String id;
    private String name;
    private String address;

     public Person() {
    }

    public Person(String id, String name, String address) {
        this.id = id;
        this.name = name;
        this.address = address;
    }

    //standard getters and setters

}
</code>```

What I want to do is have a method that will take the list of strings as an input and then create the objects dynamically. How could I best do this?

I know that I could do the following if I knew that I was definitely populating 2 objects, but the problem is that there may be more or less.

```<code>public List<Person> createObjectsFromStringList(List<String> list){

    List<person> personList = new Arraylist<>();

    Person person1 = new Person(list.get(0), list.get(1), list.get(2));
    Person person2 = new Person(list.get(3), list.get(4), list.get(5));

    personList.add(person1);
    personList.add(person2);

    return personList;

}
</code>```

答:
As you want to access your elements sequentially you should use java.util.LinkedList in such loop

```<code>    for(true)
        if(linkedList.size()>=3){
                 Person person=   new
Person(linkedList.removeFirst(),linkedList.removeFirst(),linkedList.removeFirst());

                 personList.add(person);
    }
        else break;
</code>```

But ArrayList and its get method is good for random access by index which is not your case

Body:
I am trying to create objects by using a list of Strings that will populate their fields. For example I have the list of strings, Note that the values repeat after every 3. i.e. id, name , address.

List<String> myList = "Id1", "name1", "address1", "Id2", "name2", "address2";

I would like to dynamically create a number of Person Objects (shown below) using this list

Person object:

public class Person {

    private String id;
    private String name;
    private String address;

     public Person() {
    }

    public Person(String id, String name, String address) {
        this.id = id;
        this.name = name;
        this.address = address;
    }

    //standard getters and setters

}

What I want to do is have a method that will take the list of strings as an input and then create the objects dynamically. How could I best do this?

I know that I could do the following if I knew that I was definitely populating 2 objects, but the problem is that there may be more or less.

public List<Person> createObjectsFromStringList(List<String> list){

    List<person> personList = new Arraylist<>();

    Person person1 = new Person(list.get(0), list.get(1), list.get(2));
    Person person2 = new Person(list.get(3), list.get(4), list.get(5));

    personList.add(person1);
    personList.add(person2);

    return personList;

}

Body:
As you want to access your elements sequentially you should use java.util.LinkedList in such loop

    for(true)
        if(linkedList.size()>=3){
                 Person person=   new
Person(linkedList.removeFirst(),linkedList.removeFirst(),linkedList.removeFirst());

                 personList.add(person);
    }
        else break;

But ArrayList and its get method is good for random access by index which is not your case


问:
How to combine two UIImages of difference size without altering their original aspect ratios?
My current method of combining UIImages come from this answer on SO, as well as this popular question on resizing UIImage with aspect ratio.  My current issue is the following:

I have an UIImage called pictureImage taken with the camera that comes out to the standard dimension 2448*3264. I also have a UIImageView called self.annotateView that has a frame of 320*568 where the user could draw and annotate the picture. When I present the pictureImage in a UIImageView, I set the image presentation as Aspect Fill so that it takes up the whole iPhone screen. Of course this means parts of pictureImage is cut off on both left and right (in fact 304 pixels on both sides), but this intended.

My problem is, when I combine the UIImages pictureImage and annotateView.image to a new dimension of 320*568, my combined image alters the original aspects of annotateView.image by stretching it horizontally. This is strange since the new dimensions are exactly that of annotateView.image's original dimensions.

Here is what the outcome looks like -

Before combining the UIImages

After combining the images

Note that the underlying picture is not stretched.  However, annotateView.image is stretched only horizontally, not vertically.

Here is my code for merging the UIImages.

```<code>//Note: self.firstTakenImage is set to 320*568

CGSize newSize = CGSizeMake(self.firstTakenImage.frame.size.width, self.firstTakenImage.frame.size.height);
UIGraphicsBeginImageContext(newSize);
[self.firstTakenImage.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
[self.drawView.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
</code>```

答:
Support Portrait and Landscape both type of image

Drawing and other subviews can be merged in my case I'm adding label to draw

  {

    CGSize fullSize = getImageForEdit.size;
    CGSize sizeInView = AVMakeRectWithAspectRatioInsideRect(imgViewFake.image.size, imgViewFake.bounds).size;
    CGFloat orgScale = orgScale = fullSize.width/sizeInView.width;
    CGSize newSize = CGSizeMake(orgScale * img.image.size.width, orgScale * img.image.size.height);
    if(newSize.width <= fullSize.width && newSize.height <= fullSize.height){
        newSize = fullSize;
    }
    CGRect offsetRect;
    if (getImageForEdit.size.height > getImageForEdit.size.width){
        CGFloat scale = newSize.height/fullSize.height;
        CGFloat offset = (newSize.width - fullSize.width*scale)/2;
        offsetRect = CGRectMake(offset, 0, newSize.width-offset*2, newSize.height);
    }
    else{
        CGFloat scale = newSize.width/fullSize.width;
        CGFloat offset = (newSize.height - fullSize.height*scale)/2;
        offsetRect = CGRectMake(0, offset, newSize.width, newSize.height-offset*2);
    }
    UIGraphicsBeginImageContextWithOptions(newSize, NO, getImageForEdit.scale);
    [getImageForEdit drawAtPoint:offsetRect.origin];
    //        [img.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    CGFloat oldScale = img.contentScaleFactor;
    img.contentScaleFactor = getImageForEdit.scale;
    [img drawViewHierarchyInRect:CGRectMake(0, 0, newSize.width, newSize.height) afterScreenUpdates:YES];
    img.contentScaleFactor = oldScale;
    UIImage *combImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageData = UIImageJPEGRepresentation(combImage, 1);
}
```

Body:
My current method of combining UIImages come from this answer on SO, as well as this popular question on resizing UIImage with aspect ratio.  My current issue is the following:

I have an UIImage called pictureImage taken with the camera that comes out to the standard dimension 2448*3264. I also have a UIImageView called self.annotateView that has a frame of 320*568 where the user could draw and annotate the picture. When I present the pictureImage in a UIImageView, I set the image presentation as Aspect Fill so that it takes up the whole iPhone screen. Of course this means parts of pictureImage is cut off on both left and right (in fact 304 pixels on both sides), but this intended.

My problem is, when I combine the UIImages pictureImage and annotateView.image to a new dimension of 320*568, my combined image alters the original aspects of annotateView.image by stretching it horizontally. This is strange since the new dimensions are exactly that of annotateView.image's original dimensions.

Here is what the outcome looks like -

Before combining the UIImages

After combining the images

Note that the underlying picture is not stretched.  However, annotateView.image is stretched only horizontally, not vertically.

Here is my code for merging the UIImages.

//Note: self.firstTakenImage is set to 320*568

CGSize newSize = CGSizeMake(self.firstTakenImage.frame.size.width, self.firstTakenImage.frame.size.height);
UIGraphicsBeginImageContext(newSize);
[self.firstTakenImage.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
[self.drawView.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


问:
Elasticsearch, Failed to obtain node lock, is the following location writable
Elasticsearch won't start using ./bin/elasticsearch.
It raises the following exception:

```<code>- ElasticsearchIllegalStateException[Failed to obtain node lock, is the following location writable?: [/home/user1/elasticsearch-1.4.4/data/elasticsearch]
</code>```

I checked the permissions on the same location and the location has 777 permissions on it and is owned by user1.

```<code>ls -al /home/user1/elasticsearch-1.4.4/data/elasticsearch
</code>```

```<code>drwxrwxrwx  3 user1 wheel 4096 Mar  8 13:24 .
drwxrwxrwx  3 user1 wheel 4096 Mar  8 13:00 ..
drwxrwxrwx 52 user1 wheel 4096 Mar  8 13:51 nodes
</code>```

What is the problem?

Trying to run elasticsearch 1.4.4 on linux without root access.

答:
You already have ES running.  To prove that type:

curl 'localhost:9200/_cat/indices?v'

If you want to run another instance on the same box you can set node.max_local_storage_nodes in elasticsearch.yml to a value larger than 1.

Body:
Elasticsearch won't start using ./bin/elasticsearch.
It raises the following exception:

- ElasticsearchIllegalStateException[Failed to obtain node lock, is the following location writable?: [/home/user1/elasticsearch-1.4.4/data/elasticsearch]

I checked the permissions on the same location and the location has 777 permissions on it and is owned by user1.

ls -al /home/user1/elasticsearch-1.4.4/data/elasticsearch

drwxrwxrwx  3 user1 wheel 4096 Mar  8 13:24 .
drwxrwxrwx  3 user1 wheel 4096 Mar  8 13:00 ..
drwxrwxrwx 52 user1 wheel 4096 Mar  8 13:51 nodes

What is the problem?

Trying to run elasticsearch 1.4.4 on linux without root access.


问:
C# / .NET MVC Razor language translation
this is the first time that I'm encountering this issue so I wanted to shed some light on this matter. I'm building a .NET MVC application which consumes a JSON web service, and the response messages from that server are written in chinese mandarin language. With each message comes a corresponding status code with it's English translation (not in the reply itself but documentation). So later on I noticed that not all errors are covered in the documentation and that I don't have their  status code thus I don't know what they mean except I translate them through google translate. I figured if I used some kind of translation library that offers this kind of service where I can translate Chinese mandarin into English, it would be really nice.

What would you guys suggest I' should do here?

Every advice is helpful as I want to maintain the code as simple as I can without including any extra library that I don't really need.

Thanks a lot ! =)

P.S. so the respons message example is like following:

```<code>该运输方式不可用
</code>```

Which would translate to:

```<code>The shipping method is not available
</code>```

答: What if you used the google translate api? https://cloud.google.com/translate/docs/translating-text</p>

Body:
this is the first time that I'm encountering this issue so I wanted to shed some light on this matter. I'm building a .NET MVC application which consumes a JSON web service, and the response messages from that server are written in chinese mandarin language. With each message comes a corresponding status code with it's English translation (not in the reply itself but documentation). So later on I noticed that not all errors are covered in the documentation and that I don't have their  status code thus I don't know what they mean except I translate them through google translate. I figured if I used some kind of translation library that offers this kind of service where I can translate Chinese mandarin into English, it would be really nice.

What would you guys suggest I' should do here?

Every advice is helpful as I want to maintain the code as simple as I can without including any extra library that I don't really need.

Thanks a lot ! =)

P.S. so the respons message example is like following:

该运输方式不可用

Which would translate to:

The shipping method is not available


问:
OpenCV imshow() prevents Qt / python crashing
I'm writing a GUI using python and pyQt to read in data packets through UDP socket, processing it through OpenCV, then finally showing it as real time images using Qt. I created a UDP socket outside the while loop, while using the sock.recvfrom method to read in data packets inside the while loop. Within the same while loop, i processed the data and put it into OpenCV format and use OpenCV imshow() method to show the real time video for experimenting. Everything's great and working smooth, but when i try to show the video through QLabel using QImage and QPixmap, things went bizarre. If OpenCV imshow() exist, the code works fine with additional QPixmap shown in the QLabel on top of the OpenCV cv2.imshow() window. However, if i take out the OpenCV imshow(), the UI will freeze and nothing showed leading "python not responding". I've not yet come up with a good reason why this is happening, and i also tried keeping/changing cv2.waitkey() time without succeeding. Any help would be appreciated.

import socket
import cv2
from PyQt4 import QtCore, QtGui, uic

while True:
    data, addr = self.sock.recvfrom(10240)

    # after some processing on data to get im_data ...
    self.im_data_color_resized = cv2.resize(im_data, (0, 0), interpolation = True)

    # using OpenCV to show the video (the entire code works with cv2.imshow but not without it)
    cv2.imshow('Real Time Image', self.im_data_color_resized)
    cv2.waitKey(10)

    # using QLabel to show the video
    qtimage = cv2.cvtColor(self.im_data_color_resized, cv2.COLOR_BGR2RGB)
    height, width, bpc = qtimage.shape

    bpl = bpc * width
    qimage = QtGui.QImage(qtimage.data, width, height, bpl, QtGui.QImage.Format_RGB888)

    self.imageViewer_label.setPixmap(QtGui.QPixmap.fromImage(qimage))
```

答:
You need to refresh the event queue, so that your GUI can be updated. Add QtGui.QApplication.processEvents() after the setPixamp function.

It works with cv2.waitKey() because it internally already refreshes the painting events allowing the Qt GUI to be refreshed. But I recommend not to rely on this hack, and explicitly refresh the Qt events with processEvents.

You may also want to put this processing loop in its own thread to leave the GUI/Main thread responsive.


问:
APN Push Notifications in Twilio IP Messaging
I'm trying to get push notifications on an app that's using Twilio IP Messaging. After following the instructions that I can see here: https://www.twilio.com/docs/api/ip-messaging/guides/push-notifications-ios

I'm drawing blanks.

The AppDelegate functions to register for remote notifications is working well - the iOS devices successfully provides the device token to the Twilio Client. However, the TwilioIPMessagingClient gives no indication of success or failure while registering the token. Moreover, I don't get any sign of push notifications when messages get sent. I'm not sure how to debug this any further since Twilio is a black box for APNS pushes.

Is there a logging service inside IPM/another debugging method I can access to see the status of APN pushes?

答:
I found the Twilio Debugging console to be useful diagnosing push notification issues. I only found out about it after I got an email with an error message saying my APNS token was invalid. That was after spending a while trying to diagnose the issue.

You can find the console here: https://twilio.com/console/dev-tools/debugger


问:
IceFaces: panelPopup autoCentre problem with IE
I'm having some problems with panelPopup and IE8. When I set autoCentre="true" and positionOnLoadOnly="true", I expect the popup to appear in the center of the view port and stay put there. This works fine in Safari, Chrome and Firefox, but in IE the popup "follows the scroll", if you see what I mean. I.e if the page where the popup is displayed is longer than the popup the popup is re-centered when I scroll the page. Also, and this is a bigger issue - if the popup is longer than the page I can only scroll part of the way down it, then it's re-centered. This means I can never see the information at the bottom of the popup...

This is the code used to generate the popup:

<ice:panelPopup

    id="popup"

    positionOnLoadOnly="true"

    autoCentre="true"

    style="z-index:999; background: #FFFFFF;"

    resizable="false"

    draggable="false"

    modal="true"

    clientOnly="true"

    visible="#{SomeBean.popupRendered}" >

Any ideas?

Thanks!

答: According to the documentation, the autoCentre option is supposed to keep it centered through scrolling and window resizing but dragging should disable it.  Turning draggable to true might give you reasonable results because the user can drag it to a position they can see the entire popup.</p>


问:
How to make 2 colored text in a line in a marker infowindow?
I would like to make a marker info window, which has 3 lines, and every singe line contains 2 colors.
I made the 3 lines with the help of

```<code>mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter()
</code>```

but i am stucked with the colors.

Please Help :)

答:
You can use SpannableString to set multiple color in single string sentence in TextView or other text enabled component

```<code>String strMessage="I am android developer";
Spannable spannable = new SpannableString(strMessage);

//"I am android" red colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.RED)), 0, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);

//"developer" blue colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.BLUE)), 14, strMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
</code>```

TextAppearanceSpan method to customized text with color

```<code>/*
 *get customized text with color, style
 */
private TextAppearanceSpan getTextAppearanceSpan(int color) {
    ColorStateList blueColor1 = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
    return new TextAppearanceSpan(null, Typeface.NORMAL, -1, blueColor1, null);
}
</code>```

Body:
I would like to make a marker info window, which has 3 lines, and every singe line contains 2 colors.
I made the 3 lines with the help of

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter()

but i am stucked with the colors.

Please Help :)

Body:
You can use SpannableString to set multiple color in single string sentence in TextView or other text enabled component

String strMessage="I am android developer";
Spannable spannable = new SpannableString(strMessage);

//"I am android" red colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.RED)), 0, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);

//"developer" blue colored
spannable.setSpan(getTextAppearanceSpan(ContextCompat.getColor(mContext, android.R.color.BLUE)), 14, strMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);

TextAppearanceSpan method to customized text with color

/*
 *get customized text with color, style
 */
private TextAppearanceSpan getTextAppearanceSpan(int color) {
    ColorStateList blueColor1 = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
    return new TextAppearanceSpan(null, Typeface.NORMAL, -1, blueColor1, null);
}


问:
How do I extract named groups with unknown order with a regular expression in Java?
Let's say I want to extract foo\d{2} and bar\d{2} as named groups (say, foo and bar) from strings that might contain one or two of them in any order, e.g.:

```<code>hello foo33 world bar12
bar66 something foo14
this one only has bar45
this one has neither
</code>```

Is there a way to do it in with a single regular expression in Java?

It would be best if the solution could be generalised to 3+ named groups.

答:
This can be done using the regex or operator: |

In this case, you want to find foo or bar.  So all you need to do is group them with the or operator.

```<code>(foo|bar)\\d{2}
</code>```

Here's an example on regexer!

Body:
Let's say I want to extract foo\d{2} and bar\d{2} as named groups (say, foo and bar) from strings that might contain one or two of them in any order, e.g.:

hello foo33 world bar12
bar66 something foo14
this one only has bar45
this one has neither

Is there a way to do it in with a single regular expression in Java?

It would be best if the solution could be generalised to 3+ named groups.

Body:
This can be done using the regex or operator: |

In this case, you want to find foo or bar.  So all you need to do is group them with the or operator.

(foo|bar)\\d{2}

Here's an example on regexer!


问:
'PERCENT_RANK' is not a recognized built-in function name in SQL Server
I'm using SQL Server 2012 which is supposed to have this built-in function (it even preempts the text when I type PERCENT_) however when I try to apply it it fails.

I believe my syntax is correct as it is working for other ranking and n-tiling functions.

In any case here it is:

```<code>PERCENT_RANK() OVER (PARTITION BY MONTH, SEGMENT ORDER BY SALES/NULLIF(ORDERS,0) DESC) AS PTILE
</code>```

Thanks!

答:
This is too long for a comment.  You need to look at the compatibility level that you are using:

```<code>select compatibility_level
from sys.databases;
</code>```

Because the functionality was introduced in SQL Server 2012, you need a level of 110 or above.

The compatibility allows newer versions of SQL Server to emulate previous versions.  This can be handy when you need to run code that uses obsoleted features, for instance.

Body:
I'm using SQL Server 2012 which is supposed to have this built-in function (it even preempts the text when I type PERCENT_) however when I try to apply it it fails.

I believe my syntax is correct as it is working for other ranking and n-tiling functions.

In any case here it is:

PERCENT_RANK() OVER (PARTITION BY MONTH, SEGMENT ORDER BY SALES/NULLIF(ORDERS,0) DESC) AS PTILE

Thanks!

Body:
This is too long for a comment.  You need to look at the compatibility level that you are using:

select compatibility_level
from sys.databases;

Because the functionality was introduced in SQL Server 2012, you need a level of 110 or above.

The compatibility allows newer versions of SQL Server to emulate previous versions.  This can be handy when you need to run code that uses obsoleted features, for instance.


问:
2D iterator access in C++
I'm working on a 2D table with std::map() to count how many times one number transitions to another number.  I've run into two problems.  First, my first transition doesn't show (1->2).  Second, all my transitions are showing only one time (2->3 and 3->1 both happen twice).

I can see why the transitions are only happening once.  The iterator doesn't see currentVal and goes to else, where it adds the values then exits.  I'm not sure how to fix this though.  Any help is appreciated!

```<code>#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

//import midi notes
vector <int> midiFile = {1, 2, 3, 1, 20, 5, 2, 3, 1};

//create a 2d hashmap for matrix
map <string, map <string, int> > mCounts;

//strings for the previous value and current value
string prevVal = "";
string currentVal = "";

void addNumbers(vector <int> midiFile) {

    for (int i = 0; i < midiFile.size(); i++) {
        currentVal = to_string(midiFile[i]);

        if(prevVal == "") {
            prevVal = currentVal;   //first value
        } else {
            //playCounts is temporary map to store counts of current val in relation to previous val
            map <string, int> playCounts;

            map <string, int> ::iterator iterator;
            iterator = playCounts.find(currentVal);

            //if mCounts doesn't contain the value yet, create a new hashmap
            if(iterator != playCounts.end()){

                int counter = iterator -> second;
                mCounts[prevVal] [currentVal] = counter + 1;

            } else {
                playCounts.insert(pair <string, int>(currentVal, 1));
                mCounts [prevVal] = playCounts;

            }

            prevVal = currentVal;

        }

        //find values already in map
        map <string, map <string, int> > ::iterator it;
        it = mCounts.find(prevVal);

        if (it != mCounts.end()) {
            //if value is found, do nothing
        } else {
            mCounts.insert(pair <string, map <string, int>>(prevVal, map <string, int>()));
        }
    }
}
</code>```

答:
You're dealing with small integers < 128.  Just use a matrix where transition[i][j] is the number of transitions from i to j.  Normally I recommend a flat buffer for matrices with index multiplication to access the 2d dimension, or a prewritten class wrapper around the same thing (see Eigen).  But in this case, the matrix is so small, you can just use

```<code>int transition[128][128];
</code>```

Of course you want to typedef this and pass it by reference.
Not only will all your operations be easier and more transparent, but using a transition matrix admits analysis that's not possible any other way: eigenvectors for equilibrium states, etc.

For larger problems where the transitions are sparse and you can't afford a dense matrix, use an actual sparse matrix class, which is essentially what you're trying to roll yourself.

```<code>typedef int transitionMatrix[128][128];

void addNumbers(const vector <int> &midiFile, transitionMatrix &mCounts) {
    for (int i = 0; i < midiFile.size()-1; i++) {
        int prev = midiFile[i];
        int curr = midiFile[i+1];
        mCounts[prev][curr]++;
    }
}
</code>```

Title: 2D iterator access in C++

Body:
I'm working on a 2D table with std::map() to count how many times one number transitions to another number.  I've run into two problems.  First, my first transition doesn't show (1->2).  Second, all my transitions are showing only one time (2->3 and 3->1 both happen twice).

I can see why the transitions are only happening once.  The iterator doesn't see currentVal and goes to else, where it adds the values then exits.  I'm not sure how to fix this though.  Any help is appreciated!

#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

//import midi notes
vector <int> midiFile = {1, 2, 3, 1, 20, 5, 2, 3, 1};

//create a 2d hashmap for matrix
map <string, map <string, int> > mCounts;

//strings for the previous value and current value
string prevVal = "";
string currentVal = "";

void addNumbers(vector <int> midiFile) {

    for (int i = 0; i < midiFile.size(); i++) {
        currentVal = to_string(midiFile[i]);

        if(prevVal == "") {
            prevVal = currentVal;   //first value
        } else {
            //playCounts is temporary map to store counts of current val in relation to previous val
            map <string, int> playCounts;

            map <string, int> ::iterator iterator;
            iterator = playCounts.find(currentVal);

            //if mCounts doesn't contain the value yet, create a new hashmap
            if(iterator != playCounts.end()){

                int counter = iterator -> second;
                mCounts[prevVal] [currentVal] = counter + 1;

            } else {
                playCounts.insert(pair <string, int>(currentVal, 1));
                mCounts [prevVal] = playCounts;

            }

            prevVal = currentVal;

        }

        //find values already in map
        map <string, map <string, int> > ::iterator it;
        it = mCounts.find(prevVal);

        if (it != mCounts.end()) {
            //if value is found, do nothing
        } else {
            mCounts.insert(pair <string, map <string, int>>(prevVal, map <string, int>()));
        }
    }
}

Body:
You're dealing with small integers < 128.  Just use a matrix where transition[i][j] is the number of transitions from i to j.  Normally I recommend a flat buffer for matrices with index multiplication to access the 2d dimension, or a prewritten class wrapper around the same thing (see Eigen).  But in this case, the matrix is so small, you can just use

int transition[128][128];

Of course you want to typedef this and pass it by reference.
Not only will all your operations be easier and more transparent, but using a transition matrix admits analysis that's not possible any other way: eigenvectors for equilibrium states, etc.

For larger problems where the transitions are sparse and you can't afford a dense matrix, use an actual sparse matrix class, which is essentially what you're trying to roll yourself.

typedef int transitionMatrix[128][128];

void addNumbers(const vector <int> &midiFile, transitionMatrix &mCounts) {
    for (int i = 0; i < midiFile.size()-1; i++) {
        int prev = midiFile[i];
        int curr = midiFile[i+1];
        mCounts[prev][curr]++;
    }
}


答:
Work from the bottom up and only delete if the cell above is the same value.

```<code>dim r as long

with worksheets("sheet1")
    for r = .cells(.rows.count, "A").end(xlup).row to 2 step -1
        if lcase(.cells(r, "A").value2) = lcase(.cells(r - 1, "A").value2) then
            .rows(r).entirerow.delete
        end if
    next r
end with
</code>```

If you do not want the comparison to be case-insensitive then remove the lcase functions.

Title: Delete duplicates if they are together in a column excel

Body:
Work from the bottom up and only delete if the cell above is the same value.

dim r as long

with worksheets("sheet1")
    for r = .cells(.rows.count, "A").end(xlup).row to 2 step -1
        if lcase(.cells(r, "A").value2) = lcase(.cells(r - 1, "A").value2) then
            .rows(r).entirerow.delete
        end if
    next r
end with

If you do not want the comparison to be case-insensitive then remove the lcase functions.


问:
PostgreSQL Error [42804]: operator class "_bpchar_ops" does not accept data type character
I am trying to create a gin index for a character column having length 1. (it's just a simple Y/N column). If I run this SQL:

```<code>create index INDEX_NAME on schema.table_name using gin(field_name);
</code>```

I get this error:

SQL Error [42704]: ERROR: data type character has no default operator class for access method "gin"
   Hint: You must specify an operator class for the index or define a default operator class for the data type.

If I set the operator class explicitly, like this

```<code>create index INDEX_NAME on schema.table_name using gin(field_name _bpchar_ops);
</code>```

I get this error:

SQL Error [42804]: ERROR: operator class "_bpchar_ops" does not accept data type character

Note:

I have already run this SQL to create the gin extension

```<code> create extension btree_gin;
</code>```

答:
There is no GIN operator class for character, see the documentation.

Since the length is 1, you could use the type "char" instead:

```<code>CREATE TABLE table_name (field_name "char");
CREATE INDEX ON table_name USING gin (field_name char_ops);
</code>```

But what whould be the use of such an index?

Body:
I am trying to create a gin index for a character column having length 1. (it's just a simple Y/N column). If I run this SQL:

create index INDEX_NAME on schema.table_name using gin(field_name);

I get this error:

SQL Error [42704]: ERROR: data type character has no default operator class for access method "gin"
   Hint: You must specify an operator class for the index or define a default operator class for the data type.

If I set the operator class explicitly, like this

create index INDEX_NAME on schema.table_name using gin(field_name _bpchar_ops);

I get this error:

SQL Error [42804]: ERROR: operator class "_bpchar_ops" does not accept data type character

Note:

I have already run this SQL to create the gin extension

 create extension btree_gin;

Body:
There is no GIN operator class for character, see the documentation.

Since the length is 1, you could use the type "char" instead:

CREATE TABLE table_name (field_name "char");
CREATE INDEX ON table_name USING gin (field_name char_ops);

But what whould be the use of such an index?