qid int64 1 74.7M | question stringlengths 15 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 4 30.2k | response_k stringlengths 11 36.5k |
|---|---|---|---|---|---|
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | You would probably want something like
```
day([mon,tue,wed,thu,fri,sat,sun]).
```
so that you have a list to work with.
Then monday is `mon` and you can use
```
Tomorrow = mon
```
but if you want to have a general rule for next day, then this is not optimal.
So maybe it would be better to have a predicate `day... | Here comes the canonical answer—based on [`append/3`](https://www.complang.tuwien.ac.at/ulrich/iso-prolog/prologue#append):
```
today_tomorrow(T0, T1) :-
Days = [mon,tue,wed,thu,fri,sat,sun,mon],
append(_, [T0,T1|_], Days).
```
Let's ask the *most general query*!
```
?- today_tomorrow(X, Y).
X = mon, Y = t... |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | If you don't mind using libraries, you can also do something like this:
```
:- use_module(library(clpfd)).
ord_weekday(0, mon).
ord_weekday(1, tue).
ord_weekday(2, wed).
ord_weekday(3, thu).
ord_weekday(4, fri).
ord_weekday(5, sat).
ord_weekday(6, sun).
day_next(D, N) :-
(X+1) mod 7 #= Y,
ord_weekday(X, D),
... | This may help you to get started:
```
days(mon,tue,wed,thu,fri,sat,sun).
tomorrow(X,Y) :- days(|Z), tomorrow(X,Y,Z).
tomorrow(X,Y,[X,Y|_]).
tomorrow(X,Y,[_|Z]) :- tomorrow(X,Y,Z).
?- tomorrow(X,tue), write(X), nl.
```
It writes out `mon`. |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | You would probably want something like
```
day([mon,tue,wed,thu,fri,sat,sun]).
```
so that you have a list to work with.
Then monday is `mon` and you can use
```
Tomorrow = mon
```
but if you want to have a general rule for next day, then this is not optimal.
So maybe it would be better to have a predicate `day... | This may help you to get started:
```
days(mon,tue,wed,thu,fri,sat,sun).
tomorrow(X,Y) :- days(|Z), tomorrow(X,Y,Z).
tomorrow(X,Y,[X,Y|_]).
tomorrow(X,Y,[_|Z]) :- tomorrow(X,Y,Z).
?- tomorrow(X,tue), write(X), nl.
```
It writes out `mon`. |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | An approach similar to what's been presented, but with a different means of determining "tomorrow"...
Probably the most canonical way to lay out valid day of week in Prolog would be with individual facts:
```
% Valid days of the week, in order
day_of_week(mon).
day_of_week(tue).
day_of_week(wed).
day_of_week(thu).
da... | Here comes the canonical answer—based on [`append/3`](https://www.complang.tuwien.ac.at/ulrich/iso-prolog/prologue#append):
```
today_tomorrow(T0, T1) :-
Days = [mon,tue,wed,thu,fri,sat,sun,mon],
append(_, [T0,T1|_], Days).
```
Let's ask the *most general query*!
```
?- today_tomorrow(X, Y).
X = mon, Y = t... |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | If you don't mind using libraries, you can also do something like this:
```
:- use_module(library(clpfd)).
ord_weekday(0, mon).
ord_weekday(1, tue).
ord_weekday(2, wed).
ord_weekday(3, thu).
ord_weekday(4, fri).
ord_weekday(5, sat).
ord_weekday(6, sun).
day_next(D, N) :-
(X+1) mod 7 #= Y,
ord_weekday(X, D),
... | You would probably want something like
```
day([mon,tue,wed,thu,fri,sat,sun]).
```
so that you have a list to work with.
Then monday is `mon` and you can use
```
Tomorrow = mon
```
but if you want to have a general rule for next day, then this is not optimal.
So maybe it would be better to have a predicate `day... |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | An approach similar to what's been presented, but with a different means of determining "tomorrow"...
Probably the most canonical way to lay out valid day of week in Prolog would be with individual facts:
```
% Valid days of the week, in order
day_of_week(mon).
day_of_week(tue).
day_of_week(wed).
day_of_week(thu).
da... | This may help you to get started:
```
days(mon,tue,wed,thu,fri,sat,sun).
tomorrow(X,Y) :- days(|Z), tomorrow(X,Y,Z).
tomorrow(X,Y,[X,Y|_]).
tomorrow(X,Y,[_|Z]) :- tomorrow(X,Y,Z).
?- tomorrow(X,tue), write(X), nl.
```
It writes out `mon`. |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | You would probably want something like
```
day([mon,tue,wed,thu,fri,sat,sun]).
```
so that you have a list to work with.
Then monday is `mon` and you can use
```
Tomorrow = mon
```
but if you want to have a general rule for next day, then this is not optimal.
So maybe it would be better to have a predicate `day... | ### program
```
([user]) .
%%%% database-style prolog program .
%%% for day , tomorrow , yesterday .
day( day( sk( 10'7 ) , pk( 36'sun ) , nm( 'sunday' ) , next( 36'mon ) ) ) .
day( day( sk( 10'6 ) , pk( 36'sat ) , nm( 'saturday' ) , next( 36'sun ) ) ) .
day( day( sk( 10'5 ) , pk( 36'fri ) , nm(... |
44,015,241 | I'm new at prolog and it is messing up my head. Could you guys give me a simple example like.. the days of the week! Let's say I have a
```
day(mon, tue, wed, thu, fri).
```
and I wanna know in which day of the week I'm on (assuming on start it'll akways be set as "monday", and I don't even know how to do that also... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44015241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1985937/"
] | If you don't mind using libraries, you can also do something like this:
```
:- use_module(library(clpfd)).
ord_weekday(0, mon).
ord_weekday(1, tue).
ord_weekday(2, wed).
ord_weekday(3, thu).
ord_weekday(4, fri).
ord_weekday(5, sat).
ord_weekday(6, sun).
day_next(D, N) :-
(X+1) mod 7 #= Y,
ord_weekday(X, D),
... | An approach similar to what's been presented, but with a different means of determining "tomorrow"...
Probably the most canonical way to lay out valid day of week in Prolog would be with individual facts:
```
% Valid days of the week, in order
day_of_week(mon).
day_of_week(tue).
day_of_week(wed).
day_of_week(thu).
da... |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | >
> Is it used for make sure parse i to int?
>
>
>
No, it is to make sure that `i` is a **number** (either `float` or `int`). Given what the function is doing, it was better to convert `i` to an non-decimal value though, I'm not sure how `slice` handles decimals.
More information: [`MDN - Arithmetic Operators`](h... | Almost, but *any* number is fine.
>
> `[ECMA-262: 11.4.6]:` The unary `+` operator converts its operand to `Number` type.
>
>
> The production *UnaryExpression : + UnaryExpression* is evaluated as follows:
>
>
> 1. Let *expr* be the result of evaluating UnaryExpression.
> 2. Return ToNumber(GetValue(*expr*)).
>
... |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | Almost, but *any* number is fine.
>
> `[ECMA-262: 11.4.6]:` The unary `+` operator converts its operand to `Number` type.
>
>
> The production *UnaryExpression : + UnaryExpression* is evaluated as follows:
>
>
> 1. Let *expr* be the result of evaluating UnaryExpression.
> 2. Return ToNumber(GetValue(*expr*)).
>
... | >
> `+i` makes sure that i is parsed into an number.
>
>
> |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | >
> Is it used for make sure parse i to int?
>
>
>
No, it is to make sure that `i` is a **number** (either `float` or `int`). Given what the function is doing, it was better to convert `i` to an non-decimal value though, I'm not sure how `slice` handles decimals.
More information: [`MDN - Arithmetic Operators`](h... | Yes it will make sure it is int (or a number in general as @Felix says). Try this code out:
```
var i = "2";
console.log(i === 2); // false
console.log(+i === 2); // true
``` |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | >
> Is it used for make sure parse i to int?
>
>
>
No, it is to make sure that `i` is a **number** (either `float` or `int`). Given what the function is doing, it was better to convert `i` to an non-decimal value though, I'm not sure how `slice` handles decimals.
More information: [`MDN - Arithmetic Operators`](h... | Yes, applying the unary `+` to a variable ensures that if it's some other type (a string, for instance), it gets [converted to a number](http://es5.github.com/#x9.3) (not an int, JavaScript doesn't have ints although it uses them internally for some operations). The number can be fractional, and if it's a string it's p... |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | >
> Is it used for make sure parse i to int?
>
>
>
No, it is to make sure that `i` is a **number** (either `float` or `int`). Given what the function is doing, it was better to convert `i` to an non-decimal value though, I'm not sure how `slice` handles decimals.
More information: [`MDN - Arithmetic Operators`](h... | >
> `+i` makes sure that i is parsed into an number.
>
>
> |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | Yes it will make sure it is int (or a number in general as @Felix says). Try this code out:
```
var i = "2";
console.log(i === 2); // false
console.log(+i === 2); // true
``` | >
> `+i` makes sure that i is parsed into an number.
>
>
> |
9,533,484 | In jquery source:
```
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
```
Is it used for make sure parse i to int? | 2012/03/02 | [
"https://Stackoverflow.com/questions/9533484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/524711/"
] | Yes, applying the unary `+` to a variable ensures that if it's some other type (a string, for instance), it gets [converted to a number](http://es5.github.com/#x9.3) (not an int, JavaScript doesn't have ints although it uses them internally for some operations). The number can be fractional, and if it's a string it's p... | >
> `+i` makes sure that i is parsed into an number.
>
>
> |
59,416,308 | **Json** *table\_data*
```
[
{
"country": "country one",
"city": "city one",
"Start Time": "21th December 2019 09:00 AM",
"End time": "22th December 2019 03:00 PM"
},
{
"country": "country two",
"city": "city two",
"Start Time": "23th December 2019 09:00 AM",
"End time": "23th Dece... | 2019/12/19 | [
"https://Stackoverflow.com/questions/59416308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11495299/"
] | Try:
```
import json
data = json.loads("""
[
{
"country": "country one",
"city": "city one",
"Start Time": "21th December 2019 09:00 AM",
"End time": "22th December 2019 03:00 PM"
},
{
"country": "country two",
"city": "city two",
"Start Time": "23th December 2019 09:00 AM",
"End ... | Something like this.
```
for data in table_data:
if data['country'] == 'country one':
print(data)
``` |
59,416,308 | **Json** *table\_data*
```
[
{
"country": "country one",
"city": "city one",
"Start Time": "21th December 2019 09:00 AM",
"End time": "22th December 2019 03:00 PM"
},
{
"country": "country two",
"city": "city two",
"Start Time": "23th December 2019 09:00 AM",
"End time": "23th Dece... | 2019/12/19 | [
"https://Stackoverflow.com/questions/59416308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11495299/"
] | Try:
```
import json
data = json.loads("""
[
{
"country": "country one",
"city": "city one",
"Start Time": "21th December 2019 09:00 AM",
"End time": "22th December 2019 03:00 PM"
},
{
"country": "country two",
"city": "city two",
"Start Time": "23th December 2019 09:00 AM",
"End ... | I suggest you start with something simpler. Let's say you have a `country` object:
```
country = {
"country": "country one",
"city": "city one",
"Start Time": "21th December 2019 09:00 AM",
"End time": "22th December 2019 03:00 PM"
}
```
Now we want a function to print this object:
```
def print_c... |
48,558,073 | I have followed this link to train yolo with my own dataset. I'm not using the CIAFR10 data.
<https://pjreddie.com/darknet/train-cifar/>
This is the cfg file named as cifar.cfg
```
[net]
batch=128
subdivisions=1
height=28
width=28
channels=3
max_crop=32
min_crop=32
hue=.1
saturation=.75
exposure=.75
learning_rate=0... | 2018/02/01 | [
"https://Stackoverflow.com/questions/48558073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4645831/"
] | If the pings fail consistently during Endpoint creation, we will treat the container as unhealthy and fail the Endpoint with an error message:
"ClientError: The primary container for production variant [xxx] did not pass the ping health check. Please check CloudWatch logs for this endpoint."
If the pings fail consist... | Amazon SageMaker is a managed service and the responsibility of the service team is to make sure that it is available. They are monitoring your endpoint and will replace the containers and instances for you if needed.
You can monitor the performance of your endpoint using the CloudWatch metrics (<https://docs.aws.ama... |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | Git is a platform, Mercurial is “just” an application. Git is a versioned filesystem platform that happens to ship with a DVCS app in the box, but as normal for platform apps, it is more complex and has rougher edges than focused apps do. But this also means git’s VCS is immensely flexible, and there is a huge depth of... | This link may help you to understand the difference
<http://www.techtatva.com/2010/09/git-mercurial-and-bazaar-a-comparison/> |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | Git is a platform, Mercurial is “just” an application. Git is a versioned filesystem platform that happens to ship with a DVCS app in the box, but as normal for platform apps, it is more complex and has rougher edges than focused apps do. But this also means git’s VCS is immensely flexible, and there is a huge depth of... | If you are a Windows developer looking for basic disconnected revision control, go with Hg. I found Git to be incomprehensible while Hg was simple and well integrated with the Windows shell. I downloaded Hg and followed [this tutorial (hginit.com)](http://hginit.com/) - ten minutes later I had a local repo and was back... |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | I think the best description about "Mercurial vs. Git" is:
["Git is Wesley Snipes. Mercurial is Denzel Washington"](http://www.ericsink.com/entries/hg_denzel.html) | Yet another interesting comparison of mercurial and git: [Mercurial vs Git](http://rg03.wordpress.com/2009/04/07/mercurial-vs-git/).
Main focus is on internals and their influence on branching process. |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | Git is a platform, Mercurial is “just” an application. Git is a versioned filesystem platform that happens to ship with a DVCS app in the box, but as normal for platform apps, it is more complex and has rougher edges than focused apps do. But this also means git’s VCS is immensely flexible, and there is a huge depth of... | There's one **huge** difference between *git* and *mercurial*; the way the represent each commit. *git* represents commits as snapshots, while *mercurial* represents them as diffs.
What does this means in practice? Well, many operations are faster in git, such as switching to another commit, comparing commits, etc. Sp... |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | There's one **huge** difference between *git* and *mercurial*; the way the represent each commit. *git* represents commits as snapshots, while *mercurial* represents them as diffs.
What does this means in practice? Well, many operations are faster in git, such as switching to another commit, comparing commits, etc. Sp... | If you are migrating from SVN, use Mercurial as its syntax is MUCH more understandable for SVN users. Other than that, you can't go wrong with either. But do check [GIT tutorial](http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html) and [HGinit](http://hginit.com/) before selecting one of them. |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | If I understand them correctly (and I'm far from an expert on each) they fundamentally each have a different philosophy. I first used mercurial for 9 months. Now I've used git for 6.
hg is version control software. It's main goal is to track versions of a piece of software.
git is a time based file system. It's goal ... | If you are migrating from SVN, use Mercurial as its syntax is MUCH more understandable for SVN users. Other than that, you can't go wrong with either. But do check [GIT tutorial](http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html) and [HGinit](http://hginit.com/) before selecting one of them. |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | These articles may help:
* [Git vs. Mercurial: Please Relax](http://importantshock.wordpress.com/2008/08/07/git-vs-mercurial/) (Git is MacGyver and Mercurial is James Bond)
* [The Differences Between Mercurial and Git](http://www.rockstarprogrammer.org/post/2008/apr/06/differences-between-mercurial-and-git/)
**Edit**... | Sometime last year I evaluated both git and hg for my own use, and decided to go with hg. I felt it looked like a cleaner solution, and worked better on more platforms at the time. It was mostly a toss-up, though.
More recently, I started using git because of git-svn and the ability to act as a Subversion client. This... |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | I work on Mercurial, but fundamentally I believe both systems are equivalent. They both work with the same abstractions: a series of snapshots (changesets) which make up the history. Each changeset knows where it came from (the parent changeset) and can have many child changesets. The recent [hg-git](http://hg-git.gith... | Some people think that VCS systems have to be complicated. They encourage inventing terms and concepts on the field. They would probably think that numerous PhDs on the subject would be interesting. Among those are probably the ones that designed Git.
Mercurial is designed with a different mentality. Developers should... |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | If you are a Windows developer looking for basic disconnected revision control, go with Hg. I found Git to be incomprehensible while Hg was simple and well integrated with the Windows shell. I downloaded Hg and followed [this tutorial (hginit.com)](http://hginit.com/) - ten minutes later I had a local repo and was back... | One thing to notice between mercurial of bitbucket.org and git of github is, mercurial can have as many private repositories as you want, but github you have to upgrade to a paid account. So, that's why I go for bitbucket which uses mercurial. |
35,837 | I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.
Has anyone made a side-by-side comparison between git a... | 2008/08/30 | [
"https://Stackoverflow.com/questions/35837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] | Sometime last year I evaluated both git and hg for my own use, and decided to go with hg. I felt it looked like a cleaner solution, and worked better on more platforms at the time. It was mostly a toss-up, though.
More recently, I started using git because of git-svn and the ability to act as a Subversion client. This... | I'm currently in the process of migrating from SVN to a DVCS (while blogging about my findings, my first real blogging effort...), and I've done a bit of research (=googling). As far as I can see you can do most of the things with both packages. It seems like git has a few more or better implemented advanced features,
... |
70,409,918 | i am practicing sets in python and wrote the below script to search books. it works but not proper ly(please see it below). How can i fix the problem?
```py
book_set = {"Harry Potter", "Angels and Demons", "Atlas Shrugged"}
q = input('Search our Catalog: ')
for book in book_set:
if book == q:
print(book)
e... | 2021/12/19 | [
"https://Stackoverflow.com/questions/70409918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17522882/"
] | You could do this with the help of the *itertools* module. There may be better / more efficient mechanisms. Note that the *process()* function will return None when there is no possible solution.
```
import itertools
def process(L1, L2):
for s in set(itertools.permutations(L1, len(L1))):
if all([a != b fo... | I solved it using this piece of code - however, as noted above, there are many possible cases where this very solution may not work. In this very case, you can try this:
```
import random
list1 = ['A', 'B', 'C']
list2 = ['X', 'B', 'Z']
for i in list1:
for j in list2:
if i == j in list2:
while l... |
70,409,918 | i am practicing sets in python and wrote the below script to search books. it works but not proper ly(please see it below). How can i fix the problem?
```py
book_set = {"Harry Potter", "Angels and Demons", "Atlas Shrugged"}
q = input('Search our Catalog: ')
for book in book_set:
if book == q:
print(book)
e... | 2021/12/19 | [
"https://Stackoverflow.com/questions/70409918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17522882/"
] | ```py
from itertools import permutations
def diff(list1, list2):
for item in permutations(list1, len(list1)):
if all(map(lambda a, b: a!=b, item, list2)):
return list(item)
return None
list1 = ['A', 'B', 'C']
list2 = ['X', 'B', 'Z']
result = diff(list1, list2)
if result:
print(result,... | I solved it using this piece of code - however, as noted above, there are many possible cases where this very solution may not work. In this very case, you can try this:
```
import random
list1 = ['A', 'B', 'C']
list2 = ['X', 'B', 'Z']
for i in list1:
for j in list2:
if i == j in list2:
while l... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | A fairly direct logic:
* print a line unless it ends with a comma (need to check on the next line, perhaps remove it)
* print the previous line (`$p`) if it had a comma, without it if the current line starts with `)`
```
perl -ne'
if ($p =~ /,$/) { $p =~ s/,$// if /^\s*\)/; print $p };
print unless /,$/;
... | If using `\n` newline as a record separator is awkward, use something else. In this case you're specifically interested in the sequence `,\n)`, and we can let Perl find that for us as we read the file:
```
perl -pe 'BEGIN{ $/ = ",\n)" } s/,\n\)/\n)/' input.txt >output.txt
```
This portion: `$/ = ",\n)"` tells Perl t... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | A fairly direct logic:
* print a line unless it ends with a comma (need to check on the next line, perhaps remove it)
* print the previous line (`$p`) if it had a comma, without it if the current line starts with `)`
```
perl -ne'
if ($p =~ /,$/) { $p =~ s/,$// if /^\s*\)/; print $p };
print unless /,$/;
... | Delay printing out the trailing comma and line feed until you know it's ok to print it out.
```
perl -ne'
$_ = $buf . $_;
s/^,(?=\n\))//;
$buf = s/(,\n)\z// ? $1 : "";
print;
END { print $buf; }
'
```
Faster:
```
perl -ne'
print /^\)/ ? "\n" : ",\n" if $f;
$f = s/,\n//;
print;
END { print... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | A fairly direct logic:
* print a line unless it ends with a comma (need to check on the next line, perhaps remove it)
* print the previous line (`$p`) if it had a comma, without it if the current line starts with `)`
```
perl -ne'
if ($p =~ /,$/) { $p =~ s/,$// if /^\s*\)/; print $p };
print unless /,$/;
... | This can be done more simply with just awk.
```
awk 'BEGIN{RS=".\n."; ORS=""} {gsub(",\n)", "\n)", RT); print $0 RT}'
```
Explanation:
`awk`, unlike Perl, allows a regular expression as the Record Separator, here `.\n.` which "captures" the two characters surrounding each newline.
Setting `ORS` to empty prevents `... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | A fairly direct logic:
* print a line unless it ends with a comma (need to check on the next line, perhaps remove it)
* print the previous line (`$p`) if it had a comma, without it if the current line starts with `)`
```
perl -ne'
if ($p =~ /,$/) { $p =~ s/,$// if /^\s*\)/; print $p };
print unless /,$/;
... | This might work for you (GNU sed):
```
sed 'N;s/,\n)/\n)/;P;D' file
```
Keep a moving window of two lines throughout the file and if the first ends in a `,` and the second begins with `)`, remove the `,`.
If there is white space and it needs to be preserved, use:
```
sed 'N;s/,\(\s*\n\s*)\)/\1/;P;D' file
``` |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | If using `\n` newline as a record separator is awkward, use something else. In this case you're specifically interested in the sequence `,\n)`, and we can let Perl find that for us as we read the file:
```
perl -pe 'BEGIN{ $/ = ",\n)" } s/,\n\)/\n)/' input.txt >output.txt
```
This portion: `$/ = ",\n)"` tells Perl t... | This can be done more simply with just awk.
```
awk 'BEGIN{RS=".\n."; ORS=""} {gsub(",\n)", "\n)", RT); print $0 RT}'
```
Explanation:
`awk`, unlike Perl, allows a regular expression as the Record Separator, here `.\n.` which "captures" the two characters surrounding each newline.
Setting `ORS` to empty prevents `... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | If using `\n` newline as a record separator is awkward, use something else. In this case you're specifically interested in the sequence `,\n)`, and we can let Perl find that for us as we read the file:
```
perl -pe 'BEGIN{ $/ = ",\n)" } s/,\n\)/\n)/' input.txt >output.txt
```
This portion: `$/ = ",\n)"` tells Perl t... | This might work for you (GNU sed):
```
sed 'N;s/,\n)/\n)/;P;D' file
```
Keep a moving window of two lines throughout the file and if the first ends in a `,` and the second begins with `)`, remove the `,`.
If there is white space and it needs to be preserved, use:
```
sed 'N;s/,\(\s*\n\s*)\)/\1/;P;D' file
``` |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | Delay printing out the trailing comma and line feed until you know it's ok to print it out.
```
perl -ne'
$_ = $buf . $_;
s/^,(?=\n\))//;
$buf = s/(,\n)\z// ? $1 : "";
print;
END { print $buf; }
'
```
Faster:
```
perl -ne'
print /^\)/ ? "\n" : ",\n" if $f;
$f = s/,\n//;
print;
END { print... | This can be done more simply with just awk.
```
awk 'BEGIN{RS=".\n."; ORS=""} {gsub(",\n)", "\n)", RT); print $0 RT}'
```
Explanation:
`awk`, unlike Perl, allows a regular expression as the Record Separator, here `.\n.` which "captures" the two characters surrounding each newline.
Setting `ORS` to empty prevents `... |
58,108,807 | I'm getting surprising behavior trying to convert a microsecond string date to an integer:
```
n = 20181231235959383171
int_ = np.int(n) # Works
int64_ = np.int64(n) # "OverflowError: int too big to convert"
```
Any idea why?
**Edit** - Thank you all, this is informative, however please see my actual problem:
[Da... | 2019/09/26 | [
"https://Stackoverflow.com/questions/58108807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8076158/"
] | Delay printing out the trailing comma and line feed until you know it's ok to print it out.
```
perl -ne'
$_ = $buf . $_;
s/^,(?=\n\))//;
$buf = s/(,\n)\z// ? $1 : "";
print;
END { print $buf; }
'
```
Faster:
```
perl -ne'
print /^\)/ ? "\n" : ",\n" if $f;
$f = s/,\n//;
print;
END { print... | This might work for you (GNU sed):
```
sed 'N;s/,\n)/\n)/;P;D' file
```
Keep a moving window of two lines throughout the file and if the first ends in a `,` and the second begins with `)`, remove the `,`.
If there is white space and it needs to be preserved, use:
```
sed 'N;s/,\(\s*\n\s*)\)/\1/;P;D' file
``` |
344,863 | Are the statements of the Heine-Borel Thm and Bolzano-Weierstrass Thm equivalent? | 2013/03/28 | [
"https://math.stackexchange.com/questions/344863",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/69911/"
] | See the [Wikipedia page for reverse mathematics](http://en.wikipedia.org/wiki/Reverse_mathematics). Heine-Borel needs the $WKL\_0$ axiom set, while Bolzano-Weierstrass needs $ACA\_0$. $ACA\_0$ is the stronger theory - all theorems of $WKL\_0$ are theorems in $ACA\_0$ but not visa versa. There is a base theory for which... | Jupp they are, both are equivalent to have a finite dimensional normed vector space over a complete field. (If you take that every bounded sequence has a convergent subsequence, there are more than one formulation of the bolzano weierstrass theorem). |
344,863 | Are the statements of the Heine-Borel Thm and Bolzano-Weierstrass Thm equivalent? | 2013/03/28 | [
"https://math.stackexchange.com/questions/344863",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/69911/"
] | Jupp they are, both are equivalent to have a finite dimensional normed vector space over a complete field. (If you take that every bounded sequence has a convergent subsequence, there are more than one formulation of the bolzano weierstrass theorem). | Heine-Borel and Bolzano-Weierstrass theorems are equivalent in the sense that their proofs can be derived from each other.
In fact, there are other axioms and results such as completeness axiom, the nested interval property, the Dedekind cut axiom of continuity and Cauchy’s general principle of convergence which are e... |
344,863 | Are the statements of the Heine-Borel Thm and Bolzano-Weierstrass Thm equivalent? | 2013/03/28 | [
"https://math.stackexchange.com/questions/344863",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/69911/"
] | See the [Wikipedia page for reverse mathematics](http://en.wikipedia.org/wiki/Reverse_mathematics). Heine-Borel needs the $WKL\_0$ axiom set, while Bolzano-Weierstrass needs $ACA\_0$. $ACA\_0$ is the stronger theory - all theorems of $WKL\_0$ are theorems in $ACA\_0$ but not visa versa. There is a base theory for which... | Heine-Borel and Bolzano-Weierstrass theorems are equivalent in the sense that their proofs can be derived from each other.
In fact, there are other axioms and results such as completeness axiom, the nested interval property, the Dedekind cut axiom of continuity and Cauchy’s general principle of convergence which are e... |
47,903,446 | I have a function, which should check if an Object has a `toString()` function and output it or otherwise return the object. The problem is, it also triggers on plane objects and finally returns `[Object object]` as a string which obivously looks awfull on the GUI. Is there a way to determine if an Object uses the defa... | 2017/12/20 | [
"https://Stackoverflow.com/questions/47903446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5653638/"
] | **1)** You can compare with `Object.prototype.toString`. If it is not overridden the references are equal
```js
const obj1 = {};
console.log(obj1.toString === Object.prototype.toString);
const obj3 = { toString() { } };
console.log(obj3.toString === Object.prototype.toString);
```
**2)** You can check the existen... | ```
o = new Object();
o.prop = 'exists';
o.hasOwnProperty('prop'); // returns true
o.hasOwnProperty('toString'); // returns false
o.hasOwnProperty('hasOwnProperty'); // returns false
```
prototype properties will return false if you check with `hasOwnProperty` |
47,903,446 | I have a function, which should check if an Object has a `toString()` function and output it or otherwise return the object. The problem is, it also triggers on plane objects and finally returns `[Object object]` as a string which obivously looks awfull on the GUI. Is there a way to determine if an Object uses the defa... | 2017/12/20 | [
"https://Stackoverflow.com/questions/47903446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5653638/"
] | **1)** You can compare with `Object.prototype.toString`. If it is not overridden the references are equal
```js
const obj1 = {};
console.log(obj1.toString === Object.prototype.toString);
const obj3 = { toString() { } };
console.log(obj3.toString === Object.prototype.toString);
```
**2)** You can check the existen... | We have two options:
1. `myObj.hasOwnProperty('toString')`
2. `myObj.toString !== Object.prototype.toString`
I think it is better to use second option, because method using `hasOwnProperty` isn't so robust. Check out this code snipped:
```js
class MyObj {
toString() {
return "myObj";
}
}
class MyObjEx exten... |
47,903,446 | I have a function, which should check if an Object has a `toString()` function and output it or otherwise return the object. The problem is, it also triggers on plane objects and finally returns `[Object object]` as a string which obivously looks awfull on the GUI. Is there a way to determine if an Object uses the defa... | 2017/12/20 | [
"https://Stackoverflow.com/questions/47903446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5653638/"
] | **1)** You can compare with `Object.prototype.toString`. If it is not overridden the references are equal
```js
const obj1 = {};
console.log(obj1.toString === Object.prototype.toString);
const obj3 = { toString() { } };
console.log(obj3.toString === Object.prototype.toString);
```
**2)** You can check the existen... | None of the answers worked for me. The only one that worked was:
```
if (obj1.toString) {
console.log(obj1.toString())
}
``` |
47,903,446 | I have a function, which should check if an Object has a `toString()` function and output it or otherwise return the object. The problem is, it also triggers on plane objects and finally returns `[Object object]` as a string which obivously looks awfull on the GUI. Is there a way to determine if an Object uses the defa... | 2017/12/20 | [
"https://Stackoverflow.com/questions/47903446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5653638/"
] | We have two options:
1. `myObj.hasOwnProperty('toString')`
2. `myObj.toString !== Object.prototype.toString`
I think it is better to use second option, because method using `hasOwnProperty` isn't so robust. Check out this code snipped:
```js
class MyObj {
toString() {
return "myObj";
}
}
class MyObjEx exten... | ```
o = new Object();
o.prop = 'exists';
o.hasOwnProperty('prop'); // returns true
o.hasOwnProperty('toString'); // returns false
o.hasOwnProperty('hasOwnProperty'); // returns false
```
prototype properties will return false if you check with `hasOwnProperty` |
47,903,446 | I have a function, which should check if an Object has a `toString()` function and output it or otherwise return the object. The problem is, it also triggers on plane objects and finally returns `[Object object]` as a string which obivously looks awfull on the GUI. Is there a way to determine if an Object uses the defa... | 2017/12/20 | [
"https://Stackoverflow.com/questions/47903446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5653638/"
] | We have two options:
1. `myObj.hasOwnProperty('toString')`
2. `myObj.toString !== Object.prototype.toString`
I think it is better to use second option, because method using `hasOwnProperty` isn't so robust. Check out this code snipped:
```js
class MyObj {
toString() {
return "myObj";
}
}
class MyObjEx exten... | None of the answers worked for me. The only one that worked was:
```
if (obj1.toString) {
console.log(obj1.toString())
}
``` |
11,359,333 | What is the best (idiomatic) way to concatenate Strings in Groovy?
Option 1:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
bank + branch + checkDigit + account
}
```
Option 2:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
"$bank$branch$checkDigit$account"
}
```
I've fo... | 2012/07/06 | [
"https://Stackoverflow.com/questions/11359333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/462015/"
] | I always go for the second method (using the GString template), though when there are more than a couple of parameters like you have, I tend to wrap them in `${X}` as I find it makes it more readable.
Running some benchmarks (using [Nagai Masato](https://twitter.com/#!/nagai_masato)'s excellent [GBench module](http://... | Reproducing tim\_yates answer on current hardware and adding leftShift() and concat() method to check the finding:
```
'String leftShift' {
foo << bar << baz
}
'String concat' {
foo.concat(bar)
.concat(baz)
.toString()
}
```
The outcome shows concat() to be the faster solution for a pur... |
11,359,333 | What is the best (idiomatic) way to concatenate Strings in Groovy?
Option 1:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
bank + branch + checkDigit + account
}
```
Option 2:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
"$bank$branch$checkDigit$account"
}
```
I've fo... | 2012/07/06 | [
"https://Stackoverflow.com/questions/11359333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/462015/"
] | I always go for the second method (using the GString template), though when there are more than a couple of parameters like you have, I tend to wrap them in `${X}` as I find it makes it more readable.
Running some benchmarks (using [Nagai Masato](https://twitter.com/#!/nagai_masato)'s excellent [GBench module](http://... | ```
def my_string = "some string"
println "here: " + my_string
```
Not quite sure why the answer above needs to go into benchmarks, string buffers, tests, etc. |
11,359,333 | What is the best (idiomatic) way to concatenate Strings in Groovy?
Option 1:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
bank + branch + checkDigit + account
}
```
Option 2:
```
calculateAccountNumber(bank, branch, checkDigit, account) {
"$bank$branch$checkDigit$account"
}
```
I've fo... | 2012/07/06 | [
"https://Stackoverflow.com/questions/11359333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/462015/"
] | ```
def my_string = "some string"
println "here: " + my_string
```
Not quite sure why the answer above needs to go into benchmarks, string buffers, tests, etc. | Reproducing tim\_yates answer on current hardware and adding leftShift() and concat() method to check the finding:
```
'String leftShift' {
foo << bar << baz
}
'String concat' {
foo.concat(bar)
.concat(baz)
.toString()
}
```
The outcome shows concat() to be the faster solution for a pur... |
12,555,940 | all
I am integrating a jQuery vertical accordion menu to be more specific [THIS ONE HERE](http://www.designchemical.com/lab/jquery-vertical-accordion-menu-plugin/examples/)
As you can see this nice easing menu is set to be hover or onclick function.
What im trying to achieve here to use the combination of two: speci... | 2012/09/23 | [
"https://Stackoverflow.com/questions/12555940",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1503518/"
] | This answer explains the difference betweeen using an object literal and a function for defining a view model: [Difference between knockout View Models declared as object literals vs functions](https://stackoverflow.com/questions/9589419/difference-between-knockout-view-models-declared-as-object-literals-vs-functions) | It is better because entire logic of a ViewModel can be contained in (encapsulated by) this constructor function. Logic can be very complex. It can include definitions of new functions and variables that are not global anymore.
I find following pattern:
```
ko.applyBindings((function() {
// Define local variable... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | I think you might as well use your own implementation of the BeanUtils, overriding the class [org.apache.commons.beanutils.converters.AbstractConverter](http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/converters/AbstractConverter.html) and [org.apache.commons.beanutils.converters.StringConverter](h... | It's a little old question, but I resolved this issue by implementing another solution (I think in an easier way).
I implement a `TypeConverter` to convert empty string to null.
Two files is necessary :
The converter.
```
public class StringEmptyToNullConverter implements TypeConverter {
private static final Lo... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | See Apache's [`StringUtils.stripToNull()`](http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/StringUtils.html#stripToNull%28java.lang.String%29) method.
As for a configuration, Struts has not given us that functionality (I don't recall). I would have suggested overriding `reset()` method from the `ActionF... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | It's a little old question, but I resolved this issue by implementing another solution (I think in an easier way).
I implement a `TypeConverter` to convert empty string to null.
Two files is necessary :
The converter.
```
public class StringEmptyToNullConverter implements TypeConverter {
private static final Lo... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | Cf <http://struts.apache.org/development/1.x/userGuide/configuration.html>
for convertNull ;-)
convertNull - Force simulation of the version 1.0 behavior when populating forms. If set to "true", the numeric Java wrapper class types (like java.lang.Integer ) will default to null (rather than 0). (Since version 1.1) [fa... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | I think you might as well use your own implementation of the BeanUtils, overriding the class [org.apache.commons.beanutils.converters.AbstractConverter](http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/converters/AbstractConverter.html) and [org.apache.commons.beanutils.converters.StringConverter](h... | Cf <http://struts.apache.org/development/1.x/userGuide/configuration.html>
for convertNull ;-)
convertNull - Force simulation of the version 1.0 behavior when populating forms. If set to "true", the numeric Java wrapper class types (like java.lang.Integer ) will default to null (rather than 0). (Since version 1.1) [fa... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | I think you might as well use your own implementation of the BeanUtils, overriding the class [org.apache.commons.beanutils.converters.AbstractConverter](http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/converters/AbstractConverter.html) and [org.apache.commons.beanutils.converters.StringConverter](h... | Declare String value by default in ActionForm as `NULL` .
`Eg: private String str = null;`
EDIT : solution for this is .
I think for that attribute you have setter and getter methods, in getter method check if the value is empty, then you explisitly set for null value. |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | I think you might as well use your own implementation of the BeanUtils, overriding the class [org.apache.commons.beanutils.converters.AbstractConverter](http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/converters/AbstractConverter.html) and [org.apache.commons.beanutils.converters.StringConverter](h... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | Struts 2 offers a good mechanism for this with interceptors, which I think is much safer and easier than mucking around with `BeanUtils`. Here is the code I used, based on [Cimballi's Blog](http://cimballisblog.blogspot.de/2009/10/struts2-interceptor-to-remove-empty.html) but edited to compile in Java 7 (the original w... |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | In web.xml use below code
```
<init-param>
<param-name>convertNull</param-name>
<param-value>true</param-value>
</init-param>
``` |
6,200,433 | When user decides to leave the field in the form empty the Apache Struts binds empty `String` as value for properties in the `ActionForm`. Is there any way to modify the behavior globally and opt for `null` instead of empty `String`?
I know that Spring MVC does exactly the same, but there is also [StringTrimmerEditor]... | 2011/06/01 | [
"https://Stackoverflow.com/questions/6200433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77278/"
] | A possible solution - one that will allow a single conversion entry point for all your String fields - would be to register a custom convertor, but not with Struts but with [BeanUtils](http://commons.apache.org/beanutils/).
For mapping request parameters to form properties, Struts makes use of the [populate method of ... | Declare String value by default in ActionForm as `NULL` .
`Eg: private String str = null;`
EDIT : solution for this is .
I think for that attribute you have setter and getter methods, in getter method check if the value is empty, then you explisitly set for null value. |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | This will change the value of the first [node](https://developer.mozilla.org/en-US/docs/Web/API/Node) (which is a text node in your example):
```
$('#1').contents()[0].nodeValue = 'new text';
```
[JSFiddle](http://jsfiddle.net/q5jn6/)
-------------------------------------- | If plausible, do something like the following:
```
<div id="1">
<span id="edit">some text</span>
<div id="2"></div>
</div>
```
Then, you can edit your text like so:
```
$('#edit').text('new text');
```
Basically, your putting the text you want to edit in its own element with an ID. Keep in mind that you can... |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | If plausible, do something like the following:
```
<div id="1">
<span id="edit">some text</span>
<div id="2"></div>
</div>
```
Then, you can edit your text like so:
```
$('#edit').text('new text');
```
Basically, your putting the text you want to edit in its own element with an ID. Keep in mind that you can... | My solution as an alternative to others:
```
var text_to_keep = $('#2').text();
$('#1').text('new text').append('<div id="2">' + text_to_keep + '</div>');
```
<http://jsfiddle.net/LM63t/>
P.S. I don't think `id`'s that begin with a number are valid. |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | This will change the value of the first [node](https://developer.mozilla.org/en-US/docs/Web/API/Node) (which is a text node in your example):
```
$('#1').contents()[0].nodeValue = 'new text';
```
[JSFiddle](http://jsfiddle.net/q5jn6/)
-------------------------------------- | Try the following
```
<div id="1">
<span id='myspan'>some text</span>
<div id="2"></div>
</div>
```
Then use;
```
$('#myspan').text('new text');
``` |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | Try the following
```
<div id="1">
<span id='myspan'>some text</span>
<div id="2"></div>
</div>
```
Then use;
```
$('#myspan').text('new text');
``` | My solution as an alternative to others:
```
var text_to_keep = $('#2').text();
$('#1').text('new text').append('<div id="2">' + text_to_keep + '</div>');
```
<http://jsfiddle.net/LM63t/>
P.S. I don't think `id`'s that begin with a number are valid. |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | This will change the value of the first [node](https://developer.mozilla.org/en-US/docs/Web/API/Node) (which is a text node in your example):
```
$('#1').contents()[0].nodeValue = 'new text';
```
[JSFiddle](http://jsfiddle.net/q5jn6/)
-------------------------------------- | By the way it is a bad practice to use ids with numbers as elements.
You can add a span if you don't want to change the style of your element.
So in your case you will do something like this (I removed the numbers as ids):
```
<!-- HTML -->
<div id="text-container">
<span id="some-text">some text</span>
<di... |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | This will change the value of the first [node](https://developer.mozilla.org/en-US/docs/Web/API/Node) (which is a text node in your example):
```
$('#1').contents()[0].nodeValue = 'new text';
```
[JSFiddle](http://jsfiddle.net/q5jn6/)
-------------------------------------- | My solution as an alternative to others:
```
var text_to_keep = $('#2').text();
$('#1').text('new text').append('<div id="2">' + text_to_keep + '</div>');
```
<http://jsfiddle.net/LM63t/>
P.S. I don't think `id`'s that begin with a number are valid. |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | This will change the value of the first [node](https://developer.mozilla.org/en-US/docs/Web/API/Node) (which is a text node in your example):
```
$('#1').contents()[0].nodeValue = 'new text';
```
[JSFiddle](http://jsfiddle.net/q5jn6/)
-------------------------------------- | the best solution is to check the node type as `Node.TEXT_NODE` and `nodeValue` is not null:
```
$('#1')
.contents()
.filter(function() {
return this.nodeType === Node.TEXT_NODE && this.nodeValue && this.nodeValue.trim();
})
.replaceWith("new text");
``` |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | By the way it is a bad practice to use ids with numbers as elements.
You can add a span if you don't want to change the style of your element.
So in your case you will do something like this (I removed the numbers as ids):
```
<!-- HTML -->
<div id="text-container">
<span id="some-text">some text</span>
<di... | My solution as an alternative to others:
```
var text_to_keep = $('#2').text();
$('#1').text('new text').append('<div id="2">' + text_to_keep + '</div>');
```
<http://jsfiddle.net/LM63t/>
P.S. I don't think `id`'s that begin with a number are valid. |
24,493,294 | I need to modify the following HTML using Javascript,
```
<div id="1">
some text
<div id="2"></div>
</div>
```
I have tried using `$('#1').text('new text');` However, this unintentionally removes `<div id="2">`
How should I change `some text`, without changing the surrounding elements? | 2014/06/30 | [
"https://Stackoverflow.com/questions/24493294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893345/"
] | the best solution is to check the node type as `Node.TEXT_NODE` and `nodeValue` is not null:
```
$('#1')
.contents()
.filter(function() {
return this.nodeType === Node.TEXT_NODE && this.nodeValue && this.nodeValue.trim();
})
.replaceWith("new text");
``` | My solution as an alternative to others:
```
var text_to_keep = $('#2').text();
$('#1').text('new text').append('<div id="2">' + text_to_keep + '</div>');
```
<http://jsfiddle.net/LM63t/>
P.S. I don't think `id`'s that begin with a number are valid. |
37,036,631 | I am trying to make web tool that will allow people to replace colors in simple 2 color images that I am selling. Images that I am using are saved in jpg format. I did look here and there and I did come up with following code:
```
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
... | 2016/05/04 | [
"https://Stackoverflow.com/questions/37036631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/653874/"
] | Transfer Luma To Alpha Channel
------------------------------
In the method I would recommend we can first convert the black data to an alpha channel based on the "luminance" of the the color. This will keep the anti-aliasing which is the cause for the various shades along the edges as well as allowing us to use compo... | Instead of checking the exact value you can check if the color is near a specific value. There may be a better way to do it but here's my solution:
```
var precision = 10;
var replaceColor = {
r: 0,
g: 0,
b: 0,
a: 255,
};
var isInRange = (
r >= replaceColor.r - precision &&
r <= replaceColor.... |
6,494 | I'm new to all grain brewing and one of the things I haven't been able to find much information on is the importance of water volumes for the mash and sparge steps.
There are a lot of calculators out there, and I'm trying to find out if water volumes play a key role in the extraction of sugars from the grain.
It mak... | 2012/02/28 | [
"https://homebrew.stackexchange.com/questions/6494",
"https://homebrew.stackexchange.com",
"https://homebrew.stackexchange.com/users/1750/"
] | Mash thickness has a small impact on your beer, but not really enough to stress about. I aim for a constant thickness, regardless of beer style. Some brewers give their stronger beers to have a thicker mash, while their low-gravity beers have a thinner mash.
The logic behind that latter approach is that thinner mashe... | @Hopwise addressed the issue of efficiency and mash thickness. But the amount of sparge water will affect your efficiency as well.
The more water you sparge with, the more sugar you'll extract from the mash. The grist will absorb a constant amount of water (around 0.13 gallons per pound of grist). When you add your sp... |
6,494 | I'm new to all grain brewing and one of the things I haven't been able to find much information on is the importance of water volumes for the mash and sparge steps.
There are a lot of calculators out there, and I'm trying to find out if water volumes play a key role in the extraction of sugars from the grain.
It mak... | 2012/02/28 | [
"https://homebrew.stackexchange.com/questions/6494",
"https://homebrew.stackexchange.com",
"https://homebrew.stackexchange.com/users/1750/"
] | Mash thickness has a small impact on your beer, but not really enough to stress about. I aim for a constant thickness, regardless of beer style. Some brewers give their stronger beers to have a thicker mash, while their low-gravity beers have a thinner mash.
The logic behind that latter approach is that thinner mashe... | Also, over sparging can extract extra, undesirable tannins from the husks. |
6,494 | I'm new to all grain brewing and one of the things I haven't been able to find much information on is the importance of water volumes for the mash and sparge steps.
There are a lot of calculators out there, and I'm trying to find out if water volumes play a key role in the extraction of sugars from the grain.
It mak... | 2012/02/28 | [
"https://homebrew.stackexchange.com/questions/6494",
"https://homebrew.stackexchange.com",
"https://homebrew.stackexchange.com/users/1750/"
] | @Hopwise addressed the issue of efficiency and mash thickness. But the amount of sparge water will affect your efficiency as well.
The more water you sparge with, the more sugar you'll extract from the mash. The grist will absorb a constant amount of water (around 0.13 gallons per pound of grist). When you add your sp... | Also, over sparging can extract extra, undesirable tannins from the husks. |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | This is the rationale behind Euclid's algorithm.
```
gcd(a, b) = gcd(b, a%b)
```
But except when `b` is 0. What is the result in this case? You can imagine that 0 has actually infinite factors in it: you can divide 0 by anything and the remainder will always be 0.
From this, we can derive that
```
gcd(a, 0) = a
`... | Put very simply, in this case, `!b` is the same as `b == 0`. Zero as a truthy value is false so `!0` will be true.
In other words, the function returns `a` when `b` is zero, otherwise it carries on through more recursive levels.
Your contention that `a % b` will become `NaN` is actually false - the fact that `b` beco... |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | This is the rationale behind Euclid's algorithm.
```
gcd(a, b) = gcd(b, a%b)
```
But except when `b` is 0. What is the result in this case? You can imagine that 0 has actually infinite factors in it: you can divide 0 by anything and the remainder will always be 0.
From this, we can derive that
```
gcd(a, 0) = a
`... | ```
//I'm glad that I can help others, here is my version:
//Euclid's algorithm:
//1)Find reminder of division m by n
//2)If remainder is zero, n is a solution
//3)Reduce(if r != zero)
const euclid = function(num1, num2){
//compute the remainder:
var remainder = num1 % num2;
if(remainder == 0){
retu... |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | (! b) is evaluating the variable b to return the value of false. In JavaScript NaN is falsey which means it's not false, but it will evaluate to false in a Boolean evaluation.
As others have mentioned, the variable b will equal 0 and not NaN. I was just explaining how NaN evaluates for the sake of the original questi... | Put very simply, in this case, `!b` is the same as `b == 0`. Zero as a truthy value is false so `!0` will be true.
In other words, the function returns `a` when `b` is zero, otherwise it carries on through more recursive levels.
Your contention that `a % b` will become `NaN` is actually false - the fact that `b` beco... |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | The base case for the Euclidean Algorithm happens when one of the parameters are equal to zero, which means the greatest common divisor of both numbers is the non-zero number. you can refer to this link to see some examples:
<https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclid... | Put very simply, in this case, `!b` is the same as `b == 0`. Zero as a truthy value is false so `!0` will be true.
In other words, the function returns `a` when `b` is zero, otherwise it carries on through more recursive levels.
Your contention that `a % b` will become `NaN` is actually false - the fact that `b` beco... |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | (! b) is evaluating the variable b to return the value of false. In JavaScript NaN is falsey which means it's not false, but it will evaluate to false in a Boolean evaluation.
As others have mentioned, the variable b will equal 0 and not NaN. I was just explaining how NaN evaluates for the sake of the original questi... | ```
//I'm glad that I can help others, here is my version:
//Euclid's algorithm:
//1)Find reminder of division m by n
//2)If remainder is zero, n is a solution
//3)Reduce(if r != zero)
const euclid = function(num1, num2){
//compute the remainder:
var remainder = num1 % num2;
if(remainder == 0){
retu... |
32,042,240 | I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what do... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32042240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5233635/"
] | The base case for the Euclidean Algorithm happens when one of the parameters are equal to zero, which means the greatest common divisor of both numbers is the non-zero number. you can refer to this link to see some examples:
<https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclid... | ```
//I'm glad that I can help others, here is my version:
//Euclid's algorithm:
//1)Find reminder of division m by n
//2)If remainder is zero, n is a solution
//3)Reduce(if r != zero)
const euclid = function(num1, num2){
//compute the remainder:
var remainder = num1 % num2;
if(remainder == 0){
retu... |
27,612,119 | I have a UIImageView that I want to scale its outter edges towards the center (the top and bottom edges to be precise). The best I am able to get so far is just one edge collapsing into the other (which doesn't move). I want both edges to collapse towards the middle.
I have tried setting the the anchor point to 0.5,0.... | 2014/12/22 | [
"https://Stackoverflow.com/questions/27612119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3324388/"
] | You can use scaling using UIView's transform property. It seems like scaling does not allow you to make the value 0 and it goes to the final value without any animation. So, you could basically make the scaling y value negligible like 0.001.
```
imageView.transform = CGAffineTransformMakeScale(1, 0.001)
```
You ... | Your new frame has the origin in the same place. You need to move the origin down, at the same time as you reduce the height:
```
img.frame = CGRectMake(img.frame.origin.x, img.frame.origin.y + (img.frame.size.height/2), img.frame.size.width, 0);
``` |
10,920,216 | I was just wondering if it's possible to alter the color of the Less mixin gradient by applying something like lighten or darken to the CSS code?
Here is the Less Mixin:
```
.css-gradient(@from: #20416A, @to: #3D69A5) {
background-color: @to;
background-image: -webkit-gradient(linear, left top, left bottom, f... | 2012/06/06 | [
"https://Stackoverflow.com/questions/10920216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/965879/"
] | I'd do this like so:
```
.css-gradient(darken(#20416A,10%),darken(#3D69A5,10%))
```
Of course you could also do:
```
.css-gradient(@from: #20416A, @to: #3D69A5) {
background-color: @to;
background-image: -webkit-gradient(linear, left top, left bottom, from(@from), to(@to));
background-image: -webkit-li... | Less mixin:
```
.gradient(@dir: 0deg; @colors; @prefixes: webkit, moz, ms, o; @index: length(@prefixes)) when (@index > 0) {
.gradient(@dir; @colors; @prefixes; (@index - 1));
@prefix : extract(@prefixes, @index);
@dir-old: 90 - (@dir);
background-image: ~"-@{prefix}-linear-gradient(@{dir-old}, @{col... |
4,673,250 | Can I offer the authentication, authorization, etc created using "ASP.NET MVC Open Id website" extension.. as a REST service in ASP.NET MVC? How can I create this service(maybe using WCF)?
(Please if you can, offer me some examples please). | 2011/01/12 | [
"https://Stackoverflow.com/questions/4673250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409468/"
] | Yes, you can. OpenID is *not* about authorizing web services at all. That's what OAuth does. But DotNetOpenAuth does both OpenID and OAuth, so your users can authenticate with OpenID, then authorize RESTful clients via OAuth, and the user story is probably exactly what you're looking for.
There is a [project template... | Have a look at the latest nerddinner tutorial on codeplex. It has OpenId integration built into the MVC example application: <http://nerddinner.codeplex.com/> |
4,673,250 | Can I offer the authentication, authorization, etc created using "ASP.NET MVC Open Id website" extension.. as a REST service in ASP.NET MVC? How can I create this service(maybe using WCF)?
(Please if you can, offer me some examples please). | 2011/01/12 | [
"https://Stackoverflow.com/questions/4673250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409468/"
] | You can easily create REST services using just MVC. WCF is not necessary. There are tons of posts on restful architecture in ASP.NET MVC.
There is code available with a base API for Restful services using ASP.NET MVC available here: <http://code.msdn.microsoft.com/MvcWebAPI> .
The author of this library has an excell... | Have a look at the latest nerddinner tutorial on codeplex. It has OpenId integration built into the MVC example application: <http://nerddinner.codeplex.com/> |
4,673,250 | Can I offer the authentication, authorization, etc created using "ASP.NET MVC Open Id website" extension.. as a REST service in ASP.NET MVC? How can I create this service(maybe using WCF)?
(Please if you can, offer me some examples please). | 2011/01/12 | [
"https://Stackoverflow.com/questions/4673250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409468/"
] | Yes, you can. OpenID is *not* about authorizing web services at all. That's what OAuth does. But DotNetOpenAuth does both OpenID and OAuth, so your users can authenticate with OpenID, then authorize RESTful clients via OAuth, and the user story is probably exactly what you're looking for.
There is a [project template... | You can easily create REST services using just MVC. WCF is not necessary. There are tons of posts on restful architecture in ASP.NET MVC.
There is code available with a base API for Restful services using ASP.NET MVC available here: <http://code.msdn.microsoft.com/MvcWebAPI> .
The author of this library has an excell... |
19,146,345 | I'm looking for some kind of delegate method that will be triggered when a subview is added to a view. I need this because the compass view on the iOS7 map is added to the mapview when it starts rotating (it is not there previously and unhidden). However when I try to manipulate the compass view in `regionWillChangeAni... | 2013/10/02 | [
"https://Stackoverflow.com/questions/19146345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2565551/"
] | there is no such delegate.
BUT
all you can do is subclass MKMapView and implement insertSubview and addSubview and build your own solution.
BUT
see better way
```
- (void)layoutSubviews {
[super layoutSubviews];
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
... | I don't know if it will work, buy you could try using Key Value Observing with the mapview's `camera`, which has a `heading` property. |
19,146,345 | I'm looking for some kind of delegate method that will be triggered when a subview is added to a view. I need this because the compass view on the iOS7 map is added to the mapview when it starts rotating (it is not there previously and unhidden). However when I try to manipulate the compass view in `regionWillChangeAni... | 2013/10/02 | [
"https://Stackoverflow.com/questions/19146345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2565551/"
] | there is no such delegate.
BUT
all you can do is subclass MKMapView and implement insertSubview and addSubview and build your own solution.
BUT
see better way
```
- (void)layoutSubviews {
[super layoutSubviews];
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
... | Daij-Djan has posted the correct answer, credit to him!
This is just an improvement on what I feel is too much code:
```
- (void)layoutSubviews
{
[super layoutSubviews];
for(id view in self.subviews)
{
if([view isKindOfClass:NSClassFromString(@"MKCompassView")])
[self moveCompass:... |
19,146,345 | I'm looking for some kind of delegate method that will be triggered when a subview is added to a view. I need this because the compass view on the iOS7 map is added to the mapview when it starts rotating (it is not there previously and unhidden). However when I try to manipulate the compass view in `regionWillChangeAni... | 2013/10/02 | [
"https://Stackoverflow.com/questions/19146345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2565551/"
] | Daij-Djan has posted the correct answer, credit to him!
This is just an improvement on what I feel is too much code:
```
- (void)layoutSubviews
{
[super layoutSubviews];
for(id view in self.subviews)
{
if([view isKindOfClass:NSClassFromString(@"MKCompassView")])
[self moveCompass:... | I don't know if it will work, buy you could try using Key Value Observing with the mapview's `camera`, which has a `heading` property. |
31,538,765 | I am using Atlassian Javascript framework to create tabs in my page. Every time I refresh the page it goes back to the default tab and leaves the selected tab.
I added this piece of code after searching for the same problem in stack overflow but it is not working.
```
<script>
$('#prod-discovery a').click(function... | 2015/07/21 | [
"https://Stackoverflow.com/questions/31538765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2900150/"
] | The PivotTable will always sort alphabetically unless you give it something else to sort by. If you add a new field to your data which contains the sort order, then you can tell PowerPivot to use that as the sort order.
First Select your Room Category column, click on the *Sort By Column* button, then select the colum... | I think I understand the issue (I've had the same problem with Dates as Text). I think if you create a "Named Set" based on the row Items, it will work. |
14,182,286 | I've tried a few tab scripts but I think I'm looking for something more specific.
Basically I want something that shows a div and hides all others just like tabs.
Something very similar to this
<http://jsfiddle.net/6UcDR/2/>
But I want to be able to use something other than buttons. I will have a set up images l... | 2013/01/06 | [
"https://Stackoverflow.com/questions/14182286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1952811/"
] | WHen learning jQuery it is easy to focus on needing an ID for everything since ID selectors are very specific. Using ID's can get complicated to code when faced with multiple scenarios for each group of ID. However there are many ways to match different elements using other methods that can greatly simplify code withou... | ```
$(".contet").each( function() {
$(this).hide();
});
$(".tab").on("click", function() {
var s = $(this).attr("id");
var g = $("#"+s+".contet").html();
$(".content").html(g);
});
```
[Working Fiddle With Pure jQuery](http://jsfiddle.net/AR6nr/1/) |
14,182,286 | I've tried a few tab scripts but I think I'm looking for something more specific.
Basically I want something that shows a div and hides all others just like tabs.
Something very similar to this
<http://jsfiddle.net/6UcDR/2/>
But I want to be able to use something other than buttons. I will have a set up images l... | 2013/01/06 | [
"https://Stackoverflow.com/questions/14182286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1952811/"
] | WHen learning jQuery it is easy to focus on needing an ID for everything since ID selectors are very specific. Using ID's can get complicated to code when faced with multiple scenarios for each group of ID. However there are many ways to match different elements using other methods that can greatly simplify code withou... | ```
<script src="../../jquery-1.8.0.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.tabs.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
$( "#tabs" ).ta... |
64,722,898 | Here's my problem: I have this list I've generated containing a large number of links and I want to take this list and apply a function to it to scrape some data from all those links; however, when I run the program it only takes the data from the first link of that element, reprinting that info for the correct number ... | 2020/11/06 | [
"https://Stackoverflow.com/questions/64722898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14358258/"
] | Use `mask` with `str.contains()` to perform the operation on rows with the specified condition, and then use the following operation: `.str.split(', ').str[0:2].agg(', '.join))`:
```
df['Col'] = df['Col'].mask(df['Col'].str.contains('County, Texas'),
df['Col'].str.split(', ').str[0:2].agg(',... | You can simply use a combination of `map` with a `lambda`, `split` and `join`:
```
df['Example'] = df['Example'].map(lambda x: ','.join(x.split(',')[0:2]) if 'County, Texas' in x else x)
```
In this case:
```
import pandas as pd
df = pd.DataFrame({'Example':["Jack Smith, Bank, Wilber, Lincoln County, Texas","Jack S... |
64,722,898 | Here's my problem: I have this list I've generated containing a large number of links and I want to take this list and apply a function to it to scrape some data from all those links; however, when I run the program it only takes the data from the first link of that element, reprinting that info for the correct number ... | 2020/11/06 | [
"https://Stackoverflow.com/questions/64722898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14358258/"
] | Use `mask` with `str.contains()` to perform the operation on rows with the specified condition, and then use the following operation: `.str.split(', ').str[0:2].agg(', '.join))`:
```
df['Col'] = df['Col'].mask(df['Col'].str.contains('County, Texas'),
df['Col'].str.split(', ').str[0:2].agg(',... | Data
```
df = pd.DataFrame({'text':["Jack Smith, Bank, Wilber, Lincoln County, Texas","Jack Smith, Union, Credit, Bank, Wilber, Lincoln County, Texas",
"Jack Smith, Union, Credit, Bank, Wilber, Lincoln County, Texas, Branch, Landing, Services",
"Jack Smith, U... |
64,722,898 | Here's my problem: I have this list I've generated containing a large number of links and I want to take this list and apply a function to it to scrape some data from all those links; however, when I run the program it only takes the data from the first link of that element, reprinting that info for the correct number ... | 2020/11/06 | [
"https://Stackoverflow.com/questions/64722898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14358258/"
] | You can simply use a combination of `map` with a `lambda`, `split` and `join`:
```
df['Example'] = df['Example'].map(lambda x: ','.join(x.split(',')[0:2]) if 'County, Texas' in x else x)
```
In this case:
```
import pandas as pd
df = pd.DataFrame({'Example':["Jack Smith, Bank, Wilber, Lincoln County, Texas","Jack S... | Data
```
df = pd.DataFrame({'text':["Jack Smith, Bank, Wilber, Lincoln County, Texas","Jack Smith, Union, Credit, Bank, Wilber, Lincoln County, Texas",
"Jack Smith, Union, Credit, Bank, Wilber, Lincoln County, Texas, Branch, Landing, Services",
"Jack Smith, U... |
24,269 | According to big endian byte ordering or network byte order the bits are transmitted in this order: bits 0-7 first, then bits 8-15, then 16-23 and bits 24-31 last.
Does this means that bits from version, identification, TTL etc go first and then bits from next fields?
[. Check IEEE 802.3 Clauses 3.1.1, 3.2.6, and ... |
24,269 | According to big endian byte ordering or network byte order the bits are transmitted in this order: bits 0-7 first, then bits 8-15, then 16-23 and bits 24-31 last.
Does this means that bits from version, identification, TTL etc go first and then bits from next fields?
[. Check IEEE 802.3 Clauses 3.1.1, 3.2.6, and ... | It is important to note that "ordering" is a very personal concept, dependent upon culture and experience. "Most people" fail to disclose their own personal concept of "ordering" when engaging in conversation, simply assuming that the other person holds the same concept of ordering as themselves. That assumption, then,... |
148,118 | I am trying to make a little wireless-connected gizmo to attach to my grandfather's walking cane. The idea is that when it senses the cane has fallen down, it would alert/call one of us so that we can rush to him if we're not nearby.
The question is: What sensor or combination of sensors could I use to reliably differ... | 2015/01/08 | [
"https://electronics.stackexchange.com/questions/148118",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/11636/"
] | A very simple solution is a tilt sensor such as the AT-407 from Sparkfun. It consists of 2 steel balls inside a small tube and 2 leads. When the tube is tilted, the balls separate and continuity is lost between the 2 leads. It costs only $1.95. | Seems like an accelerometer and a small microcontroller (a PIC for example) could do this quite easily. You could then set the angle at which the alarm goes off in the code.
With the light sensor approach you'd need to be careful that the area stayed clean. Otherwise if he covers the sensor with crud it will always in... |
148,118 | I am trying to make a little wireless-connected gizmo to attach to my grandfather's walking cane. The idea is that when it senses the cane has fallen down, it would alert/call one of us so that we can rush to him if we're not nearby.
The question is: What sensor or combination of sensors could I use to reliably differ... | 2015/01/08 | [
"https://electronics.stackexchange.com/questions/148118",
"https://electronics.stackexchange.com",
"https://electronics.stackexchange.com/users/11636/"
] | I agree with one of the above replies in that you need something (probably two accelerometers) to detect the angle at which the cane stands (calibrated at the factory if you are industrializing this). This way you have a continuum of what angle the cane is at, relative to upright.
This gives a distinct advantage over... | Seems like an accelerometer and a small microcontroller (a PIC for example) could do this quite easily. You could then set the angle at which the alarm goes off in the code.
With the light sensor approach you'd need to be careful that the area stayed clean. Otherwise if he covers the sensor with crud it will always in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.