问:
MPAndroid Group bar chart is not showing
Here is the code i used for group bar_chart using MPAndroid library version 3. I've tried group bar chart in lower version and it works fine but the BarData constructor is changed in latest version. And this code doesn't works. There is no crashes and error logs, still graph is loading and no data shows in it. Help me to find ma flaws

```<code>        List<BarEntry> entriesGroup1 = new ArrayList<>();
        List<BarEntry> entriesGroup2 = new ArrayList<>();
        List<BarEntry> entriesGroup3 = new ArrayList<>();

        entriesGroup1.add(new BarEntry(0, 8f));
        entriesGroup1.add(new BarEntry(1, 2f));
        entriesGroup1.add(new BarEntry(2, 5f));
        entriesGroup1.add(new BarEntry(3, 20f));
        entriesGroup1.add(new BarEntry(4, 15f));
        entriesGroup1.add(new BarEntry(5, 19f));

        entriesGroup2.add(new BarEntry(0, 6f));
        entriesGroup2.add(new BarEntry(1, 10f));
        entriesGroup2.add(new BarEntry(2, 5f));
        entriesGroup2.add(new BarEntry(3, 25f));
        entriesGroup2.add(new BarEntry(4, 4f));
        entriesGroup2.add(new BarEntry(5, 17f));

        entriesGroup3.add(new BarEntry(0, 9f));
        entriesGroup3.add(new BarEntry(1, 1f));
        entriesGroup3.add(new BarEntry(2, 15f));
        entriesGroup3.add(new BarEntry(3, 13f));
        entriesGroup3.add(new BarEntry(4, 40f));
        entriesGroup3.add(new BarEntry(5, 25f));

        BarDataSet set1 = new BarDataSet(entriesGroup1, "Group 1");
        BarDataSet set2 = new BarDataSet(entriesGroup2, "Group 2");
        BarDataSet set3 = new BarDataSet(entriesGroup3, "Group 3");

        final ArrayList<String> labels = new ArrayList<String>();
        labels.add("2016");
        labels.add("2015");
        labels.add("2014");
        labels.add("2013");
        labels.add("2012");
        labels.add("2011");
        IAxisValueFormatter formatter = new IAxisValueFormatter() {

            @Override
            public String getFormattedValue(float value, AxisBase axis) {

                if((int) value < 0 || (int) value >= labels.size()){
                    return "";
                }else{
                    return labels.get((int) value);
                }
            }

            // we don't draw numbers, so no decimal digits needed
            @Override
            public int getDecimalDigits() {  return 0; }
        };

        set1.setColor(Color.parseColor("#cd5080"));
        set2.setColor(Color.parseColor("#0d5080"));
        set3.setColor(Color.parseColor("#fc5080"));;

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
// (0.02 + 0.45) * 2 + 0.06 = 1.00 -> interval per "group"

        XAxis xAxis = barChart.getXAxis();
        xAxis.setCenterAxisLabels(true);
        xAxis.setGranularity(1f); // minimum axis-step (interval) is 1
        xAxis.setValueFormatter(formatter);

        BarData data = new BarData(set1, set2, set3);
        data.setBarWidth(barWidth); // set the width of each bar
        barChart.setData(data);
        barChart.groupBars(2016, groupSpace, barSpace);
        barChart.invalidate(); // refresh

        barChart.animateY(5000);
</code>```

Nb: I'm edited my current question since i'm banned to ask new questions. But its important for me. Thanks everyone.

答:
Create a Application class and add counter of foreground activities, if counter is 0 means your activity is in background

```<code>class MyApp extends Application{
 public int foregroundActivities  = 0 ;

 @override
 public void onCreate(){
     super.onCreate();
     this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

                @Override
                public void onActivityStarted(Activity activity) {
                    foregroundActivities++;
                }

                @Override
                public void onActivityStopped(Activity activity) {
                    foregroundActivities--;
                }
        }
   }
}
</code>```

EDIT

To answer your question, Application class is singleton to Lifecycle so you can register Activity Life cycle call backs as above which will be triggered by all your 87 activities.

Suppose,
If any of your 87 activities is started, it will call onActivityStarted() method, where the count of foreground activity will become 1, if activity is closes, it will call onActivityStopped() which will decrement count of foreground activities back to 0.

So you can detect whether application is in foreground or background based on counter,

```<code>if(applicationInstance.foregroundActivities > 0){
    //App is in foreground
 }else{
    //App is in background
 }
</code>```

Body:
Here is the code i used for group bar_chart using MPAndroid library version 3. I've tried group bar chart in lower version and it works fine but the BarData constructor is changed in latest version. And this code doesn't works. There is no crashes and error logs, still graph is loading and no data shows in it. Help me to find ma flaws

        List<BarEntry> entriesGroup1 = new ArrayList<>();
        List<BarEntry> entriesGroup2 = new ArrayList<>();
        List<BarEntry> entriesGroup3 = new ArrayList<>();

        entriesGroup1.add(new BarEntry(0, 8f));
        entriesGroup1.add(new BarEntry(1, 2f));
        entriesGroup1.add(new BarEntry(2, 5f));
        entriesGroup1.add(new BarEntry(3, 20f));
        entriesGroup1.add(new BarEntry(4, 15f));
        entriesGroup1.add(new BarEntry(5, 19f));

        entriesGroup2.add(new BarEntry(0, 6f));
        entriesGroup2.add(new BarEntry(1, 10f));
        entriesGroup2.add(new BarEntry(2, 5f));
        entriesGroup2.add(new BarEntry(3, 25f));
        entriesGroup2.add(new BarEntry(4, 4f));
        entriesGroup2.add(new BarEntry(5, 17f));

        entriesGroup3.add(new BarEntry(0, 9f));
        entriesGroup3.add(new BarEntry(1, 1f));
        entriesGroup3.add(new BarEntry(2, 15f));
        entriesGroup3.add(new BarEntry(3, 13f));
        entriesGroup3.add(new BarEntry(4, 40f));
        entriesGroup3.add(new BarEntry(5, 25f));

        BarDataSet set1 = new BarDataSet(entriesGroup1, "Group 1");
        BarDataSet set2 = new BarDataSet(entriesGroup2, "Group 2");
        BarDataSet set3 = new BarDataSet(entriesGroup3, "Group 3");

        final ArrayList<String> labels = new ArrayList<String>();
        labels.add("2016");
        labels.add("2015");
        labels.add("2014");
        labels.add("2013");
        labels.add("2012");
        labels.add("2011");
        IAxisValueFormatter formatter = new IAxisValueFormatter() {

            @Override
            public String getFormattedValue(float value, AxisBase axis) {

                if((int) value < 0 || (int) value >= labels.size()){
                    return "";
                }else{
                    return labels.get((int) value);
                }
            }

            // we don't draw numbers, so no decimal digits needed
            @Override
            public int getDecimalDigits() {  return 0; }
        };

        set1.setColor(Color.parseColor("#cd5080"));
        set2.setColor(Color.parseColor("#0d5080"));
        set3.setColor(Color.parseColor("#fc5080"));;

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
// (0.02 + 0.45) * 2 + 0.06 = 1.00 -> interval per "group"

        XAxis xAxis = barChart.getXAxis();
        xAxis.setCenterAxisLabels(true);
        xAxis.setGranularity(1f); // minimum axis-step (interval) is 1
        xAxis.setValueFormatter(formatter);

        BarData data = new BarData(set1, set2, set3);
        data.setBarWidth(barWidth); // set the width of each bar
        barChart.setData(data);
        barChart.groupBars(2016, groupSpace, barSpace);
        barChart.invalidate(); // refresh

        barChart.animateY(5000);

Nb: I'm edited my current question since i'm banned to ask new questions. But its important for me. Thanks everyone.

Body:
Create a Application class and add counter of foreground activities, if counter is 0 means your activity is in background

class MyApp extends Application{
 public int foregroundActivities  = 0 ;

