问:
Javascript recursive call creates range-error
I'm trying to  get the following script working, but when it falls into the continueAnimation function it isn't updating the cPreloaderTimeout variable and it runs in a 'Uncaught RangeError: Maximum call stack size exceeded'.

```<code>    var loadingIcon = {

    cSpeed : 8,
    cWidth : 64,
    cHeight : 32,
    cTotalFrames : 7,
    cFrameWidth : 64,
    cImageSrc : 'sprites.png',

    cImageTimeout : false,
    cIndex : 0,
    cXpos : 0,
    cPreloaderTimeout : false,
    SECONDS_BETWEEN_FRAMES : 0,

    startAnimation : function() {
        document.getElementById('loaderImage').style.backgroundImage='url('+ this.cImageSrc+')';
        document.getElementById('loaderImage').style.width=this.cWidth+'px';
        document.getElementById('loaderImage').style.height=this.cHeight+'px';

        //FPS = Math.round(100/(maxSpeed+2-speed));
        FPS = Math.round(100/this.cSpeed);
        SECONDS_BETWEEN_FRAMES = 1 / FPS;

        this.cPreloaderTimeout = setTimeout( this.continueAnimation(), SECONDS_BETWEEN_FRAMES/1000);

    },

    continueAnimation : function() {
        this.cXpos += this.cFrameWidth;
        //increase the index so we know which frame of our animation we are currently on
        this.cIndex += 1;

        //if our cIndex is higher than our total number of frames, we're at the end and should restart
        if (this.cIndex >= this.cTotalFrames) {
            this.cXpos =0;
            this.cIndex=0;
        }

        if(document.getElementById('loaderImage'))
            document.getElementById('loaderImage').style.backgroundPosition=(-this.cXpos)+'px 0';

        this.cPreloaderTimeout = setTimeout(this.continueAnimation(), SECONDS_BETWEEN_FRAMES*1000);
    },

    stopAnimation : function(){//stops animation
        clearTimeout( this.cPreloaderTimeout );
        this.cPreloaderTimeout = false;
    }

}

jQuery( document ).ready(function() {

    jQuery( document ).on("click", "#test", function(){

        var loader = loadingIcon;

        loader.startAnimation();

        setTimeout( loader.stopAnimation(), 3000);

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

It was a plain javascript script at first, but I'm trying to make an object from it so it can be re-used and multiple times at the same time. The problem is now that the cPreloaderTimeout variable isn't set correctly when startAnimation or continueAnimation is triggerd.

答:
You have a couple issues.

First, your cPreloaderTimeout isn't going to be set like you think it is, as you're not creating an object with a prototype, so the scope of this inside that function is going to be the function itself, not the object.

Second, setTimeout takes a function, but you're calling the function when you try and use it, so the value sent to setTimeout will be the results of the function, not the function itself.

Consider instead the format:

```<code>function LoadIcon() {
  this.cSpeed = 8;
  // All your other properties
}

LoadIcon.prototype.startAnimation = function() {
  // your startAnimation function, concluding with
  this.preloaderTimeout = setTimeout(this.continueAnimation.bind(this), SECONDS_BETWEEN_FRAMES/1000);
}

// the rest of the methods built the same way

//then, your calling code would look like:

var loadIcon = new LoadIcon();
loadIcon.startAnimation();
</code>```

EDIT
I updated the setTimeout call as I'd forgotten about binding to this for correct scoping when the callback fires.

Body:
I'm trying to  get the following script working, but when it falls into the continueAnimation function it isn't updating the cPreloaderTimeout variable and it runs in a 'Uncaught RangeError: Maximum call stack size exceeded'.

    var loadingIcon = {

    cSpeed : 8,
    cWidth : 64,
    cHeight : 32,
    cTotalFrames : 7,
    cFrameWidth : 64,
    cImageSrc : 'sprites.png',

    cImageTimeout : false,
    cIndex : 0,
    cXpos : 0,
    cPreloaderTimeout : false,
    SECONDS_BETWEEN_FRAMES : 0,

    startAnimation : function() {
        document.getElementById('loaderImage').style.backgroundImage='url('+ this.cImageSrc+')';
        document.getElementById('loaderImage').style.width=this.cWidth+'px';
        document.getElementById('loaderImage').style.height=this.cHeight+'px';

        //FPS = Math.round(100/(maxSpeed+2-speed));
        FPS = Math.round(100/this.cSpeed);
        SECONDS_BETWEEN_FRAMES = 1 / FPS;

        this.cPreloaderTimeout = setTimeout( this.continueAnimation(), SECONDS_BETWEEN_FRAMES/1000);

    },

    continueAnimation : function() {
        this.cXpos += this.cFrameWidth;
        //increase the index so we know which frame of our animation we are currently on
        this.cIndex += 1;

        //if our cIndex is higher than our total number of frames, we're at the end and should restart
        if (this.cIndex >= this.cTotalFrames) {
            this.cXpos =0;
            this.cIndex=0;
        }

        if(document.getElementById('loaderImage'))
            document.getElementById('loaderImage').style.backgroundPosition=(-this.cXpos)+'px 0';

        this.cPreloaderTimeout = setTimeout(this.continueAnimation(), SECONDS_BETWEEN_FRAMES*1000);
    },

    stopAnimation : function(){//stops animation
        clearTimeout( this.cPreloaderTimeout );
        this.cPreloaderTimeout = false;
    }

}

jQuery( document ).ready(function() {

    jQuery( document ).on("click", "#test", function(){

        var loader = loadingIcon;

        loader.startAnimation();

        setTimeout( loader.stopAnimation(), 3000);

    });
});

It was a plain javascript script at first, but I'm trying to make an object from it so it can be re-used and multiple times at the same time. The problem is now that the cPreloaderTimeout variable isn't set correctly when startAnimation or continueAnimation is triggerd.

Body:
You have a couple issues.

First, your cPreloaderTimeout isn't going to be set like you think it is, as you're not creating an object with a prototype, so the scope of this inside that function is going to be the function itself, not the object.

Second, setTimeout takes a function, but you're calling the function when you try and use it, so the value sent to setTimeout will be the results of the function, not the function itself.

Consider instead the format:

function LoadIcon() {
  this.cSpeed = 8;
  // All your other properties
}

LoadIcon.prototype.startAnimation = function() {
  // your startAnimation function, concluding with
  this.preloaderTimeout = setTimeout(this.continueAnimation.bind(this), SECONDS_BETWEEN_FRAMES/1000);
}

// the rest of the methods built the same way

//then, your calling code would look like:

var loadIcon = new LoadIcon();
loadIcon.startAnimation();

EDIT
I updated the setTimeout call as I'd forgotten about binding to this for correct scoping when the callback fires.


来源: stackexchange

问:
Command Line Tools not working - OS X El Capitan, Sierra, High Sierra, Mojave
I just upgraded from Yosemite to El Capitan (and replicated the problem upgrading from El Capitan to Sierra), and when I try to type for example git status inside a terminal, I get the following error:

```<code>xcrun: error: invalid active developer path
 (/Library/Developer/CommandLineTools), missing xcrun at:
 /Library/Developer/CommandLineTools/usr/bin/xcrun
