问:
jQuery tabs - Selecting all menu ul elements
I'm new to using jQuery and my first bigger improvement to static website is a jQuery tabs which let's me switch main page divs on sidebar and topbar menus.
I can't seem to get the script to work with every nav class element.
As of right now it's working on said elements: Poradnik 1,2,3,4 and I'd also want them to work on Strona główna, Spis treści, Poradniki and O autorze. Basically all elements that are located under nav.
What should I change? Could anyone help me out with it? Thank you.

Below I'll put the code for the required elements.

$(document).ready(function(){

 $('ul.nav ul li').click(function(){
  var tab_id = $(this).attr('data-tab');

  $('ul.nav ul li').removeClass('current');
  $('.tab-content').removeClass('current');

  $(this).addClass('current');
  $("#"+tab_id).addClass('current');
 })
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.tab-content{
 display: none;
 padding: 15px;
}

.tab-content.current{
 display: inherit;
}
.topmenu {
 width: 875px;
 display: block;
 position: relative;
 float: left;
 height: 90px;
 font-size: 20px;
}
.topmenu ul {
 padding: 25px;
}
.topmenu ul.nav a, ul.nav a:visited {
 display: block;
 width: 120px;
 height: 25px;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: none;
 border-right-style: none;
 border-bottom-style: none;
 border-left-style: none;
 text-align: center;
 padding: 5px;
}
.topmenu ul.nav li a:hover {
 width: 120px;
 height: 25px;
 background: #D2E2FF;
 color: #000;
 border: 1px solid black;
 padding-top: 4px;
 padding-right: 4px;
 padding-bottom: 8px;
 padding-left: 4px;
}

.topmenu ul.nav li:hover ul {
 left: 0px;
 top: 38px;
 padding: 0px;
 border:solid 1px;
}
.topmenu ul.nav li:hover ul li a {
 padding: 6px;
 width: 250px;
 background-color: #FFFFFF;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-bottom-style: solid;
 border-top-color: #000;
 border-right-color: #000;
 border-bottom-color: #000;
 border-left-color: #000;
 border-right-style: none;
 border-left-style: none;
}

ul.nav {
 list-style: none;
 margin-bottom: 15px;
}
ul.nav li {
float:left;
}
ul.nav a, ul.nav a:visited {
 display: block;
 width: 25px;
 height: 25px;
 text-decoration: none;
 background-color: #FFFFFF;
 padding: 3px;
}

ul.nav li a:hover {
 background-color: #D2E2FF;
 color: #000;
 border: solid 1px black;
 padding: 2px;
}

ul.nav ul a:hover {
 background-color: #D2E2FF;
 color: #000;
 padding: 3px;
 border-top-style: none;
 border-right-style: none;
 border-bottom-style: none;
 border-left-style: none;
}

ul.nav li a:focus, ul.nav li a:active {
 color: #000;
 text-decoration: underline;
}

ul.nav ul {
 position: absolute;
 left: -9999px;
 top: -9999px;
 list-style-type: none;
}
ul.nav li:hover {
 position: relative;
}

ul.nav li:hover ul {
 left: 30px;
 top: 0px;
 padding: 0px;
 border: solid 1px;
}

ul.nav li:hover ul li a {
 padding: 3px;
 width:300px;
 background-color: #FFFFFF;
}

ul.nav li:hover ul li a:hover {
 background: #D2E2FF;
 color: #000;
}</code>```

Strona główna

Spis treści

Poradniki

Poradnik 1

Poradnik 2

Poradnik 3

Poradnik 4

O autorze

Strona główna

Strona główna

Spis treści

Spis treści

Poradnik 1

Poradnik 1

Poradnik 2

Poradnik 2

Poradnik 3

Poradnik 3

Poradnik 4

Poradnik 4

O autorze

O autorze

```

答:
select other li like following:

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

    $('ul.nav li').click(function(){
        var tab_id = $(this).attr('data-tab');
        if(typeof(tab_id) != 'undefined'){
            $('ul.nav li').removeClass('current');
            $('.tab-content').removeClass('current');

            $(this).addClass('current');
            $("#"+tab_id).addClass('current');
        }
    })
})
</code>```

simply follow the chain in your HTML for jquery selectors.

demo fiddle.
http://jsfiddle.net/6y7z1Lmq/1/

Body:
I'm new to using jQuery and my first bigger improvement to static website is a jQuery tabs which let's me switch main page divs on sidebar and topbar menus.
I can't seem to get the script to work with every nav class element.
As of right now it's working on said elements: Poradnik 1,2,3,4 and I'd also want them to work on Strona główna, Spis treści, Poradniki and O autorze. Basically all elements that are located under nav.
What should I change? Could anyone help me out with it? Thank you.

Below I'll put the code for the required elements.

$(document).ready(function(){

 $('ul.nav ul li').click(function(){
  var tab_id = $(this).attr('data-tab');

  $('ul.nav ul li').removeClass('current');
  $('.tab-content').removeClass('current');

  $(this).addClass('current');
  $("#"+tab_id).addClass('current');
 })
})

.tab-content{
 display: none;
 padding: 15px;
}

.tab-content.current{
 display: inherit;
}
.topmenu {
 width: 875px;
 display: block;
 position: relative;
 float: left;
 height: 90px;
 font-size: 20px;
}
.topmenu ul {
 padding: 25px;
}
.topmenu ul.nav a, ul.nav a:visited {
 display: block;
 width: 120px;
 height: 25px;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: none;
 border-right-style: none;
 border-bottom-style: none;
 border-left-style: none;
 text-align: center;
 padding: 5px;
}
.topmenu ul.nav li a:hover {
 width: 120px;
 height: 25px;
 background: #D2E2FF;
 color: #000;
 border: 1px solid black;
 padding-top: 4px;
 padding-right: 4px;
 padding-bottom: 8px;
 padding-left: 4px;
}

.topmenu ul.nav li:hover ul {
 left: 0px;
 top: 38px;
 padding: 0px;
 border:solid 1px;
}
.topmenu ul.nav li:hover ul li a {
 padding: 6px;
 width: 250px;
 background-color: #FFFFFF;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-bottom-style: solid;
 border-top-color: #000;
 border-right-color: #000;
 border-bottom-color: #000;
 border-left-color: #000;
 border-right-style: none;
 border-left-style: none;
}

ul.nav {
 list-style: none;
 margin-bottom: 15px;
}
ul.nav li {
float:left;
}
ul.nav a, ul.nav a:visited {
 display: block;
 width: 25px;
 height: 25px;
 text-decoration: none;
 background-color: #FFFFFF;
 padding: 3px;
}

ul.nav li a:hover {
 background-color: #D2E2FF;
 color: #000;
 border: solid 1px black;
 padding: 2px;
}

ul.nav ul a:hover {
 background-color: #D2E2FF;
 color: #000;
 padding: 3px;
 border-top-style: none;
 border-right-style: none;
 border-bottom-style: none;
 border-left-style: none;
}

ul.nav li a:focus, ul.nav li a:active {
 color: #000;
 text-decoration: underline;
}

ul.nav ul {
 position: absolute;
 left: -9999px;
 top: -9999px;
 list-style-type: none;
}
ul.nav li:hover {
 position: relative;
}

ul.nav li:hover ul {
 left: 30px;
 top: 0px;
 padding: 0px;
 border: solid 1px;
}

ul.nav li:hover ul li a {
 padding: 3px;
 width:300px;
 background-color: #FFFFFF;
}

ul.nav li:hover ul li a:hover {
 background: #D2E2FF;
 color: #000;
}

Strona główna

Spis treści

Poradniki

Poradnik 1

Poradnik 2

Poradnik 3

Poradnik 4

O autorze

Strona główna

Strona główna

Spis treści

Spis treści

Poradnik 1

Poradnik 1

Poradnik 2

Poradnik 2

Poradnik 3

Poradnik 3

Poradnik 4

Poradnik 4

O autorze

O autorze

Body:
select other li like following:

$(document).ready(function(){

    $('ul.nav li').click(function(){
        var tab_id = $(this).attr('data-tab');
        if(typeof(tab_id) != 'undefined'){
            $('ul.nav li').removeClass('current');
            $('.tab-content').removeClass('current');

            $(this).addClass('current');
            $("#"+tab_id).addClass('current');
        }
    })
})

simply follow the chain in your HTML for jquery selectors.

demo fiddle.
http://jsfiddle.net/6y7z1Lmq/1/


来源: stackexchange

问:
Javascript - move all commas in a string to a new position
in a given string, I want to move all commas at the ends of words in a string to the end of the word before the word they are attached to.
ex: "sometime soon the, cat said let's, go!" would read: "sometime soon, the cat said, let's go!"
any suggestions?</p>

答:
This problems is easily solved using regex with capturing groups and String.replace. The arguments of String.replace are the aforementioned regex and a callback function whose second, third and fourth arguments are the captured groups:

let str = "sometime soon the, cat said let's, go!";
let result = str.replace(/(\s)(\S+)(,)/g, (match, whitespace, word, comma) =>
  comma + whitespace + word
);

console.log(result); // "sometime soon, the cat said, let's go!"```