 @override
 public void onCreate(){
     super.onCreate();
     this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

                @Override
                public void onActivityStarted(Activity activity) {
                    foregroundActivities++;
                }

                @Override
                public void onActivityStopped(Activity activity) {
                    foregroundActivities--;
                }
        }
   }
}

EDIT

To answer your question, Application class is singleton to Lifecycle so you can register Activity Life cycle call backs as above which will be triggered by all your 87 activities.

Suppose,
If any of your 87 activities is started, it will call onActivityStarted() method, where the count of foreground activity will become 1, if activity is closes, it will call onActivityStopped() which will decrement count of foreground activities back to 0.

So you can detect whether application is in foreground or background based on counter,

if(applicationInstance.foregroundActivities > 0){
    //App is in foreground
 }else{
    //App is in background
 }


来源: stackexchange

问:
Can you get this same Java SHA-1 in PHP please?
I find myself in a need to change website platforms from Java to PHP but I'd like to keep all my user's passwords...

I had this code do the password hashing prior to writting the hashed value as the password to the website:

```<code>MessageDigest md = null;
md = MessageDigest.getInstance("SHA");
md.update(plaintext.getBytes("UTF-8"));
byte raw[] = md.digest();
hash = new Base64().encodeToString(raw).replaceAll("\n", "").replaceAll("\r", "");
</code>```

I think the Java code did SHA-1 hashing of the password but just prior to that it was byte encoded to UTF-8 and afterwards it was Base64 encoded.

I'd like to have a PHP code do the same, i.e. return the same value of a hash for the same password as in Java, only it seems that the PHP code doing SHA-1 hashing I have won't return the same SHA(-1, not Base64 encoded, I think?) value when compared to a Java Base64 decoded value of the hash...could it have something to do with the fact that my passwords in PHP are not UTF-8 byte encoded first (and how can I do that in PHP) please?

p.s.

Another strange thing...my passwords in Java are all 28characters long (usually something like this rnwn4zTNgH30l4pP8V05lRVGmF4=)...but the Base64().decode(hash) value of those password hashes is 10 characters long (an example [B@14e1f2b).

I thought Base64 did an additional 1 character to each 3 charters (28 or 27, excluding the padding = charter, is much more that a third larger than those 10 charcters) so am I doing the decoding call wrong somehow maybe???

And on top of all that the SHA-1 password hashed values in PHP are 40 characters long (in a UTF-8 mysql database) like so dd94709528bb1c83d08f3088d4043f4742891f4f?

答:
What I normally do with Java to compute a SHA-1 hash that is exactly identical to the PHP sha1() function is the following. The key is that toHexString is used to show the raw bytes in a printable way. If you use the PHP function and want to obtain the same result of your convoluted process, you need to use the parameter $raw_output to true in PHP to get the raw bytes and apply Base64. Full source code.</p>

```<code>/**
 * Compute a SHA-1 hash of a String argument
 *
 * @param arg the UTF-8 String to encode
 * @return the sha1 hash as a string.
 */
public static String computeSha1OfString(String arg) {
    try {
        return computeSha1OfByteArray(arg.getBytes(("UTF-8")));
    } catch (UnsupportedEncodingException ex) {
        throw new UnsupportedOperationException(ex);
    }
}

private static String computeSha1OfByteArray(byte[] arg) {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(arg);
        byte[] res = md.digest();
        return toHexString(res);
    } catch (NoSuchAlgorithmException ex) {
        throw new UnsupportedOperationException(ex);
    }
}

private static String toHexString(byte[] v) {
    StringBuilder sb = new StringBuilder(v.length * 2);
    for (int i = 0; i < v.length; i++) {
        int b = v[i] & 0xFF;
        sb.append(HEX_DIGITS.charAt(b >>> 4)).append(HEX_DIGITS.charAt(b & 0xF));
    }
    return sb.toString();
}
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I find myself in a need to change website platforms from Java to PHP but I'd like to keep all my user's passwords...

I had this code do the password hashing prior to writting the hashed value as the password to the website:

MessageDigest md = null;
md = MessageDigest.getInstance("SHA");
md.update(plaintext.getBytes("UTF-8"));
byte raw[] = md.digest();
hash = new Base64().encodeToString(raw).replaceAll("\n", "").replaceAll("\r", "");

I think the Java code did SHA-1 hashing of the password but just prior to that it was byte encoded to UTF-8 and afterwards it was Base64 encoded.

I'd like to have a PHP code do the same, i.e. return the same value of a hash for the same password as in Java, only it seems that the PHP code doing SHA-1 hashing I have won't return the same SHA(-1, not Base64 encoded, I think?) value when compared to a Java Base64 decoded value of the hash...could it have something to do with the fact that my passwords in PHP are not UTF-8 byte encoded first (and how can I do that in PHP) please?

p.s.

Another strange thing...my passwords in Java are all 28characters long (usually something like this rnwn4zTNgH30l4pP8V05lRVGmF4=)...but the Base64().decode(hash) value of those password hashes is 10 characters long (an example [B@14e1f2b).

I thought Base64 did an additional 1 character to each 3 charters (28 or 27, excluding the padding = charter, is much more that a third larger than those 10 charcters) so am I doing the decoding call wrong somehow maybe???

And on top of all that the SHA-1 password hashed values in PHP are 40 characters long (in a UTF-8 mysql database) like so dd94709528bb1c83d08f3088d4043f4742891f4f?

Body:
What I normally do with Java to compute a SHA-1 hash that is exactly identical to the PHP sha1() function is the following. The key is that toHexString is used to show the raw bytes in a printable way. If you use the PHP function and want to obtain the same result of your convoluted process, you need to use the parameter $raw_output to true in PHP to get the raw bytes and apply Base64. Full source code.

/**
 * Compute a SHA-1 hash of a String argument
 *
 * @param arg the UTF-8 String to encode
 * @return the sha1 hash as a string.
 */
public static String computeSha1OfString(String arg) {
    try {
        return computeSha1OfByteArray(arg.getBytes(("UTF-8")));
    } catch (UnsupportedEncodingException ex) {
        throw new UnsupportedOperationException(ex);
    }
}

private static String computeSha1OfByteArray(byte[] arg) {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(arg);
        byte[] res = md.digest();
        return toHexString(res);
    } catch (NoSuchAlgorithmException ex) {
        throw new UnsupportedOperationException(ex);
    }
}

private static String toHexString(byte[] v) {
    StringBuilder sb = new StringBuilder(v.length * 2);
    for (int i = 0; i < v.length; i++) {
        int b = v[i] & 0xFF;
        sb.append(HEX_DIGITS.charAt(b >>> 4)).append(HEX_DIGITS.charAt(b & 0xF));
    }
    return sb.toString();
}

ContentLicense: CC BY-SA 3.0


问:
ASP.NET MVC CSS fails
CSS wizards, show me the light please. Trying to apply my own stylesheet (table formatting) in an MVC project but I think I'm missing something as nothing happens.

index.html:

```<code><link rel="stylesheet" href="~/Content/mystuff.css">
</code>```

BundleConfig:

```<code>bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css",
                      "~/Content/mystuff.css"));
