qid int64 1 74.7M | question stringlengths 0 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 2 48.3k | response_k stringlengths 2 40.5k |
|---|---|---|---|---|---|
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | That should do it:
```
def repeated(f, n):
def rfun(p):
return reduce(lambda x, _: f(x), xrange(n), p)
return rfun
def square(x):
print "square(%d)" % x
return x * x
print repeated(square, 5)(3)
```
output:
```
square(3)
square(9)
square(81)
square(6561)
square(43046721)
1853... | I think you want function composition:
```
def compose(f, x, n):
if n == 0:
return x
return compose(f, f(x), n - 1)
def square(x):
return pow(x, 2)
y = compose(square, 3, 2)
print y
``` |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Use an itertools recipe called `repeatfunc` that performs this operation.
**Given**
```
def square(x):
"""Return the square of a value."""
return x * x
```
**Code**
From [itertools recipes](https://docs.python.org/3/library/itertools.html#itertools-recipes):
```
def repeatfunc(func, times=None, *args):
... | Here's a recipe using `reduce`:
```
def power(f, p, myapply = lambda init, g:g(init)):
ff = (f,)*p # tuple of length p containing only f in each slot
return lambda x:reduce(myapply, ff, x)
def square(x):
return x * x
power(square, 2)(3)
#=> 81
```
I call this `power`, because this is literally what the... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Use an itertools recipe called `repeatfunc` that performs this operation.
**Given**
```
def square(x):
"""Return the square of a value."""
return x * x
```
**Code**
From [itertools recipes](https://docs.python.org/3/library/itertools.html#itertools-recipes):
```
def repeatfunc(func, times=None, *args):
... | Using reduce and itertools.repeat (as Marcin suggested):
```
from itertools import repeat
from functools import reduce # necessary for python3
def repeated(func, n):
def apply(x, f):
return f(x)
def ret(x):
return reduce(apply, repeat(func, n), x)
return ret
```
You can use it as follows... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Using `reduce` and lamba.
Build a tuple starting with your parameter, followed by all functions you want to call:
```
>>> path = "/a/b/c/d/e/f"
>>> reduce(lambda val,func: func(val), (path,) + (os.path.dirname,) * 3)
"/a/b/c"
``` | Here's a recipe using `reduce`:
```
def power(f, p, myapply = lambda init, g:g(init)):
ff = (f,)*p # tuple of length p containing only f in each slot
return lambda x:reduce(myapply, ff, x)
def square(x):
return x * x
power(square, 2)(3)
#=> 81
```
I call this `power`, because this is literally what the... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Using reduce and itertools.repeat (as Marcin suggested):
```
from itertools import repeat
from functools import reduce # necessary for python3
def repeated(func, n):
def apply(x, f):
return f(x)
def ret(x):
return reduce(apply, repeat(func, n), x)
return ret
```
You can use it as follows... | Here's a recipe using `reduce`:
```
def power(f, p, myapply = lambda init, g:g(init)):
ff = (f,)*p # tuple of length p containing only f in each slot
return lambda x:reduce(myapply, ff, x)
def square(x):
return x * x
power(square, 2)(3)
#=> 81
```
I call this `power`, because this is literally what the... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Something like this?
```
def repeat(f, n):
if n==0:
return (lambda x: x)
return (lambda x: f (repeat(f, n-1)(x)))
``` | I think you want function composition:
```
def compose(f, x, n):
if n == 0:
return x
return compose(f, f(x), n - 1)
def square(x):
return pow(x, 2)
y = compose(square, 3, 2)
print y
``` |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Using reduce and itertools.repeat (as Marcin suggested):
```
from itertools import repeat
from functools import reduce # necessary for python3
def repeated(func, n):
def apply(x, f):
return f(x)
def ret(x):
return reduce(apply, repeat(func, n), x)
return ret
```
You can use it as follows... | I think you want function composition:
```
def compose(f, x, n):
if n == 0:
return x
return compose(f, f(x), n - 1)
def square(x):
return pow(x, 2)
y = compose(square, 3, 2)
print y
``` |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | Using `reduce` and lamba.
Build a tuple starting with your parameter, followed by all functions you want to call:
```
>>> path = "/a/b/c/d/e/f"
>>> reduce(lambda val,func: func(val), (path,) + (os.path.dirname,) * 3)
"/a/b/c"
``` | Using reduce and itertools.repeat (as Marcin suggested):
```
from itertools import repeat
from functools import reduce # necessary for python3
def repeated(func, n):
def apply(x, f):
return f(x)
def ret(x):
return reduce(apply, repeat(func, n), x)
return ret
```
You can use it as follows... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | That should do it:
```
def repeated(f, n):
def rfun(p):
return reduce(lambda x, _: f(x), xrange(n), p)
return rfun
def square(x):
print "square(%d)" % x
return x * x
print repeated(square, 5)(3)
```
output:
```
square(3)
square(9)
square(81)
square(6561)
square(43046721)
1853... | Here's a recipe using `reduce`:
```
def power(f, p, myapply = lambda init, g:g(init)):
ff = (f,)*p # tuple of length p containing only f in each slot
return lambda x:reduce(myapply, ff, x)
def square(x):
return x * x
power(square, 2)(3)
#=> 81
```
I call this `power`, because this is literally what the... |
7,359,828 | I'm trying to write a function in python that is like:
```
def repeated(f, n):
...
```
where `f` is a function that takes one argument and `n` is a positive integer.
For example if I defined square as:
```
def square(x):
return x * x
```
and I called
```
repeated(square, 2)(3)
```
this would square 3,... | 2011/09/09 | [
"https://Stackoverflow.com/questions/7359828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/921229/"
] | That should do it:
```
def repeated(f, n):
def rfun(p):
return reduce(lambda x, _: f(x), xrange(n), p)
return rfun
def square(x):
print "square(%d)" % x
return x * x
print repeated(square, 5)(3)
```
output:
```
square(3)
square(9)
square(81)
square(6561)
square(43046721)
1853... | Use an itertools recipe called `repeatfunc` that performs this operation.
**Given**
```
def square(x):
"""Return the square of a value."""
return x * x
```
**Code**
From [itertools recipes](https://docs.python.org/3/library/itertools.html#itertools-recipes):
```
def repeatfunc(func, times=None, *args):
... |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | You need to anchor the match to the start of the string by adding a `^` to the front. I do not really understand what you are trying to accomplish by the most of your regular expression though.
If you just want anything that doesn't start with a currency symbol, try `^[^\$¢£].*$`.
Anything that doesn't contain *any* c... | You could just ignore values that begin with a dollar sign...
```js
var values = ['3.5 mm', '-2', '#1', '$3.50'];
var regex = new RegExp('^\\$');
var res = values.filter(function(val) {
if (val.match(regex)) {
console.log(val, 'skip');
} else {
return val;
}
})
console.log(res);
``` |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | You need to anchor the match to the start of the string by adding a `^` to the front. I do not really understand what you are trying to accomplish by the most of your regular expression though.
If you just want anything that doesn't start with a currency symbol, try `^[^\$¢£].*$`.
Anything that doesn't contain *any* c... | ```js
function check() { // if you want to match only numbers at the bigining as well as #
var a = document.getElementById("test").value;
var remove = /^-?\d*\.?\d+|#/;
var b = a.match(remove);
if (!b)
console.log("ignore");
else
console.log("true");
}
function check2() { // if you want to i... |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | You need to anchor the match to the start of the string by adding a `^` to the front. I do not really understand what you are trying to accomplish by the most of your regular expression though.
If you just want anything that doesn't start with a currency symbol, try `^[^\$¢£].*$`.
Anything that doesn't contain *any* c... | As an alternative, maybe you could match the numbers that represent a price and replace the match with an empty string:
[`[£$¢]\d+(?:\.\d+)? *`](https://regex101.com/r/ua9NXk/1)
```js
var pattern = /[£$¢]\d+(?:\.\d+)? */g;
var text = `3.5 mm
This is 3.5 mm.
-2
This is -2 and test
This is #1 and test
#1
$3.50
... |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | Unfortunately, lookbehinds are not supported in `JS`but you could use a "trick":
*match* anything you **don't want** but *capture* anything you **do want**:
```
junk_a|junk_b|junk_c|(interesting_stuff)
```
So here with your specific example:
```
[$¢£]\s*-?\d+(?:\.\d+)?|(-?\d+(?:\.\d+)*)
# ^^^^^ junk part ^^^^^
... | You could just ignore values that begin with a dollar sign...
```js
var values = ['3.5 mm', '-2', '#1', '$3.50'];
var regex = new RegExp('^\\$');
var res = values.filter(function(val) {
if (val.match(regex)) {
console.log(val, 'skip');
} else {
return val;
}
})
console.log(res);
``` |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | Unfortunately, lookbehinds are not supported in `JS`but you could use a "trick":
*match* anything you **don't want** but *capture* anything you **do want**:
```
junk_a|junk_b|junk_c|(interesting_stuff)
```
So here with your specific example:
```
[$¢£]\s*-?\d+(?:\.\d+)?|(-?\d+(?:\.\d+)*)
# ^^^^^ junk part ^^^^^
... | ```js
function check() { // if you want to match only numbers at the bigining as well as #
var a = document.getElementById("test").value;
var remove = /^-?\d*\.?\d+|#/;
var b = a.match(remove);
if (!b)
console.log("ignore");
else
console.log("true");
}
function check2() { // if you want to i... |
49,101,463 | I have a parent div element and two nested div elements. The second child div is an audio control of arbitrary length. At least I assume it's arbitrary. My question is how can I get the first child div to take on the width of the audio control?
I want the title to appear on only one line and to be cut off if it excee... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4698242/"
] | Unfortunately, lookbehinds are not supported in `JS`but you could use a "trick":
*match* anything you **don't want** but *capture* anything you **do want**:
```
junk_a|junk_b|junk_c|(interesting_stuff)
```
So here with your specific example:
```
[$¢£]\s*-?\d+(?:\.\d+)?|(-?\d+(?:\.\d+)*)
# ^^^^^ junk part ^^^^^
... | As an alternative, maybe you could match the numbers that represent a price and replace the match with an empty string:
[`[£$¢]\d+(?:\.\d+)? *`](https://regex101.com/r/ua9NXk/1)
```js
var pattern = /[£$¢]\d+(?:\.\d+)? */g;
var text = `3.5 mm
This is 3.5 mm.
-2
This is -2 and test
This is #1 and test
#1
$3.50
... |
30,927,102 | I was just install Xcode 7 beta and converted my Swift project with Swift 2 guidelines.
Build is OK but xcassets: I reached this error in logs:
```
CompileAssetCatalog /Users/phoenix/Library/Developer/Xcode/DerivedData/{...}/Build/Products/Debug-iphoneos/{...}.app {...}/Images.xcassets
cd /Users/phoenix/Dev/Xcode/{..... | 2015/06/18 | [
"https://Stackoverflow.com/questions/30927102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2037645/"
] | Navigate to `~/Library/Developer/CoreSimulator/Profiles/Runtimes`, then remove the runtime - the runtime is old. After, reboot Xcode7, and launch the Simulator...
Further explanation from [@seancook](https://forums.developer.apple.com/thread/11706?sr=stream&ru=8243):
>
> I experienced this, too, on El Capitan. NIBs ... | I just cleared the derived data and it works fine now. |
30,927,102 | I was just install Xcode 7 beta and converted my Swift project with Swift 2 guidelines.
Build is OK but xcassets: I reached this error in logs:
```
CompileAssetCatalog /Users/phoenix/Library/Developer/Xcode/DerivedData/{...}/Build/Products/Debug-iphoneos/{...}.app {...}/Images.xcassets
cd /Users/phoenix/Dev/Xcode/{..... | 2015/06/18 | [
"https://Stackoverflow.com/questions/30927102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2037645/"
] | Navigate to `~/Library/Developer/CoreSimulator/Profiles/Runtimes`, then remove the runtime - the runtime is old. After, reboot Xcode7, and launch the Simulator...
Further explanation from [@seancook](https://forums.developer.apple.com/thread/11706?sr=stream&ru=8243):
>
> I experienced this, too, on El Capitan. NIBs ... | I was using an older xCode ( I have 8.3.1 installed by appstore and I was using 8.2.1).
For me, the solution was Xcode/Preferences>Locations and setting Command Line Tools: Xcode 8.2.1 (8C1002) (it was on the newer Xcode before) |
30,927,102 | I was just install Xcode 7 beta and converted my Swift project with Swift 2 guidelines.
Build is OK but xcassets: I reached this error in logs:
```
CompileAssetCatalog /Users/phoenix/Library/Developer/Xcode/DerivedData/{...}/Build/Products/Debug-iphoneos/{...}.app {...}/Images.xcassets
cd /Users/phoenix/Dev/Xcode/{..... | 2015/06/18 | [
"https://Stackoverflow.com/questions/30927102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2037645/"
] | I was using an older xCode ( I have 8.3.1 installed by appstore and I was using 8.2.1).
For me, the solution was Xcode/Preferences>Locations and setting Command Line Tools: Xcode 8.2.1 (8C1002) (it was on the newer Xcode before) | I just cleared the derived data and it works fine now. |
30,457,048 | I am trying to set up a bit of code to automate a task I have to do on a weekly report I run. The task is to go into all the 'data' sheets and do several find and replaces so that other parts of the report that refer to the data sheets look a bit cleaner.
Currently my code looks similar to this:
```
sub FindReplaceSh... | 2015/05/26 | [
"https://Stackoverflow.com/questions/30457048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4391373/"
] | >
> will the select wait until all the inserts are done?
>
>
>
Nope. Why would it? If the insert queries were issued before the SELECT query and it's a MyISAM table, then yes, you'll get the id of the last insert. That such queries are serialized are the reason that most people use InnoDB for OLTP.
>
> Is There ... | If you use MAX, you will always get the greatest number in the database. That is like use a AUTO\_INCREMENT.
When you use "last\_insert\_id" you get the last insert id, so if you insert something in the id 4, but your max id is 10, you have to check if is something between 4 and 10.
I recommend you use "MAX" or confi... |
25,070,475 | I have a webform built using Go. Users enter a number, then I need to do some math on that number. It seems like all methods using http package use strings as the output.
How can I do simple math on the user input?
Here is the basic code I have:
```
func init() {
http.HandleFunc("/", root)
http.HandleFunc("... | 2014/07/31 | [
"https://Stackoverflow.com/questions/25070475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3896454/"
] | Convert the input to a float first using [`strconv.ParseFloat`](http://golang.org/pkg/strconv/#ParseFloat)
```
fval, err := strconv.ParseFloat(input, 64)
if err != nil {
log.Println(err)
//do something about it
}
newNum = fval + 0.25
``` | A friend just gave me this answer using fmt package. I thought I would share it too.
```
type userInput struct {
Num float64
}
input := "0.50"
s, err := fmt.Sscanf(input, "%f", &userInput.Num)
newNum := userInput.Num + 0.25
``` |
30,393,274 | i'm using the sin/cos lookup table in VHDL known as sincos\_lut.vhd and i'm getting an error when used with my code. I'm implementing my datapath and i need to perform sin and cos on an integer value. I do not know where my problem is but here is the code and error:
```
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ... | 2015/05/22 | [
"https://Stackoverflow.com/questions/30393274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4430274/"
] | You can't. Macro substitution is done at preprocessing stage and you can't set it based on a runtime condition.
Instead you can define `A` as a variable:
```
A = (fel == 1)? x: y;
``` | Define the macro using the ternary operator:
```
#define A ((fel == 1) ? x : y)
```
The macro will only work if you use it in a context where `fel` and `x` and `y` are all in scope. |
30,393,274 | i'm using the sin/cos lookup table in VHDL known as sincos\_lut.vhd and i'm getting an error when used with my code. I'm implementing my datapath and i need to perform sin and cos on an integer value. I do not know where my problem is but here is the code and error:
```
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ... | 2015/05/22 | [
"https://Stackoverflow.com/questions/30393274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4430274/"
] | You can't. Macro substitution is done at preprocessing stage and you can't set it based on a runtime condition.
Instead you can define `A` as a variable:
```
A = (fel == 1)? x: y;
``` | `if` is a statement, not an expression, thus it doesn't return any value. You need to write it as an expression, like using ternary operator, as suggested by others, or use [GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) |
30,393,274 | i'm using the sin/cos lookup table in VHDL known as sincos\_lut.vhd and i'm getting an error when used with my code. I'm implementing my datapath and i need to perform sin and cos on an integer value. I do not know where my problem is but here is the code and error:
```
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ... | 2015/05/22 | [
"https://Stackoverflow.com/questions/30393274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4430274/"
] | Macros are preprocessor directives, meaning - they are expanded before the compilation and before runtime.
So, the way you've written this, `A` will literally be replaced by `{ if (fel == 1) x; if(fel != 1) y; }`, not by `x` or `y`.
Macros can be avoided most of the time. Why not just use `A` as variable, not as macr... | Define the macro using the ternary operator:
```
#define A ((fel == 1) ? x : y)
```
The macro will only work if you use it in a context where `fel` and `x` and `y` are all in scope. |
30,393,274 | i'm using the sin/cos lookup table in VHDL known as sincos\_lut.vhd and i'm getting an error when used with my code. I'm implementing my datapath and i need to perform sin and cos on an integer value. I do not know where my problem is but here is the code and error:
```
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ... | 2015/05/22 | [
"https://Stackoverflow.com/questions/30393274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4430274/"
] | Macros are preprocessor directives, meaning - they are expanded before the compilation and before runtime.
So, the way you've written this, `A` will literally be replaced by `{ if (fel == 1) x; if(fel != 1) y; }`, not by `x` or `y`.
Macros can be avoided most of the time. Why not just use `A` as variable, not as macr... | `if` is a statement, not an expression, thus it doesn't return any value. You need to write it as an expression, like using ternary operator, as suggested by others, or use [GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) |
35,474,174 | I just went through the NIO functionalities and got basic idea about NIO and how NIO works. In my project am using **ActiveMQ** to read the messages from my client. To read the messages in **ActiveMQ** I have created consumers to speed up the processing of data which received.
I have configured **SSL** for **Activ... | 2016/02/18 | [
"https://Stackoverflow.com/questions/35474174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3908580/"
] | >
> What is NIO protocol?
>
>
>
There is no such thing. NIO is an API, not a protocol. | NIO Stands for **Non-blocking I/O** (JAVA)
The API(Application Programming Interface)s of NIO were designed to provide access to all the low-level Input Output operations of modern operating systems. |
35,474,174 | I just went through the NIO functionalities and got basic idea about NIO and how NIO works. In my project am using **ActiveMQ** to read the messages from my client. To read the messages in **ActiveMQ** I have created consumers to speed up the processing of data which received.
I have configured **SSL** for **Activ... | 2016/02/18 | [
"https://Stackoverflow.com/questions/35474174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3908580/"
] | The previous answers are right at some extent. Nio is just an option that allows you configuring the newer API to be used to process your connection at the broker site.
It makes sense to apply it when you configure a high-loaded system as it considers wider usage of multi-threading features. You should put either `ur... | NIO Stands for **Non-blocking I/O** (JAVA)
The API(Application Programming Interface)s of NIO were designed to provide access to all the low-level Input Output operations of modern operating systems. |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | Just expanding upon this answer.
You may not want all letters you write to be expandable into html. You can set another extra object in your context to restrict when the tab completion is applied. This code was found in [this gist](https://gist.github.com/max-mykhailenko/41d0c3991d92f38dcbc6) however I modified the ... | simply use `ctrl+e` (`cmd+e` on mac ) instead of tab to get emmet to work inside your jsx.
for example if I expand (using `ctrl+e`)
```
render(){
return(
.modal>.btn.btn-success{Click Me}
)
}
```
then I get
```
render(){
return(
<div className="modal">
... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | In April 2015 [Emmet added support for jsx](https://twitter.com/emmetio/status/583398878789132289), but it doesn't work by default. Well, for my surprise it was actually working with the `control + E` shortcut, but I wanted to use the `TAB` key to expand. Following the [official instructions](https://github.com/sergech... | Just expanding upon this answer.
You may not want all letters you write to be expandable into html. You can set another extra object in your context to restrict when the tab completion is applied. This code was found in [this gist](https://gist.github.com/max-mykhailenko/41d0c3991d92f38dcbc6) however I modified the ... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | In April 2015 [Emmet added support for jsx](https://twitter.com/emmetio/status/583398878789132289), but it doesn't work by default. Well, for my surprise it was actually working with the `control + E` shortcut, but I wanted to use the `TAB` key to expand. Following the [official instructions](https://github.com/sergech... | From the [JSX-SublimeText Package](https://github.com/allanhortle/JSX) readme:
>
> Emmet's default is to not support JS files. So you will need to add a keyboard shortcut to tab complete in JSX files.
>
>
> open up `Preferences > Key Bindings - user` and add this entry:
>
>
>
```json
{
"keys": ["tab"],
... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | From the [JSX-SublimeText Package](https://github.com/allanhortle/JSX) readme:
>
> Emmet's default is to not support JS files. So you will need to add a keyboard shortcut to tab complete in JSX files.
>
>
> open up `Preferences > Key Bindings - user` and add this entry:
>
>
>
```json
{
"keys": ["tab"],
... | simply use `ctrl+e` (`cmd+e` on mac ) instead of tab to get emmet to work inside your jsx.
for example if I expand (using `ctrl+e`)
```
render(){
return(
.modal>.btn.btn-success{Click Me}
)
}
```
then I get
```
render(){
return(
<div className="modal">
... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | In April 2015 [Emmet added support for jsx](https://twitter.com/emmetio/status/583398878789132289), but it doesn't work by default. Well, for my surprise it was actually working with the `control + E` shortcut, but I wanted to use the `TAB` key to expand. Following the [official instructions](https://github.com/sergech... | If you type `shift+super+p` in a file it will let you see the current selection's context in the bottom left.
The first word is always the base file type. (`source.js`, `text.html`) In the case of the [JSX](https://github.com/allanhortle/JSX) I chose to change this to `source.js.jsx`. This is because before it is comp... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | If you type `shift+super+p` in a file it will let you see the current selection's context in the bottom left.
The first word is always the base file type. (`source.js`, `text.html`) In the case of the [JSX](https://github.com/allanhortle/JSX) I chose to change this to `source.js.jsx`. This is because before it is comp... | In 2021 it's not necessary to configure anything as Emmet has support for JSX files by default.
Obviously you need to install the [JSX language definition](https://packagecontrol.io/packages/JSX) from package control after installing Emmet.
Now `TAB` will work but only when the HTML tag is prefixed with a `<`. For ex... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | From the [JSX-SublimeText Package](https://github.com/allanhortle/JSX) readme:
>
> Emmet's default is to not support JS files. So you will need to add a keyboard shortcut to tab complete in JSX files.
>
>
> open up `Preferences > Key Bindings - user` and add this entry:
>
>
>
```json
{
"keys": ["tab"],
... | Just expanding upon this answer.
You may not want all letters you write to be expandable into html. You can set another extra object in your context to restrict when the tab completion is applied. This code was found in [this gist](https://gist.github.com/max-mykhailenko/41d0c3991d92f38dcbc6) however I modified the ... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | If you type `shift+super+p` in a file it will let you see the current selection's context in the bottom left.
The first word is always the base file type. (`source.js`, `text.html`) In the case of the [JSX](https://github.com/allanhortle/JSX) I chose to change this to `source.js.jsx`. This is because before it is comp... | Just expanding upon this answer.
You may not want all letters you write to be expandable into html. You can set another extra object in your context to restrict when the tab completion is applied. This code was found in [this gist](https://gist.github.com/max-mykhailenko/41d0c3991d92f38dcbc6) however I modified the ... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | In 2021 it's not necessary to configure anything as Emmet has support for JSX files by default.
Obviously you need to install the [JSX language definition](https://packagecontrol.io/packages/JSX) from package control after installing Emmet.
Now `TAB` will work but only when the HTML tag is prefixed with a `<`. For ex... | simply use `ctrl+e` (`cmd+e` on mac ) instead of tab to get emmet to work inside your jsx.
for example if I expand (using `ctrl+e`)
```
render(){
return(
.modal>.btn.btn-success{Click Me}
)
}
```
then I get
```
render(){
return(
<div className="modal">
... |
26,089,802 | I had been previously using [Allan Hortle's JSX package](https://github.com/allanhortle/JSX) until I ran into an issue with how it handled syntax highlighting. I then noticed that there is an official package, [sublime-react](https://github.com/reactjs/sublime-react).
With Allan Hortle's package, he included a snippet... | 2014/09/28 | [
"https://Stackoverflow.com/questions/26089802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445937/"
] | In 2021 it's not necessary to configure anything as Emmet has support for JSX files by default.
Obviously you need to install the [JSX language definition](https://packagecontrol.io/packages/JSX) from package control after installing Emmet.
Now `TAB` will work but only when the HTML tag is prefixed with a `<`. For ex... | Just expanding upon this answer.
You may not want all letters you write to be expandable into html. You can set another extra object in your context to restrict when the tab completion is applied. This code was found in [this gist](https://gist.github.com/max-mykhailenko/41d0c3991d92f38dcbc6) however I modified the ... |
32,719,031 | I'm making a Rails 4 application. Each `incident` belongs to a `user`. Each incident `has many events`. I want that I can create an Incident with `current_user.incidents.new` and pass it an attribute `message` which exists in the Event model. On creation, I wish to create a new event with the said `message`.
Here's m... | 2015/09/22 | [
"https://Stackoverflow.com/questions/32719031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5155665/"
] | The problem is that you're passing the values to the default `ActiveRecord::new` method for `Incident`, which won't care about your getters, setters and accessors, it [goes straight to the columns](http://apidock.com/rails/v4.2.1/ActiveRecord/AttributeMethods/Serialization/ClassMethods/serialized_attributes).
Some peo... | Because your `Incident` model inherits from ActiveRecord::Base, it inherits the constructor. The ActiveRecord constructor only accepts model attributes (db columns) as params. You are trying to call an arbitrary instance method. You could create a class method that creates an instance then adds the message:
```
def se... |
51,345,586 | I have a scenario where many fields in JSON response that are coming as string (`"true"/"false"`).
Now I need to replace all of the values from `string` to `Boolean` in one shot via `Javascript`.
Sample:
```
{
field1: "true",
field2: "false"
}
```
Expected:
```
{
field1: true,
field2: false
}
```... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51345586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5223629/"
] | The [`JSON.parse` reviver parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Examples) can be used to exclude or modify values:
```js
var j = '{"field1":"true","field2":"false"}';
var o = JSON.parse(j, (k, v) => v === "true" ? true : v === "false" ? false : v);
c... | Here's a nice recursive `convertBools` function:
```js
function convertBools(obj) {
const newObj = {};
if (typeof obj !== 'object') {
return obj;
}
for (const prop in obj) {
if (!obj.hasOwnProperty(prop)) {
continue;
}
if (Array.isArray(obj[prop])) {
newObj[prop] = obj[p... |
51,345,586 | I have a scenario where many fields in JSON response that are coming as string (`"true"/"false"`).
Now I need to replace all of the values from `string` to `Boolean` in one shot via `Javascript`.
Sample:
```
{
field1: "true",
field2: "false"
}
```
Expected:
```
{
field1: true,
field2: false
}
```... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51345586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5223629/"
] | The [`JSON.parse` reviver parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Examples) can be used to exclude or modify values:
```js
var j = '{"field1":"true","field2":"false"}';
var o = JSON.parse(j, (k, v) => v === "true" ? true : v === "false" ? false : v);
c... | you can try something like this as well.
```js
let obj = {
field1: "true",
field2: "false",
field3: "SomeOtherValueThanBoolean"
};
for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
obj[prop] = (obj[prop] == 'true' || obj[prop] == 'false')? obj[prop] === 'true': obj[prop] ;
}
... |
51,345,586 | I have a scenario where many fields in JSON response that are coming as string (`"true"/"false"`).
Now I need to replace all of the values from `string` to `Boolean` in one shot via `Javascript`.
Sample:
```
{
field1: "true",
field2: "false"
}
```
Expected:
```
{
field1: true,
field2: false
}
```... | 2018/07/15 | [
"https://Stackoverflow.com/questions/51345586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5223629/"
] | The [`JSON.parse` reviver parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Examples) can be used to exclude or modify values:
```js
var j = '{"field1":"true","field2":"false"}';
var o = JSON.parse(j, (k, v) => v === "true" ? true : v === "false" ? false : v);
c... | My version, does not modify source object, returns new object with parsed booleans:
```js
const object = {
"test": "true",
"test1": false,
"test2": "false",
"test3": 5,
}
console.log(parseBooleansInObj(object));
function parseBooleansInObj(object) {
const newObject = { ...object };
Object.keys(n... |
4,463,886 | I am trying to get an example from the Android 2 Application Development book by Reto Meier to work (page 202). As per the instructions I have created a userpreferences.xml as follows:
```
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="PREF_AUTO_UP... | 2010/12/16 | [
"https://Stackoverflow.com/questions/4463886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/545086/"
] | I had the same problem - the user preference data from the previous example in the book used different data types when saving the preference data.
The solution is to simply check the 'clear user data' checkbox when starting the AVD to get rid of the old user preferences. | Perhaps you are running into this? <http://code.google.com/p/android/issues/detail?id=2096>.
*[update] Per the comment, yes make all of your arrays of type string-array and you should be good.* |
4,463,886 | I am trying to get an example from the Android 2 Application Development book by Reto Meier to work (page 202). As per the instructions I have created a userpreferences.xml as follows:
```
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="PREF_AUTO_UP... | 2010/12/16 | [
"https://Stackoverflow.com/questions/4463886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/545086/"
] | If you change a preference type from ListPreference to CheckBoxPreference, whilst reusing the same key, then this bug will happen.
The Android framework will store some default data in your app's shared\_prefs/preferences.xml file. These old values will be in the old format (such as Int or String, for ListPreference) ... | Perhaps you are running into this? <http://code.google.com/p/android/issues/detail?id=2096>.
*[update] Per the comment, yes make all of your arrays of type string-array and you should be good.* |
4,463,886 | I am trying to get an example from the Android 2 Application Development book by Reto Meier to work (page 202). As per the instructions I have created a userpreferences.xml as follows:
```
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="PREF_AUTO_UP... | 2010/12/16 | [
"https://Stackoverflow.com/questions/4463886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/545086/"
] | I had the same problem - the user preference data from the previous example in the book used different data types when saving the preference data.
The solution is to simply check the 'clear user data' checkbox when starting the AVD to get rid of the old user preferences. | If you change a preference type from ListPreference to CheckBoxPreference, whilst reusing the same key, then this bug will happen.
The Android framework will store some default data in your app's shared\_prefs/preferences.xml file. These old values will be in the old format (such as Int or String, for ListPreference) ... |
10,387,845 | I'm using FMOD library to extract PCM from an MP3. I get the whole 2 channel - 16 bit thing, and I also get that a sample rate of 44100hz is 44,100 samples of "sound" in 1 second. What I don't get is, what exactly does the 16 bit value represent. I know how to plot coordinates on an xy axis, but what am I plotting? The... | 2012/04/30 | [
"https://Stackoverflow.com/questions/10387845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/994337/"
] | Yes, a sample represents amplitude (at that point in time).
To get a spectrum, you typically convert it from the time domain to the frequency domain.
Last Q: Multiple approaches are used - You may want the [RMS](https://en.wikipedia.org/wiki/Root_mean_square). | Generally, the x axis is the time value and y axis is the amplitude. To get the frequency, you need to take the Fourier transform of the data (most likely using the Fast Fourier Transform [fft] algorithm).
To use one of the simplest "sounds", let's assume you have a single frequency noise with frequency f. This is re... |
10,387,845 | I'm using FMOD library to extract PCM from an MP3. I get the whole 2 channel - 16 bit thing, and I also get that a sample rate of 44100hz is 44,100 samples of "sound" in 1 second. What I don't get is, what exactly does the 16 bit value represent. I know how to plot coordinates on an xy axis, but what am I plotting? The... | 2012/04/30 | [
"https://Stackoverflow.com/questions/10387845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/994337/"
] | Yes, a sample represents amplitude (at that point in time).
To get a spectrum, you typically convert it from the time domain to the frequency domain.
Last Q: Multiple approaches are used - You may want the [RMS](https://en.wikipedia.org/wiki/Root_mean_square). | Each sample represents the voltage of the analog signal at a given time. |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | I may misunderstand your question (and I've never used Windows), so perhaps this answer is inappropriate.
If all the allowed template parameters for your template class are known at the compile time of your library (rather than that of third-party user code), then why not put all the definitions and instantinations in... | I tried this on VS2013. I found without the dllexport it links, but it doesn't run. Using depends.exe shows an unresolved import as expected. Anything implemented in a C++ file must be explicitly dllexport'ed for an EXE to link to it and templates are no different, so I don't understand how you're getting it to run. Tr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | The standard (from working draft of C++0x through working draft in 2014), section 14.7.2 describes Explicit instantiation, stating that there are two forms of explicit instantiation, definition and declaration. It says, "an explicit instantiation declaration begins with the extern keyword." It further specifies that de... | You need to forward declare usages of the template class with the proper linkage (declspec import/export for visual studio or 'extern' for everything else) so that the compiler does not try to generate code for those imported types.
Specific details are in my answer to: [C++ template specialization in different dll pr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | Here is a quote from the standard:
>
> For a given set of template arguments, if an explicit instantiation of a template appears after a declaration of an explicit specialization for that template, the explicit instantiation has no effect. [...]
>
>
>
So your explicit instantiation declaration
```
extern templat... | You need to forward declare usages of the template class with the proper linkage (declspec import/export for visual studio or 'extern' for everything else) so that the compiler does not try to generate code for those imported types.
Specific details are in my answer to: [C++ template specialization in different dll pr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | Here is a quote from the standard:
>
> For a given set of template arguments, if an explicit instantiation of a template appears after a declaration of an explicit specialization for that template, the explicit instantiation has no effect. [...]
>
>
>
So your explicit instantiation declaration
```
extern templat... | I tried this on VS2013. I found without the dllexport it links, but it doesn't run. Using depends.exe shows an unresolved import as expected. Anything implemented in a C++ file must be explicitly dllexport'ed for an EXE to link to it and templates are no different, so I don't understand how you're getting it to run. Tr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | From the language definition
A.12
Templates *[gram.temp]*
At the bottom we find the rules in question (sorry about the formatting):
§ A.12
1224c ISO/IEC
N4527
```
explicit-instantiation:
extern opt template declaration
explicit-specialization:
template < > declaration
```
So I would say the answer to the... | You need to forward declare usages of the template class with the proper linkage (declspec import/export for visual studio or 'extern' for everything else) so that the compiler does not try to generate code for those imported types.
Specific details are in my answer to: [C++ template specialization in different dll pr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | The standard (from working draft of C++0x through working draft in 2014), section 14.7.2 describes Explicit instantiation, stating that there are two forms of explicit instantiation, definition and declaration. It says, "an explicit instantiation declaration begins with the extern keyword." It further specifies that de... | I may misunderstand your question (and I've never used Windows), so perhaps this answer is inappropriate.
If all the allowed template parameters for your template class are known at the compile time of your library (rather than that of third-party user code), then why not put all the definitions and instantinations in... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | The standard (from working draft of C++0x through working draft in 2014), section 14.7.2 describes Explicit instantiation, stating that there are two forms of explicit instantiation, definition and declaration. It says, "an explicit instantiation declaration begins with the extern keyword." It further specifies that de... | Here is a quote from the standard:
>
> For a given set of template arguments, if an explicit instantiation of a template appears after a declaration of an explicit specialization for that template, the explicit instantiation has no effect. [...]
>
>
>
So your explicit instantiation declaration
```
extern templat... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | I may misunderstand your question (and I've never used Windows), so perhaps this answer is inappropriate.
If all the allowed template parameters for your template class are known at the compile time of your library (rather than that of third-party user code), then why not put all the definitions and instantinations in... | You need to forward declare usages of the template class with the proper linkage (declspec import/export for visual studio or 'extern' for everything else) so that the compiler does not try to generate code for those imported types.
Specific details are in my answer to: [C++ template specialization in different dll pr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | From the language definition
A.12
Templates *[gram.temp]*
At the bottom we find the rules in question (sorry about the formatting):
§ A.12
1224c ISO/IEC
N4527
```
explicit-instantiation:
extern opt template declaration
explicit-specialization:
template < > declaration
```
So I would say the answer to the... | I tried this on VS2013. I found without the dllexport it links, but it doesn't run. Using depends.exe shows an unresolved import as expected. Anything implemented in a C++ file must be explicitly dllexport'ed for an EXE to link to it and templates are no different, so I don't understand how you're getting it to run. Tr... |
32,054,993 | I am a developer of an Open Source library. One of our classes is templated for a bunch of different types. Currently the definition resides in the header file, which has a negative effect on compilation times and also forces users to include more headers than needed. My goal is the following:
* To reduce compilation ... | 2015/08/17 | [
"https://Stackoverflow.com/questions/32054993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3144964/"
] | The standard (from working draft of C++0x through working draft in 2014), section 14.7.2 describes Explicit instantiation, stating that there are two forms of explicit instantiation, definition and declaration. It says, "an explicit instantiation declaration begins with the extern keyword." It further specifies that de... | I tried this on VS2013. I found without the dllexport it links, but it doesn't run. Using depends.exe shows an unresolved import as expected. Anything implemented in a C++ file must be explicitly dllexport'ed for an EXE to link to it and templates are no different, so I don't understand how you're getting it to run. Tr... |
61,103 | What would cyclopropane look like if it weren't planar?
How and why does non-planar cyclopropane have higher torsional strain than planar cyclopropane? can you please show me visually via image that non-planar cyclopropane has higher torisional strain and maybe more angle strain than planar cyclopropane?
On the othe... | 2016/10/17 | [
"https://chemistry.stackexchange.com/questions/61103",
"https://chemistry.stackexchange.com",
"https://chemistry.stackexchange.com/users/36202/"
] | >
> Why is cyclopropane planar?
>
>
>
This is like asking why $\ce{HCl}$ is linear–just as two points define a line, three points define a plane. There isn't any way to orient the three methylene groups in space that they aren't coplanar.
$\hspace{8cm}$[](https://i.st... | If cyclopropane did pucker then a new plane would exist. This is because any set of three points (a.k.a three carbons) is coplanar. Cyclobutane puckering can occur and make a difference as a set of four points/carbons is not necessarily coplanar. |
41,934,836 | I have three random-access iterators `parent`, `child1`, and `child2`, which point to certain values in a permuted array. (Context: I'm implementing heapsort; those iterators comprise a binary subtree).
I need to determine the iterator, which has the largest referenced value (to maintain the max-heap property of the h... | 2017/01/30 | [
"https://Stackoverflow.com/questions/41934836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3494013/"
] | If you don't consider `std::max` with a custom comparator bulky, here it is:
```
auto iterator = std::max({ parent, child1, child2 },
[](auto it_a, auto it_b) { return *it_a < *it_b; });
``` | `std::max` accepts a comparison function object:
```
auto iterator = std::max({ parent, child1, child2 },
[](const auto& a, const auto& b){
return *a < *b;
});
```
---
Although, you may prefer to refactor into some re-usable functional parts:
```
template<class Fun>
auto indirect_args(... |
41,934,836 | I have three random-access iterators `parent`, `child1`, and `child2`, which point to certain values in a permuted array. (Context: I'm implementing heapsort; those iterators comprise a binary subtree).
I need to determine the iterator, which has the largest referenced value (to maintain the max-heap property of the h... | 2017/01/30 | [
"https://Stackoverflow.com/questions/41934836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3494013/"
] | If you don't consider `std::max` with a custom comparator bulky, here it is:
```
auto iterator = std::max({ parent, child1, child2 },
[](auto it_a, auto it_b) { return *it_a < *it_b; });
``` | since [`std::max`](http://en.cppreference.com/w/cpp/algorithm/max) has an overload for a custom comparator, you could do:
```
auto cmp = [](auto lhs, auto rhs){ return *lhs < *rhs; };
auto iterator = std::max({ parent, child1, child2 }, cmp);
``` |
57,830,232 | Here is a part of my code I am trying
```
const boom = require('boom')
exports.checkOtp = async (req, reply) => {
try {
return boom.badRequest('no active otp')
} catch (err) {
throw boom.boomify(err)
}
}
```
I am getting
```
{
"statusCode": 500,
"error": "Internal Server Error",
... | 2019/09/07 | [
"https://Stackoverflow.com/questions/57830232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/827525/"
] | In .NET Core there is an overload of [Contains](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains?view=netcore-2.1) which allows specifying comparison rules. There you could end up with something like:
```
public static class ExpressionRetriever
{
private static MethodInfo containsMethod = typeof... | From the documentation for `IndexOf`, the method returns:
>
> The index position of the value parameter if that string is found, or -1 if it is not.
>
>
>
So in order to check if `Foo.PropertyName` contains `Value`, you need to create the following expression:
```
Foo.PropertyName.IndexOf(Value, StringComparison... |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | I love the flexibility of sequences in Oracle as compared with other databases autoincrements, but the inability to set seq.nextval as a default for a pk column is somewhat annoying, and must be trivial to fix. | **Database** MySQL
**Defect** Foreign Keys supported only on some table types
**Description**
Enough said. It has obvious maintenance implications.
From the [MySQL manual](http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html)
>
> Foreign keys definitions are subject to the following conditio... |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | I love the flexibility of sequences in Oracle as compared with other databases autoincrements, but the inability to set seq.nextval as a default for a pk column is somewhat annoying, and must be trivial to fix. | **Database** Microsoft SQL Server 2005
**Defect** Lack of array type parameters
**Description**
Useful in searches, a lot of times you need to pass a series of values to be matched against. In SQL 2005 you can do a workaround by using CLR inside SQLServer. Given the usefulness it would make more sense to have this f... |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | **Database** Oracle
**Problem** Temp table definitions are not private
**Description** Many databases (eg Postgres and Sybase) allow you to create temp tables on the fly, insert into them, add indexes if you want, then query from them. Oracle has temp tables, but the temp table definitions exist in a global name spac... | **Database** Postgres
**Defect** No analytic queries
**Description**
Analytic queries, introduced by Oracle, are part of the SQL 2003 standard. Unfortunately Postgres hasn't implemented them yet. |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | **Database** MySQL 5.0.x and above
**Defect** Ring replication errors lead to inconsistent data on different nodes
**Description**
The most serious problem in production we face at the moment is that in a MySQL ring the ring itself produces an error and stops replicating.
Building a ring (or Master-Master-replicati... | PostgreSQL doesn't have a good failover solution, but I understand they're working on it. |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | **Database** MySQL
**Defect** Server will start up with damaged tables
**Description**
If MySQL has a damaged table - from either being killed during a write or some other failure - it will quite happily start up and allow the user to carry on as if the problem does not exist. Granted it will produce some erro... | **Database** Postgres
**Defect** No analytic queries
**Description**
Analytic queries, introduced by Oracle, are part of the SQL 2003 standard. Unfortunately Postgres hasn't implemented them yet. |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | Oracle databases are quite expensive
Oracle does what it does well but the licensing costs are horrendous. That has been improved by the release of Oracle XE but the limitations of that mean that it is a growth constraint on you solution. | Any SQL DBMS
Defect: Duplicate rows
One of the virtues of the relational model is that it represents everything without duplicate tuples, i.e. using relations, which have keys and no duplicates. Unfortunately SQL isn't built that way. This makes the database developer's life needlessly difficult. SQL developers have ... |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | **Database** Microsoft SQL Server 2005
**Defect** Badly implemented UI
**Description**
SQL Server management studio does not offer a great user experience:
* Tabbing behaviour is weird: you are always looking for the right tab
* Keeps on crashing on 64-bit versions
* Missing some features of preceding version, like... | Any SQL DBMS
Defect: Duplicate rows
One of the virtues of the relational model is that it represents everything without duplicate tuples, i.e. using relations, which have keys and no duplicates. Unfortunately SQL isn't built that way. This makes the database developer's life needlessly difficult. SQL developers have ... |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | Database: Oracle
Problem: The names of tables, procedures, columns, etc cannot exceed 30 characters. This is infuriating.
Problem: It's slapdash JDBC compliance. For example, stored procedures do not return results sets in a JDBC-compliant way, but instead of a proprietary OUT parameter type. This means you can't use... | PostgreSQL doesn't have a good failover solution, but I understand they're working on it. |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | I love the flexibility of sequences in Oracle as compared with other databases autoincrements, but the inability to set seq.nextval as a default for a pk column is somewhat annoying, and must be trivial to fix. | PostgreSQL doesn't have a good failover solution, but I understand they're working on it. |
119,707 | We all have our favourite database. If you look objectively at your chosen database, what drawbacks does it have and what could be improved?
The rules:
* One reply per drawback with;
* a short description of the limitation, followed by;
* a more detailed description, an explanation of how it could be done better or a... | 2008/09/23 | [
"https://Stackoverflow.com/questions/119707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494/"
] | **Database** Oracle
**Defect** Did not handle long datatype well for too long
**Description**
Oracle only had the long datatype until 9i (I believe) at which point it was deprecated in favor of the LOBs. There is a ton of code out there, however, which still has longs and all of the related restrictions. The biggest... | **Database : PostgreSQL**
\*\*Problem : \*\* is that connector for C# for example are not really up-to-date and crash with advanced feature. |
14,327,989 | I have a `IEnumerable` ViewModel. This has the same names and I want to select only one name and display it in the header. Please suggest.
My code is a below. I am trying to use distinct but it does not work
```
@foreach (var item in Model.abc)
{
{
<table>
<tr>
<td style="width:100p... | 2013/01/14 | [
"https://Stackoverflow.com/questions/14327989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1825391/"
] | >
> This has the same names and i want to select only one name and display
> it in the header.
>
>
>
If they all are the same and assuming `Name` implements `IEnumerable` you could try [First](http://msdn.microsoft.com/en-us/library/bb291976.aspx):
**Update**: add a new property to your model
```
otherProperty ... | **use this code in your app**
```
@foreach (var item in Model.Select(x => x.Title).Distinct())
{
<option>@item</option>
}
```
>
> you can use `@html.display(X=>item)` instead `@item`
>
>
> |
197,771 | I am using redwood 4x4s for the posts on an exterior deck. EVERY 4x4 at the Home Depot is stained with black from the binding straps, etc. See pic. Obviously this is not going to work if we're going to use a transparent stain and want it to look good.
Is there an effective way to remove this type of staining from redw... | 2020/07/15 | [
"https://diy.stackexchange.com/questions/197771",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/90784/"
] | Both [finewoodworking.com](https://www.finewoodworking.com/2018/10/10/remove-iron-stains-wood) and [landscapetutorials.com](https://www.landscapetutorials.com/2019/02/how-to-renew-fence-or-deck.html) recommend using oxalic acid.
The first one has a powder/paste approach, likely appropriate for individual pieces.
>
> ... | ### It looks like you need to plane it anyway!
From that picture, it looks like that post has a lot of surface damage. Has it rattled around in the back of a pickup on the way home, to pick up all those dents and scratches? If you're worried about how it'll look, I think those should be your first thing to worry about... |
197,771 | I am using redwood 4x4s for the posts on an exterior deck. EVERY 4x4 at the Home Depot is stained with black from the binding straps, etc. See pic. Obviously this is not going to work if we're going to use a transparent stain and want it to look good.
Is there an effective way to remove this type of staining from redw... | 2020/07/15 | [
"https://diy.stackexchange.com/questions/197771",
"https://diy.stackexchange.com",
"https://diy.stackexchange.com/users/90784/"
] | Two suggestions:
1. Try finding a different supplier. Check out another big-box store, or even better try to find a local lumberyard/sawmill. The local place may well have sawn their own on site and they'll never have been banded, so there won't be an issue. The time saved in cleaning may be worth an extra buck or two... | ### It looks like you need to plane it anyway!
From that picture, it looks like that post has a lot of surface damage. Has it rattled around in the back of a pickup on the way home, to pick up all those dents and scratches? If you're worried about how it'll look, I think those should be your first thing to worry about... |
40,704,910 | I'm trying to compare dates from database (firebase) with NOW. I'm using moment.js and it's not working. I think it has something to do with the time zone (or UTC+01:00)...
Example.
* date1: "2016-11-20T14:00:00"
* NOW: "2016-11-20T14:49:20+01:00"
I get NOW with `moment()` and compare like this:
```
var date1 = mom... | 2016/11/20 | [
"https://Stackoverflow.com/questions/40704910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1736012/"
] | Get the data using [eager loading](https://laravel.com/docs/5.3/eloquent-relationships#eager-loading):
```
$user = User::where('id', $userId)->with('roles')->first();
```
Then display the data:
```
{{-- Display full name --}}
{{ $user->first_name.' '.$user->last_name }}
{{-- Display all role names of the user --}}... | ```
@foreach($users as $user)
{{$user->name}} {{$user->roles->first()->name}}
@endforeach
``` |
182,367 | Recently I’ve got stumbled upon the question: What’s the difference between *quite a lot*, *quite a few*, and *quite a bit*?
This is very confusing considering *a lot* and *a few* have almost opposite meanings.
As far as I can see in dictionaries *quite a <COUNT-WORD>* is always *many*. Is that so, or am I missing so... | 2014/07/05 | [
"https://english.stackexchange.com/questions/182367",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/83106/"
] | Regarding the fact that I agree with you about the same meaning of *quite a <COUNT-WORD>* and *many*. I think these there have the exact same meaning but they better be used when they fit in the context of the sentence although they can be replace each other pretty freely. For example, I
* It's better to say *"He wrot... | Also, I would probably say "There are *quite a lot* of words on the page", but "There are *quite a few* words on the page" also sounds correct. However, "quite a bit" doesn't work in the same context. |
182,367 | Recently I’ve got stumbled upon the question: What’s the difference between *quite a lot*, *quite a few*, and *quite a bit*?
This is very confusing considering *a lot* and *a few* have almost opposite meanings.
As far as I can see in dictionaries *quite a <COUNT-WORD>* is always *many*. Is that so, or am I missing so... | 2014/07/05 | [
"https://english.stackexchange.com/questions/182367",
"https://english.stackexchange.com",
"https://english.stackexchange.com/users/83106/"
] | A few only with countable nouns. Generally a low quantity.
A few people helped me finish.
A bit of only with uncountable nouns. Low quantity.
A bit of help goes a long way
A lot of with either countable or uncountable nouns. High quantity.
A lot of people know me!
Now by adding quite to these, they reduce the idea o... | Also, I would probably say "There are *quite a lot* of words on the page", but "There are *quite a few* words on the page" also sounds correct. However, "quite a bit" doesn't work in the same context. |
17,720,002 | **Short Version:**
How do you collect the results of a complicated operation that is spread over several objects?
**Long Version:**
I am developing a data exchange system that will push customer orders from one system to another system. This will be done via an API and unfortunately this require 12 individual steps ... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17720002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2023210/"
] | For anyone who is interested, I did finally stumble across a design pattern that suited my needs.
My question could have been condensed down to simply:
How do you collect the results of a complicated operation that is spread over several objects?
(I have now edited the question)
The answer was the Collecting Parame... | How you do this will depend upon whether or not you need to stop at a failed point or whether you wish to cancel the whole lot if any part fails.
For the former, it is simple - just test at each step and if any fails, generate an error report.
The latter is a little harder and will depend upon the db you are using. F... |
17,720,002 | **Short Version:**
How do you collect the results of a complicated operation that is spread over several objects?
**Long Version:**
I am developing a data exchange system that will push customer orders from one system to another system. This will be done via an API and unfortunately this require 12 individual steps ... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17720002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2023210/"
] | What you really have described there is an algorithm for getting something done.
If the order of these steps is very important but sometimes the implementation can vary then that could become a [Template method](http://en.wikipedia.org/wiki/Template_method_pattern) where the steps are static (i.e. the order has to be ... | How you do this will depend upon whether or not you need to stop at a failed point or whether you wish to cancel the whole lot if any part fails.
For the former, it is simple - just test at each step and if any fails, generate an error report.
The latter is a little harder and will depend upon the db you are using. F... |
17,720,002 | **Short Version:**
How do you collect the results of a complicated operation that is spread over several objects?
**Long Version:**
I am developing a data exchange system that will push customer orders from one system to another system. This will be done via an API and unfortunately this require 12 individual steps ... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17720002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2023210/"
] | For anyone who is interested, I did finally stumble across a design pattern that suited my needs.
My question could have been condensed down to simply:
How do you collect the results of a complicated operation that is spread over several objects?
(I have now edited the question)
The answer was the Collecting Parame... | What you really have described there is an algorithm for getting something done.
If the order of these steps is very important but sometimes the implementation can vary then that could become a [Template method](http://en.wikipedia.org/wiki/Template_method_pattern) where the steps are static (i.e. the order has to be ... |
53,393,566 | here is my code, we have parent div with "cont" class, this div has three children --> 1.video with "vid" class
2.mask with "maskHeaderajans" which is layer mask like a filter on video and it should be stick on overlay whole video
3.and the last we have "main-caption" which includes logo and some text and should stic... | 2018/11/20 | [
"https://Stackoverflow.com/questions/53393566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10010714/"
] | I think you have a problem with bodyParser.
```
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
```
Add these just after `app.set('view engine', 'ejs');`
And your post function should be like this
```
app.pos... | ```
app.use(express.urlencoded({
extended: true
}));
app.post('/index', function(req, res){
res.render('form-data', {data : req.body});
request.post({
"headers": { "content-type": "application/json" },
"url": "http://mysafeinfo.com/api/data?list=englishmonarchs&format="+req.body.name,... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | >
> Yeah, sure, I could just get rid of the if's and else's and replace ((Item)list...) with Item item = list... and wrap it all in a single Try{}Catch{}, but I really do hate using Try{}Catch{} unless there is something I am not expecting. And to be honest, using Try{} Catch{} makes me feel lazy and like I'm not doin... | You should place the properties in variables and call the variable in the inner if/else statements. Otherwise in *every* if statement the condition has to step through every property again and again **(**`((Item)list.SelectedItems[0].Tag)...`**)**. Here's how you can do this:
```
private void PlayRecording()
{
if ... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | You check if there are one **or more** selected items but the the rest of your code only works on the first selection. I think you should specifically check for a single selected item. I've used `SingleOrDefault` from the `System.Linq` namespace.
I wonder about the value you get from saying the list is empty - surely ... | You should place the properties in variables and call the variable in the inner if/else statements. Otherwise in *every* if statement the condition has to step through every property again and again **(**`((Item)list.SelectedItems[0].Tag)...`**)**. Here's how you can do this:
```
private void PlayRecording()
{
if ... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | I might have missed it in one of the other answers, but in this code:
>
>
> ```
> using (MemoryStream memoryStream = new MemoryStream(recording))
> {
> if (memoryStream != null)
>
> ```
>
>
`memoryStream` will never be null, so the check is redundant. | You should place the properties in variables and call the variable in the inner if/else statements. Otherwise in *every* if statement the condition has to step through every property again and again **(**`((Item)list.SelectedItems[0].Tag)...`**)**. Here's how you can do this:
```
private void PlayRecording()
{
if ... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | You should place the properties in variables and call the variable in the inner if/else statements. Otherwise in *every* if statement the condition has to step through every property again and again **(**`((Item)list.SelectedItems[0].Tag)...`**)**. Here's how you can do this:
```
private void PlayRecording()
{
if ... | May be you could consider to make some constraints in the UI (the list view/form), so the user won't be able to select items with no streaming data. The five outmost if-statements are all concerned with missing data on an item selected by the user. It will give a better user experience, and you will be able to separate... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | >
> Yeah, sure, I could just get rid of the if's and else's and replace ((Item)list...) with Item item = list... and wrap it all in a single Try{}Catch{}, but I really do hate using Try{}Catch{} unless there is something I am not expecting. And to be honest, using Try{} Catch{} makes me feel lazy and like I'm not doin... | You check if there are one **or more** selected items but the the rest of your code only works on the first selection. I think you should specifically check for a single selected item. I've used `SingleOrDefault` from the `System.Linq` namespace.
I wonder about the value you get from saying the list is empty - surely ... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | >
> Yeah, sure, I could just get rid of the if's and else's and replace ((Item)list...) with Item item = list... and wrap it all in a single Try{}Catch{}, but I really do hate using Try{}Catch{} unless there is something I am not expecting. And to be honest, using Try{} Catch{} makes me feel lazy and like I'm not doin... | I might have missed it in one of the other answers, but in this code:
>
>
> ```
> using (MemoryStream memoryStream = new MemoryStream(recording))
> {
> if (memoryStream != null)
>
> ```
>
>
`memoryStream` will never be null, so the check is redundant. |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | >
> Yeah, sure, I could just get rid of the if's and else's and replace ((Item)list...) with Item item = list... and wrap it all in a single Try{}Catch{}, but I really do hate using Try{}Catch{} unless there is something I am not expecting. And to be honest, using Try{} Catch{} makes me feel lazy and like I'm not doin... | May be you could consider to make some constraints in the UI (the list view/form), so the user won't be able to select items with no streaming data. The five outmost if-statements are all concerned with missing data on an item selected by the user. It will give a better user experience, and you will be able to separate... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | You check if there are one **or more** selected items but the the rest of your code only works on the first selection. I think you should specifically check for a single selected item. I've used `SingleOrDefault` from the `System.Linq` namespace.
I wonder about the value you get from saying the list is empty - surely ... | May be you could consider to make some constraints in the UI (the list view/form), so the user won't be able to select items with no streaming data. The five outmost if-statements are all concerned with missing data on an item selected by the user. It will give a better user experience, and you will be able to separate... |
90,616 | I populate a ListView with Items. Each Item has data attached to its `.Tag` property.
Over time, I have needed to handle many cases where something would be null or missing or corrupt or whatever.
And so was born this beast:
```
private void PlayRecording()
{
if (list.Items.Count >= 1)
{
if (list.Sel... | 2015/05/13 | [
"https://codereview.stackexchange.com/questions/90616",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/73475/"
] | I might have missed it in one of the other answers, but in this code:
>
>
> ```
> using (MemoryStream memoryStream = new MemoryStream(recording))
> {
> if (memoryStream != null)
>
> ```
>
>
`memoryStream` will never be null, so the check is redundant. | May be you could consider to make some constraints in the UI (the list view/form), so the user won't be able to select items with no streaming data. The five outmost if-statements are all concerned with missing data on an item selected by the user. It will give a better user experience, and you will be able to separate... |
7,804,698 | I want sql script of postgres 9 database schema which is not on local server. I tried pg\_dump command on sql editor of pgAdmin and its not working there. I m not sure where to run that command. Please assist me with the same....
Thanks.. | 2011/10/18 | [
"https://Stackoverflow.com/questions/7804698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/674699/"
] | [`pg_dump`](http://www.postgresql.org/docs/8.4/static/app-pgdump.html) is a command line utility; it isn't SQL, so it won't work in pgAdmin or anywhere else that executes SQL.
[`pgAdmin`](http://www.pgadmin.org/) however does have a facility to do what you want:
1. Right-click on the database you want to export
2. Se... | You can also use pgAdmin tool to generate or take plain text Database Backup.
You can generate plain text backup for data or schema only.
I have shared few screen shots, please visit **[this blog](http://www.dbrnd.com/2016/09/postgresql-generate-full-database-script-using-pgadmin-tool-schema-data-script-plain-text-b... |
10,529,825 | I know that binding to CLR properties is slower than INotifyPropertyChanged.
But if my View Model does not change any of its property after it has been created then will it give me any performance gain if I provide empty implementation of INotifyPropertyChanged in my View Model?
Thanks. | 2012/05/10 | [
"https://Stackoverflow.com/questions/10529825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366141/"
] | It won't give you any performance benefits implementing this if you are not using it.
If the properties are only being set at initialisation you can change your binding mode to OneTime this should reduce the overhead.
Also this is a great page to checkout for databinding performance
<http://msdn.microsoft.com/en-u... | be aware that you set the **Mode=OneTime for all your bindings**. otherwise you can run into some memoryleak problems. see this [post](http://code.logos.com/blog/2008/10/detecting_bindings_that_should_be_onetime.html). |
10,529,825 | I know that binding to CLR properties is slower than INotifyPropertyChanged.
But if my View Model does not change any of its property after it has been created then will it give me any performance gain if I provide empty implementation of INotifyPropertyChanged in my View Model?
Thanks. | 2012/05/10 | [
"https://Stackoverflow.com/questions/10529825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366141/"
] | It won't give you any performance benefits implementing this if you are not using it.
If the properties are only being set at initialisation you can change your binding mode to OneTime this should reduce the overhead.
Also this is a great page to checkout for databinding performance
<http://msdn.microsoft.com/en-u... | Use Binding Mode=OneTime or implement INotifyPropertyChanged interface.
Otherwise you will have memory leak. See <http://support.microsoft.com/kb/938416>. |
10,529,825 | I know that binding to CLR properties is slower than INotifyPropertyChanged.
But if my View Model does not change any of its property after it has been created then will it give me any performance gain if I provide empty implementation of INotifyPropertyChanged in my View Model?
Thanks. | 2012/05/10 | [
"https://Stackoverflow.com/questions/10529825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366141/"
] | Use Binding Mode=OneTime or implement INotifyPropertyChanged interface.
Otherwise you will have memory leak. See <http://support.microsoft.com/kb/938416>. | be aware that you set the **Mode=OneTime for all your bindings**. otherwise you can run into some memoryleak problems. see this [post](http://code.logos.com/blog/2008/10/detecting_bindings_that_should_be_onetime.html). |
16,031,515 | Trying to setup jenkins but my builds fails with:
```
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
```
If I manually run "ant test" on the machine it works just fine and the JAVA\_HOME is set t... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16031515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | The problem was this, I had forgot to check the box "Restrict where this project can be run" in the project configuration. Thus the testing tried to execute on "master" where JAVA\_HOME was not the same as expected on the build executor I intended to run it on. Thus where I tested and where it actually ran was differen... | For me the options above did not help, solved by creating a link to what's asked:
```
sudo ln -s ${actual_java_location} /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
```
actual\_java\_location can be read by this:
```
readlink -f $(which java)
``` |
16,031,515 | Trying to setup jenkins but my builds fails with:
```
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
```
If I manually run "ant test" on the machine it works just fine and the JAVA\_HOME is set t... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16031515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | The problem was this, I had forgot to check the box "Restrict where this project can be run" in the project configuration. Thus the testing tried to execute on "master" where JAVA\_HOME was not the same as expected on the build executor I intended to run it on. Thus where I tested and where it actually ran was differen... | Set `JAVA_HOME` in your Jenkins system config in Jenkins 2.107.1.
open your jenkins, e.g. <http://192.168.1.12:9090>, then add `/configure` to the url,
that is `http://192.168.1.12:9090/configure`, then you can find like next:
[](https://i.stack.img... |
16,031,515 | Trying to setup jenkins but my builds fails with:
```
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
```
If I manually run "ant test" on the machine it works just fine and the JAVA\_HOME is set t... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16031515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | For others, I had to add the `PATH` `/usr/bin/` to my PATH variable within Jenkins. (Find your correct path using `which java`).
Jenkins > `Manage Jenkins` > `Configure System`
Add an `Environment Variable` >>
`e.g:`
Name: `PATH`
Value: `/usr/local/bin/:/usr/bin/`
Screenshot
----------
![enter image descriptio... | For me the options above did not help, solved by creating a link to what's asked:
```
sudo ln -s ${actual_java_location} /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
```
actual\_java\_location can be read by this:
```
readlink -f $(which java)
``` |
16,031,515 | Trying to setup jenkins but my builds fails with:
```
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
```
If I manually run "ant test" on the machine it works just fine and the JAVA\_HOME is set t... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16031515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | For others, I had to add the `PATH` `/usr/bin/` to my PATH variable within Jenkins. (Find your correct path using `which java`).
Jenkins > `Manage Jenkins` > `Configure System`
Add an `Environment Variable` >>
`e.g:`
Name: `PATH`
Value: `/usr/local/bin/:/usr/bin/`
Screenshot
----------
](https://i.stack.img... |
16,031,515 | Trying to setup jenkins but my builds fails with:
```
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
```
If I manually run "ant test" on the machine it works just fine and the JAVA\_HOME is set t... | 2013/04/16 | [
"https://Stackoverflow.com/questions/16031515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | Set `JAVA_HOME` in your Jenkins system config in Jenkins 2.107.1.
open your jenkins, e.g. <http://192.168.1.12:9090>, then add `/configure` to the url,
that is `http://192.168.1.12:9090/configure`, then you can find like next:
[](https://i.stack.img... | For me the options above did not help, solved by creating a link to what's asked:
```
sudo ln -s ${actual_java_location} /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
```
actual\_java\_location can be read by this:
```
readlink -f $(which java)
``` |
73,374,715 | I want to get the Default value of **OnlineAvailability** as **True**. By default, all Doctors will have all Slot Timings Available.
If I give the JSON Body data in **Postman** and **POST** the data:
>
> <http://127.0.0.1:8000/online>
>
>
>
```
{
"OnlineTimeSlot": "18:30"
}
```
Here, OnlineAvailability is ... | 2022/08/16 | [
"https://Stackoverflow.com/questions/73374715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16332780/"
] | Just a small change in the code mentioned by [nstvnsn](https://stackoverflow.com/users/11620108/nstvnsn),
Flask-RESTPlus is no longer being maintained.
So, instead, we can use flask\_restx.
```
from flask_restx import inputs
parser.add_argument("OnlineAvailability", required=False, type=inputs.boolean)
``` | When you are adding an argument to the parser, you can leave out the type argument for simple primitive types. For boolean, you may need to declare it for wider boolean handling. Different databases handle boolean values differently.
If you look at the docs for sqlite3, which is the engine your app is using, it stores... |
47,945,481 | Using bash on macos I can create COW file clones with `cp -c`. Is there a Python library that provides the same functionality? The copy functions in shutil doesn't seem to mention cloning.
On APFS clones: <https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/APFS_Guide/Features/Features.... | 2017/12/22 | [
"https://Stackoverflow.com/questions/47945481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1220706/"
] | The Python standard library does not support cloning files.
To clone a file using `cp -c` in a subprocess you can use this function:
```
def clonefile(source, dest):
subprocess.check_output(["cp", "-c", source, dest])
``` | Ok, I marked this as a duplicate but didn't know the difference between copying and cloning.
This is the location of the instructions for copying files with as much detail as possible in Python:
<https://docs.python.org/3.6/library/shutil.html>
It starts with the following warning:
**Warning Even the higher-level fil... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.