I recommend consulting Mozilla's MDN for such questions in the future as it is a valuable resource containing many good examples and best practices.

ContentLicense: CC BY-SA 3.0

Body:
This problems is easily solved using regex with capturing groups and String.replace. The arguments of String.replace are the aforementioned regex and a callback function whose second, third and fourth arguments are the captured groups:

let str = "sometime soon the, cat said let's, go!";
let result = str.replace(/(\s)(\S+)(,)/g, (match, whitespace, word, comma) =>
  comma + whitespace + word
);

console.log(result); // "sometime soon, the cat said, let's go!"

I recommend consulting Mozilla's MDN for such questions in the future as it is a valuable resource containing many good examples and best practices.


问:
What is flow wake mode?
What is flow wake mode?

```<code>// @flow wake
... ... ...
</code>```

I started work with flow few weeks ago. I saw @flow wake three days ago, but I'm not sure when and where to use it.

Please help me! :-)

答:
It's not a thing. I just searched the codebase to be sure and found nothing about "wake" mode.

Probably, somebody misspelled "weak." Weak mode basically means that missing annotations are treated as any (no type checking).

Title: What is flow wake mode?

Body:
What is flow wake mode?

// @flow wake
... ... ...

I started work with flow few weeks ago. I saw @flow wake three days ago, but I'm not sure when and where to use it.

Please help me! :-)


问:
How does daylight saving work in php (difference between php and hhvm)?
I need to detect when a timestamp is in daylight saving or not.

I'm using this code to test the functionality:

```<code><?php
date_default_timezone_set('Europe/Berlin');

$timestamp = $baseTimestamp = 1509234900; // Sunday, 29 October of 2017 1:55:00 GMT+02:00 DST
$date = (new DateTime)->setTimestamp($baseTimestamp);

echo "DateTime\t\t| Is in summer \t| Minutes passed\n";

for($i = 0; $i < 70; $i++) {
    $date = (new DateTime)->setTimestamp($timestamp);
    echo $date->format("Y-m-d H:i:s \t|I") . "\t\t| " . ($timestamp - $baseTimestamp)/60 . "\n";
    $timestamp = $timestamp + 60;
}
</code>```

https://3v4l.org/dqNlK

Working with Europe/Berlin, I've seen that in March, when at 2.00 we pass from winter to summer, php solves it right, but then in October, when it is supposed to come back from summer to winter at 3.00, it doesn't work as expected.

In this case, we have two timestamps corresponding to the same hour (at 3 is 2 again), but the timestamp is unique, so for 2.00 there must be one timestamp in the summer time and another one in the winter time.

Using hhvm, it shows the right value, but normal php interpreters show that is not in summer for both 2.00 (the first one, which is 2am and the second one which is when at 3am is 2am again. This is the one that should say is not in summer anymore)

答:
Yes, there are several long-lived, unresolved, DST-related bugs in PHP.

You appear to have hit on this one:
https://bugs.php.net/bug.php?id=68549

Body:
I need to detect when a timestamp is in daylight saving or not.

I'm using this code to test the functionality:

<?php
date_default_timezone_set('Europe/Berlin');

$timestamp = $baseTimestamp = 1509234900; // Sunday, 29 October of 2017 1:55:00 GMT+02:00 DST
$date = (new DateTime)->setTimestamp($baseTimestamp);

echo "DateTime\t\t| Is in summer \t| Minutes passed\n";

for($i = 0; $i < 70; $i++) {
    $date = (new DateTime)->setTimestamp($timestamp);
    echo $date->format("Y-m-d H:i:s \t|I") . "\t\t| " . ($timestamp - $baseTimestamp)/60 . "\n";
    $timestamp = $timestamp + 60;
}

https://3v4l.org/dqNlK

Working with Europe/Berlin, I've seen that in March, when at 2.00 we pass from winter to summer, php solves it right, but then in October, when it is supposed to come back from summer to winter at 3.00, it doesn't work as expected.

In this case, we have two timestamps corresponding to the same hour (at 3 is 2 again), but the timestamp is unique, so for 2.00 there must be one timestamp in the summer time and another one in the winter time.

Using hhvm, it shows the right value, but normal php interpreters show that is not in summer for both 2.00 (the first one, which is 2am and the second one which is when at 3am is 2am again. This is the one that should say is not in summer anymore)


问:
How to get store and assign it to spied variable
I have two files: x.component and x.service

x.service.ts

```<code>store$: Store<DogsStore>;

constructor(private store: Store<DogsStore>) {
  this.store$ = store;
}
</code>```

x.component.ts

```<code>constructor(private xService: X) {}

ngOnInit() {
  this.xService.store$.select('something').subscribe(...)
}
</code>```

Testing x.component I'm getting an error that cannot subscribe of undefined. In x.spec.ts I'm using x.service.spy.ts where I have

```<code>store$: Store<DogsStore>;
</code>```

as you can see I didn't initialize it because I can't use something like store$: Store<DogsStore> = new Store(). How can I get the store and assign it to variable? Maybe there is other issue to do that?

答:
If I got the question right, here is how to do it:

Basically, your app module provides the store, yet your test doesn't. So in your spec file, part of the beforeEach should provide it by importing it:

```<code>    TestBed.configureTestingModule({
      imports: [
        SomeModule,
        StoreModule.provideStore(reducer), // or your reducer name
        ....
      ],
      ....
    });
</code>```

and then spy on it (still in the beforeEach call):

```<code>    spyOn(getTestBed().get(Store), 'dispatch').and.callThrough();
</code>```

This way your component will get it.

Now to get access to the dispatch wrapper you should inject it in the test:

```<code>it('test something', inject([Type1, Type2, Store],
    (dep1: Type1, dep2: Type2, store) => {
       expect(store.dispatch.calls.count()).toEqual(<count_value>);
    }
</code>```

Now note that in the method signature I left store untyped, this is because otherwise the static checker complains that store.dispatch has no member calls

Body:
I have two files: x.component and x.service

x.service.ts

store$: Store<DogsStore>;

constructor(private store: Store<DogsStore>) {
  this.store$ = store;
}

x.component.ts

constructor(private xService: X) {}

ngOnInit() {
  this.xService.store$.select('something').subscribe(...)
}

Testing x.component I'm getting an error that cannot subscribe of undefined. In x.spec.ts I'm using x.service.spy.ts where I have

store$: Store<DogsStore>;

as you can see I didn't initialize it because I can't use something like store$: Store<DogsStore> = new Store(). How can I get the store and assign it to variable? Maybe there is other issue to do that?

Body:
If I got the question right, here is how to do it:

Basically, your app module provides the store, yet your test doesn't. So in your spec file, part of the beforeEach should provide it by importing it:

    TestBed.configureTestingModule({
      imports: [
        SomeModule,
        StoreModule.provideStore(reducer), // or your reducer name
        ....
      ],
      ....
    });

and then spy on it (still in the beforeEach call):

    spyOn(getTestBed().get(Store), 'dispatch').and.callThrough();

This way your component will get it.

Now to get access to the dispatch wrapper you should inject it in the test:

it('test something', inject([Type1, Type2, Store],
    (dep1: Type1, dep2: Type2, store) => {
       expect(store.dispatch.calls.count()).toEqual(<count_value>);
    }

Now note that in the method signature I left store untyped, this is because otherwise the static checker complains that store.dispatch has no member calls


问:
Getter and Setter Aliasing in C#
How would I go about aliasing a variable from it's plural form so that referencing the plural form changes or returns the single form?

I have a global variable as such with a Getter and Setter:

```<code>public string UserName { get; set; }
</code>```

And would like to set up an aliased variable UserNames that would return UserName and when set would modify UserName?

I've tried public string UserNames { get => UserName; set => UserName = UserNames } but that didn't seem to work.

答:
C# <7.0

```<code>public string UserNames { get { return UserName; } set { UserName = value; }}
</code>```

C# 7.0

```<code>public string UserNames { get => UserName; set => UserName = value; }
</code>```

Title: Getter and Setter Aliasing in C#

Body:
How would I go about aliasing a variable from it's plural form so that referencing the plural form changes or returns the single form?

I have a global variable as such with a Getter and Setter:

public string UserName { get; set; }

And would like to set up an aliased variable UserNames that would return UserName and when set would modify UserName?

I've tried public string UserNames { get => UserName; set => UserName = UserNames } but that didn't seem to work.

Body:
C# <7.0

public string UserNames { get { return UserName; } set { UserName = value; }}

C# 7.0

public string UserNames { get => UserName; set => UserName = value; }


问:
What is the difference between `-fpic` and `-fPIC` gcc parameters?
I've already read the gcc manpage, but I still can't understand the difference between -fpic and -fPIC. Can someone explain it, in a very simple and clear way?

Related questions:

What does -fPIC mean when building a shared library?

What, if any, are the implications of compiling objects with gcc -fPIC flag if they get used in executables?

答:
From the Gcc manual page:

When generating code for shared libraries, -fpic implies
-msmall-data and -fPIC implies -mlarge-data.

Where:

```<code> -msmall-data
 -mlarge-data
       When -mexplicit-relocs is in effect, static data is accessed
       via gp-relative relocations.  When -msmall-data is used,
       objects 8 bytes long or smaller are placed in a small data
       area (the ".sdata" and ".sbss" sections) and are accessed via
       16-bit relocations off of the $gp register.  This limits the
       size of the small data area to 64KB, but allows the variables
       to be directly accessed via a single instruction.

       The default is -mlarge-data.  With this option the data area
       is limited to just below 2GB.  Programs that require more
       than 2GB of data must use "malloc" or "mmap" to allocate the
       data in the heap instead of in the program's data segment.

       When generating code for shared libraries, -fpic implies
       -msmall-data and -fPIC implies -mlarge-data.
</code>```

Body:
From the Gcc manual page:

When generating code for shared libraries, -fpic implies
-msmall-data and -fPIC implies -mlarge-data.

Where:

 -msmall-data
 -mlarge-data
       When -mexplicit-relocs is in effect, static data is accessed
       via gp-relative relocations.  When -msmall-data is used,
       objects 8 bytes long or smaller are placed in a small data
       area (the ".sdata" and ".sbss" sections) and are accessed via
       16-bit relocations off of the $gp register.  This limits the
       size of the small data area to 64KB, but allows the variables
       to be directly accessed via a single instruction.

       The default is -mlarge-data.  With this option the data area
       is limited to just below 2GB.  Programs that require more
       than 2GB of data must use "malloc" or "mmap" to allocate the
       data in the heap instead of in the program's data segment.

       When generating code for shared libraries, -fpic implies
       -msmall-data and -fPIC implies -mlarge-data.

ContentLicense: CC BY-SA 4.0


问:
Paste lagging values into collapsed string/vector
How can I take lagging values of a column, and vectorize the pasting of values into a string?

For example, assuming the following data frame, the result would be column 'lagged'

```<code>     date             total_volume      lagged
     <date>           <int>             <chr>
     2017-01-01       323512            323512
     2017-01-02        28014            323512, 28014
     2017-01-03        12323            323512, 28014, 12323
     2017-01-04        11580            323512, 28014, 12323, 11580
     2017-01-05        12161
     2017-01-06        10796
     2017-01-07        10087
     2017-01-08        10406
     2017-01-09        11261
     2017-01-10        11333
</code>```

I tried using the approach:

```<code>df %>%
 mutate(lagged = paste(total_volume[1:row_number()], collapse = ','))
</code>```

but that returns an error.  I can create a function that loops and creates it, but when using the function in dplyr, it does not work correctly.

```<code>function(x) {
 for (i in 1:nrow(x)){
  print(paste(x$total_volume[1:i], collapse = ','))
 }
}
</code>```

Body:
How can I take lagging values of a column, and vectorize the pasting of values into a string?

For example, assuming the following data frame, the result would be column 'lagged'

     date             total_volume      lagged
     <date>           <int>             <chr>
     2017-01-01       323512            323512
     2017-01-02        28014            323512, 28014
     2017-01-03        12323            323512, 28014, 12323
     2017-01-04        11580            323512, 28014, 12323, 11580
     2017-01-05        12161
     2017-01-06        10796
     2017-01-07        10087
     2017-01-08        10406
     2017-01-09        11261
     2017-01-10        11333

I tried using the approach:

df %>%
 mutate(lagged = paste(total_volume[1:row_number()], collapse = ','))

but that returns an error.  I can create a function that loops and creates it, but when using the function in dplyr, it does not work correctly.

function(x) {
 for (i in 1:nrow(x)){
  print(paste(x$total_volume[1:i], collapse = ','))
 }
}

Body:
You could use the Reduce function with accumulate=T, which applies the paste recursively:

df %>% mutate(lagged = Reduce(function(i,j) paste(i,j,sep=","),total_volume,accumulate=T))

This returns:

        date   total_volume                                                      lagged
1  2017-01-01       323512                                                       323512
2  2017-01-02        28014                                                 323512,28014
3  2017-01-03        12323                                           323512,28014,12323
4  2017-01-04        11580                                     323512,28014,12323,11580
5  2017-01-05        12161                               323512,28014,12323,11580,12161
6  2017-01-06        10796                         323512,28014,12323,11580,12161,10796
7  2017-01-07        10087                   323512,28014,12323,11580,12161,10796,10087
8  2017-01-08        10406             323512,28014,12323,11580,12161,10796,10087,10406
9  2017-01-09        11261       323512,28014,12323,11580,12161,10796,10087,10406,11261
10 2017-01-10        11333 323512,28014,12323,11580,12161,10796,10087,10406,11261,11333


问:
How to get even spacing between TextView in ConstraintLayout?
I got this issue here, which is easily fixed if I would use nested linearlayout like this:

```<code><LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>
</LinearLayout>
</code>```

But is there a way to solve this in constraints layout?
In the image, the square represents a fixed size imageview, the rectangle is a textview which can 1 line (smaller height than imageview) or multiline (height is larger than imageview)

I tried constraints spacing each imageview with xDp, it is ok if ALL textviews are not higher than the imageview, but if a textview is higher than a imageview, it will overlap.
I also tried to do spacing from ImageView to TextView, but then if the TextView is smaller than the ImageView, the spacing will be wrong again.

Is there a way to solve this in ConstraintLayout?

This is how it looks in Editor

and its layout xml

```<code>  <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView3"
            android:layout_marginTop="24dp"
            app:layout_constraintTop_toBottomOf="@+id/imageView3" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            android:layout_marginTop="24dp"
            app:layout_constraintTop_toBottomOf="@+id/imageView" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            tools:layout_editor_absoluteX="40dp"
            tools:layout_editor_absoluteY="32dp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:fontFamily="@font/source_sans"
            android:text="This text is a lot longer and overlaps the one below which is bad."
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="@+id/imageView" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:fontFamily="@font/source_sans"
            android:text="This is a normal length text and that makes it."
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageView4"
            app:layout_constraintTop_toTopOf="@+id/imageView4"
            app:layout_constraintHorizontal_bias="0.0" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:fontFamily="@font/source_sans"
            android:text="Small Text"
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintTop_toTopOf="@+id/imageView3"
            app:layout_constraintStart_toEndOf="@+id/imageView3"
            android:layout_marginStart="16dp" />

    </android.support.constraint.ConstraintLayout>
</code>```

答:
for information i am posting this answer will be useful for future reference
I think that was ConstarintLayout problem with wrap_content data handling where this is now easy from new ConstraintLayout version which is now in beta

It introduced new feature  by using this we can tackle this wrap_content problem, also @kazhiu's answer will do workaround here because of fixed height of ImageView it will not work if ImageView have an wrap_content or dynamic height so in this case constraint.Barrier is useful.
 for setup bet ContraintLayout we have to do following

add maven support in project gradle file as below

```<code>allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
}
</code>```

then in app gardle dependencies add ConstarintLayout library dependency

```<code>compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
</code>```

Here is the same @kazhiu's code using constraint.Barrier

```<code><android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text="Lorem ipsum"
        app:layout_constraintLeft_toRightOf="@+id/imageView"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/barrierone"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="16dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
        app:layout_constraintLeft_toRightOf="@+id/imageView2"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView2" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toBottomOf="@+id/barrierone2" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginRight="0dp"
        app:layout_constraintLeft_toRightOf="@+id/imageView4"
        android:layout_marginLeft="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView4"
        android:layout_marginTop="0dp" />

    <android.support.constraint.Barrier
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/barrierone"
        app:layout_constraintTop_toBottomOf="@+id/imageView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:constraint_referenced_ids="imageView,textView"
        app:barrierDirection="bottom" />

    <android.support.constraint.Barrier
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/barrierone2"
        app:layout_constraintTop_toBottomOf="@+id/imageView2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:constraint_referenced_ids="imageView2,textView2"
        app:barrierDirection="bottom" />

</android.support.constraint.ConstraintLayout>
</code>```

Design and blue print

in android.support.constraint.Barrier

```<code>app:constraint_referenced_ids="id1,id2"
</code>```

will contain the id's of views which are wrap_content on top of other views, also we can create horizontal barrier by replacing height to match_constraint(0dp) and width to wrap_content

Body:
I got this issue here, which is easily fixed if I would use nested linearlayout like this:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>

    <LinearLayout android:layout_marginTop="32dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
        <ImageView/>
        <TexView/>
    </LinearLayout>
</LinearLayout>

But is there a way to solve this in constraints layout?
In the image, the square represents a fixed size imageview, the rectangle is a textview which can 1 line (smaller height than imageview) or multiline (height is larger than imageview)

I tried constraints spacing each imageview with xDp, it is ok if ALL textviews are not higher than the imageview, but if a textview is higher than a imageview, it will overlap.
I also tried to do spacing from ImageView to TextView, but then if the TextView is smaller than the ImageView, the spacing will be wrong again.

Is there a way to solve this in ConstraintLayout?

This is how it looks in Editor

and its layout xml

  <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView3"
            android:layout_marginTop="24dp"
            app:layout_constraintTop_toBottomOf="@+id/imageView3" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            android:layout_marginTop="24dp"
            app:layout_constraintTop_toBottomOf="@+id/imageView" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_timer_black_24dp"
            tools:layout_editor_absoluteX="40dp"
            tools:layout_editor_absoluteY="32dp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:fontFamily="@font/source_sans"
            android:text="This text is a lot longer and overlaps the one below which is bad."
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="@+id/imageView" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:fontFamily="@font/source_sans"
            android:text="This is a normal length text and that makes it."
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageView4"
            app:layout_constraintTop_toTopOf="@+id/imageView4"
            app:layout_constraintHorizontal_bias="0.0" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:fontFamily="@font/source_sans"
            android:text="Small Text"
            android:textColor="@color/primary_text"
            android:textSize="24sp"
            android:typeface="normal"
            app:layout_constraintTop_toTopOf="@+id/imageView3"
            app:layout_constraintStart_toEndOf="@+id/imageView3"
            android:layout_marginStart="16dp" />

    </android.support.constraint.ConstraintLayout>

Body:
for information i am posting this answer will be useful for future reference
I think that was ConstarintLayout problem with wrap_content data handling where this is now easy from new ConstraintLayout version which is now in beta

It introduced new feature  by using this we can tackle this wrap_content problem, also @kazhiu's answer will do workaround here because of fixed height of ImageView it will not work if ImageView have an wrap_content or dynamic height so in this case constraint.Barrier is useful.
 for setup bet ContraintLayout we have to do following

add maven support in project gradle file as below

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
}

then in app gardle dependencies add ConstarintLayout library dependency

compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'

Here is the same @kazhiu's code using constraint.Barrier

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text="Lorem ipsum"
        app:layout_constraintLeft_toRightOf="@+id/imageView"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/barrierone"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="16dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
        app:layout_constraintLeft_toRightOf="@+id/imageView2"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView2" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:srcCompat="@mipmap/ic_launcher"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toBottomOf="@+id/barrierone2" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginRight="0dp"
        app:layout_constraintLeft_toRightOf="@+id/imageView4"
        android:layout_marginLeft="16dp"
        app:layout_constraintTop_toTopOf="@+id/imageView4"
        android:layout_marginTop="0dp" />

    <android.support.constraint.Barrier
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/barrierone"
        app:layout_constraintTop_toBottomOf="@+id/imageView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:constraint_referenced_ids="imageView,textView"
        app:barrierDirection="bottom" />

    <android.support.constraint.Barrier
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/barrierone2"
        app:layout_constraintTop_toBottomOf="@+id/imageView2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:constraint_referenced_ids="imageView2,textView2"
        app:barrierDirection="bottom" />

</android.support.constraint.ConstraintLayout>

Design and blue print

in android.support.constraint.Barrier

app:constraint_referenced_ids="id1,id2"

will contain the id's of views which are wrap_content on top of other views, also we can create horizontal barrier by replacing height to match_constraint(0dp) and width to wrap_content


问:
Convert all words from text file to UpperCase using cmd or vbsscript
I have a text file called C:\Test.txt. I would like to convert all words inside the text file to UpperCases using cmd. Could you please help me?

I tried with

```<code>@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
   set "line=%%a"
   for %%b in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "line=!line:%%b=%%b!"
   )
   echo !line!
)
</code>```

but i do not see where to put the location of the test.txt file

答:
You can try something like that :

Where %1 is the first parameter, means the InputFile and %2 is the second parameter, means the OutputFile

@echo off
set "InputFile=C:\Test.txt"
set "OuputFile=C:\UpCaseTest.txt"
If Exist "%OuputFile%" Del "%OuputFile%"
Call :Convert2UpCase "%InputFile%" "%OuputFile%"
Start "" "%OuputFile%"
Exit /b
::**********************************************************************
:Convert2UpCase <InputFile> <OutputFile>
setlocal EnableDelayedExpansion
for /F "delims=" %%a in ('Type %1') do (
   set "line=%%a"
   for %%b in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "line=!line:%%b=%%b!"
   )
   echo !line!>>%2
)
::**********************************************************************
```

Body:
I have a text file called C:\Test.txt. I would like to convert all words inside the text file to UpperCases using cmd. Could you please help me?

I tried with

@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
   set "line=%%a"
   for %%b in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "line=!line:%%b=%%b!"
   )
   echo !line!
)

but i do not see where to put the location of the test.txt file


问:
Build error: "The process cannot access the file because it is being used by another process"
I've got a C# webforms app, that until today had been working just swimmingly.

Now today, all of a sudden, every time I try run the app, I get a file locking error:

Unable to copy file "obj\Debug\MyProject.exe" to "bin\Debug\MyProject.exe". The process cannot access the file "bin\Debug\MyProject.exe" because it is being used by another process.

Googling the error doesn't come up with anything beyond the obvious, i.e. VS thinks the file is locked.  And it is definitely Visual Studio itself that locks the file, because when I close VS and reopen it, the project executes fine - the first time.  When I try to run it a second time, I get the file locking error.

Closing VS and reopening every time I want to run the app is not a viable workaround!  How do I find out what's locking the file, and stop it from getting locked?

EDIT: Another interesting discovery: I don't even have to run the app.  Just compiling it once causes the file locking; I cannot compile twice in a row!

This problem is specific to one project in my solution.  All other projects work fine and can be executed as many times as I like.  It's only this one project that gets itself locked up.

答: In my case there were some vstest processes running (with various names but all containing the string vstest). I had to terminate them in taskmgr.</p>


问:
Design View option disabled when right-clicking objects in navigation pane
When I right-click an object in the Navigation Pane (Access 2010) the Design View option is disabled (greyed-out).

I have tested this on multiple objects (forms, tables, and queries) in multiple database (both mdb and accdb) with the same results. I have had other users test this (using the same databases and objects I tested with) and nobody else is having this problem. I tried rebooting. I compared my Access options to other users and they were identical.

Fortunately, I am able to open objects by double-clicking them, then I can change the view from the ribbon. However, in cases where the object is an executable query (i.e. queries that delete, update, append, or make a table), I have no way to enter design view. Additionally, if there is an error preventing an object from being opened normally (i.e. in datasheet/form view) then I have no way of fixing it in design view!

At this point I'm considering reinstalling Access. Looking for alternative suggestions here. Please help!

答: As I mentioned in a previous comment, I had been testing a new security module provided by IT. I confirmed this module caused the problem by testing it on a different machine. I informed IT and they were able to provide a sub routine to undo the issue. </p>


问:
Google Apps Script: How to set return to my page?
I'm using Google Apps Script to write values from a form to a Google Spreadsheet.

I have the form in my HTML page and its action calls the Google Apps Script to write in the sheet.

Now I'd like to go back to my site with a flag var and show a message (Error or Complete) based on the result of the function.

I know how to create and set the flag variable but I don't know how to "send" it to my page. I was only able to show my flag with something like this (that's the whole function I have in GAS)

```<code>function doPost(e){

var id = "";
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['email'];
var text = e.parameter['text'];
var date = new Date();
var ans = ""
var ctrl= "WIP";

var vals = [id, date, name, surname, serial, eMail, text, ans, flag];
var sheetObj =SpreadsheetApp.openById("myKey").getSheetByName('Requests').appendRow(vals);
return ContentService.createTextOutput(someOutput);
}
</code>```

Someone knows how to do what I need?

Thanks a lot for your help!

S.

答:
You can do something like this

return ContentService.createTextOutput("Complete").setMimeType(ContentService.MimeType.TEXT);

Or in case of exception return 'Error' from your catch block like this

return ContentService.createTextOutput("Error").setMimeType(ContentService.MimeType.TEXT);

Body:
I'm using Google Apps Script to write values from a form to a Google Spreadsheet.

I have the form in my HTML page and its action calls the Google Apps Script to write in the sheet.

Now I'd like to go back to my site with a flag var and show a message (Error or Complete) based on the result of the function.

I know how to create and set the flag variable but I don't know how to "send" it to my page. I was only able to show my flag with something like this (that's the whole function I have in GAS)

function doPost(e){

var id = "";
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['email'];
var text = e.parameter['text'];
var date = new Date();
var ans = ""
var ctrl= "WIP";

var vals = [id, date, name, surname, serial, eMail, text, ans, flag];
var sheetObj =SpreadsheetApp.openById("myKey").getSheetByName('Requests').appendRow(vals);
return ContentService.createTextOutput(someOutput);
}

Someone knows how to do what I need?

Thanks a lot for your help!

S.


问:
CSS Variable height does not work correctly
I am getting a weird behavior when I make height as a variable $main-height in CSS.

```<code>height: $main-height/2;
</code>```

Result of checkbox check

Demo fiddles are listed below:

Hard coded height JSFiddle

Variable height JSFiddle

When I use the same code in CodePen it works - CodePen .

How to fix this in jsFiddle and my HTML?

Please note that I have no experience in LESS/SASS.

答:
Thanks for the comments. Based on the comments, I am adding it as answer.

Why the HTML is not working: This code need to be compiled as CSS.

How to make it work in JsFiddle:  On top/right of the css box and choose "scss" as the language. (as mentioned by @MichaelCoker)

How to get Compiled CSS: In codepen, on top/right arrow in the css panel, select  "View compiled css" to get the compiled CSS (as mentioned by @MichaelCoker)

Body:
I am getting a weird behavior when I make height as a variable $main-height in CSS.

height: $main-height/2;

Result of checkbox check

Demo fiddles are listed below:

Hard coded height JSFiddle

Variable height JSFiddle

When I use the same code in CodePen it works - CodePen .

How to fix this in jsFiddle and my HTML?

Please note that I have no experience in LESS/SASS.


问:
Bootstrap 3 blocking styling of disabled select in IE11
I am trying to change the foreground text color of a disabled select in IE11.

I have an example where it is working (in IE11) with only plain HTML and CSS.

The key part there is this code:

```<code>select:disabled { color: green !important; }
</code>```

But, then I add in Bootstrap 3 (but keep my code the same) :

In Chrome and Firefox, the color stays changed.

In IE11, the addition of bootstrap 3 causes the foreground to go back to a "hard to read gray".  (Something in the btn bootstrap style seems to cause this.)

Is there a way to get Bootstrap 3 to not force the select disabled color to be grey in IE11?

答:
Try to add:</p>

```<code><meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
        @media all and (-ms-high-contrast:none)
         {
         select:disabled { color: green !important; } /* IE10 */
         *::-ms-backdrop, select:disabled { color: green !important; } /* IE11 */
         }