</code>```

Despite this setup, bootstrap still seems to override my own settings. Am I missing any reference? Thanks a bunch

答:
Sometimes in a css files you have !important attribute after a property.

Like:

```<code> color:red !important;
</code>```

and in this case, even if you add a new class or modify the style of html element and put for exemple

```<code> color:yellow;
</code>```

the browser will override your yellow color.
try to put !important after your css property to see what it will do.

If it doesn't work, by pressing F12 key you can show the tools window and examine your html element to be sure if it takes properties of your new css file.

Title: ASP.NET MVC CSS fails

Body:
CSS wizards, show me the light please. Trying to apply my own stylesheet (table formatting) in an MVC project but I think I'm missing something as nothing happens.

index.html:

<link rel="stylesheet" href="~/Content/mystuff.css">

BundleConfig:

bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css",
                      "~/Content/mystuff.css"));

Despite this setup, bootstrap still seems to override my own settings. Am I missing any reference? Thanks a bunch

Body:
Sometimes in a css files you have !important attribute after a property.

Like:

 color:red !important;

and in this case, even if you add a new class or modify the style of html element and put for exemple

 color:yellow;

the browser will override your yellow color.
try to put !important after your css property to see what it will do.

If it doesn't work, by pressing F12 key you can show the tools window and examine your html element to be sure if it takes properties of your new css file.


问:
angular @NgModule Can't bind to 'model' since it isn't a known property of 'tag'
I originally tried to include a shared component in two modules as a declaration.

BatchStatusComponent is part of the declarations of 2 modules: DashboardModule and ControlJobModule! Please consider moving...

So I have tried to create a common @NgModule,

I have declared a common module:

```<code>@NgModule({
    imports: [
        CommonModule,
        FormsModule
    ],
    declarations: [
        BatchStatusComponent // moved to here
    ]
})
export class SharedComponentsModule { }
</code>```

I have included the above module in a child module as follows

```<code>@NgModule({
    imports: [
        SharedComponentsModule, // added module
        DashboardRoutingModule,
        CommonModule,
        FormsModule,
        ChartsModule,
        BsDropdownModule
    ],
    providers: [DashboardApiService, IntegrationSignalService],
    declarations: [
        DashboardComponent,
        // BatchStatusComponent, // removed from here.
        ServiceStatusComponent,
        StatisticsCounterComponent,
        ClearingDashboardComponent
    ]
})
export class DashboardModule {
}
</code>```

But I am now getting this error:

Can't bind to 'batchStatuses' since it isn't a known property of 'batch-status'.

If 'batch-status' is an Angular component and it has 'batchStatuses' input, then verify that it is part of this module.

If 'batch-status' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

What am I missing?

When the component is included as a declaration (in the DashboardModule) it works just fine.

答:
You need to also export the component if you want other modules to see it:

```<code>@NgModule({
    imports: [
        CommonModule,
        FormsModule
    ],
    declarations: [
        BatchStatusComponent // moved to here
    ],
    exports: [
        BatchStatusComponent
    ]
})
export class SharedComponentsModule { }
</code>```

FYI, you can also export entire modules (i.e. CommonModule) so that its available downstream as well.

Body:
I originally tried to include a shared component in two modules as a declaration.

BatchStatusComponent is part of the declarations of 2 modules: DashboardModule and ControlJobModule! Please consider moving...

So I have tried to create a common @NgModule,

I have declared a common module:

@NgModule({
    imports: [
        CommonModule,
        FormsModule
    ],
    declarations: [
        BatchStatusComponent // moved to here
    ]
})
export class SharedComponentsModule { }

I have included the above module in a child module as follows

@NgModule({
    imports: [
        SharedComponentsModule, // added module
        DashboardRoutingModule,
        CommonModule,
        FormsModule,
        ChartsModule,
        BsDropdownModule
    ],
    providers: [DashboardApiService, IntegrationSignalService],
    declarations: [
        DashboardComponent,
        // BatchStatusComponent, // removed from here.
        ServiceStatusComponent,
        StatisticsCounterComponent,
        ClearingDashboardComponent
    ]
})
export class DashboardModule {
}

But I am now getting this error:

Can't bind to 'batchStatuses' since it isn't a known property of 'batch-status'.

If 'batch-status' is an Angular component and it has 'batchStatuses' input, then verify that it is part of this module.

If 'batch-status' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

What am I missing?

When the component is included as a declaration (in the DashboardModule) it works just fine.

Body:
You need to also export the component if you want other modules to see it:

@NgModule({
    imports: [
        CommonModule,
        FormsModule
    ],
    declarations: [
        BatchStatusComponent // moved to here
    ],
    exports: [
        BatchStatusComponent
    ]
})
export class SharedComponentsModule { }

FYI, you can also export entire modules (i.e. CommonModule) so that its available downstream as well.


问:
Connection String of Membership is Problem
Connection String:

```<code>data source=mssql2008.chaiyohosting.com;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
</code>```

Error:

```<code>Invalid value for key 'attachdbfilename'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.
</code>```

Source Error:

```<code>Line 20:     protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
Line 21:     {
Line 22:         if (Membership.ValidateUser(Login1.UserName, Login1.Password))
Line 23:         {
Line 24:             e.Authenticated = true;

Source File: c:\inetpub\vhosts\vcantop.com\httpdocs\Default.aspx.cs    Line: 22
</code>```

Stack Trace:

```<code>[ArgumentException: Invalid value for key 'attachdbfilename'.]
   System.Data.SqlClient.SqlConnectionString.VerifyLocalHostAndFixup(String& host, Boolean enforceLocalHost, Boolean fixup) +811400
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +2207
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +200
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +62
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
   System.Data.SqlClient.SqlConnection..ctor(String connectionString) +24
   System.Web.DataAccess.SqlConnectionHolder..ctor(String connectionString) +54

[ArgumentException: An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString]
   System.Web.DataAccess.SqlConnectionHolder..ctor(String connectionString) +136
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +134
   System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +815
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
   System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78
   System.Web.Security.Membership.ValidateUser(String username, String password) +46
   _Default.Login1_Authenticate(Object sender, AuthenticateEventArgs e) in c:\inetpub\vhosts\vcantop.com\httpdocs\Default.aspx.cs:22
   System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +108
   System.Web.UI.WebControls.Login.AttemptLogin() +115
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
</code>```

What's Wrong?

答:
The error seems clear - the value you have for AttachDBFilename is invalid.

|DataDirectory| should be the physical path to the .mdf file:

```<code>c:\data dir\aspnetdb.mdf
</code>```

All together:

```<code>data source=mssql2008.chaiyohosting.com;Integrated
Security=SSPI;AttachDBFilename=c:\data dir\aspnetdb.mdf;User Instance=true
</code>```

Body:
Connection String:

data source=mssql2008.chaiyohosting.com;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

Error:

Invalid value for key 'attachdbfilename'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.

Source Error:

Line 20:     protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
Line 21:     {
Line 22:         if (Membership.ValidateUser(Login1.UserName, Login1.Password))
Line 23:         {
Line 24:             e.Authenticated = true;

Source File: c:\inetpub\vhosts\vcantop.com\httpdocs\Default.aspx.cs    Line: 22

Stack Trace:

[ArgumentException: Invalid value for key 'attachdbfilename'.]
   System.Data.SqlClient.SqlConnectionString.VerifyLocalHostAndFixup(String& host, Boolean enforceLocalHost, Boolean fixup) +811400
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +2207
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +200
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +62
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
   System.Data.SqlClient.SqlConnection..ctor(String connectionString) +24
   System.Web.DataAccess.SqlConnectionHolder..ctor(String connectionString) +54

[ArgumentException: An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString]
   System.Web.DataAccess.SqlConnectionHolder..ctor(String connectionString) +136
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +134
   System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +815
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
   System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78
   System.Web.Security.Membership.ValidateUser(String username, String password) +46
   _Default.Login1_Authenticate(Object sender, AuthenticateEventArgs e) in c:\inetpub\vhosts\vcantop.com\httpdocs\Default.aspx.cs:22
   System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +108
   System.Web.UI.WebControls.Login.AttemptLogin() +115
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

What's Wrong?

Body:
The error seems clear - the value you have for AttachDBFilename is invalid.

|DataDirectory| should be the physical path to the .mdf file:

c:\data dir\aspnetdb.mdf

All together:

data source=mssql2008.chaiyohosting.com;Integrated
Security=SSPI;AttachDBFilename=c:\data dir\aspnetdb.mdf;User Instance=true


问:
jQuery autocomplete - how to prevent auto focus when minLength is zero

 var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Perl",
    "PHP",
    "Python",
    "Ruby",
    "Scala",
    "Scheme"];

    $("#test").autocomplete({
        minLength: 0,
        source: availableTags,
        autoFocus: true,
        select: function (event, ui) {
            if (ui.item) {
                event.preventDefault();
                $(this).val(ui.item.label);
            }
        },
        open: function (event, ui) {
            var menu = $(this).data("uiAutocomplete").menu;
            var items = $('li', menu.element);

            for (var i = 0; i < items.length; i++) {
                if (items.eq(i).text().startsWith($(this).val())) {
                    menu.focus(null, items.eq(i));
                    break;
                }
            }
        },
        focus: function (event, ui) {
            event.preventDefault();
            if ($(this).val() == "" && !event.keyCode) {
                //debugger;
                $('.ui-menu-item a').removeClass('ui-state-focus');
            }
            else {
                //$(this).data("uiAutocomplete").menu.element.children().first().focus();
            }
        }
    }).on("focus", function () {
        $(this).autocomplete("search", "");
    });```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
    <label for="test" class="col-md-3 col-lg-3 control-label"></label>
    <div class="col-md-9 col-lg-7">
        <input id="test" type="text" class="form-control" />
    </div>
</div></code>```

While tabbing through the page, inputs with autocomplete are filling out by default with the first option in dropdown. If I set minLength = 1, problem solved. However, I have to keep minLength = 0 in order to pop up the dropdown when the input is focused.

One thought is that removing the focus class when first popping up the dropdown. But the problem is when I press the arrowdown, the second option is focused instead of the first one.

I cannot find any solution to manually focus the first option. Please help.

Any other solutions are more than welcome. Thanks in advance.

答:
I think This will help you.

    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#test" ).autocomplete({
      source: availableTags
    });
  ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
   <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">

<div class="form-group">
    <label for="test" class="col-md-3 col-lg-3 control-label"></label>
    <div class="col-md-9 col-lg-7">
        <input id="test" type="text" class="form-control" />
    </div>
</div></code>```

Body:
 var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Perl",
    "PHP",
    "Python",
    "Ruby",
    "Scala",
    "Scheme"];

    $("#test").autocomplete({
        minLength: 0,
        source: availableTags,
        autoFocus: true,
        select: function (event, ui) {
            if (ui.item) {
                event.preventDefault();
                $(this).val(ui.item.label);
            }
        },
        open: function (event, ui) {
            var menu = $(this).data("uiAutocomplete").menu;
            var items = $('li', menu.element);

            for (var i = 0; i < items.length; i++) {
                if (items.eq(i).text().startsWith($(this).val())) {
                    menu.focus(null, items.eq(i));
                    break;
                }
            }
        },
        focus: function (event, ui) {
            event.preventDefault();
            if ($(this).val() == "" && !event.keyCode) {
                //debugger;
                $('.ui-menu-item a').removeClass('ui-state-focus');
            }
            else {
                //$(this).data("uiAutocomplete").menu.element.children().first().focus();
            }
        }
    }).on("focus", function () {
        $(this).autocomplete("search", "");
    });

        <input id="test" type="text" class="form-control" />

While tabbing through the page, inputs with autocomplete are filling out by default with the first option in dropdown. If I set minLength = 1, problem solved. However, I have to keep minLength = 0 in order to pop up the dropdown when the input is focused.

One thought is that removing the focus class when first popping up the dropdown. But the problem is when I press the arrowdown, the second option is focused instead of the first one.

I cannot find any solution to manually focus the first option. Please help.

Any other solutions are more than welcome. Thanks in advance.

Body:
I think This will help you.

    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#test" ).autocomplete({
      source: availableTags
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
   <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">

<div class="form-group">
    <label for="test" class="col-md-3 col-lg-3 control-label"></label>
    <div class="col-md-9 col-lg-7">
        <input id="test" type="text" class="form-control" />
    </div>
</div>


问:
Connect to TFS GIT domain\username + password
I'm trying to clone a TFS GIT repository into a linux redhat machine.

```<code>git clone myTFSGitURL
Username for 'https://tfs.domain.net': DOMAIN\myUSER
Password for 'https://DOMAIN\myUSER@tfs.domain.net':
</code>```

I expected to be able to connect to the repository, but I get the error:

```<code>fatal: Authentication failed for myTFSGitURL
</code>```

I believe that the domain is the issue as it looks weird that it states

```<code>Password for 'https://DOMAIN\myUSER@tfs.domain.net':
</code>```

答:
Try to use SSH key authentication to clone git repo.

You can refer to this case: git clone from Linux to TFS git repo

Body:
I'm trying to clone a TFS GIT repository into a linux redhat machine.

git clone myTFSGitURL
Username for 'https://tfs.domain.net': DOMAIN\myUSER
Password for 'https://DOMAIN\myUSER@tfs.domain.net':

I expected to be able to connect to the repository, but I get the error:

fatal: Authentication failed for myTFSGitURL

I believe that the domain is the issue as it looks weird that it states

Password for 'https://DOMAIN\myUSER@tfs.domain.net':


问:
Installing Laravel homestead on a virtual machine in windows 10 - after I created a VM box do I need to install virtualbox again within this box?
Trying to install laravel homestead in windows but inside a virtualbox. So first I installed VirtualBox which then allows me to install a VM which I called LaravelBox (so this is an empty machine) - which means I need to install ubuntu 16.04, then vagrant (as the documents on the laravel homestead site (https://laravel.com/docs/5.5/homestead#installation-and-setup) - which instruct me to install the homestead vagrant box, then configure, etc. When I get to he final step to run vagrant up, I get the error:

```<code>**Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
</code>```

Vagrant uses the VBoxManage binary that ships with VirtualBox, and requires
this to be available on the PATH. If VirtualBox is installed, please find the
VBoxManage binary and add it to the PATH environmental variable.**

Does this mean then I now need to install virtualbox inside the VM I just created called LaravelBox? - so it's the case of a VM that contains the laravel homestead vagrant box is inside a a VM? Any help is appreciated, thanks.

答:
Homestead was meant to provide a Unix like dev environment so that it would be easier to work with symlinks and permissions, it uses Ubuntu vagrant box by default.

So you can either install homestead directly on your host machine i.e windows or as you already have a Ubuntu VM you can setup a basic dev server manually.

It does not make sense to run a VM inside a VM

Body:
Trying to install laravel homestead in windows but inside a virtualbox. So first I installed VirtualBox which then allows me to install a VM which I called LaravelBox (so this is an empty machine) - which means I need to install ubuntu 16.04, then vagrant (as the documents on the laravel homestead site (https://laravel.com/docs/5.5/homestead#installation-and-setup) - which instruct me to install the homestead vagrant box, then configure, etc. When I get to he final step to run vagrant up, I get the error:

**Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.

Vagrant uses the VBoxManage binary that ships with VirtualBox, and requires
this to be available on the PATH. If VirtualBox is installed, please find the
VBoxManage binary and add it to the PATH environmental variable.**

Does this mean then I now need to install virtualbox inside the VM I just created called LaravelBox? - so it's the case of a VM that contains the laravel homestead vagrant box is inside a a VM? Any help is appreciated, thanks.


问:
Determining the type of Jenkins project
Ideally I would like to clone a jenkins project, but it is in say /dir1/dir2/dir3/dir4/dir5 and I am in /dir1/dir2/dir6/dir7/dir8 and I can "copy existing item from" but it does not offer a browse, and I don't know how to specify a project from a different directory.  If someone knows, you could let me know.

In the meantime, I will just have two window open.  One window displaying the current project and the other window creating a new one, and I will just copy the things over.  My problem, and I bet it is very simple but I could not find out during research or else it is so simple I overlooked it ;-)  Jenkins wants me to specify the type (Freestyle project, MultiJob Project, Maven project, Pipeline, etc) and I am not sure.  I want to make it the same as the existing project, but I can't figure out how to tell what type the existing project is.  It does check out files from SVN and build via Java.

Can someone tell me how to find out what type of project an existing maven project is?

答:
There is no specific tag, but if you open a project, delete button have the type of project information available. pipleline project will have "Delete Pipeline" button, maven project will have "Delete Maven Project" button and a freestyle project will only have "Delete Project" button.

In addition one should have description text about this information.

Title: Determining the type of Jenkins project


问:
Conditional function in APL
Is there a symbol or well-known idiom for the conditional function, in any of the APL dialects?

I'm sure I'm missing something, because it's such a basic language element. In other languages it's called conditional operator, but I will avoid that term here, because an APL operator is something else entirely.

For example C and friends have x ? T : F

LISPs have (if x T F)

Python has T if x else F

and so on.

I know modern APLs have :If and friends, but they are imperative statements to control program flow: they don't return a value, cannot be used inside an expression and certainly cannot be applied to arrays of booleans. They have a different purpose altogether, which is just fine by me.

The only decent expression I could come up with to do a functional selection is (F T)[⎕IO+x], which doesn't look particularly shorthand or readable to me, although it gets the job done, even on arrays:

```<code>      ('no' 'yes')[⎕IO+(⍳5)∘.>(⍳5)]
no  no  no  no  no
yes no  no  no  no
yes yes no  no  no
yes yes yes no  no
yes yes yes yes no
</code>```

I tried to come up with a similar expression using squad ⌷, but failed miserably on arrays of booleans. Even if I could, it would still have to embed ⎕IO or an hardcoded 1, which is even worse as far as readability is concerned.

Before I go ahead and define my own if and use it on every program I will ever write, is there any canon on this? Am I missing an obvious function or operator?

(Are there any APL programmers on SO? :-)

答:
The APL expression:

```<code>(1+x=0)⌷y z
</code>```

should be the C language equivalent for

```<code>x?y:z
</code>```

And all the others

```<code>(1+x>0)⌷y z
</code>```

for

```<code>x<=0?y:z
</code>```

Etc. In general if a b c are expressions of respective languages the APL expression:

```<code>(1+~a)⌷b c
</code>```

It should be equivalent to the C language:

```<code>a?b:c
</code>```

Title: Conditional function in APL

Body:
Is there a symbol or well-known idiom for the conditional function, in any of the APL dialects?

I'm sure I'm missing something, because it's such a basic language element. In other languages it's called conditional operator, but I will avoid that term here, because an APL operator is something else entirely.

For example C and friends have x ? T : F

LISPs have (if x T F)

Python has T if x else F

and so on.

I know modern APLs have :If and friends, but they are imperative statements to control program flow: they don't return a value, cannot be used inside an expression and certainly cannot be applied to arrays of booleans. They have a different purpose altogether, which is just fine by me.

The only decent expression I could come up with to do a functional selection is (F T)[⎕IO+x], which doesn't look particularly shorthand or readable to me, although it gets the job done, even on arrays:

      ('no' 'yes')[⎕IO+(⍳5)∘.>(⍳5)]
no  no  no  no  no
yes no  no  no  no
yes yes no  no  no
yes yes yes no  no
yes yes yes yes no

I tried to come up with a similar expression using squad ⌷, but failed miserably on arrays of booleans. Even if I could, it would still have to embed ⎕IO or an hardcoded 1, which is even worse as far as readability is concerned.

Before I go ahead and define my own if and use it on every program I will ever write, is there any canon on this? Am I missing an obvious function or operator?

(Are there any APL programmers on SO? :-)

Body:
The APL expression:

(1+x=0)⌷y z

should be the C language equivalent for

x?y:z

And all the others

(1+x>0)⌷y z

for

x<=0?y:z

Etc. In general if a b c are expressions of respective languages the APL expression:

(1+~a)⌷b c

It should be equivalent to the C language:

a?b:c


问:
A lot of space between two scrollviews because wrap - React Native
I am creating different scrollviews and the view is not correct. Between ScrollView End and ScrollView Start there is a long space and I don't know what style to modify to avoid that.
When the scrollview is set to wrap, the long space appear!

Any idea?

I am creating something like this:

```<code> <View>
<ScrollView
    contentContainerStyle={{
        flexDirection: "column",
        alignContent: "space-around"
    }}
    automaticallyAdjustContentInsets={false}
    contentInSet={{ bottom: 49 }}
    style={{ paddingBottom: 0, marginBottom: 0 }}
>
    <Text>Testing</Text>
    <ScrollView
        contentContainerStyle={globalStyles.COMMON_STYLES.scrollView}
        automaticallyAdjustContentInsets={false}
        contentInSet={{ bottom: 49 }}
        style={{ padding: 0, margin: 0 }}
    >
        <Text>ScrollView End</Text>
    </ScrollView>
    //Here is the problem!!! Lot of space in the IOS Simulator.
    <Text>ScrollView Start</Text>
    <ScrollView>
        <Text>Test</Text>
    </ScrollView>
</ScrollView>
</View>;

 globalStyles.COMMON_STYLES.scrollview
   scrollView: {
    flexDirection: 'row',
    flexWrap: 'wrap',
 }
</code>```

There is a long space up to the following scrollview:

答:
Try using this on ScrollView</p>

```<code>automaticallyAdjustContentInsets = {false}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I am creating different scrollviews and the view is not correct. Between ScrollView End and ScrollView Start there is a long space and I don't know what style to modify to avoid that.
When the scrollview is set to wrap, the long space appear!

Any idea?

I am creating something like this:

 <View>
<ScrollView
    contentContainerStyle={{
        flexDirection: "column",
        alignContent: "space-around"
    }}
    automaticallyAdjustContentInsets={false}
    contentInSet={{ bottom: 49 }}
    style={{ paddingBottom: 0, marginBottom: 0 }}
>
    <Text>Testing</Text>
    <ScrollView
        contentContainerStyle={globalStyles.COMMON_STYLES.scrollView}
        automaticallyAdjustContentInsets={false}
        contentInSet={{ bottom: 49 }}
        style={{ padding: 0, margin: 0 }}
    >
        <Text>ScrollView End</Text>
    </ScrollView>
    //Here is the problem!!! Lot of space in the IOS Simulator.
    <Text>ScrollView Start</Text>
    <ScrollView>
        <Text>Test</Text>
    </ScrollView>
</ScrollView>
</View>;

 globalStyles.COMMON_STYLES.scrollview
   scrollView: {
    flexDirection: 'row',
    flexWrap: 'wrap',
 }

There is a long space up to the following scrollview:

Body:
Try using this on ScrollView

automaticallyAdjustContentInsets = {false}


问:
Drawing onClick in Android
I am trying to make a program the makes a graph using user input values from 2 EditText Fields. The program should use this input to draw a line from the center of an axis to a point specified by the information. I have a button that each time it is clicked should make a new line to the point specified (so there can be more than one line) I have created a custom view to hold the axis, but that utilizes its onDraw method, obviously, so I cant use it also to draw the new line.

Here is the code for my custom view:

```<code>package android.physicsengine;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class AxisDrawing extends View{

public AxisDrawing(Context context){

    super(context);
}
public AxisDrawing(Context context, AttributeSet attrs){

    super(context, attrs);

}
public AxisDrawing(Context context, AttributeSet attrs, int defStyle){

    super(context, attrs, defStyle);
}

@Override
protected void onDraw(Canvas canvas){
    canvas.drawColor(Color.BLACK);
    Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    linePaint.setColor(Color.RED);
    canvas.drawLine(canvas.getWidth()/2, canvas.getHeight()/2-200,        canvas.getWidth()/2 ,canvas.getHeight()/2+100, linePaint);
    canvas.drawLine(canvas.getWidth()/2-150, canvas.getHeight()/2-75, canvas.getWidth()/2+150 ,canvas.getHeight()/2-75, linePaint);
}
}
</code>```

答:
If your custom view class is defined in the activity, then it is an inner class of that activity and has access to variables and arrays which are defined on the activity level.

Every time the user clicks the button, you should process and store the information into these common variables or arrays which onDraw can access and from them calculate the next line or the entire graph. If your custom view is a separate class, then you need to pass the data, one way to do it is to use static varibales..

to make onDraw() method draw again your graph you need to state:

myCustomView.invalidate();

in the button click event, just after you set the new data for the graph.

Title: Drawing onClick in Android

Body:
I am trying to make a program the makes a graph using user input values from 2 EditText Fields. The program should use this input to draw a line from the center of an axis to a point specified by the information. I have a button that each time it is clicked should make a new line to the point specified (so there can be more than one line) I have created a custom view to hold the axis, but that utilizes its onDraw method, obviously, so I cant use it also to draw the new line.

Here is the code for my custom view:

package android.physicsengine;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class AxisDrawing extends View{

public AxisDrawing(Context context){

    super(context);
}
public AxisDrawing(Context context, AttributeSet attrs){

    super(context, attrs);

}
public AxisDrawing(Context context, AttributeSet attrs, int defStyle){

    super(context, attrs, defStyle);
}

@Override
protected void onDraw(Canvas canvas){
    canvas.drawColor(Color.BLACK);
    Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    linePaint.setColor(Color.RED);
    canvas.drawLine(canvas.getWidth()/2, canvas.getHeight()/2-200,        canvas.getWidth()/2 ,canvas.getHeight()/2+100, linePaint);
    canvas.drawLine(canvas.getWidth()/2-150, canvas.getHeight()/2-75, canvas.getWidth()/2+150 ,canvas.getHeight()/2-75, linePaint);
}
}


问:
How to hide textarea if input is empty
How do I use jQuery to hide textarea if input text is empty?

My attempt:

```<code>jQuery(document).chnage(function($) {
    var value=$.trim($('input').val());

    if (value.length < 0) {
        $('textarea[name="your-message"]').hide();
    }
});
</code>```

答:
Use keypress or html5 input event instead of change event for the input element and toggle using toggle() method in jQuery.

// bind input event handler
$('input').on('input', function() {
  // toggle visible state based on value
  $('textarea[name="your-message"]').toggle(this.value.trim() !== '');
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>textarea {
  display: none
}</code>```

<input type="text" />
<textarea name="your-message"></textarea>```

Issues in your code:

Since you are providing $ as the callback param it holds event object inside the callback(not jQuery).

Change event only fires when the element loses focus after its value was changed.

You are only hiding the element inside the callback, no code present for showing it again.

chnage should be change(I think its a typo).

Title: How to hide textarea if input is empty

Body:
How do I use jQuery to hide textarea if input text is empty?

My attempt:

jQuery(document).chnage(function($) {
    var value=$.trim($('input').val());

    if (value.length < 0) {
        $('textarea[name="your-message"]').hide();
    }
});

Body:
Use keypress or html5 input event instead of change event for the input element and toggle using toggle() method in jQuery.

// bind input event handler
$('input').on('input', function() {
  // toggle visible state based on value
  $('textarea[name="your-message"]').toggle(this.value.trim() !== '');
});

textarea {
  display: none
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" />
<textarea name="your-message"></textarea>

Issues in your code:

Since you are providing $ as the callback param it holds event object inside the callback(not jQuery).

Change event only fires when the element loses focus after its value was changed.

You are only hiding the element inside the callback, no code present for showing it again.

chnage should be change(I think its a typo).


问:
VBA - if cell is empty then skip the sub
I have code, which put formula into area and it works fine:

```<code>Private Sub Jeeves_account2_C()

Dim lastrow As Long
Dim rng As Range, C As Range

With Worksheets("Crd_Headers") ' <-- here should be the Sheet's name
    lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
    Set rng = .Range("C2:C" & lastrow) ' set the dynamic range to be searched

    ' loop through all cells in column B
    For Each C In rng
        If Not IsEmpty(C.Value) Then
            C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
        End If
    Next C
End With

End Sub
</code>```

But I would like to add condition, if cell C2 on the sheet Crd_Headers is empty, then skip the whole sub:

```<code>If Worksheets("Crd_Headers").Cells("C2") = "" Then
    Exit Sub
End If
</code>```

So the code looks like:

```<code>Private Sub Jeeves_account2_C()

If Worksheets("Crd_Headers").Cells("C2") = "" Then
    Exit Sub
End If

Dim lastrow As Long
Dim rng As Range, C As Range

With Worksheets("Crd_Headers") ' <-- here should be the Sheet's name
    lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
    Set rng = .Range("C2:C" & lastrow) ' set the dynamic range to be searched

    ' loop through all cells in column B
    For Each C In rng
        If Not IsEmpty(C.Value) Then
            C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
        End If
    Next C
End With

End Sub
</code>```

But it gives me error message invalid procedure call or argument

Could you advise me, what do I do wrong?

Thank you!

答:
You simply mixed up Cells and Range object references.

To refer single cell you have two solutions:

```<code>If Worksheets("Crd_Headers").Range("C2") = "" Then
</code>```

or

```<code>If Worksheets("Crd_Headers").Cells(2, "C") = "" Then
</code>```

Body:
I have code, which put formula into area and it works fine:

Private Sub Jeeves_account2_C()

Dim lastrow As Long
Dim rng As Range, C As Range

With Worksheets("Crd_Headers") ' <-- here should be the Sheet's name
    lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
    Set rng = .Range("C2:C" & lastrow) ' set the dynamic range to be searched

    ' loop through all cells in column B
    For Each C In rng
        If Not IsEmpty(C.Value) Then
            C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
        End If
    Next C
End With

End Sub

But I would like to add condition, if cell C2 on the sheet Crd_Headers is empty, then skip the whole sub:

If Worksheets("Crd_Headers").Cells("C2") = "" Then
    Exit Sub
End If

So the code looks like:

Private Sub Jeeves_account2_C()

If Worksheets("Crd_Headers").Cells("C2") = "" Then
    Exit Sub
End If

Dim lastrow As Long
Dim rng As Range, C As Range

With Worksheets("Crd_Headers") ' <-- here should be the Sheet's name
    lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
    Set rng = .Range("C2:C" & lastrow) ' set the dynamic range to be searched

    ' loop through all cells in column B
    For Each C In rng
        If Not IsEmpty(C.Value) Then
            C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
        End If
    Next C
End With

End Sub

But it gives me error message invalid procedure call or argument

Could you advise me, what do I do wrong?

Thank you!

Body:
You simply mixed up Cells and Range object references.

To refer single cell you have two solutions:

If Worksheets("Crd_Headers").Range("C2") = "" Then

or

If Worksheets("Crd_Headers").Cells(2, "C") = "" Then


问:
Upload file using HTML  control without file selection dialog
I want upload the file using HTML file control but without selection dialog since i have to upload file which has fixed path "c:\finsts\finstmt.xml".

Scenario 1:

I have tried to upload file using HTML control . In which it shows browse button and on click you have to select file from file chooser dialog box. It works. Its upload file to server fine. Server side code is correct and works fine.

Scenario 2:

But when I hide the file chooser control, with following HTML code:

```<code> <div name="filediv" style="display:none">
  <html type="file" id="uploadfile" value="c:\finsts\finstmt.xml">
 </div>
</code>```

As file path is fixed and I don't want to user select file. When I tried with this scenario it doesn't work while first works fine. I don't understood how file control works.

Anyone here knows any work around to work the second scenario?

Thanks.

答:
The best choice you have is to put the file name you desire in text directly above the file chooser, and tell your users to cut and paste it into the file box. You might even be able to get a little js tool that a user can click and fill the copy buffer so they only have to hit paste.

note: I am not proposing that javascript populate the file upload box directly using a 'copy/paste' trick.  I'm proposing a UI where helping the user populate the box with the least amount of effort is the only approach you can take due to the security requirements in the browser.

Title: Upload file using HTML <html type="file" id="uploadfile"> control without file selection dialog

Body:
I want upload the file using HTML file control but without selection dialog since i have to upload file which has fixed path "c:\finsts\finstmt.xml".

Scenario 1:

I have tried to upload file using HTML control . In which it shows browse button and on click you have to select file from file chooser dialog box. It works. Its upload file to server fine. Server side code is correct and works fine.

Scenario 2:

But when I hide the file chooser control, with following HTML code:

As file path is fixed and I don't want to user select file. When I tried with this scenario it doesn't work while first works fine. I don't understood how file control works.

Anyone here knows any work around to work the second scenario?

Thanks.


问:
How to clean or clean build my Maven project in IntelliJ IDEA?
I'm using Apache Maven in my Java project. in NetBeans there are build and clean build icons but there aren't in IntellIJ IDEA. How can I clean or clean build my project in it?</p>

答:
If it's a Maven project:

Go to your project's root folder (where your pom.xml is located)

In address bar of windows explorer type cmd

You should be prompted with cmd window where you should type mvn clean

That will clean your target folder which is getting created after build

Make sure you have your system variables set so mvn commands can work (otherwise you will get "mvn is not recognized as an internal or external command")

This is how it should look:

Hope this helps.


问:
How to save generic object to an array in swift
I have on class

```<code>class SomeClass<T>: AsyncOperation, NetworkOperationProtocol {

    /// The resource model object that conforms to Parsable Response
    public typealias Resource = T
}
</code>```

I want to save instance of this class to an array, and want retrieve it later.
How can I achieve this?

答:
If your generic type would be:

```<code>struct GenericType {}
</code>```

You would specify the generic class using:

```<code>let array = [SomeClass<GenericType>]()
</code>```

Or you can let it infer the type on its own with something like:

```<code>class SomeClass<T>: AsyncOperation, NetworkOperationProtocol {

    /// The resource model object that conforms to Parsable Response
    public typealias Resource = T
    let resource: Resource

    init(with resource: Resource) {
        self.resource = resource
    }
}

let item = SomeClass(with: GenericType())
let array = [item]
</code>```

Body:
I have on class

class SomeClass<T>: AsyncOperation, NetworkOperationProtocol {

    /// The resource model object that conforms to Parsable Response
    public typealias Resource = T
}

I want to save instance of this class to an array, and want retrieve it later.
How can I achieve this?

Body:
If your generic type would be:

struct GenericType {}

You would specify the generic class using:

let array = [SomeClass<GenericType>]()

Or you can let it infer the type on its own with something like:

class SomeClass<T>: AsyncOperation, NetworkOperationProtocol {

    /// The resource model object that conforms to Parsable Response
    public typealias Resource = T
    let resource: Resource

    init(with resource: Resource) {
        self.resource = resource
    }
}

let item = SomeClass(with: GenericType())
let array = [item]


问:
Trying to match regex for mask got issue with min-max length
hello everyone I'm new to regex and i'm trying to match this mask:
xxxx xxxx xxxx xxxx so far I've done this

```<code>^(\d{4}) (\d{4}) (\d{4}) (\d{4})$
</code>```

but how to control min-max length on validation? i need to make it possible to submit 4,8,12 or 16 digits and i can't figure it out. Thank you for your help.

答:
You can go for the following solution:

```<code>^\d{4}(\h+\d{4}){0,3}$
</code>```

Explanations:

\d{4}exactly 4 digits

\h one horizontal whitespace character

(\h+\d{4}) one or more horizontal whitespace char

{0,3} 0 to 3 repetitions of the previous char/block of char

^ and $ are respectively start of line and end of line

Good luck and let me know if something is not clear.

Body:
hello everyone I'm new to regex and i'm trying to match this mask:
xxxx xxxx xxxx xxxx so far I've done this

^(\d{4}) (\d{4}) (\d{4}) (\d{4})$

but how to control min-max length on validation? i need to make it possible to submit 4,8,12 or 16 digits and i can't figure it out. Thank you for your help.

Body:
You can go for the following solution:

^\d{4}(\h+\d{4}){0,3}$

Explanations:

\d{4}exactly 4 digits

\h one horizontal whitespace character

(\h+\d{4}) one or more horizontal whitespace char

{0,3} 0 to 3 repetitions of the previous char/block of char

^ and $ are respectively start of line and end of line

Good luck and let me know if something is not clear.


问:
ruby-debug install error: failed to build gem native extension
I'm running 1.9.2 with rails 3.

I'm using rvm.

I did:

```<code>sudo gem install ruby-gem
</code>```

and got:

```<code>Building native extensions.  This could take a while...
ERROR:  Error installing ruby-debug:
    ERROR: Failed to build gem native extension.

/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
Can't handle 1.9.x yet
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby

Gem files will remain installed in /Users/blankman/.rvm/gems/ruby-1.9.2-head/gems/linecache-0.43 for inspection.
Results logged to /Users/blankman/.rvm/gems/ruby-1.9.2-head/gems/linecache-0.43/ext/gem_make.out
</code>```

UPDATE

Added:

gem 'ruby-debug19'

and when running bundle install I get:

```<code>Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0.rc2)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.0.rc2)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.0.rc2)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.0.rc2)
Using arel (1.0.1)
Using activerecord (3.0.0.rc2)
Using activeresource (3.0.0.rc2)
Using archive-tar-minitar (0.5.2)
Using bundler (1.0.3)
Using columnize (0.3.1)
Using ruby_core_source (0.1.4)
Installing linecache19 (0.5.11) with native extensions /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for vm_core.h... no
checking for vm_core.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby
    --with-ruby-dir
    --without-ruby-dir
    --with-ruby-include
    --without-ruby-include=${ruby-dir}/include
    --with-ruby-lib
    --without-ruby-lib=${ruby-dir}/lib
/Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:268:in `block (2 levels) in read': Looking for http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz and all I got was a 404! (URI::NotFoundError)
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1186:in `block in transport_request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:2334:in `reading_body'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1185:in `transport_request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1169:in `request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1162:in `block in request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:627:in `start'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1160:in `request'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:239:in `block in read'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:286:in `connect'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:234:in `read'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:128:in `download'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/ruby_core_source.rb:55:in `block in create_makefile_with_core'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/tempfile.rb:320:in `open'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/ruby_core_source.rb:51:in `create_makefile_with_core'
    from extconf.rb:20:in `<main>'
Requesting http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz

Gem files will remain installed in /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/linecache19-0.5.11 for inspection.
Results logged to /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/linecache19-0.5.11/ext/trace_nums/gem_make.out
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:486:in `block in build_extensions'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `each'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `build_extensions'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:198:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/source.rb:100:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:55:in `block in run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:44:in `run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:8:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/cli.rb:221:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/bin/bundle:13:in `<top (required)>'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `load'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `<main>'
blankmans-MacBook-Pro:hz blankman$
</code>```

答:
The problem here can be that the install script is going off to get the Ruby Header files over the web (to build the debugger gem against) but doesn't find them for the particular patch-level of Ruby you're after. This is what's going on in the output line

```<code>Looking for http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz and all I got was a 404! (URI::NotFoundError)
</code>```