</code>```

I don't have Xcode installed, never did.
Anyone have a solution?

答: I just updated to High Sierra and I couldn't just run xcode-select --install. First, I had to actually install xcode from the app store. Then I ran xcode-select --install. Then I had to run sudo xcodebuild -license, agree to the terms, then I could finally run git commands again.

ContentLicense: CC BY-SA 4.0

Body:
I just upgraded from Yosemite to El Capitan (and replicated the problem upgrading from El Capitan to Sierra), and when I try to type for example git status inside a terminal, I get the following error:

xcrun: error: invalid active developer path
 (/Library/Developer/CommandLineTools), missing xcrun at:
 /Library/Developer/CommandLineTools/usr/bin/xcrun

I don't have Xcode installed, never did.
Anyone have a solution?

ContentLicense: CC BY-SA 3.0


问:
search filter using regex similar to sql Like 'a%'
i have this search filter, how do i implement a regex to make it work like the sql ( Like 'a%' ) that finds any values that starts with a ?

```<code>function SFName() {

    var input, filter, table, tr, td, i;
    input = document.getElementById("SFNameInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");

    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[0];
        if (td) {
            if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";

            } else {
                tr[i].style.display = "none";
            }
        }
    }
}
</code>```

this is what i tried :

```<code>function SFName() {

    var input, regex, table, tr, td, i;
    input = document.getElementById("SFNameInput").value;
    regex = /^/gi;
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");

    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[2];
        if (td) {
            if (regex.exec(td.innerHTML).indexOf(input) > -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
}
</code>```

https://jsfiddle.net/j7t5d9ud/

答:
To find any values that start with a use: /^a[\s\S]*/ or /^a.*/

^ gets makes sure the match starts at the beginning.

a matches a.

[\s\S] or . matches all.

* matches 0 or more of the preceding character. In this case it's a wildcard.

EDIT:

To implement this you would replace filter with:

```<code>filter = new RegExp("^" + input.value + ".*", "i");
</code>```

and the condition to:

```<code>if (td.innerHTML.match(filter)) {
  tr[i].style.display = "";
} else {
  tr[i].style.display = "none";
}
</code>```

The "i" in the RegExp makes the regular expression case insensitive.

Body:
i have this search filter, how do i implement a regex to make it work like the sql ( Like 'a%' ) that finds any values that starts with a ?

function SFName() {

    var input, filter, table, tr, td, i;
    input = document.getElementById("SFNameInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");

    for (i = 0; i
 -1) {
                tr[i].style.display = "";

            } else {
                tr[i].style.display = "none";
            }
        }
    }
}

this is what i tried :

function SFName() {

    var input, regex, table, tr, td, i;
    input = document.getElementById("SFNameInput").value;
    regex = /^/gi;
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");

    for (i = 0; i
 -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
}

https://jsfiddle.net/j7t5d9ud/

Body:
To find any values that start with a use: /^a[\s\S]*/ or /^a.*/

^ gets makes sure the match starts at the beginning.

a matches a.

[\s\S] or . matches all.

* matches 0 or more of the preceding character. In this case it's a wildcard.

EDIT:

To implement this you would replace filter with:

filter = new RegExp("^" + input.value + ".*", "i");

and the condition to:

if (td.innerHTML.match(filter)) {
  tr[i].style.display = "";
} else {
  tr[i].style.display = "none";
}

The "i" in the RegExp makes the regular expression case insensitive.


问:
Adapting VBA Code to Hide Columns based off values from multiple rows
I have a piece of code I've used to hide columns based off of values being in that column, essentially it looks at all cells in that column underneath a certain row and if there's a value in there it'll keep it showing and if not it'll hide it.

Now I need it to also hide things based off values from a specific row. This is the code:

```<code>Sub HideCols()
Dim LC As Integer, j As Integer
Dim LR As Integer, curCnt As Integer
Dim k As Integer
Dim Data As Variant

Application.ScreenUpdating = False

LC = Cells(3, Columns.Count).End(xlToLeft).Column

For j = 6 To LC
    LR = Cells(Rows.Count, j).End(xlUp).Row
    curCnt = 0
    Data = Range(Cells(1, 1), Cells(LR, LC))
    For k = 3 To LR
       If Rows(k).Hidden = False And Data(k, j) <> "" Then _
       curCnt = curCnt + 1
    Next k
    Columns(j).Hidden = curCnt < 2
Next j

Application.ScreenUpdating = True

End Sub
</code>```

I tried adding:

```<code>Dim i As Long
Dim c As Variant
Dim l As Integer
For i = 6 To j
    For Each c In ActiveSheet.Cells(2, i)
    If Columns(i).Hidden and c.Value Like "Tri-Annual" Then
        ActiveSheet.Columns(i).Hidden = False
    Else
        ActiveSheet.Columns(i).Hidden = True
    End If
    Next c
Next i
</code>```

This was added in following, so the hope was that it would only look at the columns that weren't hidden by the first macro and then hide all columns that don't also have "Tri-Annual" in that column in row 2. It does complete the task, but I have to run it twice. Is there any easier way of doing this?

答:
Try this. I think I have it the right way round.</p>

```<code>Sub HideCols()

Dim LC As Long, j As Long
Dim LR As Long, curCnt As Long
Dim k As Long
Dim Data As Variant

Application.ScreenUpdating = False

LC = Cells(3, Columns.Count).End(xlToLeft).Column

For j = 6 To LC
    LR = Cells(Rows.Count, j).End(xlUp).Row
    curCnt = 0
    Data = Range(Cells(1, 1), Cells(LR, LC))
    For k = 3 To LR
       If Rows(k).Hidden = False And Data(k, j) <> "" Then _
       curCnt = curCnt + 1
    Next k
    Columns(j).Hidden = curCnt < 2 Or Cells(2, j).Value <> "Tri-Annual"
Next j

Application.ScreenUpdating = True

End Sub
</code>```

Body:
I have a piece of code I've used to hide columns based off of values being in that column, essentially it looks at all cells in that column underneath a certain row and if there's a value in there it'll keep it showing and if not it'll hide it.

Now I need it to also hide things based off values from a specific row. This is the code:

Sub HideCols()
Dim LC As Integer, j As Integer
Dim LR As Integer, curCnt As Integer
Dim k As Integer
Dim Data As Variant

Application.ScreenUpdating = False

LC = Cells(3, Columns.Count).End(xlToLeft).Column

For j = 6 To LC
    LR = Cells(Rows.Count, j).End(xlUp).Row
    curCnt = 0
    Data = Range(Cells(1, 1), Cells(LR, LC))
    For k = 3 To LR
       If Rows(k).Hidden = False And Data(k, j) <> "" Then _
       curCnt = curCnt + 1
    Next k
    Columns(j).Hidden = curCnt < 2
Next j

Application.ScreenUpdating = True

End Sub

I tried adding:

Dim i As Long
Dim c As Variant
Dim l As Integer
For i = 6 To j
    For Each c In ActiveSheet.Cells(2, i)
    If Columns(i).Hidden and c.Value Like "Tri-Annual" Then
        ActiveSheet.Columns(i).Hidden = False
    Else
        ActiveSheet.Columns(i).Hidden = True
    End If
    Next c
Next i

This was added in following, so the hope was that it would only look at the columns that weren't hidden by the first macro and then hide all columns that don't also have "Tri-Annual" in that column in row 2. It does complete the task, but I have to run it twice. Is there any easier way of doing this?

Body:
Try this. I think I have it the right way round.

Sub HideCols()

Dim LC As Long, j As Long
Dim LR As Long, curCnt As Long
Dim k As Long
Dim Data As Variant

Application.ScreenUpdating = False

LC = Cells(3, Columns.Count).End(xlToLeft).Column

For j = 6 To LC
    LR = Cells(Rows.Count, j).End(xlUp).Row
    curCnt = 0
    Data = Range(Cells(1, 1), Cells(LR, LC))
    For k = 3 To LR
       If Rows(k).Hidden = False And Data(k, j) <> "" Then _
       curCnt = curCnt + 1
    Next k
    Columns(j).Hidden = curCnt < 2 Or Cells(2, j).Value <> "Tri-Annual"
Next j

Application.ScreenUpdating = True

End Sub


问:
Django not finding apps in virtualenv when using manage.py syncdb
My problem is in getting manage.py syncdb to run within a virtualenv.

It was working fine at one point, but seems to have broken sometime around when I installed South and updated pip and distribute.

Anyways, when the virtualenv is activated, I can import apps fine within the interactive interpreter. Running through mod_wsgi, the apps are imported as well, and the site can run.

When I run manage.py syncdb, it fails to find any app in INSTALLED_APPS that is in my virtualenv. It picks up system-installed apps fine, but fails when it tries to import virtualenv only apps.

答:
I have a simple solution to this

Just launch manage.py from the python in the bin of your virtual environment.

So say your python is here /home/tom/environments/my_env/bin/python you could launch manage.py like so:

/home/tom/environments/my_env/bin/python manage.py syncdb

then just create a symlink to the virtual environment's python inside your django project and call it env_python then you can do this:

./env_python manage.py syncdb

ContentLicense: CC BY-SA 2.5


问:
Octopus - Steps to take code backup on server (tentacle) before deployment
I have created a new release on Octopus server to deploy the code on live tentacle virtual machine (in Azure environment). It all works okay.
I would like to know the steps to take code backup in another folder on the live tentacle node before deploying new code on to it. Not sure how to do this. I am new to power shell. Thanks.</p>

答:
The idea behind Octopus is that all deployments are repeatable, including older versions. The code you deployed for previous versions lives on the Octopus server (depending on how you setup your retention policies) so you can deploy it again.

The default manner of installing to IIS is to leave the previous deployment alone and deploy to a new folder and update IIS to point to the new version.


问:
Room cannot find implementation
I have a problem with testing a Room database:
when I run the test, I get this exception:

```<code>java.lang.RuntimeException: cannot find implementation for database.TicketDatabase. TicketDatabase_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:92)
at android.arch.persistence.room.RoomDatabase$Builder.build(RoomDatabase.java:454)
at com.sw.ing.gestionescontrini.DatabaseTest.setDatabase(DatabaseTest.java:36)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1886)
</code>```

Class DatabaseTest:

```<code>public class DatabaseTest {

    TicketDatabase database;
    DAO ticketDAO;

    @Before
    public void setDatabase() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Context context = InstrumentationRegistry.getTargetContext();
        database = Room.inMemoryDatabaseBuilder(context, TicketDatabase.class).build();

        Method method = TicketDatabase.class.getDeclaredMethod("ticketDao()");
        method.setAccessible(true);
        ticketDAO = (DAO) method.invoke(database, null);
    }
}
</code>```

gradle file:

```<code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.sw.ing.gestionescontrini"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    defaultConfig {
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
    compile 'android.arch.persistence.room:rxjava2:1.0.0-rc1'
    testCompile'android.arch.persistence.room:testing:1.0.0-rc1'

}
</code>```

I don't really know what this implementation should be, I searched for a solution but all I found doesn't work for me. For instance, many found a solution adding kapt "android.arch.persistence.room..." but gradle doesn't recognize "kapt".

答:
kapt is for Kotlin.

First, add:

```<code>annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
</code>```

to your dependencies closure.

Then, upgrade android.arch.persistence.room:rxjava2 and android.arch.persistence.room:testing to 1.0.0 instead of 1.0.0-rc1.

ref: https://developer.android.com/jetpack/androidx/releases/room

Title: Room cannot find implementation

Body:
I have a problem with testing a Room database:
when I run the test, I get this exception:

java.lang.RuntimeException: cannot find implementation for database.TicketDatabase. TicketDatabase_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:92)
at android.arch.persistence.room.RoomDatabase$Builder.build(RoomDatabase.java:454)
at com.sw.ing.gestionescontrini.DatabaseTest.setDatabase(DatabaseTest.java:36)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1886)

Class DatabaseTest:

public class DatabaseTest {

    TicketDatabase database;
    DAO ticketDAO;

    @Before
    public void setDatabase() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Context context = InstrumentationRegistry.getTargetContext();
        database = Room.inMemoryDatabaseBuilder(context, TicketDatabase.class).build();

        Method method = TicketDatabase.class.getDeclaredMethod("ticketDao()");
        method.setAccessible(true);
        ticketDAO = (DAO) method.invoke(database, null);
    }
}

gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.sw.ing.gestionescontrini"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    defaultConfig {
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
    compile 'android.arch.persistence.room:rxjava2:1.0.0-rc1'
    testCompile'android.arch.persistence.room:testing:1.0.0-rc1'

}

I don't really know what this implementation should be, I searched for a solution but all I found doesn't work for me. For instance, many found a solution adding kapt "android.arch.persistence.room..." but gradle doesn't recognize "kapt".

Body:
kapt is for Kotlin.

First, add:

annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

to your dependencies closure.

Then, upgrade android.arch.persistence.room:rxjava2 and android.arch.persistence.room:testing to 1.0.0 instead of 1.0.0-rc1.

ref: https://developer.android.com/jetpack/androidx/releases/room


问:
Tornado: get request arguments
I have following code:

```<code>application = tornado.web.Application([
    (r"/get(.*)", GetHandler),
])

class GetHandler(tornado.web.RequestHandler):
    def get(self, key):
        response = {'key': key}
        self.write(response)