</style>
</code>```

Body:
I am trying to change the foreground text color of a disabled select in IE11.

I have an example where it is working (in IE11) with only plain HTML and CSS.

The key part there is this code:

select:disabled { color: green !important; }

But, then I add in Bootstrap 3 (but keep my code the same) :

In Chrome and Firefox, the color stays changed.

In IE11, the addition of bootstrap 3 causes the foreground to go back to a "hard to read gray".  (Something in the btn bootstrap style seems to cause this.)

Is there a way to get Bootstrap 3 to not force the select disabled color to be grey in IE11?

Body:
Try to add:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
        @media all and (-ms-high-contrast:none)
         {
         select:disabled { color: green !important; } /* IE10 */
         *::-ms-backdrop, select:disabled { color: green !important; } /* IE11 */
         }
</style>


问:
From jpg to animated gif
I'm desperate, I need to convert some jpg images into an animated gif.

I've tried ffmpeg, but the result has a terrible quality.

Also tried imagemagick, and the result looks great but it weights 511 KB !!

Anyone please can tell me what to use or how to use the before applications to get a final animated gif with a normal quality and a normal weight for a gif??

As I said I'm desperate, I need to finish this asap :(

Thanks a lot

答:
Not looking too deeply into the details, this link might have what you are looking for: http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/, in particular the first link in the comment by Almar on June 16, 2009.

This approach uses the Python and the Python Imaging Library. If you're not handy with either, then it sounds like this approach is going to take longer than you're hoping.

By the way, you might want to ask this question on superuser ... stackoverflow is for programming questions, superuser is more generally about 'doing stuff with computers'.

ContentLicense: CC BY-SA 2.5

Title: From jpg to animated gif


问:
How to change the arrow color of the html select box?
I want to style a select element of bootstrap like the following picture provided:

but unfortunately couldn't change the color of the arrow.

#test{
    border: 1px solid #dd6592;
    border-radius: 0px;
    text-align: center;
    width:20%;
    font-size: 16px;
    margin-bottom: 20px;
}```
<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://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<select class="form-control" id="test">
  <option>Test</option>
  <option>Test</option>
  <option>Test</option>