As a solution you can point to your local copy of the Ruby source which rvm has already used to build ruby on your machine. Here goes...

```<code>gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-head/
</code>```

Many thanks to Dirk at the following link which helped solve this

http://dirk.net/2010/04/17/ruby-debug-with-ruby-19x-and-rails-3-on-rvm/

Body:
I'm running 1.9.2 with rails 3.

I'm using rvm.

I did:

sudo gem install ruby-gem

and got:

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-debug:
    ERROR: Failed to build gem native extension.

/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
Can't handle 1.9.x yet
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby

Gem files will remain installed in /Users/blankman/.rvm/gems/ruby-1.9.2-head/gems/linecache-0.43 for inspection.
Results logged to /Users/blankman/.rvm/gems/ruby-1.9.2-head/gems/linecache-0.43/ext/gem_make.out

UPDATE

Added:

gem 'ruby-debug19'

and when running bundle install I get:

Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0.rc2)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.0.rc2)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.0.rc2)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.0.rc2)
Using arel (1.0.1)
Using activerecord (3.0.0.rc2)
Using activeresource (3.0.0.rc2)
Using archive-tar-minitar (0.5.2)
Using bundler (1.0.3)
Using columnize (0.3.1)
Using ruby_core_source (0.1.4)
Installing linecache19 (0.5.11) with native extensions /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for vm_core.h... no
checking for vm_core.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/blankman/.rvm/rubies/ruby-1.9.2-head/bin/ruby
    --with-ruby-dir
    --without-ruby-dir
    --with-ruby-include
    --without-ruby-include=${ruby-dir}/include
    --with-ruby-lib
    --without-ruby-lib=${ruby-dir}/lib
/Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:268:in `block (2 levels) in read': Looking for http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz and all I got was a 404! (URI::NotFoundError)
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1186:in `block in transport_request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:2334:in `reading_body'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1185:in `transport_request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1169:in `request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1162:in `block in request'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:627:in `start'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/net/http.rb:1160:in `request'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:239:in `block in read'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:286:in `connect'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:234:in `read'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/contrib/uri_ext.rb:128:in `download'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/ruby_core_source.rb:55:in `block in create_makefile_with_core'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/tempfile.rb:320:in `open'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/ruby_core_source-0.1.4/lib/ruby_core_source.rb:51:in `create_makefile_with_core'
    from extconf.rb:20:in `'
Requesting http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz

Gem files will remain installed in /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/linecache19-0.5.11 for inspection.
Results logged to /Users/blankman/.rvm/gems/ruby-1.9.2-head@hz/gems/linecache19-0.5.11/ext/trace_nums/gem_make.out
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:486:in `block in build_extensions'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `each'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `build_extensions'
    from /Users/blankman/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:198:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/source.rb:100:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:55:in `block in run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:44:in `run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/installer.rb:8:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/cli.rb:221:in `install'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.3/bin/bundle:13:in `<top (required)>'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `load'
    from /Users/blankman/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `'
blankmans-MacBook-Pro:hz blankman$