</code>```

when I go to localhost:port/get?key=python I receive empty key value {'key': ''}. What is wrong here?

答:
(.*) in regex matches everything. So this — (r"/get(.*)", GetHandler) — will match anything followed by /get, example:

```<code>/get
/getsomething
/get/something
/get.asldfkj%5E&(*&fkasljf
</code>```

Let's say a request comes in at localhost:port/get/something, then the value of key argument in GetHandler.get(self, key) will be /something (yes, including the slash because .* matches everything).

But if a request comes in at localhost:port/get?key=python, the value of key argument in GETHandler.get(self, key) will be an empty string. It happens because the part containing ?key=python is called a Query String. It's not part of the url path. Tornado (or almost every other web framework) doesn't pass this to the view as an argument.

There are two ways you can change your code:

If you want to access your view like this - localhost:port/get?key=python, you'll need to make changes to your url config and to your view:

```<code>application = tornado.web.Application([
    (r"/get", GetHandler),
])

class GetHandler(tornado.web.RequestHandler):
    def get(self):
        key = self.get_argument('key', None)
        response = {'key': key}
        self.write(response)
</code>```

If you don't want to change your app url config and your view, you'll need to make the request like this - localhost:port/get/python.

But still you'll need to make a small change to your url config. Add a slash - / - between get and (.*), because otherwise the value of key would be /python instead of python.

```<code>application = tornado.web.Application([
    (r"/get/(.*)", GetHandler), # note the slash
])
</code>```

Title: Tornado: get request arguments

Body:
I have following code:

application = tornado.web.Application([
    (r"/get(.*)", GetHandler),
])

class GetHandler(tornado.web.RequestHandler):
    def get(self, key):
        response = {'key': key}
        self.write(response)

when I go to localhost:port/get?key=python I receive empty key value {'key': ''}. What is wrong here?

Body:
(.*) in regex matches everything. So this — (r"/get(.*)", GetHandler) — will match anything followed by /get, example:

/get
/getsomething
/get/something
/get.asldfkj%5E&(*&fkasljf

Let's say a request comes in at localhost:port/get/something, then the value of key argument in GetHandler.get(self, key) will be /something (yes, including the slash because .* matches everything).

But if a request comes in at localhost:port/get?key=python, the value of key argument in GETHandler.get(self, key) will be an empty string. It happens because the part containing ?key=python is called a Query String. It's not part of the url path. Tornado (or almost every other web framework) doesn't pass this to the view as an argument.

There are two ways you can change your code:

If you want to access your view like this - localhost:port/get?key=python, you'll need to make changes to your url config and to your view:

application = tornado.web.Application([
    (r"/get", GetHandler),
])

class GetHandler(tornado.web.RequestHandler):
    def get(self):
        key = self.get_argument('key', None)
        response = {'key': key}
        self.write(response)

If you don't want to change your app url config and your view, you'll need to make the request like this - localhost:port/get/python.

But still you'll need to make a small change to your url config. Add a slash - / - between get and (.*), because otherwise the value of key would be /python instead of python.

application = tornado.web.Application([
    (r"/get/(.*)", GetHandler), # note the slash
])


问:
Add multiple rows to Google Spreadsheet via API
I can add a new row to a Google spreadsheet with this code:

```<code>$valueRange = new Google_Service_Sheets_ValueRange();
$valueRange->setValues(["values" => ['data1', 'data2']]);
$range = 'Sheet1!A1:A';
$conf = ["valueInputOption" => "USER_ENTERED"];
$service->spreadsheets_values->append($spreadsheetId, $range, $valueRange, $conf);
</code>```

How should I change the setValues params to add multiple rows?

Thank you.

UPDATE

In the meantime I use this approach:

```<code>$range_number = 1; // Keep spreadsheet header
$data = array();
for($i=0;$i<count($data);$i++){
    $range_number++;
    $range = 'Sheet1!A'.$range_number.':XX';
    $values = array( array($data1[$i], $data2[$i], $data3[$i]) );
    $data[] = new Google_Service_Sheets_ValueRange(
        array( 'range' => $range, 'values' => $values )
    );
}
$body = new Google_Service_Sheets_BatchUpdateValuesRequest(array(
  'valueInputOption' => "USER_ENTERED",
  'data' => $data
));
$result = $service->spreadsheets_values->batchUpdate($spreadsheetId, $body);

// Clear rest of spreadsheet
$range_number++;
$range = 'Sheet1!A'.$range_number.':XX';
$clearRange = new Google_Service_Sheets_ClearValuesRequest();
$service->spreadsheets_values->clear($spreadsheetId, $range, $clearRange);
</code>```

But this way I have to send the previous data as well. My goal would be just to append the new data.

答:
For those of you who want to append multiple rows instead of update rows. You can use this solution.

```<code>$valueRange = new Google_Service_Sheets_ValueRange();

$valueRange->setValues([['John', 'Doe'],['Jane', 'Doe']]);

$range = 'Sheet1!A1:A';
$conf = ["valueInputOption" => "USER_ENTERED"];
$service->spreadsheets_values->append($spreadsheetId, $range, $valueRange, $conf);
</code>```

It took me ages to work this out hope it helps.

Body:
I can add a new row to a Google spreadsheet with this code:

$valueRange = new Google_Service_Sheets_ValueRange();
$valueRange->setValues(["values" => ['data1', 'data2']]);
$range = 'Sheet1!A1:A';
$conf = ["valueInputOption" => "USER_ENTERED"];
$service->spreadsheets_values->append($spreadsheetId, $range, $valueRange, $conf);

How should I change the setValues params to add multiple rows?

Thank you.

UPDATE

In the meantime I use this approach:

$range_number = 1; // Keep spreadsheet header
$data = array();
for($i=0;$i<count($data);$i++){
    $range_number++;
    $range = 'Sheet1!A'.$range_number.':XX';
    $values = array( array($data1[$i], $data2[$i], $data3[$i]) );
    $data[] = new Google_Service_Sheets_ValueRange(
        array( 'range' => $range, 'values' => $values )
    );
}
$body = new Google_Service_Sheets_BatchUpdateValuesRequest(array(
  'valueInputOption' => "USER_ENTERED",
  'data' => $data
));
$result = $service->spreadsheets_values->batchUpdate($spreadsheetId, $body);

// Clear rest of spreadsheet
$range_number++;
$range = 'Sheet1!A'.$range_number.':XX';
$clearRange = new Google_Service_Sheets_ClearValuesRequest();
$service->spreadsheets_values->clear($spreadsheetId, $range, $clearRange);

But this way I have to send the previous data as well. My goal would be just to append the new data.

Body:
For those of you who want to append multiple rows instead of update rows. You can use this solution.

$valueRange = new Google_Service_Sheets_ValueRange();

$valueRange->setValues([['John', 'Doe'],['Jane', 'Doe']]);

$range = 'Sheet1!A1:A';
$conf = ["valueInputOption" => "USER_ENTERED"];
$service->spreadsheets_values->append($spreadsheetId, $range, $valueRange, $conf);

It took me ages to work this out hope it helps.


问:
How to configure a Amazon Route with SSL for a Heroku App
I need to set an Amazon Domain as a custom domain for a Heroku app. I found the next tutorial https://devcenter.heroku.com/articles/route-53 but it doesn't work if the app needs https requests. The first idea was to set up the SSL Certificate in Heroku, but the SSL Amazon Domain manager doesn't allow to download the certificate, so the SSL need to be managed by AWS.

What is the best way to add Amazon SSL to a Heroku app?

答:
Amazon created SSL certificates only work with supported Amazon services such as Elastic Load Balancers, CloudFront distributions and API Gateway.

The easiest method to use Amazon SSL certificates is to add a load balancer. Another method is to enable CloudFront.

AWS Certificate Manager


问:
Docker - max depth exceeded
So I am using this example:

https://github.com/mcmoe/mssqldocker

In order to create a SQL Server image and load it with data.  I have several sql scripts which I run when I run the container.

However, I started getting this error when building the image:

```<code>Step 7/9 : ENTRYPOINT ./entrypoint.sh
 ---> Running in c8c654f6a630
max depth exceeded
</code>```

I'm not sure how to fix this, I restarted docker and even updated it.
I read something about 125 layers?  Can anyone explain the cause of this and a potential fix?

I found this command to run:

```<code>docker history microsoft/mssql-server-linux:latest | wc -l
 312
</code>```

My docker-compose yml:

```<code>version: "3"
services:
  mssql:
      build: .
      image: 'microsoft/mssql-server-linux'
      ports:
          - '1433:1433'
      environment:
          - ACCEPT_EULA=Y
          - SA_PASSWORD=Abcgfgh123!
      volumes:
          - db_volume:/var/lib/mssql/data
volumes:
  db_volume:
</code>```

答:
The image parameter for a service in a docker-compose.yml definition has dual meanings depending on the existence of a build parameter.

If there is no build stanza, The image will just be pulled and run.

If you have a build stanza, image will be the name your built
image is tagged as, and run.

By naming the built image microsoft/mssql-server-linux, which is the same as the FROM microsoft/mssql-server-linux image. Docker was layering the build on top of itself each time.

The original build started on the "official" microsoft/mssql-server-linux but then each subsequent build would start from your local microsoft/mssql-server-linux image which had been appended to, until eventually you hit the maximum number of layers for your storage driver.

Use your own namespace for all images you build:

```<code>version: "3"
services:
  mssql:
      build: .
      image: 'user3437721/mssql-server-linux'
</code>```

Title: Docker - max depth exceeded

Body:
So I am using this example:

https://github.com/mcmoe/mssqldocker

In order to create a SQL Server image and load it with data.  I have several sql scripts which I run when I run the container.

However, I started getting this error when building the image:

Step 7/9 : ENTRYPOINT ./entrypoint.sh
 ---> Running in c8c654f6a630
max depth exceeded

I'm not sure how to fix this, I restarted docker and even updated it.
I read something about 125 layers?  Can anyone explain the cause of this and a potential fix?

I found this command to run:

docker history microsoft/mssql-server-linux:latest | wc -l
 312

My docker-compose yml:

version: "3"
services:
  mssql:
      build: .
      image: 'microsoft/mssql-server-linux'
      ports:
          - '1433:1433'
      environment:
          - ACCEPT_EULA=Y
          - SA_PASSWORD=Abcgfgh123!
      volumes:
          - db_volume:/var/lib/mssql/data
volumes:
  db_volume:

Body:
The image parameter for a service in a docker-compose.yml definition has dual meanings depending on the existence of a build parameter.

If there is no build stanza, The image will just be pulled and run.

If you have a build stanza, image will be the name your built
image is tagged as, and run.

By naming the built image microsoft/mssql-server-linux, which is the same as the FROM microsoft/mssql-server-linux image. Docker was layering the build on top of itself each time.

The original build started on the "official" microsoft/mssql-server-linux but then each subsequent build would start from your local microsoft/mssql-server-linux image which had been appended to, until eventually you hit the maximum number of layers for your storage driver.

Use your own namespace for all images you build:

version: "3"
services:
  mssql:
      build: .
      image: 'user3437721/mssql-server-linux'


答:
Here is a solution using dplyr

```<code>table1 <- read.table(text = " Group  Component  Data  High_Limit  LOW_LIMIT
                 group1  R1         10     12          8
                 group1  R1         11     12          8
                 group1  R2         50     60          45
                 group1  R2         55     60          45
                 group2  C1         9      12          8.5
                 group2  C1         10.5   12          9
                 group2  R3         11.5   12          9
                 group2  R3         9.5    12          9", header = TRUE)
library(dplyr)
table2 <- table1 %>%
  group_by(Group, Component) %>%
  summarise(m = mean(Data), s = sd(Data), Ts = max(High_Limit),
            Ts = max(High_Limit), Ti = min(LOW_LIMIT)) %>%
  mutate(CpK = min((m-Ti)/(3*s), (Ts-m)/(3*s)))
# final data frame
table3 <- left_join(table1, table2, by = c("Group", "Component"))
</code>```

Title: Add a data frame calculated column on filtered element

Body:
I want to add a calculated column to a data frame to find CpK on each series of group / Component (group1 /R1, group1 / R2 ...), data frame is like :

Table1 :
! Group ! Component ! Data ! High_Limit ! LOW_LIMIT !
!-------!-----------!------!------------!-----------!
!group1 ! R1        ! 10   !  12        !  8        !
!group1 ! R1        ! 11   !  12        !  8        !
!group1 ! R2        ! 50   !  60        !  45       !
!group1 ! R2        ! 55   !  60        !  45       !
!group2 ! C1        ! 9    !  12        !  8.5      !
!group2 ! C1        ! 10.5 !  12        !  9        !
!group2 ! R3        ! 11.5 !  12        !  9        !
!group2 ! R3        ! 9.5  !  12        !  9        !
and so on ...

Calcul for Cpk is :

m <- mean(table1$Data)
s <- sd(table1$Data)

Ts <- max(table1$HIGH_LIMIT)
Ti <- min(table1$LOW_LIMIT)

CpK <- min((m-Ti)/(3*s), (Ts-m)/(3*s))

Could you please help me ?

Here the real data frame exported (on samples)

"UUT_NAME"  "STATION_NUM"   "START_DATE_TIME"   "LOW_LIMIT" "DATA"  "HIGH_LIMIT"    "UNITS" "STEP_NAME"

"32"    "CELOGIC.MA-6475"   "00 00297"  2014-01-27 16:30:38 88  103.83455   112 "pF"    "C10"
"104"   "CELOGIC.MA-6475"   "00 00297"  2014-01-27 16:30:38 87.9    89.64711    93.9    "KO"    "R1"
"105"   "CELOGIC.MA-6475"   "00 00297"  2014-01-27 16:30:38 2.08    2.13345 2.22    "KO"    "R2"
"106"   "CELOGIC.MA-6475"   "00 00297"  2014-01-27 16:30:38 29.1    30.057545   31.1    "KO"    "R3"
"107"   "CELOGIC.MA-6475"   "00 00297"  2014-01-27 16:30:38 29.1    30.086464   31.1    "KO"    "R4"
"1005"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 13:58:38 88  104.37667   112 "pF"    "C10"
"1077"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 13:58:38 87.9    89.788269   93.9    "KO"    "R1"
"1078"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 13:58:38 2.08    2.13431 2.22    "KO"    "R2"
"1079"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 13:58:38 29.1    30.045176   31.1    "KO"    "R3"
"1080"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 13:58:38 29.1    30.049561   31.1    "KO"    "R4"
"1978"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 14:09:17 88  104.7235    112 "pF"    "C10"
"2050"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 14:09:17 87.9    89.813126   93.9    "KO"    "R1"
"2051"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 14:09:17 2.08    2.134059    2.22    "KO"    "R2"
"2052"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 14:09:17 29.1    30.048182   31.1    "KO"    "R3"
"2053"  "CELOGIC.MA-2161"   "00 00362"  2014-05-13 14:09:17 29.1    30.056608   31.1    "KO"    "R4"
"2951"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:30:51 88  104.03241   112 "pF"    "C10"
"3023"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:31:38 88  103.96976   112 "pF"    "C10"
"3095"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:31:38 87.9    89.63073    93.9    "KO"    "R1"
"3096"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:31:38 2.08    2.141897    2.22    "KO"    "R2"
"3097"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:31:38 29.1    30.035461   31.1    "KO"    "R3"
"3098"  "CELOGIC.MA-4329"   "00 00362"  2014-05-13 14:31:38 29.1    30.104946   31.1    "KO"    "R4"
"3996"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:30:36 88  104.51376   112 "pF"    "C10"
"4068"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:30:36 87.9    90.733009   93.9    "KO"    "R1"
"4069"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:30:36 2.08    2.141215    2.22    "KO"    "R2"
"4070"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:30:36 29.1    30.147131   31.1    "KO"    "R3"
"4071"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:30:36 29.1    30.113092   31.1    "KO"    "R4"
"4892"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:39:36 88  107.34245   112 "pF"    "C10"
"4964"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:39:36 87.9    90.934967   93.9    "KO"    "R1"
"4965"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:39:36 2.08    2.140769    2.22    "KO"    "R2"
"4966"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:39:36 29.1    30.136806   31.1    "KO"    "R3"
"4967"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:39:36 29.1    30.114983   31.1    "KO"    "R4"
"5534"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:42:13 88  105.98895   112 "pF"    "C10"
"5606"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:42:13 87.9    90.628517   93.9    "KO"    "R1"
"5607"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:42:13 2.08    2.141326    2.22    "KO"    "R2"
"5608"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:42:13 29.1    30.142355   31.1    "KO"    "R3"
"5609"  "CELOGIC.MA-2374"   "00 00297"  2014-06-19 14:42:13 29.1    30.122778   31.1    "KO"    "R4"
"6507"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:26:10 88  103.49479   112 "pF"    "C10"
"6579"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:26:10 87.9    90.358688   93.9    "KO"    "R1"
"6580"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:26:10 2.08    2.141122    2.22    "KO"    "R2"
"6581"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:26:10 29.1    30.058239   31.1    "KO"    "R3"
"6582"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:26:10 29.1    30.06591    31.1    "KO"    "R4"
"7430"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:35:27 88  103.60199   112 "pF"    "C10"
"7502"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:35:27 87.9    90.354286   93.9    "KO"    "R1"
"7503"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:35:27 2.08    2.142168    2.22    "KO"    "R2"
"7504"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:35:27 29.1    30.063662   31.1    "KO"    "R3"
"7505"  "CELOGIC.MA-2454"   "00 00297"  2014-09-05 09:35:27 29.1    30.070904   31.1    "KO"    "R4"
"8414"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:50:56 88  102.51865   112 "pF"    "C10"
"8486"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:50:56 87.9    90.974564   93.9    "KO"    "R1"
"8487"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:50:56 2.08    2.148871    2.22    "KO"    "R2"
"8488"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:50:56 29.1    29.983458   31.1    "KO"    "R3"
"8489"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:50:56 29.1    30.128607   31.1    "KO"    "R4"
"8918"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:59:56 88  103.016 112 "pF"    "C10"
"8990"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:59:56 87.9    90.883461   93.9    "KO"    "R1"
"8991"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:59:56 2.08    2.148184    2.22    "KO"    "R2"
"8992"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:59:56 29.1    29.975309   31.1    "KO"    "R3"
"8993"  "CELOGIC.MA-1610"   "00 00366"  2015-03-06 07:59:56 29.1    30.137098   31.1    "KO"    "R4"
"9426"  "CELOGIC.MA-1610"   "00 00362"  2015-03-09 13:52:21 88  102.54838   112 "pF"    "C10"
"9498"  "CELOGIC.MA-1610"   "00 00362"  2015-03-09 13:52:21 87.9    89.871902   93.9    "KO"    "R1"
"9499"  "CELOGIC.MA-1610"   "00 00362"  2015-03-09 13:52:21 2.08    2.142678    2.22    "KO"    "R2"
"9500"  "CELOGIC.MA-1610"   "00 00362"  2015-03-09 13:52:21 29.1    29.947052   31.1    "KO"    "R3"
"9501"  "CELOGIC.MA-1610"   "00 00362"  2015-03-09 13:52:21 29.1    30.094099   31.1    "KO"    "R4"
"10399" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:36:44 88  102.50674   112 "pF"    "C10"
"10471" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:36:44 87.9    89.974739   93.9    "KO"    "R1"
"10472" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:36:44 2.08    2.142947    2.22    "KO"    "R2"
"10473" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:36:44 29.1    29.953632   31.1    "KO"    "R3"
"10474" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:36:44 29.1    30.089359   31.1    "KO"    "R4"
"10903" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:50:37 88  102.88899   112 "pF"    "C10"
"10975" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:50:37 87.9    90.077881   93.9    "KO"    "R1"
"10976" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:50:37 2.08    2.142447    2.22    "KO"    "R2"
"10977" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:50:37 29.1    29.951406   31.1    "KO"    "R3"
"10978" "CELOGIC.MA-1610"   "00 00362"  2015-03-09 14:50:37 29.1    30.092203   31.1    "KO"    "R4"
"11876" "CELOGIC.MA-0887"   "00 00362"  2015-03-17 14:19:37 88  105.72658   112 "pF"    "C10"
"11948" "CELOGIC.MA-0887"   "00 00362"  2015-03-17 14:19:37 87.9    89.542099   93.9    "KO"    "R1"
"11949" "CELOGIC.MA-0887"   "00 00362"  2015-03-17 14:19:37 2.08    2.143392    2.22    "KO"    "R2"
"11950" "CELOGIC.MA-0887"   "00 00362"  2015-03-17 14:19:37 29.1    29.941921   31.1    "KO"    "R3"
"11951" "CELOGIC.MA-0887"   "00 00362"  2015-03-17 14:19:37 29.1    29.980062   31.1    "KO"    "R4"
"12849" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:47:55 88  104.56109   112 "pF"    "C10"
"12921" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:47:55 87.9    90.826813   93.9    "KO"    "R1"
"12922" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:47:55 2.08    2.13772 2.22    "KO"    "R2"
"12923" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:47:55 29.1    29.979958   31.1    "KO"    "R3"
"12924" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:47:55 29.1    30.028364   31.1    "KO"    "R4"
"13445" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:22 88  104.10088   112 "pF"    "C10"
"13517" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:22 87.9    90.849869   93.9    "KO"    "R1"
"13518" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:22 2.08    2.136499    2.22    "KO"    "R2"
"13519" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:22 29.1    29.981756   31.1    "KO"    "R3"
"13520" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:22 29.1    30.028885   31.1    "KO"    "R4"
"13748" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:49 88  105.10763   112 "pF"    "C10"
"13820" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:49 87.9    90.826553   93.9    "KO"    "R1"
"13821" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:49 2.08    2.137116    2.22    "KO"    "R2"
"13822" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:49 29.1    29.984587   31.1    "KO"    "R3"
"13823" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 14:49:49 29.1    30.029911   31.1    "KO"    "R4"
"14721" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 15:03:52 88  104.18301   112 "pF"    "C10"
"14793" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 15:03:52 87.9    90.603035   93.9    "KO"    "R1"
"14794" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 15:03:52 2.08    2.136766    2.22    "KO"    "R2"
"14795" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 15:03:52 29.1    29.987928   31.1    "KO"    "R3"
"14796" "CELOGIC.MA-2189"   "00 00399"  2015-10-30 15:03:52 29.1    30.042906   31.1    "KO"    "R4"
"15694" "CELOGIC.MA-2316"   "00 00399"  2015-11-02 14:52:56 88  103.85734   112 "pF"    "C10"
"15766" "CELOGIC.MA-2316"   "00 00399"  2015-11-02 14:52:56 87.9    90.941826   93.9    "KO"    "R1"
"15767" "CELOGIC.MA-2316"   "00 00399"  2015-11-02 14:52:56 2.08    2.135956    2.22    "KO"    "R2"
"15768" "CELOGIC.MA-2316"   "00 00399"  2015-11-02 14:52:56 29.1    29.919226   31.1    "KO"    "R3"
"15769" "CELOGIC.MA-2316"   "00 00399"  2015-11-02 14:52:56 29.1    30.054958   31.1    "KO"    "R4"
"16667" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:30:48 88  106.41589   112 "pF"    "C10"
"16739" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:30:48 87.9    90.797607   93.9    "KO"    "R1"
"16740" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:30:48 2.08    2.134154    2.22    "KO"    "R2"
"16741" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:30:48 29.1    30.109236   31.1    "KO"    "R3"
"16742" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:30:48 29.1    30.025709   31.1    "KO"    "R4"
"17640" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:52:41 88  106.77251   112 "pF"    "C10"
"17712" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:52:41 87.9    90.557838   93.9    "KO"    "R1"
"17713" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:52:41 2.08    2.132611    2.22    "KO"    "R2"
"17714" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:52:41 29.1    30.115213   31.1    "KO"    "R3"
"17715" "CELOGIC.MA-0906"   "00 00399"  2015-11-02 15:52:41 29.1    30.049799   31.1    "KO"    "R4"
"18144" "CELOGIC.MA-3154"   "00 00399"  2015-11-02 16:12:23 88  104.15064   112 "pF"    "C10"
"18216" "CELOGIC.MA-3154"   "00 00399"  2015-11-02 16:12:23 87.9    90.598541   93.9    "KO"    "R1"
"18217" "CELOGIC.MA-3154"   "00 00399"  2015-11-02 16:12:23 2.08    2.136247    2.22    "KO"    "R2"
"18218" "CELOGIC.MA-3154"   "00 00399"  2015-11-02 16:12:23 29.1    30.099293   31.1    "KO"    "R3"
"18219" "CELOGIC.MA-3154"   "00 00399"  2015-11-02 16:12:23 29.1    29.956236   31.1    "KO"    "R4"
"18787" "CELOGIC.MA-3154"   "00 00399"  2015-11-03 09:20:08 88  104.50943   112 "pF"    "C10"
"18859" "CELOGIC.MA-3154"   "00 00399"  2015-11-03 09:20:08 87.9    90.196915   93.9    "KO"    "R1"
"18860" "CELOGIC.MA-3154"   "00 00399"  2015-11-03 09:20:08 2.08    2.136503    2.22    "KO"    "R2"
"18861" "CELOGIC.MA-3154"   "00 00399"  2015-11-03 09:20:08 29.1    30.089535   31.1    "KO"    "R3"
"18862" "CELOGIC.MA-3154"   "00 00399"  2015-11-03 09:20:08 29.1    29.956837   31.1    "KO"    "R4"
"19760" "CELOGIC.MA-2610"   "00 00362"  2016-03-09 16:12:04 88  104.67191   112 "pF"    "C10"
"19832" "CELOGIC.MA-2610"   "00 00362"  2016-03-09 16:12:04 87.9    90.35878    93.9    "KO"    "R1"
"19833" "CELOGIC.MA-2610"   "00 00362"  2016-03-09 16:12:04 2.08    2.145689    2.22    "KO"    "R2"
"19834" "CELOGIC.MA-2610"   "00 00362"  2016-03-09 16:12:04 29.1    30.158304   31.1    "KO"    "R3"
"19835" "CELOGIC.MA-2610"   "00 00362"  2016-03-09 16:12:04 29.1    30.004744   31.1    "KO"    "R4"
"20264" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 14:14:01 88  103.27634   112 "pF"    "C10"
"20336" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 14:14:01 87.9    90.543076   93.9    "KO"    "R1"
"20337" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 14:14:01 2.08    2.144124    2.22    "KO"    "R2"
"20338" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 14:14:01 29.1    30.138008   31.1    "KO"    "R3"
"20339" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 14:14:01 29.1    29.987755   31.1    "KO"    "R4"
"21237" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 16:02:18 88  103.43541   112 "pF"    "C10"
"21309" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 16:02:18 87.9    90.312469   93.9    "KO"    "R1"
"21310" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 16:02:18 2.08    2.145076    2.22    "KO"    "R2"
"21311" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 16:02:18 29.1    30.144836   31.1    "KO"    "R3"
"21312" "CELOGIC.MA-2610"   "00 00399"  2016-03-09 16:02:18 29.1    29.99951    31.1    "KO"    "R4"
"22210" "CELOGIC.MA-2610"   "00 00362"  2016-03-10 09:07:24 88  103.84418   112 "pF"    "C10"
"22282" "CELOGIC.MA-2610"   "00 00362"  2016-03-10 09:07:24 87.9    90.39769    93.9    "KO"    "R1"
"22283" "CELOGIC.MA-2610"   "00 00362"  2016-03-10 09:07:24 2.08    2.145807    2.22    "KO"    "R2"
"22284" "CELOGIC.MA-2610"   "00 00362"  2016-03-10 09:07:24 29.1    30.145554   31.1    "KO"    "R3"
"22285" "CELOGIC.MA-2610"   "00 00362"  2016-03-10 09:07:24 29.1    29.995651   31.1    "KO"    "R4"
"23183" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 09:45:43 88  103.39602   112 "pF"    "C10"
"23255" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 09:45:43 87.9    90.332397   93.9    "KO"    "R1"
"23256" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 09:45:43 2.08    2.146439    2.22    "KO"    "R2"
"23257" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 09:45:43 29.1    30.082825   31.1    "KO"    "R3"
"23258" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 09:45:43 29.1    30.07023    31.1    "KO"    "R4"
"24156" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 10:35:59 88  103.07425   112 "pF"    "C10"
"24228" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 10:35:59 87.9    90.374924   93.9    "KO"    "R1"
"24229" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 10:35:59 2.08    2.145505    2.22    "KO"    "R2"
"24230" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 10:35:59 29.1    30.075659   31.1    "KO"    "R3"
"24231" "CELOGIC.MA-2609"   "00 00399"  2016-06-02 10:35:59 29.1    30.067387   31.1    "KO"    "R4"
"25128" "CELOGIC.MA-102"    "00 00323"  2016-07-22 15:43:27 88  102.41218   112 "pF"    "C10"
"25200" "CELOGIC.MA-102"    "00 00323"  2016-07-22 15:43:27 87.9    89.970772   93.9    "KO"    "R1"
"25201" "CELOGIC.MA-102"    "00 00323"  2016-07-22 15:43:27 2.08    2.135011    2.22    "KO"    "R2"
"25202" "CELOGIC.MA-102"    "00 00323"  2016-07-22 15:43:27 29.1    30.171347   31.1    "KO"    "R3"
"25203" "CELOGIC.MA-102"    "00 00323"  2016-07-22 15:43:27 29.1    30.038151   31.1    "KO"    "R4"
"26101" "CELOGIC.MA-102"    "00 00323"  2016-07-25 08:52:49 88  102.64326   112 "pF"    "C10"
"26173" "CELOGIC.MA-102"    "00 00323"  2016-07-25 08:52:49 87.9    90.041145   93.9    "KO"    "R1"
"26174" "CELOGIC.MA-102"    "00 00323"  2016-07-25 08:52:49 2.08    2.13542 2.22    "KO"    "R2"
"26175" "CELOGIC.MA-102"    "00 00323"  2016-07-25 08:52:49 29.1    30.17922    31.1    "KO"    "R3"
"26176" "CELOGIC.MA-102"    "00 00323"  2016-07-25 08:52:49 29.1    30.034796   31.1    "KO"    "R4"
"26605" "CELOGIC.MA-102"    "00 00323"  2016-07-25 09:48:51 88  102.55943   112 "pF"    "C10"
"26677" "CELOGIC.MA-102"    "00 00323"  2016-07-25 09:48:51 87.9    89.94989    93.9    "KO"    "R1"
"26678" "CELOGIC.MA-102"    "00 00323"  2016-07-25 09:48:51 2.08    2.136524    2.22    "KO"    "R2"
"26679" "CELOGIC.MA-102"    "00 00323"  2016-07-25 09:48:51 29.1    30.172457   31.1    "KO"    "R3"
"26680" "CELOGIC.MA-102"    "00 00323"  2016-07-25 09:48:51 29.1    30.039785   31.1    "KO"    "R4"
"27578" "CELOGIC.MA-100"    "00 00323"  2016-07-25 10:31:02 88  106.16189   112 "pF"    "C10"
"27650" "CELOGIC.MA-100"    "00 00323"  2016-07-25 10:31:02 87.9    90.254478   93.9    "KO"    "R1"
"27651" "CELOGIC.MA-100"    "00 00323"  2016-07-25 10:31:02 2.08    2.143642    2.22    "KO"    "R2"
"27652" "CELOGIC.MA-100"    "00 00323"  2016-07-25 10:31:02 29.1    30.03858    31.1    "KO"    "R3"
"27653" "CELOGIC.MA-100"    "00 00323"  2016-07-25 10:31:02 29.1    30.034452   31.1    "KO"    "R4"
"28082" "CELOGIC.MA-100"    "00 00323"  2016-07-25 11:22:45 88  105.13081   112 "pF"    "C10"
"28154" "CELOGIC.MA-100"    "00 00323"  2016-07-25 11:22:45 87.9    90.153961   93.9    "KO"    "R1"
"28155" "CELOGIC.MA-100"    "00 00323"  2016-07-25 11:22:45 2.08    2.143321    2.22    "KO"    "R2"
"28156" "CELOGIC.MA-100"    "00 00323"  2016-07-25 11:22:45 29.1    30.020109   31.1    "KO"    "R3"
"28157" "CELOGIC.MA-100"    "00 00323"  2016-07-25 11:22:45 29.1    30.049246   31.1    "KO"    "R4"
"29055" "CELOGIC.MA-100"    "00 00362"  2016-07-25 13:25:13 88  106.46228   112 "pF"    "C10"
"29127" "CELOGIC.MA-100"    "00 00362"  2016-07-25 13:25:13 87.9    90.300667   93.9    "KO"    "R1"

Body:
Here is a solution using dplyr

table1 <- read.table(text = " Group  Component  Data  High_Limit  LOW_LIMIT
                 group1  R1         10     12          8
                 group1  R1         11     12          8
                 group1  R2         50     60          45
                 group1  R2         55     60          45
                 group2  C1         9      12          8.5
                 group2  C1         10.5   12          9
                 group2  R3         11.5   12          9
                 group2  R3         9.5    12          9", header = TRUE)
library(dplyr)
table2 <- table1 %>%
  group_by(Group, Component) %>%
  summarise(m = mean(Data), s = sd(Data), Ts = max(High_Limit),
            Ts = max(High_Limit), Ti = min(LOW_LIMIT)) %>%
  mutate(CpK = min((m-Ti)/(3*s), (Ts-m)/(3*s)))
# final data frame
table3 <- left_join(table1, table2, by = c("Group", "Component"))


问:
In KRL, how do I detect if a variable is an array or hash?
In KRL, I'd like to detect whether a variable is an array or hash so that I know if I need to use the decode or encode operator on it.  Is that possible?

I'd like to do something like this:

```<code> my_var = var.is_array => var.decode() | my_var
</code>```

答:
The only way that I have figured out how to detect the data structure type is by coercing to a string and then checking to see if the resulting pointer string contains the word 'array' or 'hash'.

'One liner'

```<code>myHashIsHash = "#{myHash}".match(re/hash/gi);
</code>```

myHashIsHash will be true/1

Example app built to demonstrate concept

```<code>ruleset a60x547 {
  meta {
    name "detect-array-or-hash"
    description <<
      detect-array-or-hash
    >>
    author "Mike Grace"
    logging on
  }

  global {
    myHash = {
      "asking":"Mike Farmer",
      "question":"detect type"
    };
    myArray = [0,1,2,3];
  }

  rule detect_types {
    select when pageview ".*"
    pre {
      myHashIsArray = "#{myHash}".match(re/array/gi);
      myHashIsHash = "#{myHash}".match(re/hash/gi);
      myArrayIsArray = "#{myArray}".match(re/array/gi);
      myArrayIsHash = "#{myArray}".match(re/hash/gi);

      hashAsString = "#{myHash}";
      arrayAsString = "#{myArray}";
    }
    {
      notify("hash as string",hashAsString) with sticky = true;
      notify("array as string",arrayAsString) with sticky = true;

      notify("hash is array",myHashIsArray) with sticky = true;
      notify("hash is hash",myHashIsHash) with sticky = true;
      notify("array is array",myArrayIsArray) with sticky = true;
      notify("array is hash",myArrayIsHash) with sticky = true;
    }
  }
}
</code>```

Example app in action!

Body:
In KRL, I'd like to detect whether a variable is an array or hash so that I know if I need to use the decode or encode operator on it.  Is that possible?

I'd like to do something like this:

 my_var = var.is_array => var.decode() | my_var

Body:
The only way that I have figured out how to detect the data structure type is by coercing to a string and then checking to see if the resulting pointer string contains the word 'array' or 'hash'.

'One liner'

myHashIsHash = "#{myHash}".match(re/hash/gi);

myHashIsHash will be true/1

Example app built to demonstrate concept

ruleset a60x547 {
  meta {
    name "detect-array-or-hash"
    description <<
      detect-array-or-hash
    >>
    author "Mike Grace"
    logging on
  }

  global {
    myHash = {
      "asking":"Mike Farmer",
      "question":"detect type"
    };
    myArray = [0,1,2,3];
  }

  rule detect_types {
    select when pageview ".*"
    pre {
      myHashIsArray = "#{myHash}".match(re/array/gi);
      myHashIsHash = "#{myHash}".match(re/hash/gi);
      myArrayIsArray = "#{myArray}".match(re/array/gi);
      myArrayIsHash = "#{myArray}".match(re/hash/gi);

      hashAsString = "#{myHash}";
      arrayAsString = "#{myArray}";
    }
    {
      notify("hash as string",hashAsString) with sticky = true;
      notify("array as string",arrayAsString) with sticky = true;

      notify("hash is array",myHashIsArray) with sticky = true;
      notify("hash is hash",myHashIsHash) with sticky = true;
      notify("array is array",myArrayIsArray) with sticky = true;
      notify("array is hash",myArrayIsHash) with sticky = true;
    }
  }
}

Example app in action!


问:
GDB x/i get wrong address
```<code>#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("Hello world");
    return 0;
}
</code>```

I was using GDB to debug this program, after running several si command,

```<code>gdb-peda$
[----------------------------------registers-----------------------------------]
...
[-------------------------------------code-------------------------------------]
   0x4003ec:    add    BYTE PTR [rax],al
   0x4003ee:    add    BYTE PTR [rax],al
   0x4003f0:    push   QWORD PTR [rip+0x200c12]        # 0x601008
=> 0x4003f6:    jmp    QWORD PTR [rip+0x200c14]        # 0x601010
 | 0x4003fc:    nop    DWORD PTR [rax+0x0]
 | 0x400400 <printf@plt>:   jmp    QWORD PTR [rip+0x200c12]        # 0x601018
 | 0x400406 <printf@plt+6>: push   0x0
 | 0x40040b <printf@plt+11>:    jmp    0x4003f0
 |->   0x7ffff7dee870 <_dl_runtime_resolve_avx>:    push   rbx
       0x7ffff7dee871 <_dl_runtime_resolve_avx+1>:  mov    rbx,rsp
       0x7ffff7dee874 <_dl_runtime_resolve_avx+4>:  and    rsp,0xffffffffffffffe0
       0x7ffff7dee878 <_dl_runtime_resolve_avx+8>:  sub    rsp,0x180
                                                                  JUMP is taken
[------------------------------------stack-------------------------------------]
...
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x00000000004003f6 in ?? ()
</code>```

When i tried to show the instructions in *0x601010, i got an error, because GDB was using the wrong address (0xfffffffff7dee870), however, when using x/g command, the address (0x00007ffff7dee870) is correct.

```<code>gdb-peda$ x/4i *0x601010
   0xfffffffff7dee870:  Cannot access memory at address 0xfffffffff7dee870
gdb-peda$ x/g 0x601010
0x601010:   0x00007ffff7dee870
gdb-peda$ x/8xb 0x601010
0x601010:   0x70    0xe8    0xde    0xf7    0xff    0x7f    0x00    0x00
gdb-peda$ x/4i 0x00007ffff7dee870
   0x7ffff7dee870 <_dl_runtime_resolve_avx>:    push   rbx
   0x7ffff7dee871 <_dl_runtime_resolve_avx+1>:  mov    rbx,rsp
   0x7ffff7dee874 <_dl_runtime_resolve_avx+4>:  and    rsp,0xffffffffffffffe0
   0x7ffff7dee878 <_dl_runtime_resolve_avx+8>:  sub    rsp,0x180
</code>```

Can anyone explain the reason?

Thanks!

答:
```<code>gdb-peda$ x/4i *0x601010
   0xfffffffff7dee870:  Cannot access memory at address 0xfffffffff7dee870
gdb-peda$ x/g 0x601010
0x601010:   0x00007ffff7dee870
</code>```

In the first command, you write *0x601010 -- that means the contents of the memory at that location.  In the second command, you omit the *, which shows that the contents of that memory are indeed what gdb tried to access in response to the first command.

I think what you probably want is x/4i 0x601010, or perhaps the disassemble command.

Title: GDB x/i get wrong address

Body:
#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("Hello world");
    return 0;
}

I was using GDB to debug this program, after running several si command,

gdb-peda$
[----------------------------------registers-----------------------------------]
...
[-------------------------------------code-------------------------------------]
   0x4003ec:    add    BYTE PTR [rax],al
   0x4003ee:    add    BYTE PTR [rax],al
   0x4003f0:    push   QWORD PTR [rip+0x200c12]        # 0x601008
=> 0x4003f6:    jmp    QWORD PTR [rip+0x200c14]        # 0x601010
 | 0x4003fc:    nop    DWORD PTR [rax+0x0]
 | 0x400400 <printf@plt>:   jmp    QWORD PTR [rip+0x200c12]        # 0x601018
 | 0x400406 <printf@plt+6>: push   0x0
 | 0x40040b <printf@plt+11>:    jmp    0x4003f0
 |->   0x7ffff7dee870 <_dl_runtime_resolve_avx>:    push   rbx
       0x7ffff7dee871 <_dl_runtime_resolve_avx+1>:  mov    rbx,rsp
       0x7ffff7dee874 <_dl_runtime_resolve_avx+4>:  and    rsp,0xffffffffffffffe0
       0x7ffff7dee878 <_dl_runtime_resolve_avx+8>:  sub    rsp,0x180
                                                                  JUMP is taken
[------------------------------------stack-------------------------------------]
...
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x00000000004003f6 in ?? ()

When i tried to show the instructions in *0x601010, i got an error, because GDB was using the wrong address (0xfffffffff7dee870), however, when using x/g command, the address (0x00007ffff7dee870) is correct.

gdb-peda$ x/4i *0x601010
   0xfffffffff7dee870:  Cannot access memory at address 0xfffffffff7dee870
gdb-peda$ x/g 0x601010
0x601010:   0x00007ffff7dee870
gdb-peda$ x/8xb 0x601010
0x601010:   0x70    0xe8    0xde    0xf7    0xff    0x7f    0x00    0x00
gdb-peda$ x/4i 0x00007ffff7dee870
   0x7ffff7dee870 <_dl_runtime_resolve_avx>:    push   rbx
   0x7ffff7dee871 <_dl_runtime_resolve_avx+1>:  mov    rbx,rsp
   0x7ffff7dee874 <_dl_runtime_resolve_avx+4>:  and    rsp,0xffffffffffffffe0
   0x7ffff7dee878 <_dl_runtime_resolve_avx+8>:  sub    rsp,0x180

Can anyone explain the reason?

Thanks!

Body:
gdb-peda$ x/4i *0x601010
   0xfffffffff7dee870:  Cannot access memory at address 0xfffffffff7dee870
gdb-peda$ x/g 0x601010
0x601010:   0x00007ffff7dee870

In the first command, you write *0x601010 -- that means the contents of the memory at that location.  In the second command, you omit the *, which shows that the contents of that memory are indeed what gdb tried to access in response to the first command.

I think what you probably want is x/4i 0x601010, or perhaps the disassemble command.


问:
Save image in Full HD size using OpenCv Python
When i try to save a image using cv2.imwrite() method, it save a file in 640x480 pixel size. My web cam is FUll HD (1920×1080 px). How can i save the picture in this FHD size. </p>

```<code>import numpy as np
import cv2

cap = cv2.VideoCapture(0)

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

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame', frame)
    cv2.imwrite('a.jpg',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

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

答:
```<code>import numpy as np
import cv2

cap = cv2.VideoCapture(0)
cap.set(3, 1920)
cap.set(4, 1080)
cap.set(6, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))

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

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame', frame)
    cv2.imwrite('a.jpg',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

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

Body:
When i try to save a image using cv2.imwrite() method, it save a file in 640x480 pixel size. My web cam is FUll HD (1920×1080 px). How can i save the picture in this FHD size.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

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

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame', frame)
    cv2.imwrite('a.jpg',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

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


问:
Windows 10 UWP Smooth Streaming Video set the heuristic profile
I got smooth streaming working... that was an adventure but it works nicely with Azure Media Services. However what's not so nice is the blurry video at first because it's fast playing without caching enough to use a higher quality stream.
Using the AMP video player for azure on web you can set the heuristicProfile flag to "High Quality" and voilà it buffers more and uses the higher quality stream.

How does one set the heuristic profile on UWP Video playback with smooth streaming so that it will choose the highest quality resolution that will work with the current connection so that video looks good right from the start of playback?

答:
Have you tried to use the Select Track method to select the highest bitrate on startup and then after start unselect that track to allow it to adapt naturally?

See this sample:
https://code.msdn.microsoft.com/windowsapps/A-Windows-8-Smooth-883c3b44


问:
Python Set Comprehension Nested in Dict Comprehension
I have a list of tuples, where each tuple contains a string and a number in the form of:

```<code>[(string_1, num_a), (string_2, num_b), ...]
</code>```

The strings are nonunique, and so are the numbers, e.g. (string_1 , num_m) or (string_9 , num_b) are likely to exist in the list.

I'm attempting to create a dictionary with the string as the key and a set of all numbers occurring with that string as the value:

```<code>dict = {string_1: {num_a, num_m}, string_2: {num_b}, ...}
</code>```

I've done this somewhat successfully with the following dictionary comprehension with nested set comprehension:

```<code>#st_id_list = [(string_1, num_a), ...]
#st_dict = {string_1: {num_a, num_m}, ...}
st_dict = {
    st[0]: set(
        st_[1]
        for st_ in st_id_list
        if st_[0] == st[0]
    )
    for st in st_id_list
}
</code>```

There's only one issue: st_id_list is 18,000 items long. This snippet of code takes less than ten seconds to run for a list of 500 tuples, but over twelve minutes to run for the full 18,000 tuples. I have to think this is because I've nested a set comprehension inside a dict comprehension.

Is there a way to avoid this, or a smarter way to it?

答:
Why are you using two loops when you could do in one loop like this:

```<code>list_1=[('string_1', 'num_a'), ('string_2', 'num_b'),('string_1' , 'num_m'),('string_9' , 'num_b')]

string_num={}
for i in list_1:
    if i[0] not in string_num:
        string_num[i[0]]={i[1]}
    else:
        string_num[i[0]].add(i[1])

print(string_num)
</code>```

output:

```<code>{'string_9': {'num_b'}, 'string_1': {'num_a', 'num_m'}, 'string_2': {'num_b'}}
</code>```

Body:
I have a list of tuples, where each tuple contains a string and a number in the form of:

[(string_1, num_a), (string_2, num_b), ...]

The strings are nonunique, and so are the numbers, e.g. (string_1 , num_m) or (string_9 , num_b) are likely to exist in the list.

I'm attempting to create a dictionary with the string as the key and a set of all numbers occurring with that string as the value:

dict = {string_1: {num_a, num_m}, string_2: {num_b}, ...}

I've done this somewhat successfully with the following dictionary comprehension with nested set comprehension:

#st_id_list = [(string_1, num_a), ...]
#st_dict = {string_1: {num_a, num_m}, ...}
st_dict = {
    st[0]: set(
        st_[1]
        for st_ in st_id_list
        if st_[0] == st[0]
    )
    for st in st_id_list
}

There's only one issue: st_id_list is 18,000 items long. This snippet of code takes less than ten seconds to run for a list of 500 tuples, but over twelve minutes to run for the full 18,000 tuples. I have to think this is because I've nested a set comprehension inside a dict comprehension.

Is there a way to avoid this, or a smarter way to it?

Body:
Why are you using two loops when you could do in one loop like this:

list_1=[('string_1', 'num_a'), ('string_2', 'num_b'),('string_1' , 'num_m'),('string_9' , 'num_b')]

string_num={}
for i in list_1:
    if i[0] not in string_num:
        string_num[i[0]]={i[1]}
    else:
        string_num[i[0]].add(i[1])

print(string_num)

output:

{'string_9': {'num_b'}, 'string_1': {'num_a', 'num_m'}, 'string_2': {'num_b'}}


问:
How to display nested lists like this?
I have lists nested within lists like this:

```<code><ul>
    <li><a href="#">Rings</a></li>
    <li><a href="#">Bracelets</a></li>
    <li><a href="#">Earrings</a>
        <ul>
            <li><a href="#">Diamond Earrings</a></li>
            <li><a href="#">Hoop Earrings</a></li>
            ...
        </ul>
    </li>
    <li><a href="#">Necklaces and Pendants</a>
    ...
</ul>
</code>```

The lists are floated left. The nested lists are defaulted to not be displayed. So it ends up looking like this:

This so far I have. Now what I want to do is whenever a list is hovered that has a nested list (for example Earrings). I want the nested list to be revealed like so:

Notice what all is going on here, its not just telling the nested list to be displayed, that would not look right. Its putting them in a block between the first level lists where they wrap (between "Sports Jewelry" and "Charms").

I am not sure how to go about this.

Any ideas?

答:
You want to make your hover change the sublist from display:none to display:block.

It should be something like this:

```<code>ul li ul { display: none; }
ul li:hover ul { display: block }
</code>```

That won't show at all when it's not hovered, and will add space between list items when you hover.

You probably also need to do some absolute positioning to make it appear below the hovered item, otherwise it will push the things beside it down as well.

Title: How to display nested lists like this?

Body:
I have lists nested within lists like this:

Rings

Bracelets

Earrings

Diamond Earrings

Hoop Earrings

            ...

Necklaces and Pendants
    ...

The lists are floated left. The nested lists are defaulted to not be displayed. So it ends up looking like this:

This so far I have. Now what I want to do is whenever a list is hovered that has a nested list (for example Earrings). I want the nested list to be revealed like so:

Notice what all is going on here, its not just telling the nested list to be displayed, that would not look right. Its putting them in a block between the first level lists where they wrap (between "Sports Jewelry" and "Charms").

I am not sure how to go about this.

Any ideas?

Body:
You want to make your hover change the sublist from display:none to display:block.

It should be something like this:

ul li ul { display: none; }
ul li:hover ul { display: block }

That won't show at all when it's not hovered, and will add space between list items when you hover.

You probably also need to do some absolute positioning to make it appear below the hovered item, otherwise it will push the things beside it down as well.


问:
Linked list in julia
can anybody help me to understand next things please:

1) Why do we need to make a new abstract class of a future struct, while making linked list?

2) Why there is an argument T?

3) What does this operator do <: (haven't found it in the book) ?

4) Can we write in the following way, instead of Example ?:

```<code>type LinkedList
    name = Ptr{Uint8}
    next :: LinkedList
end
</code>```

Example:

```<code>abstract type LinkedList{T} end

mutable struct Nil{T} <: LinkedList{T}
end

mutable struct Cons{T} <: LinkedList{T}
   head::T
   tail::LinkedList{T}
end
</code>```

Thank you!

答:
You don't. You actually can define recursive structures like the one you posted just fine.  Well, sorta.  name = Ptr{Uint8} is not the correct syntax — instead you want name::Ptr{UInt8}.  Although, really, you probably really just want name::String.  Now you'll still run into trouble:

```<code>julia> struct BrokenList
           name::String
           next::BrokenList
   end

julia> BrokenList("first", BrokenList("last", #= uh, what goes here? =# ))
</code>```

You need something of type BrokenList to already exist… but in order to create one you need one!  So a simple "out" is to allow next to either be another node of the list or some placeholder for the last element. nothing (which is of type Nothing) is a simple option:

```<code>julia> struct BetterList
           name::String
           next::Union{BetterList, Nothing}
       end

julia> BetterList("first", BetterList("last", nothing))
BetterList("first", BetterList("last", nothing))
</code>```

That T isn't an argument; it's a type parameter. Of course, our BetterList could just as easily hold Ints instead of Strings… so we can use a type parameter to dynamically parameterize the type based upon the values it holds:

```<code>julia> struct LinkedList{T}
           value::T
           next::Union{LinkedList{T}, Nothing}
       end

julia> LinkedList("first", LinkedList("last", nothing))
LinkedList{String}("first", LinkedList{String}("last", nothing))

julia> LinkedList(1, LinkedList(2, nothing))
LinkedList{Int64}(1, LinkedList{Int64}(2, nothing))
</code>```

Instead of using Unions, the example code you posted uses abstract types and subtypes to describe the possibility of having either a node or the final nil element.  <: is the subtyping operator.

Title: Linked list in julia

Body:
can anybody help me to understand next things please:

1) Why do we need to make a new abstract class of a future struct, while making linked list?

2) Why there is an argument T?

3) What does this operator do <: (haven't found it in the book) ?

4) Can we write in the following way, instead of Example ?:

type LinkedList
    name = Ptr{Uint8}
    next :: LinkedList
end

Example:

abstract type LinkedList{T} end

mutable struct Nil{T} <: LinkedList{T}
end

mutable struct Cons{T} <: LinkedList{T}
   head::T
   tail::LinkedList{T}
end

Thank you!

Body:
You don't. You actually can define recursive structures like the one you posted just fine.  Well, sorta.  name = Ptr{Uint8} is not the correct syntax — instead you want name::Ptr{UInt8}.  Although, really, you probably really just want name::String.  Now you'll still run into trouble:

julia> struct BrokenList
           name::String
           next::BrokenList
   end

julia> BrokenList("first", BrokenList("last", #= uh, what goes here? =# ))

You need something of type BrokenList to already exist… but in order to create one you need one!  So a simple "out" is to allow next to either be another node of the list or some placeholder for the last element. nothing (which is of type Nothing) is a simple option:

julia> struct BetterList
           name::String
           next::Union{BetterList, Nothing}
       end

julia> BetterList("first", BetterList("last", nothing))
BetterList("first", BetterList("last", nothing))

That T isn't an argument; it's a type parameter. Of course, our BetterList could just as easily hold Ints instead of Strings… so we can use a type parameter to dynamically parameterize the type based upon the values it holds:

julia> struct LinkedList{T}
           value::T
           next::Union{LinkedList{T}, Nothing}
       end

julia> LinkedList("first", LinkedList("last", nothing))
LinkedList{String}("first", LinkedList{String}("last", nothing))

julia> LinkedList(1, LinkedList(2, nothing))
LinkedList{Int64}(1, LinkedList{Int64}(2, nothing))

Instead of using Unions, the example code you posted uses abstract types and subtypes to describe the possibility of having either a node or the final nil element.  <: is the subtyping operator.


问:
How to plot in multiple subplots
I am a little confused about how this code works:

```<code>fig, axes = plt.subplots(nrows=2, ncols=2)
plt.show()
</code>```

How does the fig, axes work in this case? What does it do?

Also why wouldn't this work to do the same thing:

```<code>fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)
</code>```

答:
You might be interested in the fact that as of matplotlib version 2.1 the second code from the question works fine as well.

From the change log:

Figure class now has subplots method
  The Figure class now has a subplots() method which behaves the same as pyplot.subplots() but on an existing figure.

Example:

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

fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)

plt.show()
</code>```

Title: How to plot in multiple subplots

Body:
I am a little confused about how this code works:

fig, axes = plt.subplots(nrows=2, ncols=2)
plt.show()

How does the fig, axes work in this case? What does it do?

Also why wouldn't this work to do the same thing:

fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)

Body:
You might be interested in the fact that as of matplotlib version 2.1 the second code from the question works fine as well.

From the change log:

Figure class now has subplots method
  The Figure class now has a subplots() method which behaves the same as pyplot.subplots() but on an existing figure.

Example:

import matplotlib.pyplot as plt

fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)

plt.show()


问:
Arduino Uno + ESP8266 12E + Blynk + Relay
I started adventure with arduino and programming 2 months ago.So, I am new in this topics.
Until now I realized few projects including Blynk connected with arduino. The last one was similar to one described in topic but I used the ENC28j60 instead of ESP8266 module and then it worked fine.

The problem started with ESP module.

Short description of project:

The main idea is to control AC light with Blynk App support.
First of all I made a connection according to picture below:

As power source I used the USB phone charger connected with step by voltage converter to get in final the 3.3V source.
I additionally connected the Arduino Uno with relay module like this:

Arduino ====> Relay module

5V ====> VCC

GND ====> GND

Pin 5 ====> IN1

Everythink you can see in pictures below (sorry for quality)

And for now I did almost every step (with so many problems). Here I mean:
1. I checked if arduino is connected with ESP module by serial port -> system report "ready" status.
2. I upload the below (template) Arduino IDE sketch for my project:

```<code>#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console--
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

}

void loop()
{
  Blynk.run();

}
</code>```

And finally I started the New project in Blynk. I set the Arduino uno as a hardware model and WiFi as connection type. Then I added the Button and set the Output to D5.

And now (close to the end of project) I met with a problem. After pushing the connect button (in up-right corner) I receive the information that device is connected (Online). Then when I try to push the button to Active Relay - nothing happens.
Whats more. I tried with different pins on Arduino with the same results. And I don't know why (probably because I have still small knowladge) but when I set the Button output value to D2 - after connection when I push it then the diode on ESP module Turn OFF and Turn ON.
I tried to find solution on this forum and in many other places for last 3 days but without any results. That's why I decided to ask You for help. Do you know what did I wrong or what should I add to project to make connection between the Blynk and relay work correct?

Write if you will need some more or detailed information from my side.

答:
When looking at the pictures and code you have postet, it seems that you have flashed the ESP with a Arduino sketch. This is fine if you would like to activate the relay directly with the ESP (without the Arduino UNO).
Then you just have to connect the relay to the ESP instead of to the Arduino. Unfortunately not all relay boards can operate with the 3.3V logic that the ESP supplies, but maybe you'r lucky.

On the other hand, if you would like to use the Arduino UNO with the ESP as Wi-Fi, then you would have to reflash the ESP with the original AT firmware. Then you could connect it to the Arduino and use a sketch that looks something like this.

```<code>#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = "YourAuthToken";

char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3);
// pin 3 connected to ESP RX and pin 2 connected to ESP TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}
</code>```

And you should remove the connection between RST and GND on the Arduino

Body:
I started adventure with arduino and programming 2 months ago.So, I am new in this topics.
Until now I realized few projects including Blynk connected with arduino. The last one was similar to one described in topic but I used the ENC28j60 instead of ESP8266 module and then it worked fine.

The problem started with ESP module.

Short description of project:

The main idea is to control AC light with Blynk App support.
First of all I made a connection according to picture below:

As power source I used the USB phone charger connected with step by voltage converter to get in final the 3.3V source.
I additionally connected the Arduino Uno with relay module like this:

Arduino ====> Relay module

5V ====> VCC

GND ====> GND

Pin 5 ====> IN1

Everythink you can see in pictures below (sorry for quality)

And for now I did almost every step (with so many problems). Here I mean:
1. I checked if arduino is connected with ESP module by serial port -> system report "ready" status.
2. I upload the below (template) Arduino IDE sketch for my project:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console--
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

}