</select></code>```

答:
It is not possible to change color on that arrow cross browser.

Here is a workaround, using a wrapper and a pseudo element.

.myselect {
  position: relative;
  display: inline-block;
}
.myselect select {
  height: 30px;
  border-color: red;
  padding-right: 10px;
  outline: none;
}
.myselect::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 11px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid rgba(255,0,0,1);
  pointer-events: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="myselect">
  <select class="form-control" id="test">
    <option>Test</option>
    <option>Test</option>
    <option>Test</option>
  </select>
</div></code>```

Body:
I want to style a select element of bootstrap like the following picture provided:

but unfortunately couldn't change the color of the arrow.

#test{
    border: 1px solid #dd6592;
    border-radius: 0px;
    text-align: center;
    width:20%;
    font-size: 16px;
    margin-bottom: 20px;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<select class="form-control" id="test">
  <option>Test</option>
  <option>Test</option>
  <option>Test</option>
</select>

Body:
It is not possible to change color on that arrow cross browser.

Here is a workaround, using a wrapper and a pseudo element.

.myselect {
  position: relative;
  display: inline-block;
}
.myselect select {
  height: 30px;
  border-color: red;
  padding-right: 10px;
  outline: none;
}
.myselect::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 11px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid rgba(255,0,0,1);
  pointer-events: none;
}

<div class="myselect">
  <select class="form-control" id="test">
    <option>Test</option>
    <option>Test</option>
    <option>Test</option>
  </select>
</div>


问:
Scaling :hover effect isn't working in css on

Short and simple, I'm trying to use a hover effect, and I can't seem to get it to work within this DIV at the moment and I've never came across this problem and I can't find out where I went wrong.

.navbar {
      border: solid 0px; background-color: #E6E6E6; padding-top: 15px; padding-
      bottom: 15px;
      position: absolute; top: 230px; left: 320px;
      font-family: sans-serif;
      }
     .shopping,
     .food,
     .hotels,
     .entertainment,
     .guide {
      display: inline;
      padding-right: 90px;
      padding-left: 90px;
      }
      .shopping:hover,
      .food:hover,
      .hotels:hover,
      .entertainment:hover,
      .guide:hover {
       color: yellow;
       -webkit-transform: scale(1.3);
       -ms-transform: scale(1.3);
       transform: scale(1.3);
       }```
<pre class="snippet-code-html lang-html prettyprint-override"><code> <div class="navbar">
      <p class="shopping">Shopping</p>
      <p class="food">href="food.html">Food</p>
      <p class="hotels">href="hotels.html">Hotels</p>
      <p class="entertainment">href="entertainment.html">Entertainment</p>
      <p class="guide">href="guide.html">The total NOLA guide.</p>
     </div>
     </code>```

The weird part is that the color yellow ends up being shown but the hover that I want the scaling portion is not working and I can't figure it out.

答:
I would switch the nesting to have the  tag on the outer, and then inner use a  tag.

a.f > span {
  font-size: 1em;
  color: grey;
  -webkit-transition: all 0.3s ease;
  -moz-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  -ms-transition: all 0.3s ease;
}