Body:
The problem here can be that the install script is going off to get the Ruby Header files over the web (to build the debugger gem against) but doesn't find them for the particular patch-level of Ruby you're after. This is what's going on in the output line

Looking for http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p14.tar.gz and all I got was a 404! (URI::NotFoundError)

As a solution you can point to your local copy of the Ruby source which rvm has already used to build ruby on your machine. Here goes...

gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-head/

Many thanks to Dirk at the following link which helped solve this

http://dirk.net/2010/04/17/ruby-debug-with-ruby-19x-and-rails-3-on-rvm/


问:
Run two delays at once C++
I want to make a program in which there are two dots blinking (with a break of 10ms) simultaneously, but one with delay 200ms and other with delay of 300ms. How can I play these two dots simultaneously from beginning? Is there a better way to that from following:</p>

```<code>for(int i=1;i<100;i++)
{
  if (i%2==0)
    circle(10,10,2);
  if (i%3==0)
    circle(20,10,2);
  delay(10);
  cleardevice();
  delay(100);
}
</code>```

答:
To display the two circles simultaneously in the first round, you have to satisfy both conditions i%2==0 and i%3==0 at once. You can achieve it by simply changing

```<code>for(int i=1;i<100;i++)
</code>```

to

```<code>for(int i=0;i<100;i++)
//        ↑ zero here
</code>```