void loop()
{
  Blynk.run();

}

And finally I started the New project in Blynk. I set the Arduino uno as a hardware model and WiFi as connection type. Then I added the Button and set the Output to D5.

And now (close to the end of project) I met with a problem. After pushing the connect button (in up-right corner) I receive the information that device is connected (Online). Then when I try to push the button to Active Relay - nothing happens.
Whats more. I tried with different pins on Arduino with the same results. And I don't know why (probably because I have still small knowladge) but when I set the Button output value to D2 - after connection when I push it then the diode on ESP module Turn OFF and Turn ON.
I tried to find solution on this forum and in many other places for last 3 days but without any results. That's why I decided to ask You for help. Do you know what did I wrong or what should I add to project to make connection between the Blynk and relay work correct?

Write if you will need some more or detailed information from my side.

Body:
When looking at the pictures and code you have postet, it seems that you have flashed the ESP with a Arduino sketch. This is fine if you would like to activate the relay directly with the ESP (without the Arduino UNO).
Then you just have to connect the relay to the ESP instead of to the Arduino. Unfortunately not all relay boards can operate with the 3.3V logic that the ESP supplies, but maybe you'r lucky.

On the other hand, if you would like to use the Arduino UNO with the ESP as Wi-Fi, then you would have to reflash the ESP with the original AT firmware. Then you could connect it to the Arduino and use a sketch that looks something like this.

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = "YourAuthToken";