a.f > span:hover {
    font-size: 22em;
    color: brown;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><span class="f">Food</span></code>```

Title: Scaling :hover effect isn't working in css on <p>

Body:
Short and simple, I'm trying to use a hover effect, and I can't seem to get it to work within this DIV at the moment and I've never came across this problem and I can't find out where I went wrong.

.navbar {
      border: solid 0px; background-color: #E6E6E6; padding-top: 15px; padding-
      bottom: 15px;
      position: absolute; top: 230px; left: 320px;
      font-family: sans-serif;
      }
     .shopping,
     .food,
     .hotels,
     .entertainment,
     .guide {
      display: inline;
      padding-right: 90px;
      padding-left: 90px;
      }
      .shopping:hover,
      .food:hover,
      .hotels:hover,
      .entertainment:hover,
      .guide:hover {
       color: yellow;
       -webkit-transform: scale(1.3);
       -ms-transform: scale(1.3);
       transform: scale(1.3);
       }

Shopping

Food

Hotels

Entertainment

The total NOLA guide.

The weird part is that the color yellow ends up being shown but the hover that I want the scaling portion is not working and I can't figure it out.

Body:
I would switch the nesting to have the <a> tag on the outer, and then inner use a <span> tag.

a.f > span {
  font-size: 1em;
  color: grey;
  -webkit-transition: all 0.3s ease;
  -moz-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  -ms-transition: all 0.3s ease;
}

a.f > span:hover {
    font-size: 22em;
    color: brown;
}

<a href="food.html" class="f"><span class="f">Food</span></a>


问:
Android sqlExcetion opening db : Permission denied JDBC
I try to create and use SQLite database in Android(API 25).
I provide permission in manifest. I think maybe there is problem with database Path. But I can`t solve this problem...

```<code><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permissio8n.READ_EXTERNAL_STORAGE"/>
</code>```

There is database opening code

```<code>String db = "jdbc:sqlite:" + Environment.getDataDirectory().getAbsolutePath() + "/MyDatabase.db";
        Class.forName("org.sqlite.JDBC");
</code>```

But there is some errors regarding permissions

```<code>06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err: java.sql.SQLException: opening db: '/data/MyDatabase.db': Permission denied
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.core.CoreConnection.open(CoreConnection.java:203)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:24)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.JDBC.createConnection(JDBC.java:114)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.JDBC.connect(JDBC.java:88)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:569)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:237)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.DB.openDbConnection(DB.java:33)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.Helpers.isTableIsEmpty(Helpers.java:24)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.activity.BachelorITFCourses1.onCreate(BachelorITFCourses1.java:42)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.Activity.performCreate(Activity.java:6679)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.-wrap12(ActivityThread.java)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.os.Looper.loop(Looper.java:154)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
</code>```

P.S. I have special class DB for dtabase actions.

答:
So you think I need to request the permissions I need? Something like this?</p>

```<code>if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {

    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {

        // Show an explanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.

        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_CONTACTS},
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}
</code>```

Body:
I try to create and use SQLite database in Android(API 25).
I provide permission in manifest. I think maybe there is problem with database Path. But I can`t solve this problem...

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permissio8n.READ_EXTERNAL_STORAGE"/>

There is database opening code

String db = "jdbc:sqlite:" + Environment.getDataDirectory().getAbsolutePath() + "/MyDatabase.db";
        Class.forName("org.sqlite.JDBC");

But there is some errors regarding permissions

06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err: java.sql.SQLException: opening db: '/data/MyDatabase.db': Permission denied
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.core.CoreConnection.open(CoreConnection.java:203)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:24)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.JDBC.createConnection(JDBC.java:114)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at org.sqlite.JDBC.connect(JDBC.java:88)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:569)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:237)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.DB.openDbConnection(DB.java:33)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.Helpers.isTableIsEmpty(Helpers.java:24)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at com.example.user.app.activity.BachelorITFCourses1.onCreate(BachelorITFCourses1.java:42)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.Activity.performCreate(Activity.java:6679)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
06-05 21:05:35.962 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.-wrap12(ActivityThread.java)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.os.Looper.loop(Looper.java:154)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
06-05 21:05:35.963 3698-3698/com.example.user.app W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

P.S. I have special class DB for dtabase actions.

Body:
So you think I need to request the permissions I need? Something like this?

if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {

    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {

        // Show an explanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.

        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_CONTACTS},
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}


问:
In Linux, how do I know if an ACK is received to a certain TCP packet?
Long story short: in Linux, how do I ensure that an ACK message is received for a certain TCP packet?

Full story:

I'm debugging an Asterisk/OpenH323 <-> Panasonic IP-GW16 issue.

An H323 connection involves two sessions: H225.0 and H245. These are just two TCP sessions, over which some data are transmitted.

Let's call them Session 1 (for H225.0) and Session 2 (for H245).

Session 1 has well-known TCP port number of 1720, while port for Session 2 is chosen at runtime.

Control flow goes as follows:

Panasonic calls Asterisk: it opens Session 1 (TCP/1720) to Asterisk and sends a SETUP message over Session 1, which contains the port 2 that Panasonic will listen to.

Asterisk sends Panasonic a CALL PROCEEDING message over Session 1

Panasonic starts listening on the port 2

Panasonic sends a TCP ACK over Session 1.

Asterisk opens TCP Session 2 on port 2.

Order of steps 2 and 3 is important: Panasonic will not listen to port 2 unless it has received a CALL PROCEEDING message on step 2.

But in OpenH323 code, step 2 and step 5 are only several lines away.

That's why connection sometimes works in debug mode and quite never works in release.

It is clearly seen in a packet dump. I made a series of experiments, and in 52 cases out of 52, if step 5 goes before step 4, the connection fails; if not, the connection succeeds.

There are no other messages sent from Panasonic except that ACK in step 4, and it seems that the only way Asterisk may know that port 2 is listened to is receiving that ACK.

Of course I may implement a timed wait, but I want a cleaner solution.

So the question goes again: after sending a message over TCP connection in step 2, how do I know if an ACK is received to the packet containing the message?

答:
The timing sequence seems odd, although if the Panasonic is using a proprietary O/S that might explain it.

To clarify - AIUI - if the Panasonic was running a "normal" O/S, the ACK sent by it in stage 4 would happen immediately after the Panasonic's software has read() the data from the control TCP socket.

Similarly the OpenH323 code call to write() (in step 2) shouldn't return (assuming that it's not a non-blocking socket!) until the ACK from the Panasonic has been received by the Asterisk server.  That is how you're supposed to know that the ACK has been received.

Essentially it seems that the Panasonic isn't doing the equivalent of listen() on the second socket until after it has read() the CALL PROCEEDING message.  It looks like a race condition - sometimes Open323 will try to connect() before the other end is ready.

When this happens, do you get ECONNREFUSED at the OpenH23 end?

OwnerDisplayName: Quassnoi

OwnerDisplayName: Alnitak


答:
Here is an answer on how to achieve your output in away you can reuse in different cases (print out in console, write to textfile, use in logs etc). It's basically the same as the first answer, but building the output as String using StringBuilder and returning it. This way you can use the String for others places, too. I checked with your example output and everything fits.</p>

```<code>private final static int lineLength = 63;

public static void printSeparatorTitle(String heading) {

    System.out.println(createSeparator(lineLength));
    System.out.println(createSeparator(lineLength, heading));
    System.out.println(createSeparator(lineLength));
}

public static String createSeparator(int length) {

    final StringBuilder builder = new StringBuilder();
    while (length-- > 0) {
        builder.append("*");
    }
    return builder.toString();
}

public static String createSeparator(int length, String heading) {

    final int position = (length - heading.length() - 1) / 2;
    final StringBuilder builder = new StringBuilder();
    while (builder.length() < position) {
        builder.append("*");
    }

    builder.append(' ').append(heading).append(' ');

    while (builder.length() < length) {
        builder.append("*");
    }
    return builder.toString();
}

public static void main(String[] args) {

    printSeparatorTitle("Select Character");
    printSeparatorTitle("Select Stats");
    printSeparatorTitle("Select Display Method");

    // checking expected output:
    System.out.println("*********************** Select Character **********************"
            .equals(createSeparator(63, "Select Character")));

    System.out.println("************************* Select Stats ************************"
            .equals(createSeparator(63, "Select Stats")));

    System.out.println("******************** Select Display Method ********************"
            .equals(createSeparator(63, "Select Display Method")));
}
</code>```

Title: Autofill static character in string to match string length

Body:
I'm using this method as a line separator in a console and I wanted to make it easy to pass through titles.

public class Test {
    private int consoleLineSeparatorLength = "***************************************************************".length();

    private void printTitleLineSeparator(String title){
        String lineTitleSeperatorBorder = "";
        String lineTitleSeperator = "* " + title + " *";
        for(int charInString = 0; charInString < consoleLineSeparatorLength; charInString++){
            lineTitleSeperatorBorder += "*";
        }

        System.out.println();
        System.out.println(lineTitleSeperatorBorder);
        System.out.println(lineTitleSeperator);
        System.out.println(lineTitleSeperatorBorder);
        System.out.println();
    }

    public static void main(String[] args) {
        Test tester = new Test();

        tester.printTitleLineSeparator("Select Character");
        tester.printTitleLineSeparator("Select Stats");
        tester.printTitleLineSeparator("Select Display Method");

    }
}

Current Output...

***************************************************************
* Select Character *
***************************************************************

***************************************************************
* Select Stats *
***************************************************************

***************************************************************
* Select Display Method *
***************************************************************

Expected output...

***************************************************************
*********************** Select Character **********************
***************************************************************

***************************************************************
************************* Select Stats ************************
***************************************************************

***************************************************************
******************** Select Display Method ********************
***************************************************************

If the center title is an even amount of characters including whitespaces (meaning one side or the other will have one extra asterisk), put the extra asterisk on the left side so everything still looks centered.

Anyone have any ideas how to do this?

Body:
Here is an answer on how to achieve your output in away you can reuse in different cases (print out in console, write to textfile, use in logs etc). It's basically the same as the first answer, but building the output as String using StringBuilder and returning it. This way you can use the String for others places, too. I checked with your example output and everything fits.

private final static int lineLength = 63;

public static void printSeparatorTitle(String heading) {

    System.out.println(createSeparator(lineLength));
    System.out.println(createSeparator(lineLength, heading));
    System.out.println(createSeparator(lineLength));
}

public static String createSeparator(int length) {

    final StringBuilder builder = new StringBuilder();
    while (length-- > 0) {
        builder.append("*");
    }
    return builder.toString();
}

public static String createSeparator(int length, String heading) {

    final int position = (length - heading.length() - 1) / 2;
    final StringBuilder builder = new StringBuilder();
    while (builder.length() < position) {
        builder.append("*");
    }

    builder.append(' ').append(heading).append(' ');

    while (builder.length() < length) {
        builder.append("*");
    }
    return builder.toString();
}

public static void main(String[] args) {

    printSeparatorTitle("Select Character");
    printSeparatorTitle("Select Stats");
    printSeparatorTitle("Select Display Method");

    // checking expected output:
    System.out.println("*********************** Select Character **********************"
            .equals(createSeparator(63, "Select Character")));

    System.out.println("************************* Select Stats ************************"
            .equals(createSeparator(63, "Select Stats")));

    System.out.println("******************** Select Display Method ********************"
            .equals(createSeparator(63, "Select Display Method")));
}


问:
php backup sqlite3 db issue
I'm attempting to backup a few sqlite3 databases via a small php script. This script successfully outputs all the files of the correct size into the proper location. The problem arises (And I've only just realized this today when trying to migrate my website to a new location) that these backups do not work.

When I go to import these backups using phpLiteAdmin, I get an error near "SQLite": syntax error

If I open this file in notepad++, all the data is there. The file starts with SQLite format 3 which I believe is causing the issue. But removing this on a copy of this backup does not fix the issue.

I have tried many different ways to backup the databases, all using PHP's exec() command to execute sqlite3 code.

Here is my current backup script. This basically loops through all the databases and backs them up into their own folder with a timestamp in a backups folder. I am using sqlite3's .backup which outputs the file, currently with a .sql extension. I have also tried .schema and .dump but neither of these output anything.

I am at a complete loss here, I'm lucky I still have the original databases in-tact, but I need to be able to automatically back up these databases to be restored at a later date if needed.

```<code>    <?
$today = date("m-d-Y");
$time = date("g:iA");

backup("db");
backup("development");
backup("inventory");
backup("permissions");
backup("reports");
backup("rollcall");
backup("upc");

$files = getDirContents('backups');
$start = "/home5/aspiretw/public_html/myticketroll/otherdb/modelfinder/pages/db/";

foreach($files as $value) {
    $value = substr($value, strlen($start));
    @$act = explode("_", $value);
    @$act = explode("/", $act[0]);

    if(strtotime("$act[2] 17:14:40") > strtotime('-7 days')) {
        unlink($value);
    }
}

function backup($db) {

    global $today, $time;

    $dir = "backups/$db/";
    if (!is_dir($dir)) {
        mkdir($dir, 0777, true);
    }

    $path = $dir.$today."_".$db."_".$time.".sql";

    exec("sqlite3 '$db' '.backup '".$path."''");
}

function getDirContents($dir, &$results = array()){
    $files = scandir($dir);

    foreach($files as $key => $value){
        $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
        if(!is_dir($path)) {
            $results[] = $path;
        } else if($value != "." && $value != "..") {
            getDirContents($path, $results);
            if(substr($path, -4) == ".bak") {
                $results[] = $path;
            }
        }
    }

    return $results;
}
?>
</code>```

答:
The .backup command simply copies the database file (while correctly handling transaction isolation).

To restore it, simply copy it back.

Title: php backup sqlite3 db issue

Body:
I'm attempting to backup a few sqlite3 databases via a small php script. This script successfully outputs all the files of the correct size into the proper location. The problem arises (And I've only just realized this today when trying to migrate my website to a new location) that these backups do not work.

When I go to import these backups using phpLiteAdmin, I get an error near "SQLite": syntax error

If I open this file in notepad++, all the data is there. The file starts with SQLite format 3 which I believe is causing the issue. But removing this on a copy of this backup does not fix the issue.

I have tried many different ways to backup the databases, all using PHP's exec() command to execute sqlite3 code.

Here is my current backup script. This basically loops through all the databases and backs them up into their own folder with a timestamp in a backups folder. I am using sqlite3's .backup which outputs the file, currently with a .sql extension. I have also tried .schema and .dump but neither of these output anything.

I am at a complete loss here, I'm lucky I still have the original databases in-tact, but I need to be able to automatically back up these databases to be restored at a later date if needed.

    <?
$today = date("m-d-Y");
$time = date("g:iA");

backup("db");
backup("development");
backup("inventory");
backup("permissions");
backup("reports");
backup("rollcall");
backup("upc");

$files = getDirContents('backups');
$start = "/home5/aspiretw/public_html/myticketroll/otherdb/modelfinder/pages/db/";

foreach($files as $value) {
    $value = substr($value, strlen($start));
    @$act = explode("_", $value);
    @$act = explode("/", $act[0]);

    if(strtotime("$act[2] 17:14:40") > strtotime('-7 days')) {
        unlink($value);
    }
}

function backup($db) {

    global $today, $time;

    $dir = "backups/$db/";
    if (!is_dir($dir)) {
        mkdir($dir, 0777, true);
    }

    $path = $dir.$today."_".$db."_".$time.".sql";

    exec("sqlite3 '$db' '.backup '".$path."''");
}

function getDirContents($dir, &$results = array()){
    $files = scandir($dir);

    foreach($files as $key => $value){
        $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
        if(!is_dir($path)) {
            $results[] = $path;
        } else if($value != "." && $value != "..") {
            getDirContents($path, $results);
            if(substr($path, -4) == ".bak") {
                $results[] = $path;
            }
        }
    }

    return $results;
}
?>


问:
Processing group policy with GP Extension
I created a Group Policy extension that implements ProcessGroupPolicyEx.
I sucesfully am notified when I receive a group policy.

I am however at a loss to how to read the policy from inside the GPO. The example stops at looping through GPOs:

```<code> for( pCurGPO = pChangedGPOList; pCurGPO; pCurGPO = pCurGPO->pNext )
   {
       if( *pbAbort )
       {
           // Abort.
           break;
       }
       // ...
   }
</code>```

That is fine, but how do I get the policy (the actual settings) inside the pCurGPO? I need to get either the settings that this GPO contains, or the registry key where it stores them.  This is because I created multiple ADMX templates that target my extension, so I need to tell them apart.

So far, I've found some samples, but they assume that the extension knows what registries will be changed, in advance. However, in my case, I do not want the extension to make this assumption, I want it to check the updated GPO and determine exactly what is being changed.

Any pointers would be greatly appreciated.

答:
So after squirreling through the Chromium code (per amritanshu comment), I found one way which seems to work, however I am not yet understanding what exceptions there may be (if any):

get lpFileSysPath field of the pCurObj which will be a UNC path.

Append "\Registry.pol" to the path.

Read and parse the resulting file, which will be a PReg file.

The PReg file is documented here:
https://msdn.microsoft.com/en-us/library/aa374407(v=vs.85).aspx

If anyone sees anything wrong with this approach, or knows of any exceptions for this algorithm, please let me know.

EDIT:
Also found this blog with a better written, though similar explanation: https://redsigil.weebly.com/home/group-policy-callbacks-the-missing-documentation

Body:
I created a Group Policy extension that implements ProcessGroupPolicyEx.
I sucesfully am notified when I receive a group policy.

I am however at a loss to how to read the policy from inside the GPO. The example stops at looping through GPOs:

 for( pCurGPO = pChangedGPOList; pCurGPO; pCurGPO = pCurGPO->pNext )
   {
       if( *pbAbort )
       {
           // Abort.
           break;
       }
       // ...
   }

That is fine, but how do I get the policy (the actual settings) inside the pCurGPO? I need to get either the settings that this GPO contains, or the registry key where it stores them.  This is because I created multiple ADMX templates that target my extension, so I need to tell them apart.

So far, I've found some samples, but they assume that the extension knows what registries will be changed, in advance. However, in my case, I do not want the extension to make this assumption, I want it to check the updated GPO and determine exactly what is being changed.

Any pointers would be greatly appreciated.


问:
Not all data in a column is being copied to another csv file
So I have two csv files. One is in the following format:

last name, first name, Number
```

<p>The other is in this format:</p>

```number, quiz
```

<p>I want to create a new output file that takes these two csv files and gives me a file in the following format:</p>

```last name, first name, number, quiz.
```

<p>I have tried the follwoing code and it works, but only for the first person listed in the first two input files. I am not sure what I am doing wrong. Also, I do not want to assume that the two input files follow the same order.</p>

```import sys, re
import numpy as np
import smtplib
from random import randint
import csv
import math

col = sys.argv[1]
source = sys.argv[2]
target = sys.argv[3]
newtarg = sys.argv[4]

input_source = csv.DictReader(open(source))
input_target = csv.DictReader(open(target))
data = {}
t = ()

for row in input_target:
    t = row['First Name'], row['number']
    for rows in input_source:
        if rows['number'] == row['number']:
            t = t + (rows[col],)
            name = row['Last Name']
            data[name] = [t]
            rows.next()
        row.next()

with open(newtarg,'w') as out:
    csv_out=csv.writer(out)
    for key, val in data.items():
        csv_out.writerow([key] + list(val))
```

答:
This might be a job for pandas, the Python Data Analysis Library:

```<code>import pandas as pd

x1 = pd.read_csv('x1.csv')
x2 = pd.read_csv('x2.csv')
result = pd.merge(x1, x2, on='number')
result.to_csv('result.csv',
              index=False,
              columns=['Last Name', 'First Name', 'number', 'quiz'])
</code>```

Reference: https://chrisalbon.com/python/pandas_join_merge_dataframe.html

Body:
So I have two csv files. One is in the following format:

last name, first name, Number

The other is in this format:

number, quiz

I want to create a new output file that takes these two csv files and gives me a file in the following format:

last name, first name, number, quiz.

I have tried the follwoing code and it works, but only for the first person listed in the first two input files. I am not sure what I am doing wrong. Also, I do not want to assume that the two input files follow the same order.

import sys, re
import numpy as np
import smtplib
from random import randint
import csv
import math

col = sys.argv[1]
source = sys.argv[2]
target = sys.argv[3]
newtarg = sys.argv[4]

input_source = csv.DictReader(open(source))
input_target = csv.DictReader(open(target))
data = {}
t = ()

for row in input_target:
    t = row['First Name'], row['number']
    for rows in input_source:
        if rows['number'] == row['number']:
            t = t + (rows[col],)
            name = row['Last Name']
            data[name] = [t]
            rows.next()
        row.next()

with open(newtarg,'w') as out:
    csv_out=csv.writer(out)
    for key, val in data.items():
        csv_out.writerow([key] + list(val))

Body:
This might be a job for pandas, the Python Data Analysis Library:

import pandas as pd

x1 = pd.read_csv('x1.csv')
x2 = pd.read_csv('x2.csv')
result = pd.merge(x1, x2, on='number')
result.to_csv('result.csv',
              index=False,
              columns=['Last Name', 'First Name', 'number', 'quiz'])

Reference: https://chrisalbon.com/python/pandas_join_merge_dataframe.html


问:
In ASP.NET MVC, How do I synchronise or combine two collections of different types
I have two collections, OrderItems and Items. The reason there are two is because in my model I have an Item which is fixed, and an OrderItem which relates to an Item and adds order specific information such as quantity and a property (OrderID) that relates back to my Order object.

In Entity Framework 4, in order to have a collection of objects in a model you need to relate back to that model in the collection type's object. This makes the OrderID property in Item necessary.

Here are the POCO's in code:

```<code>public class Order {
    public int OrderID { get; set; }
    public DateTime DatePlaced { get; set; }
    public bool Filled { get; set; }
    public string Comment { get; set; }

    public virtual ICollection<OrderItem> OrderItems { get; set; }
}

public class OrderItem {
    public int OrderItemID { get; set; }
    public int OrderID { get; set; }
    public int Quantity { get; set; }
    public int ItemID { get; set; }
}

public class Item {
    public int ItemID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public int Size { get; set; }
}
</code>```

So now I have my models, and I want to display an Order Details page. I can send over the Order to the ViewModel (MVC 3) or ViewData (MVC 2/1) from the controller which works fine, and I can send a collection of Item as well, but how do I display a list of Items that contain both the Item properties and the Quantity from the OrderItem? Since both are collections, I could OrderBy ItemID and loop over both at the same time in the view, but that seems really messy.

I fiddled with creating an anonymous class that combined both Items and Order but that didn't really work when it came to combining the collections.

I basically want to loop through each Item and OrderItem and display the following properties, without doing it in the view:

Name

Description

Size

Quantity

Ideas?

答:
Is Item not supposed to derive from OrderItem and you only show Item which has all info for OrderItem and a bit more?

So you will only get the items from database and display using templates, ...

```<code>public class OrderItem {
    public int OrderItemID { get; set; }
    public int OrderID { get; set; }
    public int Quantity { get; set; }
    public int ItemID { get; set; }
}

public class Item : OrderItem {
    // public int ItemID { get; set; } not anymore needed
    public string Name { get; set; }
    public string Description { get; set; }
    public int Size { get; set; }
}
</code>```

Body:
I have two collections, OrderItems and Items. The reason there are two is because in my model I have an Item which is fixed, and an OrderItem which relates to an Item and adds order specific information such as quantity and a property (OrderID) that relates back to my Order object.

In Entity Framework 4, in order to have a collection of objects in a model you need to relate back to that model in the collection type's object. This makes the OrderID property in Item necessary.

Here are the POCO's in code:

public class Order {
    public int OrderID { get; set; }
    public DateTime DatePlaced { get; set; }
    public bool Filled { get; set; }
    public string Comment { get; set; }

    public virtual ICollection<OrderItem> OrderItems { get; set; }
}

public class OrderItem {
    public int OrderItemID { get; set; }
    public int OrderID { get; set; }
    public int Quantity { get; set; }
    public int ItemID { get; set; }
}

public class Item {
    public int ItemID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public int Size { get; set; }
}

So now I have my models, and I want to display an Order Details page. I can send over the Order to the ViewModel (MVC 3) or ViewData (MVC 2/1) from the controller which works fine, and I can send a collection of Item as well, but how do I display a list of Items that contain both the Item properties and the Quantity from the OrderItem? Since both are collections, I could OrderBy ItemID and loop over both at the same time in the view, but that seems really messy.

I fiddled with creating an anonymous class that combined both Items and Order but that didn't really work when it came to combining the collections.

I basically want to loop through each Item and OrderItem and display the following properties, without doing it in the view:

Name

Description

Size

Quantity

Ideas?

Body:
Is Item not supposed to derive from OrderItem and you only show Item which has all info for OrderItem and a bit more?

So you will only get the items from database and display using templates, ...

public class OrderItem {
    public int OrderItemID { get; set; }
    public int OrderID { get; set; }
    public int Quantity { get; set; }
    public int ItemID { get; set; }
}

public class Item : OrderItem {
    // public int ItemID { get; set; } not anymore needed
    public string Name { get; set; }
    public string Description { get; set; }
    public int Size { get; set; }
}


问:
Electron <webview> back using backspace
I'm writing an electron app. I used webview to show a website inside my app. I want the website inside the webview to go back when I press the backspace key. The Official documentary on webview was not helpful for me. How do I make the webview content go back when the backspace is pressed,please?</p>

答:
Try:

```<code>myView.executeJavaScript(`
    addEventListener("keyup", e=>{
        if(e.keyCode === 8) history.back();
    });
`);
</code>```

(Uses ES6 arrow functions and template literals)

Title: Electron <webview> back using backspace

Body:
Try:

myView.executeJavaScript(`
    addEventListener("keyup", e=>{
        if(e.keyCode === 8) history.back();
    });
`);

(Uses ES6 arrow functions and template literals)


问:
How can I parse HTTP urls in C#?
My requirement is to parse Http Urls and call functions accordingly. In my current implementation, I am using nested if-else statement which i think is not an optimized way. Can you suggest some other efficient approch?

Urls are like these:

server/func1

server/func1/SubFunc1

server/func1/SubFunc2

server/func2/SubFunc1

server/func2/SubFunc2

答:
This might come as a bit of a late answer but I found myself recently trying to parse some URLs and I went along using a combination of Uri and System.Web.HttpUtility as seen here, my URLs were like http://one-domain.com/some/segments/{param1}?param2=x.... so this is what I did:

```<code>var uri = new Uri(myUrl);
string param1 = uri.Segments.Last();

var parameters = HttpUtility.ParseQueryString(uri.Query);
string param2 = parameters["param2"];
</code>```

note that in both cases you'll be working with strings, and be specially weary when working with segments.

Title: How can I parse HTTP urls in C#?

Body:
This might come as a bit of a late answer but I found myself recently trying to parse some URLs and I went along using a combination of Uri and System.Web.HttpUtility as seen here, my URLs were like http://one-domain.com/some/segments/{param1}?param2=x.... so this is what I did:

var uri = new Uri(myUrl);
string param1 = uri.Segments.Last();

var parameters = HttpUtility.ParseQueryString(uri.Query);
string param2 = parameters["param2"];

note that in both cases you'll be working with strings, and be specially weary when working with segments.