Title: Run two delays at once C++

Body:
I want to make a program in which there are two dots blinking (with a break of 10ms) simultaneously, but one with delay 200ms and other with delay of 300ms. How can I play these two dots simultaneously from beginning? Is there a better way to that from following:

for(int i=1;i<100;i++)
{
  if (i%2==0)
    circle(10,10,2);
  if (i%3==0)
    circle(20,10,2);
  delay(10);
  cleardevice();
  delay(100);
}

Body:
To display the two circles simultaneously in the first round, you have to satisfy both conditions i%2==0 and i%3==0 at once. You can achieve it by simply changing

for(int i=1;i<100;i++)

to

for(int i=0;i<100;i++)
//        ↑ zero here


问:
OAuth2, creating local accounts using Facebook and Google
I'm currently trying to implement OAuth2-based registration/login to a project that I'm working on.

A thought struck me; if a user decides to login to the site the first time using Facebook and the second time using Google;

1) Is it possible to connect the two different login methods to the same account?

2) Is it a good idea?

At first I thought I could use the email as a unique identifier, but I doubt that is secure enough.

Is there a way to accomplish this, or should you simply create two separate accounts for the two, depending on which login method they used?

答:
Facebook has a page for guidance on this issue. It's quite comprehensive with respect to security issues and best practices:

If you use an email address as the unique credential which identifies each account, your app should verify that the email address associated with the person's Facebook account (and obtained during Facebook Login) is valid. You can do this by creating code in your app to send a verification email to the address obtained after Facebook Login (you will probably need to have this step as part of your regular login system anyway).

https://developers.facebook.com/docs/facebook-login/multiple-providers

Whether or not you deem this necessary will depend upon what your website does or allows via a login.


问:
Stata input command not allowing local macros
I found this curious behavior in the input command for Stata.

When you pass a local macro as an argument either for one variable or multiple, the input command gives this error:

'`' cannot be read as a number

Here are two examples that give the same error:

```<code>clear
local nums 1 1 1
input a b c
    `nums'
end

clear
local num 1
input a b c
    1 1 `num'
end
</code>```

Is there a way to pass macros into the input command?

答:
This does not pass a macro to the input command per se, but it does achieve your desired result, so perhaps this can help with what you are trying to do?

General idea is to set the value of a variable to a local, then split the local (similar to the text-to-column button in Excel).

```<code>clear
local  nums "1 1 1"
foreach n of local nums {
    if "`nums_2'" == "" local nums_2 "`n'"
    else local nums_2 = "`nums_2'/`n'"
}

set obs 1
gen a = "`nums_2'"
split a, parse("/") gen(b) destring
drop a
</code>```

Body:
I found this curious behavior in the input command for Stata.

When you pass a local macro as an argument either for one variable or multiple, the input command gives this error:

'`' cannot be read as a number

Here are two examples that give the same error:

clear
local nums 1 1 1
input a b c
    `nums'
end

clear
local num 1
input a b c
    1 1 `num'
end

Is there a way to pass macros into the input command?

Body:
This does not pass a macro to the input command per se, but it does achieve your desired result, so perhaps this can help with what you are trying to do?

General idea is to set the value of a variable to a local, then split the local (similar to the text-to-column button in Excel).

clear
local  nums "1 1 1"
foreach n of local nums {
    if "`nums_2'" == "" local nums_2 "`n'"
    else local nums_2 = "`nums_2'/`n'"
}

set obs 1
gen a = "`nums_2'"
split a, parse("/") gen(b) destring
drop a


问:
How to tell Xcode to attach debugger to a process as soon as the process will start?
I'm working on something that happens just when my app restarts, and I'm trying to get logs for that. So I build my app, kill it, and restart it.

Killing the app makes Xcode disconnect from the running process.

After I restart the app, I can select Debug > Attach to Process to attach Xcode to the new process, but I'll miss everything that happens between the app start and when I manually attach to the process.

Is there a way to tell Xcode there no process running currently, but as soon as process X starts, attach the debugger to it?

答:
Use the Attach to process by PID or Name feature.

It's under the Debug -> Attach to process by PID or Name menu in Xcode, then simply type in the process name that you normally attach to, and select Attach.

Once your app with said PID or name starts up, the debugger will attach to it immediately.

Make sure to set breakpoints for as early as late as you want to catch the launch.


问:
Current timestamp as filename in Java
I want to name new files created by my Java application with the current timestamp.

I need help with this. How do I name the new files created with the current timestamp? Which classes should I include?

答:
try this one</p>

```<code>String fileSuffix = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
</code>```

Title: Current timestamp as filename in Java

Body:
try this one

String fileSuffix = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());