char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3);
// pin 3 connected to ESP RX and pin 2 connected to ESP TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

And you should remove the connection between RST and GND on the Arduino


问:
Origin of the word Refactoring
Code refactoring is the process of changing a computer program's internal structure without modifying its external behavior or existing functionality.

What is the origin of the word refactoring and why was it chosen to denote the above?

答:
In Refactoring, Fowler wrote that he hasn't "succeded in pinning down the
   real birth of the term    Refactoring". Wikipedia mentions the term was used by Forth programmers in the 80s, Fowler also spoke about the Smalltalk community.

Math factorization's certainly helped coining this term as you don't change the value of a mathematical expression what you factorize it.

OwnerDisplayName: Diego Deberdt

Title: Origin of the word Refactoring

OwnerDisplayName: philippe

LastEditorDisplayName: philippe


问:
java -update database by editing cells not working?
I'm having trouble updating data from the database by editing / changing cell values and clicking on the update button, but he can not change the database that I changed to the cell. it's still the same into the last value. </p>

<p>here is my code: </p>

```<code>    public void directlyup() {
       int col=tablesample.getSelectedColumn();
       int row=tablesample.getSelectedRow();
       int index;
       index = Integer.parseInt(tablesample.getModel().getValueAt(row, 0).toString());
        try {
            String sql ="UPDATE invoice SET description = ?,qty = ?,unitprice = ?"
                    + ",total = ? WHERE id ="+row;
            pst = conn.prepareStatement(sql);
            pst.setString(1, (String) tablesample.getValueAt(row, 1));
            pst.setString(2, (String) tablesample.getValueAt(row, 2));
            pst.setString(3, (String) tablesample.getValueAt(row, 3));
            pst.setString(4, (String) tablesample.getValueAt(row, 4));
            pst.execute();
            JOptionPane.showMessageDialog(null, "Successfully Updated");
        } catch (Exception e) {
         JOptionPane.showMessageDialog(null, e);
        }
    }
</code>```

答:
assuming you have multiple row selected, if your id is int:

```<code>    int[]rows=tablesample.getSelectedRows();

String sql="UPDATE invoice SET description = ?,qty = ?,unitprice = ?"
        + ",total = ? WHERE id =?";

try{
    PreparedStatement pst = conn.prepareStatement(sql);
    for(int currentRow:rows){

                 pst.setString(1, (String) tablesample.getValueAt(currentRow, 1));
                 pst.setString(2, (String) tablesample.getValueAt(currentRow, 2));
                 pst.setString(3, (String) tablesample.getValueAt(currentRow, 3));
                 pst.setString(4, (String) tablesample.getValueAt(currentRow, 4));
                 pst.setInt(5,  currentRow);
                 pst.executeUpdate();

       }
    JOptionPane.showMessageDialog(null, "Successfully Updated");
   } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
     }  finally{
         try {
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     }
</code>```

for best performance you can use executeBatch like this example

Body:
I'm having trouble updating data from the database by editing / changing cell values and clicking on the update button, but he can not change the database that I changed to the cell. it's still the same into the last value.

here is my code:

    public void directlyup() {
       int col=tablesample.getSelectedColumn();
       int row=tablesample.getSelectedRow();
       int index;
       index = Integer.parseInt(tablesample.getModel().getValueAt(row, 0).toString());
        try {
            String sql ="UPDATE invoice SET description = ?,qty = ?,unitprice = ?"
                    + ",total = ? WHERE id ="+row;
            pst = conn.prepareStatement(sql);
            pst.setString(1, (String) tablesample.getValueAt(row, 1));
            pst.setString(2, (String) tablesample.getValueAt(row, 2));
            pst.setString(3, (String) tablesample.getValueAt(row, 3));
            pst.setString(4, (String) tablesample.getValueAt(row, 4));
            pst.execute();
            JOptionPane.showMessageDialog(null, "Successfully Updated");
        } catch (Exception e) {
         JOptionPane.showMessageDialog(null, e);
        }
    }

Body:
assuming you have multiple row selected, if your id is int:

    int[]rows=tablesample.getSelectedRows();

String sql="UPDATE invoice SET description = ?,qty = ?,unitprice = ?"
        + ",total = ? WHERE id =?";

try{
    PreparedStatement pst = conn.prepareStatement(sql);
    for(int currentRow:rows){

                 pst.setString(1, (String) tablesample.getValueAt(currentRow, 1));
                 pst.setString(2, (String) tablesample.getValueAt(currentRow, 2));
                 pst.setString(3, (String) tablesample.getValueAt(currentRow, 3));
                 pst.setString(4, (String) tablesample.getValueAt(currentRow, 4));
                 pst.setInt(5,  currentRow);
                 pst.executeUpdate();

       }
    JOptionPane.showMessageDialog(null, "Successfully Updated");
   } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
     }  finally{
         try {
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     }

for best performance you can use executeBatch like this example


问:
Detect if key is down mac python
I've googled all over the place.

I have a python application and I'd like to detect if a key is down (on OSX).

The only answers I've been able to find are either libraries for windows, or libraries that require an application window to be active (like pygame).

Similar to how pymouse has a position() method.

I'd like to be able to do something in my code like:

```<code>if keyboard.keydown(<key code>):
  # do something
elif keyboard.keycode(<some other keycode>):
  # do something
</code>```

On Mac.

答:
You could use the input command
awesome = input("how awesome are you")

although this requires the user to press enter

then you could do something like this
print(awesome)

Title: Detect if key is down mac python

Body:
I've googled all over the place.

I have a python application and I'd like to detect if a key is down (on OSX).

The only answers I've been able to find are either libraries for windows, or libraries that require an application window to be active (like pygame).

Similar to how pymouse has a position() method.

I'd like to be able to do something in my code like:

if keyboard.keydown(<key code>):
  # do something
elif keyboard.keycode(<some other keycode>):
  # do something

On Mac.