text:
Q: How to unit test for turning off request validation? I'm new at this TDD thing but making a serious effort, so I'm hoping to get some feedback here.
I created a little web service to minify JavaScript, and everything was nice, with all my tests passing. Then I noticed a bug: if I tried to minify alert('<script>');, it would throw a HttpRequestValidationException.
So that's easy enough to fix. I'll just add [AllowHtml] to my controller. But what would be a good way to unit test that this doesn't happen in the future?
The following was my first thought:
[TestMethod]
public void Minify_DoesntChokeOnHtml()
{
    try
    {
        using (var controller = ServiceLocator.Current.GetInstance<MinifyController>())
        {
            return controller.Minify("alert('<script></script>');");
        }
    }
    catch (HttpRequestValidationException)
    {
        Assert.Fail("Request validation prevented HTML from existing inside the JavaScript.");
    }
}

However, this doesn't work since I am just getting a controller instance and running methods on it, instead of firing up the whole ASP.NET pipeline.
What would be a good unit test for this? Maybe reflector on the controller method to see if the [AllowHtml] attribute is present? That seems very structural, and unlikely to survive a refactoring; something functional might make more sense. Any ideas?

A: You have only two options:
First
Write integration test that hosts MVC in-proc or runs using browser (using Watin for instance) that will cover you scenario.
Second
Write unit test that will check that method is marked with needed attribute.
I would go with the first option.


text:
Q: Simple formula conversion I have this formula $Av = (R1+R2)/R2$ and I convert it like this
\begin{align}
Av = {} & (R_1+R_2)/R_2 \\
R_2\cdot Av = {} & R_1+R_2 \\
R_2\cdot Av-R_1 = {} & R_2 \\
R_2(Av-R_1) = {} & R_2 \\
(R_2(Av-R_1))/R_2 = {} & R_2/R_2
\end{align}
and $R_2/R_2 = 1$
Any idea why this wouldn't work? Do I misplace the paranthesis? It feels it.
Any answers would be greatly appreciated.
Thanks in advance!

A: Assuming you want to make $R_2$ the subject of the formula:$$\begin{align}A_v&=\frac{R_1+R_2}{R_2}\\
\therefore R_2\times A_v&=R_1+R_2\\
\therefore R_2\times A_v-R_2&=R_1\\
\therefore R_2(A_v-1)&=R_1\\
\therefore R_2&=\frac{R_1}{A_v-1}\end{align}$$

redpajama_set_name: RedPajamaStackExchange


text:
Q: Python dataframe group by following values I am looking for the best pythonic way to group the sum of values that follow each other from hour to hour. Example: I have the following Dataframe with the columns 'date' and'rainfall' and I have added an example of the desired result :

        date        rainfall    RE
    31/12/17 23:00  0.88    None
    01/01/18 00:00  0.38    1.26
    01/01/18 01:00  0       None
    01/01/18 02:00  0.22    0.22
    01/01/18 03:00  0       None
    01/01/18 04:00  0       None
    01/01/18 13:00  0       None
    01/01/18 14:00  0       None
    01/01/18 15:00  0.55    0.55
    01/01/18 16:00  0       None
    01/01/18 17:00  1.31    1.31
    01/01/18 18:00  0       None
    01/01/18 19:00  0.49    0.49
    01/01/18 20:00  0       None
    01/01/18 21:00  0       None
    01/01/18 22:00  0       None
    01/01/18 23:00  0       None
    02/01/18 00:00  0.7     None
    02/01/18 01:00  0.22    None
    02/01/18 02:00  0.61    None
    02/01/18 03:00  0.42    1.95
    02/01/18 04:00  0       None
    02/01/18 05:00  1.69    1.69
    02/01/18 06:00  0       None
    02/01/18 07:00  0       None
    02/01/18 08:00  0       None

I hope to be clear,
thanks a lot for your help,
Rémy

A: If I understand correctly, what you want is a rolling sum.
The following will output a Pandas Series of the rolling sums of 'rainfall' over 2 periods
df['rainfall'].rolling(2).sum()

Ofcourse, your DataFrame must stay sorted as you show in your example.
adding it as a part of your DataFrame would be:
df['rainfall_rolling_sum'] = df['rainfall'].rolling(2).sum()

EDIT1:
If you mean you just want to accumulate the rainfall use:
df['rainfall_cumsum'] = df['rainfall'].cumsum()

as the function cumsum() is accumulative sum
EDIT2:
rf_not_zero = df['rainfall'] != 0
df['rainfall_accum'] = df['rainfall'].cumsum()-df['rainfall'].cumsum().where(~df_not_zero).ffill().fillna(0).astype(int)

A: Okey it is not the best, but when you have big dataframes this could be a simple approach. (If it rains at the beginning or at the end, this will be ignored in this example. See Warning)
import pandas as pd
import numpy as np

# generate pseudo dataframe
rng = pd.date_range('1/1/2012', periods=20, freq='H')
rain = np.random.choice([0,0.5,1,2], size=20, p=[0.4,0.2,0.2,0.2])

df = pd.DataFrame()
df['data'] = rng
df['rain'] = rain

# convert rain to boolean
df['is_rain'] = df['rain'] > 0

# shift rain for one slot to recognice if the state has changed
data = list(df['is_rain'].values[0:-1])
shifted = [data[0]]
shifted.extend(data)
df['is_rain_next'] = shifted

# get start and endpoints of rain (the end has to be excluded!
# it is always the next period, when it isn't raining anymore)
df['rain_start'] = df['is_rain'] < df['is_rain_next']
df['rain_end'] = df['is_rain'] > df['is_rain_next']

# this are the starts and ends you can use them for getting the groups from dataframe
df[df['rain_start']].index
df[df['rain_end']].index

Warning: The arrays can have different sizes, thats caused by the unknown state at the end and at the beginning. So check if the first element in rain_end smaller than the first element in rain_start than you can delete it. Also if the last element of rain_start is greater than the last element of rain_end (sound logical i think)


text:
Q: Build Error with TypeScript 3 and Immutable.js 4 Given these versions in package.json:
"typescript": "^3.0.1",
"immutable": "^4.0.0-rc.9"

I simply import setIn in a file (without even using it):
import { setIn } from "immutable"

I get this error from Typescript when I build:
[at-loader] ./node_modules/immutable/dist/immutable-nonambient.d.ts:2381:30
  0:0  error  TS2677: A type predicate's type must be assignable to its parameter's type.

It seems like there is a library conflict, but I can't figure out what that is. Any insight is appreciated.

A: Setting this config in tsconfig.json solves the build issue:
"skipLibCheck": true


text:
Q: How to make Repeater fall particles? Whan you fall in Minecraft, particles appear underneath you. But when you fall on a not-full block, for example a Repeater, you get the particles of the block underneath:

How do I get to have Repeater particles?  Is there any bug making repeater fall particles possible? It seems to me that the fall particles are made from the block texture, not premade, so you could somehow get little parts of repeater textures flying around you.

A: Currently, repeater fall particles are impossible to create by directly falling onto it. However, you can create them by placing a block at the side if the repeater and jumping/falling from a specific height exactly on the side of the block.  Here is a picture of when you do it right:

There are no stone blocks underneath the repeater block and as you can notice because of the red lines in the particles. I'm not directly standing on the repeater because I landed on the side of the full block.

A: I don't think there's such thing in Vanilla Minecraft, however you could have custom resource pack, which texture of any block(stone block for example) replaced with repeater texture and automatically place that(stone) block under the repeater whenever it is placed.

A: Actually, the particles are the same, whether you land on a repeater or not. (i.e. there is no such thing as "repeater particles").
I think you either took the photos at different times, when the particles didn't have enough time to spread out, or you fell from a different height.
Anyone, please correct me if I'm wrong.


text:
Q: C++ prevent program executed manually My Problem is that I have 2 .exe files (MainGUI and it's updater). I only want the update.exe be executed via Main-program and not by Double-Clicking it.
Is there a well-known method to realize this?
My idea is that the Program checks if its executed with argc = 0 and if so it just terminates but you can still open it then with an own argument.

A: I don't know what's well known or not, but anything on the command line is going to be easy to work around; to some extent this all depends on just how determined you are.
1) Parent puts a magic string in the environment, executes the child updater, which expects to find that magic string, refusing to run if not.
2) Child could verify that its parent is the MainGUI executable; there are process helper APIs for that.
3) Parent MainGUI creates a pipe, launches the child with the numeric value of the handle on the command line, then the parent writes some critical data that the updater requires to run (I dunno, actual update content, version info, not sure). If the child updater finds anything out of order, refuses to run.
There are surely other ways, though it's going to be hard to beat somebody who's really determined.


text:
Q: OpenFaaS : Receiving Timeout errors during health check of function Pod Issue:
We have added health check configuration to our function. However pod becomes Unhealthy due to timeout error in liveness and readiness checks and consequently getting restarted.
However if I hit same health check url using CURL or browser it returns correct response.
Health check configuration reference.
We are using Kubernetes HPAv2 for auto-scaling (Reference).
test-function.yml
  test-function:
    lang: quarkus-java-with-fonts
    handler: ./test-function
    image: repo.azurecr.io/test-function:0.1
    labels:
      agentpool: openfaas
      com.openfaas.scale.min: "2"
      com.openfaas.scale.max: "10"
      com.openfaas.scale.factor: 0
    annotations:
     com.openfaas.health.http.path: "/health"
     com.openfaas.health.http.initialDelay: "30s"
    environment:
        secret_name: environment-variables
    secrets:
        - environment-variables
    constraints:
        - agentpool=openfaas
    limits:
      cpu: 1500m
      memory: 1Gi
    requests:
      cpu: 500m
      memory: 500Mi

Error Trace :
Liveness probe failed: Get "http://XX.XXX.XX.XX:8080/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Readiness probe failed: Get "http://XX.XXX.XX.XX:8080/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

Any idea what could be wrong.

A: These errors:
Liveness probe failed: Get "http://XX.XXX.XX.XX:8080/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Readiness probe failed: Get "http://XX.XXX.XX.XX:8080/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

mean that the HTTP request has failed. For the readiness and liveness probe to work properly, this type of request must be successful.
To find out where the problem is, you need to get the pod IP address. Run:
kubectl get pods -o wide

You should see an output similar to this:
NAME                        READY   STATUS    RESTARTS   AGE   IP          NODE                                       NOMINATED NODE   READINESS GATES
<my-pod-name>               1/1     Running   0          25d   10.92.3.4   <my-node-name>                             <none>           1/1

Take your IP and run:
kubectl exec -t <another_pod> -- curl -I <pod's cluster IP>

If you get a 200 response code, it means the endpoint is properly created and configured. Any other answer suggests there is a problem with your image.
See also:

*

*this similar question (with solution) on github

*very similar question on Stack Overflow

*guide how to set up liveness and readiness probes

*this nice article


text:
Q: Training bias weight backpropagation I'm trying to write an XOR solution using neural networks and the sigmoid activation function. (With True=0.9 and False=0.1)
I'm at the backpropagation part now.
The formula I was given for computing weight adjustments is:
delta_weight(l,i,j) = gamma*output(l,i)*error_signal(l,j)

i.e - the weight adjustment for the link between layer 1 (hidden), node 2 and layer 2(output), node 0 is:
delta_weight(1,2,0)

I chose gamma=0.5
Since bias weights are associated with a single node I guessed the weight adjustment formula was:
delta_weight(l,i) = gamma*output(l,i)

My program is not working, clearly my guess was incorrect. Could someone help me along?
Thanks a bunch!
EDIT: CODE
def applyInputs(self, inps):

    for i in range(len(self.layers)-1):
        for n, node in enumerate(self.layers[i+1].nodes):

            ans = 0

            for m, mode in enumerate(self.layers[i].nodes):
                ans += self.links[stringify(i,m,i+1,n)].weight * mode.output

            if node.bias == True:
                ans+= self.links[stringify(-1,-1,i+1,n)].weight

            node.set_output(response(ans))

    return self.layers[len(self.layers)-1].nodes[0].output

def computeErrorSignals(self, out): # 'out' is the output of the entire network (only 1 output node)

    # output node error signal

    output_node = self.layers[len(self.layers)-1].nodes[0]
    fin_err = (out - output_node.output)*output_node.output*(1-output_node.output)
    output_node.set_error(fin_err)

    # hidden node error signals

    for j in range(len(self.layers[1].nodes)):

        hid_node = self.layers[1].nodes[j]
        err = (hid_node.output)*(1-hid_node.output)*self.layers[2].nodes[0].error_signal*self.links[stringify(1,j,2,0)].weight
        hid_node.set_error(err)

def computeWeightAdjustments(self):

    for i in range(len(self.layers)-1):
        for n, node in enumerate(self.layers[i+1].nodes):
            for m, mode in enumerate(self.layers[i].nodes):
                self.links[stringify(i,m,i+1,n)].weight += ((0.5)*self.layers[i+1].nodes[n].error_signal*self.layers[i].nodes[m].output)

            if node.bias == True:
                self.links[stringify(-1,-1,i+1,n)].weight += ((0.5)*self.layers[i].nodes[m].output)


text:
Q: RXjs canceling debounce from source I'm learning Rx so i dont get quiet well some of the mechanics on Rx, what i want to do i can do it easly with callbacks, but i want to understand Rx.
So what i want to do is, debounce a mouse over event 500ms and show a ui interface, and on mouse out hide that interface, so i have this code:
var outStream = Rx.Observable.fromEventPattern(
          function add (h) {
            asset.events.onInputOut.add(function(){
                h('out');
            });
          }
        );

        var overStream = Rx.Observable.fromEventPattern(
          function add (h) {
            asset.events.onInputOver.add(function(e){
                h('over');
            });
          }
        ).debounce(500);

        var source = Rx.Observable.merge(overStream, outStream);

        source.subscribe(function (x) {
            console.log(x);
          });

What i want is something like this:
.
.mouse over fired after 500ms
.mouseout
.
.mouse over
.mouse out fired before 500ms trigger cancel mouse over

I need some directions, thanks in advance.

A: I'd use something like this:
var hoverStream = overStream.flatMapLatest(function() {
  return Rx.Observable.timer(500).takeUntil(outStream).map(function() { return 'hover'; })
});

This says "map each overStream element into an observable that will yield a single element after 500ms, but stop listening if outStream yields an element before it arrives". For this to work properly you'll need to remove the debounce from your overStream (and just keep it as a simple stream of all such events).
You could then merge the values into whatever result stream you wanted.


text:
Q: Solution for inequality equation - "Cannot be solved with the methods available to Reduce" I am trying to solve the following inequality for $v$: $b>e^{\frac{-v}{\alpha}}\cdot \alpha + v$.
(Where I know: $b>0$, $v \in [0, 1]$, and $\alpha >0$).
However the following doesn't work: Reduce[b>E^(-v/a)*a+v, v]. I get the error message "This system cannot be solved with the methods available to Reduce".
Simplify, and Solve doesn't work either.
Could you think of an alternative? Or is it unsolvable?
Thank you.

A: There is unlikely to be a "nice" closed-form solution for this equation, since it involves both transcendental and algebraic expressions for $v$.  However, it can be solved in terms of special functions with a bit of work.
We can make the substitution $v = \alpha x + b$ to rewrite the equation (after some algebra) as
$$
x e^x < - e^{-b/\alpha }.
$$
Now, $x e^x$ is a monotonically increasing function so long as $x > -1$:
Reduce[D[x Exp[x], x] > 0, x]
(* x > -1 *)

Given the provided constraints on $\alpha$, $v$, and $b$, we will always have $x \geq 0$.  This means that $x$ must be less than the solution to the equation $x e^x = - e^{-b/\alpha}$, and Mathematica can solve this in terms of a special function:
Solve[x Exp[x] == - Exp[-b/a], x]
(* {{x -> ProductLog[-E^(-(b/a))]}} *)

Thus, the solution to the inequality will be $x < W(-e^{-b/\alpha})$, where $w$ is the Lambert $W$-function (aka the product-log function.)  In terms of $v$, this then means that
$$
v < b + \alpha W(-e^{-b/\alpha}).
$$


text:
Q: Reading .csv files into Python lists I have a lot of .csv files in a directory and I'd like to open each of them in a loop within Python such that the first .csv is read into list[0] and the second .csv is read into list[1] and so on.
Unfortunately, while my code loops through all of the .csv files, it puts all the .csv files into list[0]. How can I modify my code so that I can achieve my goal above? Many thanks.
John
Here's the code:
def create_data_lists():
i=0
for symbol in symbols:
    with open(symbols[i]+'.csv', 'r') as f:
        print i
        reader = csv.reader(f)
        reader.next()
        for row in reader:
            rowdata.append(row)
    data_by_symbol.append(rowdata)
    i=i+1

A: why not store the readers themselves in a list?
list_of_csv_files = []

for f in filenames:
    list_of_csv_files.append(csv.DictReader(open(f)))

This will store the reader itself in a list, allowing you to later on do something such as:
for row in list_of_csv_files[0]:
    # do some processing on the row

The biggest advantage of this method is taht you can then do stuff like filter columns easily, using methods such as:
one_row = [row["name of column heading"] for row in list_of_csv_files[0]]
two_rows = [[row["name col 2"], row["name col 2"]] for row in list_of_csv_files[0]]

which I suspect would be more helpful to your program than storing pre-read (and thus de-structured) csv files.
but if you really want to have all the CSV files read in and stored in a list, you will need a list of lists, I don't recommend this, it will be very memory intensive:
list_of_csv_files = [[]]

for f in filenames:
    list_of_csv_files.append([row.values() for row in csv.DictReader(open(f))])

A: inside the for loop, near the top, you have to refresh the list rowdata.  otherwise you are adding to that one forever.  have something like rowdata = [] right after print i
def create_data_lists():

    for symbol in symbols:
        with open(symbol+'.csv', 'r') as f:
        print symbol
        rowdata = []
        reader = csv.reader(f)
        reader.next()
        for row in reader:
            rowdata.append(row)
    data_by_symbol.append(rowdata)

EDIT got rid of i, as i am really not using it


text:
Q: What is the most popular C++ gui framework in windows? Nowadays there are many windows applications. Several years ago, MFC may be the most popular gui framework to create windows applications. But I think MFC is too old and doesn't have a good OO design. So here I want to know is there any modern, well designed and widely used C++ gui framework in windows?

A: My company use Qt framework.
Adobe Photoshop (AFAIK) and other popular Windows programs are using it.
Qt is modern, well documented and tested. Just try it and enjoy :)

A: If you need a free portable GUI framework you can use wxWidgets. QT is also a choice, but AFAIK it's not completely free.
So the answer depends on what you want to do with it.

A: There's this post which seems similar to yours.
It states QT as a decent free GUI solution.


text:
Q: Full addresses from nested dictionaries We have data like this
input = {
    'a': 3,
    'b': {'g': {'l': 12}},
    'c': {
        'q': 3,
        'w': {'v': 3},
        'r': 8,
        'g': 4
    },
    'd': 4
}

It is not known in advance how many nesting levels there will be
We need to get the full address to the final value, all points of which are separated by a dot, or another special character
Like this:
a:3
b.g.l: 12
c.q: 3
c.w.v: 3
etc

I tried to solve this problem with a recursive function.
def recursive_parse(data: dict, cache: Optional[list]=None):
    if cache is None:
        cache = []
    for k in data:
        cache.append(k)
        if not isinstance(data[k], dict):
            print(f"{'.'.join(cache) } :{data[k]}")
            cache.clear()
        else:
            recursive_parse(data[k], cache)

But I have problems with "remembering" the previous key of the nested dictionary.
a :3
b.g.l :12
c.q :3
w.v :3
r :8
g :4
d :4

What is the correct algorithm to solve this?

A: Try:
dct = {
    "a": 3,
    "b": {"g": {"l": 12}},
    "c": {"q": 3, "w": {"v": 3}, "r": 8, "g": 4},
    "d": 4,
}

def parse(d, path=None):
    if path is None:
        path = []

    if isinstance(d, dict):
        for k, v in d.items():
            yield from parse(v, path + [k])
    else:
        yield "{}: {}".format(".".join(path), d)

for p in parse(dct):
    print(p)

Prints:
a: 3
b.g.l: 12
c.q: 3
c.w.v: 3
c.r: 8
c.g: 4
d: 4

A: It's probably better to use an explicit stack for this, rather than the Python call stack. Recursion is slow in Python, due to high function call overhead, and the recursion limit is fairly conservative.
def dotted(data):
    result = {}
    stack = list(data.items())
    while stack:
        k0, v0 = stack.pop()
        if isinstance(v0, dict):
            for k1, v1 in v0.items():
                item = ".".join([k0, k1]), v1
                stack.append(item)
        else:
            result[k0] = v0
    return result

Demo:
>>> data
{'a': 3,
 'b': {'g': {'l': 12}},
 'c': {'q': 3, 'w': {'v': 3}, 'r': 8, 'g': 4},
 'd': 4}
>>> for k, v in reversed(dotted(data).items()):
...     print(k, v)
...
a 3
b.g.l 12
c.q 3
c.w.v 3
c.r 8
c.g 4
d 4


text:
Q: Are there special rules for naming and calling Procs? I completed a Ruby challenge on Hacker Rank, but I don't understand why a Proc is able to be called with an abbreviated version of its saved name.
The proc was defined as:
proc_sum_array = proc {|arr| arr.reduce(:+)}

But it was called like this:
proc_sum.call(my_array)

...without the "_array" part of the name proc_sum_array
This confused me, so I changed 'proc_sum.call(my_array)' to 'proc_sum_array.call(my_array)' but then I got the error:
undefined local variable or method `proc_sum_array' for main:Object (NameError)
Did you mean?  proc_sum

So it appears that it is important that the proc is called as proc_sum and not proc_sum_array, as it was named.
def square_of_sum (my_array, proc_square, proc_sum)
    sum = proc_sum.call(my_array) # QUESTION: Why is this proc_sum, and not proc_sum_array ?
    proc_square.call(sum)
end

proc_square_number = proc {|x| x ** 2}
proc_sum_array     = proc {|arr| arr.reduce(:+)} # This is where the proc is defined.
my_array = gets.split().map(&:to_i)

puts square_of_sum(my_array, proc_square_number, proc_sum_array)

I would expect that proc_sum_arry would be called as proc_sum_array.call. Why is this not the case?

A: This is called a parameter. A parameter is kind of like a "hole" that you leave in the definition of a subroutine. When you invoke that subroutine, you "fill" that "hole" with an argument. (This is called "passing an argument".)
Here:
def square_of_sum (my_array, proc_square, proc_sum)
#                                         ↑↑↑↑↑↑↑↑

You define a method named square_of_sum with a couple of parameters. The third one of those parameters is called proc_sum.
Here:
puts square_of_sum(my_array, proc_square_number, proc_sum_array)
#                                                ↑↑↑↑↑↑↑↑↑↑↑↑↑↑

You pass the object that is referenced by the local variable proc_sum_array as an argument to the invocation of the square_of_sum method.
What this means is that inside the body of the method, the object that you passed as an argument will be bound to the parameter (this is called binding an argument to a parameter), i.e. when you dereference the parameter proc_sum inside the body of square_of_sum, it will evaluate to whatever object was passed as an argument.
Note that proc_sum_array is a local variable (you know that it is a local variable because 1) it starts with a lowercase letter and 2) it is not a method). Local variables are called "local" variables because they are local to the scope they are defined in. In this particular case, proc_sum_array is local to the script scope, which means that it doesn't even exist inside the method scope of square_of_sum, so you simply can't refer to it at all!
Note also that this is exactly the same as for every other parameter of square_of_sum: you refer to the object that is passed as an argument for the proc_square parameter as proc_square and not as proc_square_number.

A: Ok, now as you linked actual example, I can answer you.
The reason why it's referred to as proc_sum, not proc_sum_array is because it's how the argument passed into square_of_sum method is named. It's not magical at all. It's similar to:
a = 2
def sqr(b)
  b * b
end
sqr(a)

You see, you define a local variable, but you pass it as b argument in the sqr method, so inside of this method you refer to it as b.


text:
Q: Unable to understand behavior of Future.set_result on futures in another thread I want a class function to pause execution till value of a class variable is changed as requested by the function by another thread. I am new to python asyncio module.
asyncio.Future seem to provide a mechanism for waiting for future value hence I tried following on a toy example:
class RandomReader:
    def __init__(self):
        self.loop = asyncio.get_event_loop()
        self.service = 3
        self.thread = threading.Thread(target=self.reader)
        self.thread.start()
        self.futures: Dict[int, asyncio.Future] = {}

    def reader(self):
        asyncio.set_event_loop(self.loop)
        while self.service != 0:
            k, v = read()
            if k in self.futures:
                if self.futures[k].done():
                    continue

                self.futures[k].set_result(v)
                self.service -= 1

    async def wait(self, v: int):
        self.futures[v] = self.loop.create_future()
        a = await self.futures[v]
        logging.debug("value %d received %f", v, a)
        return v, a

The read function above reads random key and values that potentially match with wait.
Calling function makes calls like below 3 times (RandomReader.service)
    t1 = asyncio.create_task(random_reader.wait(3))
    print(await t1)

I expected self.futures[k].set_result(v) to assign value to a in wait function like documentation of Future object, but the await doesn't actually execute. Though status of futures in self.futures does change to "FINISHED".
Any help with this is really appreciated.

A: Asyncio futures are not thread-safe - nor is any other asyncio API, except where explicitly noted otherwise. To mark a future as done from a different thread, use call_soon_threadsafe:
self.loop.call_soon_threadsafe(self.futures[k].set_result, v)

That call will notify the event loop that something is going on, and will have the event loop set the future's result, immediately noticing it and waking up the awaiting coroutine.
Also note that the call to asyncio.set_event_loop() in reader() does not look correct, since the event loop is in fact not running in reader's thread.


text:
Q: Error while parsing JSON babel failure When I run gulp I get error while parsing JSON:
Syntax Error 'C:\Path\main.js' Error while parsing JSON
at: 98
text: '{\r\n   "development":

"text" is truncated in the command line.  I tried piping the output to a file and that failed because the error did not showup in the file:
Powershell cmd
gulp | Out-File C:\temp.txt -width 120
package.json
{
  "name": "helloreact",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "dependencies": {
    "babel": "^6.5.1",
    "babel-plugin-react-transform": "^2.0.0",
    "babel-preset-react": "^6.3.13",
    "babelify": "^7.2.0",
    "bootstrap": "^3.3.5",
    "flux": "^2.0.3",
    "gulp": "^3.9.0",
    "gulp-concat": "^2.6.0",
    "gulp-connect": "^2.2.0",
    "gulp-eslint": "^1.1.1",
    "gulp-open": "^1.0.0",
    "gulp-sourcemaps": "^1.6.0",
    "jquery": "^2.1.4",
    "jquery-csv": "^0.8.1",
    "lodash": "^4.0.1",
    "object-assign": "^4.0.1",
    "react": "^0.13.3",
    "react-router": "^0.13.3",
    "react-tools": "^0.10.0",
    "react-transform": "0.0.3",
    "reactify": "^1.1.1",
    "redbox-react": "^1.2.2",
    "toastr": "^2.1.0",
    "vinyl-source-stream": "^1.1.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

.babelrc
{
  "env": {
    "development": {
      "plugins": ["react-transform"],
      }
    }
  }
}

My gulp task uses babelify
gulp.task('js', function(){
  browserify(config.paths.mainJs,  { debug: true })
      .transform(babel, {presets: ["react"]})
      .transform(reactify)
      .bundle()
      .on('error', console.error.bind(console))
      .pipe(source('bundle.js'))
      .pipe(sourcemaps.init({ loadMaps: true }))
      .pipe(sourcemaps.write('./'))//TODO: not sure if this syntax is correct
      .pipe(gulp.dest(config.paths.dist + '/scripts'))
      .pipe(connect.reload())
});

A: Try removing the extra comma in your bablerc
{
  "env": {
    "development": {
      "plugins": ["react-transform"]
      }
    }
  }
}

A: my situation is : react + redux project . my origin .babelrc content is

{
  "presets" : ["es2015","react"]
}

i remove "es2015" from presets and webpack worked

A: Changing it to
{ "presets": ["@babel/env"] }

in .babelrc file, fixed it for me.


text:
Q: When to use bash ANSI C style escape, e.g. $'\n' I don't use bash often but I recall in the past to pass a tab or newline on the command line I would have to escape the character using the special $ character before a single quoted string. Like $'\t', $'\n', etc. I had read about quotes and escaping in the bash manual.
What I want to know is when it's appropriate to use an ANSI C style escape. For example I was working with a regex in grep and it appeared I needed an ANSI C style escape for a newline. Then I switched to perl and it seemed I didn't.
Take for example my recent question on stackoverflow about a perl regex that didn't work. Here's the regex I was using:
echo -e -n "ab\r\ncd" | perl -w -e $'binmode STDIN;undef $/;$_ = <>;if(/ab\r\ncd/){print "test"}'

It turns out that is actually incorrect because I gave the string ANSI C style escape by using $. I just don't understand when I'm supposed to prepend the dollar sign and when I'm not.

A: You use $'...' when you want escape sequences to be interpreted by the shell.
$ echo 'a\nb'
a\nb

$ echo $'a\nb'
a
b

In perl, -e option get a string. If you use $'...', the escape sequences in string are interpreted before passing to perl. In your case, \r had gone and never passed to perl.
With $'...':
$ perl -MO=Deparse -we $'binmode STDIN;undef $/;$_ = <>;if(/ab\r\ncd/){print "test"}'
BEGIN { $^W = 1; }
binmode STDIN;
undef $/;
$_ = <ARGV>;
if (/ab\ncd/) {
    print 'test';
}
-e syntax OK

Without it:
$ perl -MO=Deparse -we 'binmode STDIN;undef $/;$_ = <>;if(/ab\r\ncd/){print "test"}'
BEGIN { $^W = 1; }
binmode STDIN;
undef $/;
$_ = <ARGV>;
if (/ab\r\ncd/) {
    print 'test';
}
-e syntax OK

A: $'\n' is basically the same as typing Enter.
So in your Perl example, it turns into*
  if(/ab
cd/)

Which isn't what you wanted.
Reasons I can think of to use $'...':

*

*You want to put a single quote inside a single-quote delimited string, e.g. logger $'Can\'t open file'

*To make non-printable characters clearer, e.g. $'a\tb' rather than 'a<TAB character>b'
(Not sure if \r\n is treated as equivalent to \n or if Perl sees carriage return + newline, but in either case, it's not it what you wanted.)


text:
Q: window.location not replaced but concatenated I have this code:
$(window).ready(function() {
  var url = window.location.href;
  if (url.includes("#/projet/")) {
    projectId = url.substring(url.indexOf("#")+1).split("/").slice(2, 3).toString();
    window.location.href = "projects/" + projectId;
  };
})

I'm redirected but the window.location is not replaced, just concatenated.
For instance, if my URL is localhost:3000/users/212323/dashboard, after the javascript redirection, I get localhost:3000/users/212323/projects/123456 instead of localhost:3000/projects/123456
I don't understand why the href is concatenated and not replaced, do you have an idea?

A: window.location.href = 'someurl' works the same way as clicking that someurl in a <a> tag.
When using a relative path (i.e. without / in the beginning), your browser will concatenate the URL to the existing URL.
Simple fix in your case is to prepend the /:
window.location.href = "/projects/" + projectId;

Note though, that this will cause the site possibly not work anymore if it is moved to another location. That is why many web frameworks use full URLs and some kind of base-url to get the linking correctly.

A: You need to add another / to the beginning of the url, otherwise the browser interprets the url as a relative url to the curent url.
window.location.href = "/projects/" + projectId;

The extra / at the start tells the browser to start from the root url.


text:
Q: What Exactly is Axis of A Solenoid? How does placing a soft Iron Core Along The Axis increase its Strength of Magnetic Field? I have trouble understanding what is meant by axis of solenoid.
According to textbooks placing a soft iron core "along the axis of solenoid" increases the strength of the magnetic field of the solenoid as the soft iron has a high magnetic permeability
Can someone explain how this works ^

A: The axis of a solenoid is its geometrical axis.
As a first approximation, the magnetic field in the region of space "inside" a solenoid is uniform, and equal to
$\mathbf{B} = \mu \dfrac{N}{L} i \, \mathbf{\hat{z}}$,
being:

*

*$\mu$ the magnetic permeability of the medium "inside" the solenoid,

*$\frac{N}{L} = \dfrac{\text{n. windings of the
   solenoid}}{\text{length of the solenoid}}$ the density of windings
per unit length,

*and $i$ the electric current in the wire.

With the same current, if you put a ferromagnetic medium inside the solenoid, the magnitude of the magnetic field increases, since $\mu = \mu_r \mu_0 \gg \mu_0$, with $\mu_0$ the permeability of vacuum as a good approximation of permeability of air, and with relative permeability of order $\mu_r = 10^2 \div 10^5$ for ferromagnetic materials,
$B^{ferro} = \mu_r\mu_0 \dfrac{N}{L} i = \mu_r B^{air} = ( 10^2 \div 10^5 ) \cdot B^{air}$.


text:
Q: How to Install TP-Link TL-WN823N V3 driver on Rasperry Pi 1 A+ without internet abilities? My raspberry pi A1 can't connect to the internet without a dongle. However, the dongle I bought (TP-Link TL-WN823N V3) requires the internet to install its' driver.
https://www.tp-link.com/us/support/download/tl-wn823n/
I've done my best to read the documentation and search around, but it's rather unclear. Can anyone point me to a single file to download, or a set of commands that don't require the internet?

A: Here is how to do it in about five days...maybe.
Go here: http://packages.ubuntu.com/
Select your Ubuntu version, i.e. Jammie, Kinetic, etc. in the drop-down box. Search for bc, dkms and build-essential. Be sure to locate their dependencies and the dependencies of the dependencies. Once you've download about fifteen or so packages on another computer, transfer them with a USB stick or similar to the desktop of your Ubuntu computer. Open a terminal and install them:
cd ~/Desktop
sudo dpkg -i *.deb

It may complain that a package is missing a dependency. If so, download that and add it to the desktop and try again.
Write many posts to tell old Chili how you're stuck. Rinse and repeat.
Once that's all done, get this: https://github.com/morrownr/88x2bu-20210702/archive/refs/heads/main.zip Download it and then transfer it to your desktop, too. Right-click it and select 'Extract Here.' Now, back to the terminal.
cd ~/Desktop/88x2bu-20210702-main
sudo ./install-driver.sh

Reboot. Your wireless should now be working.


text:
Q: jHipster production build error. Failed to run task: 'yarn run webpack:prod' failed I've generated monolithic application using jHipster 4.9.0 and when I run mvn -Pprod package the build failed with the following errors.
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:yarn (webpack build prod) on project itob-p: Failed to run task: 'yarn run webpack:prod' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

I've also reinstalled Nodejs containing npm package 5.3.0 and also deleted the folder node_modules and re install npm on the generated folder but got no success. I'm stuck and unable to identify the problem if i'm doing something wrong please point it out.
What is done so far :
1) Operating system = Windows 7 64bit
2) generated source code of nonpolitical application [yo jhipster]
3) Database postgrase
4) OAuth2
5) mvn -Pprod package
6) successfully deploys on Pivotal Cloud Foundry in [Dev] mode
Note this issue occurs while making build for production.
here is the complete stack of this command.
I'm unable to identify and understand the problem. Please help me and if you have any kind of suggestion please share.
Here is the complete stack of error.
[INFO]
[INFO] --- frontend-maven-plugin:1.6:yarn (webpack build prod) @ itob-p ---
[INFO] Running 'yarn run webpack:prod' in C:\Users\hassnan.ali\Desktop\del.me\postgres2
[INFO] yarn run v1.1.0
[INFO] $ yarn run cleanup && yarn run webpack:prod:main && yarn run clean-www
[ERROR] warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarde
d as-is to the scripts.
[INFO] Starting compilation using the angular compiler.
[ERROR] (node:7220) DeprecationWarning: Chunk.modules is deprecated. Use     Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead.
[INFO] Angular compilation done, starting webpack bundling.
[ERROR] TypeError: Cannot read property 'flags' of undefined
[ERROR]     at checkUnreachable     (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\typescrip
t.js:20770:30)
[ERROR]     at bindChildrenWorker     (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-    wrapped\node_modules\typescript\lib\typescript.js:19014:17)
[ERROR]     at bindChildren (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\typescript.js
:18969:17)
[ERROR]     at bind (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\typescript.js:20199:2
1)
[ERROR]     at bindSourceFile (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\typescript.
js:18588:17)
[ERROR]     at Object.bindSourceFile (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\type
script.js:18539:9)
[ERROR]     at initializeTypeChecker (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\type
script.js:44253:20)
[ERROR]     at Object.createTypeChecker (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\lib\t
ypescript.js:23058:9)
[ERROR]     at getDiagnosticsProducingTypeChecker (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typesc
ript\lib\typescript.js:70194:93)
[ERROR]     at Object.getGlobalDiagnostics (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\node_modules\typescript\li
b\typescript.js:70570:53)
[ERROR]     at Tsc.typeCheck (C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-    wrapped\src\tsc.js:166:23)
[ERROR]     at C:\Users\hassnan.ali\Desktop\del.me\postgres2\node_modules\@angular\tsc-wrapped\src\main.js:122:23
[ERROR]     at process._tickCallback (internal/process/next_tick.js:109:7)
[ERROR] error Command failed with exit code 1.
[ERROR] error Command failed with exit code 1.
[ERROR] error Command failed with exit code 1.
[INFO] info Visit https://yarnpkg.com/en/docs/cli/run for documentation     about this command.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13:43 min
[INFO] Finished at: 2017-12-13T13:08:13+05:00
[INFO] Final Memory: 30M/208M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:yarn (webpack build prod) on project itob-p: Failed to run task: 'yarn ru
n webpack:prod' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

A: Just run yarn and if it is needed, update it. And try again. It works for me.


text:
Q: Regex Pattern for EMail I searched a lot for a regex pattern which is convenient for me. I couldn't find any.
Here is my conditions,
1. email should not contain any space or special characters(excep @ and .)
2. email should not start with dot(.) or should not end with .(before @ symbot)
3. two dots should not come near.
4. @ symbol should not repeat.

Here some valid and invalid email IDS,
firstname@gmail.com -- valid
firstname.@gmail.com -- invalid(dot and @ should not come closer)
firstname..lastname@gmail.com --invlid(two dots should not come closer)
firstname#lastname@gmail.com -- invalid(should not contain any special characters appart @ and .)
frist1991@gmail.com -- valid
first name@gmai.com -- invalie( should not allow any spaces)
.fristname@gmail.com --invalid(should not start with .)

I found lot of regex pattern for email. but didn't satisfy my conditions
Thanks in advance,

A: This would work:
^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$

https://regex101.com/r/nen2SZ/1


text:
Q: Pokemon Go Evolving a Pokemon vs Catching it in the Wild Is there a difference if I were to evolve a pidgey into a pidgeot vs catching a pidgeot in the wild?

A: There are multiple.
The biggest one is that pokemon you evolve tend to have a higher CP than an already evolved pokemon in the wild but their maximum CP will always be the same. An exception would be if you evolved a pokemon when you're at level 5 but then you catch the same pokemon at level 10. Because your maximum CP for every pokemon is higher with trainer levels the pokemon you find also have higher CP.
The other reason is that you gain a fair amount of experience from evolving a pokemon. It is 500 experience per evolution and an extra 500 if the evolved pokemon is not something you have caught before.

A: I caught a Pigeoto and evolved a Pidgey but the wild one was still stronger; plus the wild one has better attacks. I do not understand it. Might as well evolve the wild Pigeoto at some point and just power up to max CP.


text:
Q: Error in std::list::sort with custom comparator (expected primary-expression before ')' token) The title is the main question. The exact scenario (I am 'using namespace std;'):
void SubstringMiner::sortByOccurrence(list<Substring *> & substring_list) {
   list::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator);
}

This is the comparator definition:
class Substring {
    // ...
    class OccurrenceComparator {
        public:
            bool operator() (Substring * a, Substring *b);
    }
};

Implementation of the comparator is intuitive and trivial. I am also using a very similar comparator in a std::set and it works fine. When I add the sortByOccurrence() funcion it gives me the error in the title.
What should I do?
EDIT: I'm now trying to pass Substring::OccurrenceComparator() as the comparator, and am getting the following error:
g++ -Wall -g -c substring_miner.cpp -o obj/subtring_miner.o
substring_miner.cpp: In function 'void SubstringMiner::sortByOccurrence(std::list<Substring*, std::allocator<Substring*> >&)':
substring_miner.cpp:113: error: no matching function for call to 'std::list<Substring*, std::allocator<Substring*> >::sort(std::_List_iterator<Substring*>, std::_List_iterator<Substring*>, Substring::OccurrenceComparator)'
/usr/include/c++/4.3/bits/list.tcc:303: note: candidates are: void std::list<_Tp, _Alloc>::sort() [with _Tp = Substring*, _Alloc = std::allocator<Substring*>]
make: *** [substring_miner] Error 1

My code line is now:
list<Substring *>::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator());

I can't remove the template or it gives me an error saying that template parameters were wrong.

A: You're passing a class as an argument to a function. You cannot do that - you have to create an instance of the class, and pass that:
substring_list.sort(Substring::OccurrenceComparator());

Note the extra parentheses after OccurenceComparator above that create a temporary object of the class using default constructor.
Another mistake is that you're calling list::sort as a static function on class std::list. It's not static, so you need to call it as a member function on substring_list.

A: list member sort is a non-static function so must be called on a list instance.
substring_list.sort( Substring::OccurrenceComparator() );

Edit: You can't use the free function std::sort as it requires random access iterators which list iterators are not.

A: The original problem was already solved by Pavel Minaev above.
But some extra notes.
The operator() should probably be const (as well as the parameters).
For simple classes like this it is easier to just make them structures.
struct OccurrenceComparator
{
    bool operator() (Substring const* a, Substring const* b)  const;
};

Note the comparison must provide a strict weak ordering:

template<class BinaryPredicate>
  void sort(BinaryPredicate comp);
Comp must be a comparison function that induces a strict weak ordering (as defined in the LessThan Comparable requirements on objects of type T. This function sorts the list *this according to Comp. The sort is stable, that is, the relative order of equivalent elements is preserved. All iterators remain valid and continue to point to the same elements. [6] The number of comparisons is approximately N log N, where N is the list's size.


text:
Q: I can't get Python logging module to write to the log file from different module I have a project that consists of several modules. There is main module (main.py) that creates a TK GUI and loads the data. It passes this data to process.py which processes the data using functions from checks.py.  I am trying to implement logging for all the modules to log to a file.  In the main.py log messages are written to the log file but in the other modules they are only written to the console.  I assume its to do with the import module line executing part of the code before the code in main.py has set up the logger, but i can't work out how to arrange it to avoid that. It seems like a reasonably common question on Stackoverflow, but i couldn't get the other answers to work for me. I am sure I am not missing much. Simplified code is shown below:
Moving the logging code inside and outside of various functions in the modules. The code I used to start me off is the code from Corey Schaffer's Youtube channel.
Main.py
import logging
from process import process_data

def main():

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s')
    templogfile = tempfile.gettempdir() + '\\' + 'TST_HA_Debug.log'
    file_handler = logging.FileHandler(templogfile)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(formatter)

    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.addHandler(stream_handler)

    logger.debug('Logging has started') # This gets written to the file

    process_data(data_object) # call process_data in process.py

process.py
import logging

def process_data(data):

    logger = logging.getLogger(__name__)

    logger.debug('This message is logged by process') #This wont get written to the log file but get written to the console

   #do some stuff with data here and log some msgs

   return

Main.py will write to the log file, process.py will only write to the console.

A: I've rewritten your scripts a little so that this code can stand alone. If I changed this too much let me know and I can revisit it.  These two files are an example of having it log to file.  Note my comments:
##  main.py

import logging
from process import process_data
import os

def main():
    # Give this logger a name
    logger = logging.getLogger("Example")
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter('%(asctime)s:%(name)s:%(message)s')
    # I changed this to the same directory, for convenience
    templogfile = os.path.join(os.getcwd(), 'TST_HA_Debug.log')
    file_handler = logging.FileHandler(templogfile)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(formatter)

    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.addHandler(stream_handler)

    logging.getLogger("Example").debug('Logging has started') # This still gets written to the file

    process_data() # call process_data in process.py

if __name__ == '__main__':
    main()

##  process.py

import logging

def process_data(data=None):

    # make sure to grab the correct logger
    logger = logging.getLogger("Example")

    logger.debug('This message is logged by process') # This does get logged to file now

   #do some stuff with data here and log some msgs

    return

Why does this work?  Because the module-level functions use the default root logger, which is not the one you've configured. For more details on this see these docs.  There is a similar question that goes more into depth here.
By getting the configured logger before you start logging, you are able to log to the right configuration.  Hope this helps!


text:
Q: How can i update if MYSQL [BLOB] is NULL How can i update if Image field in MYSQL is empty or no image is uploaded?
I tried this but doesnt update anything.
     UPDATE `db`.`ts126` SET `Image` = LOAD_FILE('C:\Users\user\Desktop\aa\bb\cc\placeholder.png') WHERE Image=""

Also i tried
    UPDATE `db`.`ts126`
   SET `Image` = 'C:\Users\user\Desktop\aa\bb\cc\placeholder.png'
 WHERE Image="" OR Image IS NULL

Which is without LOAD_FILE in this case it updates the images [BLOB - 64 B] but When i display the image using PHP code Nothing shows up

A: Try:
UPDATE `db`.`ts126`
  SET `Image` = LOAD_FILE('C:\Users\user\Desktop\aa\bb\cc\placeholder.png')
WHERE Image="" OR Image IS NULL


text:
Q: How to trigger change detection when array object is modified? In my angular4 app i have a component with a *ngFor directive based in a array:
 <div *ngFor="let person of persons">
   {{person.name}}
   {{person.car}}
 </div>

In the other part of the component im able to delete a car, so in the subscribe of the deleteCar() method i update the persons array to:
 deleteCar(car) {
   this.carService.deleteCar(car).subscribe(() =>  {
   this.persons.filter(obj => obj.car == car.name)
               .forEach(i => i.car = null);
   }
 }

The problem is that the *ngFor loop is not triggered when i modify a existing person object in the persons array. How to solve this?

A: The best way to achieve this is to have a behavior subject in a service and accesss it in you component.
So your service class may look like this
@Injectable()
export class PersonService {

private persons=  new BehaviorSubject<any[]>([]);
public persons$ = this.persons.asObservable();//--> You can access this in your component

constructor() {
   //set the persons array here;
}

function deleteCar()//todo

}

On the component
constructor(private personService: PersonService) {

}

ngOnInit() {
    this.persons= this.personService.persons$//Dont forget to do add the assync pipe or subscribe
}

delete(car){
    this.personService.deleteCar(car);
}

This Should work.
More info in -> https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service

A: I solve it by destructuring the array. I'm not sure it's the best way to do it.
this.persons = [...this.persons];

As far as it will change the reference of the array, angular will notice that the array has been updated.


text:
Q: Compare three arrays in bash, diff and identical values This question refers to the answered question:
Compare/Difference of two arrays in bash
Let's take two arrays:
Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" "key13" )
Array2=( "key1" "key2" "key3" "key4" "key5" "key6" "key11" "key12" "key13" )

Symetrical Differences between arrays:
Array3=(`echo ${Array1[@]} ${Array2[@]} | tr ' ' '\n' | sort | uniq -u `)

Array3 values:
echo $Array3
key10
key11
key12
key7
key8
key9

Values only in Array1:
echo ${Array1[@]} ${Array3[@]} | tr ' ' '\n' | sort | uniq -D | uniq
key10
key7
key8
key9

Values only in Array2
echo ${Array2[@]} ${Array3[@]} | tr ' ' '\n' | sort | uniq -D | uniq
key11
key12

My question, how can we get values that are in Array1 & Array2 but not in Array3 (identical)?
Expected result:
key1
key13
key2
key3
key4
key5
key6

Thanks for your help.

A: OK after few test, it seems the answer I was looking for was just:
echo ${Array1[@]} ${Array2[@]} | tr ' ' '\n' | sort | uniq -D | uniq
key1
key13
key2
key3
key4
key5
key6

A: You can achieve this by using :
#!/bin/bash

Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" "key13" )
Array2=( "key1" "key2" "key3" "key4" "key5" "key6" "key11" "key12" "key13" )

Array3=(`echo ${Array1[@]} ${Array2[@]} | tr ' ' '\n' | sort | uniq -u `)

intersections=()

for item1 in "${Array1[@]}"; do
    for item2 in "${Array2[@]}"; do
        for item3 in "${Array3[@]}"; do
            if [[ $item1 == "$item2" && $item1 != "$item3" ]]; then
                    intersections+=( "$item1" )
                    break
            fi
        done
    done
done

printf '%s\n' "${intersections[@]}"

Output :
key1
key2
key3
key4
key5
key6
key13


text:
Q: Serializing JSON with DataContractJsonSerializer in C# gives trailing null characters (\0) When serializing a JSON I get trailing null characters which makes my unit test fail. The serializer looks like this:
public static string SerializeJSON<T>(T ObjectToSerialize)
    {
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(ObjectToSerialize.GetType());

        using (MemoryStream memoryStream = new MemoryStream())
        {
            using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(memoryStream, Encoding.UTF8, false, true))
            {
                serializer.WriteObject(jsonWriter, ObjectToSerialize);
            }
            return Encoding.UTF8.GetString(memoryStream.GetBuffer());
        }
    }

I have written a unit test for it that looks like this:
[TestMethod]
    public void SerializeJSON()
    {
        string testJSON = File.ReadAllText(@"Util\\TestCurrency.json");
        Currency currency = StaticExamples.ccy1;
        string json = SerializeUtil.SerializeJSON(currency);
        Assert.AreEqual(testJSON, json);
    }

Which compares the serialized currency to the file example, they should be identical. But the test fails saying:
Message: Assert.AreEqual failed. Expected:<{
"code": "USD",
"currencyId": 1,
"name": "Dollar",
"status": "Active"
}>.
Actual:<{
"code": "USD",
"currencyId": 1,
"name": "Dollar",
"status": "Active"
}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>.

The trailing characters are null characters from what I understand. Any idea of why they appear? It works to Deserialize this JSON again but my test still fails.
This is tha class being serialized:
public class Currency
{
    public int currencyId { get; set; }
    public string code { get; set; }
    public string name { get; set; }
    public string status { get; set; }
}

EDIT with answer
Thanks to @DavidG I changed the way I converted the stream to a string and it works know. This is the generic serializer code for anyone who wants it:
public static string SerializeJSON<T>(T ObjectToSerialize)
    {
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(ObjectToSerialize.GetType());

        using (MemoryStream memoryStream = new MemoryStream())
        {
            using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(memoryStream, Encoding.UTF8, false, true))
            {
                serializer.WriteObject(jsonWriter, ObjectToSerialize);
            }
            memoryStream.Position = 0;
            return new StreamReader(memoryStream).ReadToEnd();
        }
    }


text:
Q: Button to open another activity I know this may seem simple, and I've tried everything mentioned in other threads, but for some reason it's not working.
I simply want the button on the phind.xml to open the activity_alerts.xml and vice versa, but for some reason it's not working. I guess I'm missing something simple.
phind.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/phind"
    android:background="#ff0000">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Alert Message!"
        android:gravity="center"
        android:textSize="36sp"
        android:textColor="@color/black"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/disable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Disable alert"/>

</LinearLayout>

Phind.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.phinder.phinder.R;

public class Phind extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phind);

        Button button = (Button) findViewById(R.id.disable);
        button.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {

                Intent i = new Intent(getApplicationContext(),ActivityAlerts.class);
                startActivity(i);
            }

        });
    }
}

activity_alerts.xml:
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_gray"
        android:orientation="vertical"
        tools:context="com.phinder.phinder.Menu.Alerts">

        <Button
            android:id="@+id/test"
            android:layout_height="wrap_content"
            android:text="test your alert"
            android:height="24dp"
            android:layout_width="match_parent"/>

    </LinearLayout>

ActivityAlerts.java:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.phinder.phinder.R;

public class ActivityAlerts extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alerts);

        Button button = (Button) findViewById(R.id.test);
        button.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {

                Intent i = new Intent(getApplicationContext(),Phind.class);
                startActivity(i);
            }

        });
    }
}

Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.phinder.phinder">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Menu.About"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Menu.Alerts"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".Menu.Pin"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name=".Menu.Help"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Phind"
            android:label="@string/app_name" />
        <activity
            android:name=".ActivityAlerts"
            android:label="@string/app_name"/>

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    </application>

</manifest>

I removed some of the excess code in the activity_alerts.xml to make it easier to find the button
Logcat starting from when I open the activity_alerts.xml and ending at when I click on the button that should take me to the phind.xml (nothing happens after that, so the report ends):
12-18 15:03:10.704 9207-9207/com.phinder.phinder I/Timeline: Timeline: Activity_launch_request id:com.phinder.phinder time:53000744
12-18 15:03:10.749 9207-9207/com.phinder.phinder D/ViewRootImpl: #3 mView = null
12-18 15:03:10.799 9207-9207/com.phinder.phinder D/SecWifiDisplayUtil: Metadata value : none
12-18 15:03:10.799 9207-9207/com.phinder.phinder D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{e76390 I.E...... R.....ID 0,0-0,0}
12-18 15:03:10.824 9207-9261/com.phinder.phinder D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
12-18 15:03:10.839 9207-9207/com.phinder.phinder W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
12-18 15:03:10.854 9207-9207/com.phinder.phinder D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
12-18 15:03:10.884 9207-9207/com.phinder.phinder I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3371e53 time:53000921
12-18 15:03:10.904 9207-9207/com.phinder.phinder V/ActivityThread: updateVisibility : ActivityRecord{e144243 token=android.os.BinderProxy@62090c2 {com.phinder.phinder/com.phinder.phinder.MainActivity}} show : false
12-18 15:03:13.769 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-18 15:03:13.769 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-18 15:03:14.379 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-18 15:03:14.379 9207-9257/com.phinder.phinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-18 15:03:16.799 9207-9207/com.phinder.phinder D/ViewRootImpl: ViewPostImeInputStage processPointer 0
12-18 15:03:16.909 9207-9207/com.phinder.phinder D/ViewRootImpl: ViewPostImeInputStage processPointer 1

A: Try change your intent to: in Phind.java
Intent i = new Intent(ActivityAlerts.this, Phind.class);
ActivityAlerts.this.startActivity(i);
finish();

also declare your activity in menifest:
<activity android:name=".ActivityAlerts" android:label="@string/app_name">
</activity>

In phind.xml use
tools:context=".Phind"

and In activity_alerts.xml use
tools:context=".ActivityAlerts"


text:
Q: Grep a word and need to replace the above line for that particular tag I have HTML code as shown below:

version2
FAIL

version1
FAIL

version6
PASS

Whenever I see the keyword FAIL in  tags then I need to replace the above code as below. For PASS no need to do anything.

version2
FAIL

version1
FAIL

version6
PASS

Using sed I can search for a word and I can replace it by using below command:
sed -i 's/
/
/g'

But in my case first I need to search for FAIL keyword then that particular
 tag needs to be replaced.

A: Using GNU awk, to define a multi-character Record Separator:
awk -v RS='
' 'NR > 1 { rs = /FAIL/ ? "
" : RS } { printf "%s%s", rs, $0 }' file

This uses the opening
 tag as the record separator and replaces it if /FAIL/ matches any part of the record.
We use NR > 1 so that this only starts happening after the first record, to avoid getting an extra
 at the start of the output. For the first record (everything up to the first
 in the input), rs is left unset, so will evaluate to an empty string when printed.

A: awk 'BEGIN {
             RS="
|
"
           }
$0 ~ /FAIL/ {
             print "
"$0"
"
            }
$0 ~ /PASS/ {
             print "
"$0"
"
            }
!/PASS/ && !/FAIL/ {
             print $0
            }' html

One liner:
awk 'BEGIN { RS="
|
" } $0 ~ /FAIL/ { print "
"$0"
" } $0 ~ /PASS/ { print "
"$0"
" } !/PASS/ && !/FAIL/ { print $0 }' html

Using awk with a file named html, set the record separator to opening or closing tr tags, Then search the record ($0) for FAIL printing the tr tags with $0 accordingly. Do the same for PASS.

A: As per your Samples, Can you please try the following one.
tac file | awk '/FAIL<\/td>/{y=1} y && /^
/{print "
";next} {print}' | tac

I am using tac and awk solution for the same, where tac will read the file in reverse order and awk will process the records as per given condition. Further to this, passing awk cmd output to tac to get the records in desired order

A: Below is a solution which buffers the input. It also handles indentation and lets other HTML elements pass through.
# if current line starts a table row, save it in tr
$0 ~ "
" { tr = $0; next }

# if we are inside a table row, append it to tr
$0 !~ "
" && tr != "" { tr = tr "\n" $0; next }

# if current line ends a table row, insert bgcolor if needed
# and print the previously saved tr variable
$0 ~ "
" {
    if (index(tr, "FAIL	") > 0) {
        sub("
", "
", tr)
    }
    print tr "\n" $0
    tr = ""
    next
}

# when current line is not inside a table row just print it
{ print }

If the script is stored in highlight-failing.awk and the HTML in versions.html, the command can be invoked with
awk -f highlight-failing.awk versions.html


text:
Q: What is the difference between normal Select query and a Select query inside Common Table Expression(CTE)? I'm having a table 'Products' and if Execute this query
SELECT TOP 1000 [ProductID]
      ,[ProductDesc]
      ,[ManufacturingDate]
      ,[ExpiryDate]
      ,[Price]
  FROM [TestSat].[dbo].[Products]

I got the output:

and If I use this select query:
SELECT ProductDesc,Price
  FROM [Products]
  WHERE Price>20.00

I got this output:

If I use CTE-Select like this:
 ;WITH ProductsCTE(ProdName,Price) AS
( SELECT ProductDesc,Price
  FROM [Products]
  WHERE Price>20.00
)

I got this output:

The only difference I found between this simple Select Query as well as CTE Select query is the Column name (ProductDesc as ProdName).
Does it is the only difference between normal Select query as well as CTE Select query?


text:
Q: Show filtered data with angular I'm a very begginer in AngularJS(1.6) and I need to filter some results from a selected option.
I have to filter cities from states, and until there i'm doing fine. But then I need to filter and show the stores in this city on a list. Does anyone knows how to do It?
My code:
    <!DOCTYPE html>

    <select id="state" ng-model="stateSrc" ng-options="state for (state, city) in states" ng-change="GetSelectedState()">
        <option value=''>State</option>
    </select>
    <select id="city" ng-model="citySrc" ng-options="city for (city,store) in stateSrc" ng-change="GetSelectedCity()" ng-disabled="!stateSrc">
        <option value=''>City</option>
    </select>
    <select id="city" ng-model="store" ng-options="store for store in citySrc" ng-disabled="!stateSrc || !citySrc">
        <option value=''>Store</option>
    </select>

Thank's a lot!

A: It would be really helpful if you posted what your data source looks like. Assuming citySrc has objects containing arrays of stores, I would set a selectedCity in your controller when you call GetSelectedCity(), and then:

{{store}}

This will create list items for each store in your selectedCity object.


text:
Q: Using preprocessor to define pointers In my program I allocate five NxN matricies using one allocation. Each segment of NxN doubles is treated as a separate matrix. When I first wrote the code, I defined pointers to each matrix like this.
#define MAX_N 1024 // could be anything
double* matricies = aligned_alloc(32, 5 * MAX_N * MAX_N * sizeof(double));
double* MA = matricies;
double* MB = matricies + MAX_N * MAX_N;
double* MC1 = matricies + 2 * MAX_N * MAX_N;
double* MC2 = matricies + 3 * MAX_N * MAX_N;
double* MC3 = matricies + 4 * MAX_N * MAX_N;

After thinking about it for awhile, and due to the fact the offset of each matrix can be determined at compile time I wrote this code.
double* matricies = aligned_alloc(32, 5 * MAX_N * MAX_N * sizeof(double));

#define MA (matricies)
#define MB (matricies + MAX_N * MAX_N)
#define MC1 (matricies + 2 * MAX_N * MAX_N)
#define MC2 (matricies + 3 * MAX_N * MAX_N)
#define MC3 (matricies + 4 * MAX_N * MAX_N)

These identifiers are used as pointers in the rest of the program. My question is whether or not this is a good practice? I have the feeling that this will not scale because identifiers could collide with other text in the source code. You can of course #undef as needed, but it could get clunky.

A: It is primarily opinion based whether you will use one way or the other. The "defines" approach will save a little memory as you wont need the pointer variables. However, the compiler may optimize the variables out of the code so ... perhaps there isn't anything saved anyway. In my opinion the "defines" approach makes the code harder to understand and maintain so I would not use the defines.
The important problem with your code is however that it doesn't do what you say you want it to do. You say you want NxN matricies but your code does not allow us to use it like that. Example:
#define MAX_N 1024

int main(){
    double* matricies = aligned_alloc(32, 5 * MAX_N * MAX_N * sizeof(double));
    double* MA = matricies;
    double* MB = matricies + MAX_N * MAX_N;

    MA[0][3] = 42.1;          // error
    MB[2][1] = 123.8;         // error

    printf("%f\n", MA[0][3]); // error
    printf("%f\n", MB[2][1]); // error

    return 0;
}

This code result in compiler errors like:
main.cpp:12:10: error: subscripted value is neither array nor pointer nor vector
     MA[0][3] = 42.1;

because MA is a pointer to a double. To access data using MA[..][..] you need a different type for MA. That could be "a pointer to an array of double". Like:
#define MAX_N 1024

int main(){
    void* matricies = aligned_alloc(32, 5 * MAX_N * MAX_N * sizeof(double));
    double (*MA)[MAX_N] = matricies;
    double (*MB)[MAX_N] = MA + MAX_N;

    MA[0][3] = 42.1;
    MB[2][1] = 123.8;

    printf("%f\n", MA[0][3]);
    printf("%f\n", MB[2][1]);

    return 0;
}

This code compiles with no errors and the NxN matricies can be accessed as one will expect. Finally, it is IMO also easier to read and understand than your original "defines approach".

A:
whether or not this is a good practice?

#define MC3 (matricies + 4 * MAX_N * MAX_N) is not a good idea.  Code is hiding an unusual coding approach leads to higher maintenance costs.

Note a problem with 5 * MAX_N * MAX_N.  It is done with int math yet array indexing and sizing is best done with size_t math.  The original code can  overflow when MAX_N > 21000  Recommend 1) leading multiplication with  sizeof(double) and 2) use u on size constants like #define MAX_N 1024u  3) don't do this macro trick


text:
Q: Why after upgrading to Lubuntu 12.10 from 12.04 I can't login other than using the "Guest Account"? Why after upgrading to Lubuntu 12.10 from 12.04 I can't login other than using the "Guest Account". On the login screen there is the option for "Guest Account" and "Other...".
I select "Other..." and type in the [administrator] user name and password I just used in the install [the original user name & password from 12.04] and it keeps on giving me the message "Incorrect password, please try again".
I have tried reinstalling with a different user name and password without any success.  The only option I haven't tried yet is to set it to "Auto Login" during the install.


text:
Q: Screen freeze while loading UIWebview I am Loading HTML String in UIWebView,text content get loaded in a sec but there is lot of images in HTML String, cause of this image my UIWebView get freeze, after loaded all images my screen get free to use.
Any Suggestion on this?

A: Load webview in dispatch thread, try this:
dispatch_async(dispatch_get_main_queue(), ^{
    [self.webView loadHTMLString:@"htmlstring" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
});

A: I think it's freezing because you're loading a images from web in your main thread, Which is also responsible for redrawing your UI. By loading a large images inside your thread, your UI freezes as well.
I would recommend moving the code that does images loading into a separate thread.
(you can use @Andey's answer)

A: Like @Andey said, you should dispatch off the main queue whenever the thing you're doing will take some time and you don't want your view to freeze.
Try lecture 9:
https://itunes.apple.com/en/course/developing-ios-8-apps-swift/id961180099

UPDATE (Swift ver.):
Although I do not know how to write this in Obj-C, it will look something like this in Swift, which you can later translate it back to Obj-c.
dispatch_async(notTheMainQueue) {
    // Some time consuming stuff you're doing (downloading data, calculating..)
    ...
    dispatch_async(dispatch_get_main_queue) {
        // Set your view here, which dispatches *back* to the main queue and will not block your UI
        ...
    }
}


text:
Q: Why are database features being ignored, and instead reinvented in the middle tier? What are the top reasons (apart from "database independence") that most IT projects today seem to ignore the wealth of features that exist in modern database engines such as Oracle 11g and SQL Server 2008?
Or, to borrow from the Helsinki Declaration blog which puts it this way:

In the past twenty years we observe that the functionality (features) that is available to us inside the DBMS, has exponentially grown. These features enabled us to build database applications. Which is what we all started doing in the booming nineties.
But then at the dawn of the new millennium, something happened. And that something mysteriously made the role of the DBMS inside a database application project diminish to insignificant. (...) As of the new millennium we are pushing all application logic out of the DBMS into middle tier servers. The functionality of stuff implemented outside the DBMS has exploded, and the feature rich DBMS is hardly used for anything but row-storage.

We are talking about stuff like

*

*Stored procedures used as data APIs (for security and to avoid excessive network traffic)

*Materialized views

*Instead-Of triggers

*Hierarchical queries (connect by)

*Geography (spatial data types)

*Analytics (lead, lag, rollup, cube, etc.)

*Virtual Private Database (VPD)

*Database-level Auditing

*Flashback queries

*XML generation and XSL transformation in database

*HTTP callouts from database

*Background job scheduler

Why are these features not being used? Why are most Java, .NET and PHP developers sticking with the "SELECT * FROM mytable" approach?

A: MySQL.
When web applications exploded in the late 1990s and early 2000s, MySQL was at version 3.3 or 4.0 and didn't support anything above simple SELECTs. It was, however, free, and installed with most Linux distributions. As a result, a generation of programmers didn't learn about databases and don't know how to use them.
Even now that MySQL is at 5.1 and supports most of the features of a commercial system, the same cruddy old blogs and articles are used as templates when a new LAMP project is kicked off, and MySQL is deployed with MyISAM tables and 3.3-era functionality.

A: SQL is failing for the same reason as e.g. Haskell. The metric that determines language success is not purity, not ease of interpretation by computers, but how hard it is to maintain programs written in it.
Mere mortals fail with even the most simple language. Perhaps 1 in 10 people do have the skills to use a straightforward language like C#. But of those 10%, only 1 in 10 or 1% of all people can effectively use languages like SQL or Haskell.
Now, SQL is incomplete as a language, in the sense that there are very few things you can do with just SQL. You'll always need another language. What role does that leave for SQL? Developers will understand the ACID advantages over flat-file storage, but besides that databases really have nothing to offer them.
A second problem is that SQL effectively is not very compatible with Source Versioning. SQL seems really built along the notion that you get it right the first time. So, it's not just ill-suited for developers, it's also a poor match for the development process.

A: It's easier to fix/redeploy the middle tier than the DBMS.
This probably depends on your architecture, but it is our reason.  Couple that with the fact that we have one DBA who is busier and (probably) is paid more than our developers.  All the developers know SQL and some of them are semi-versed in the procedural language.  If a really hairy production problem comes up, it would be easier and faster for the developers to work on the middle tier than the database, regardless of whether the architecture would be better one way or the other.

A: I've run into quite a few people who just weren't aware that such features existed -- they cut their teeth in the early days of mySQL, and they've never really used anything else, and they haven't kept up with the advancement of the new storage tables in mySQL, even.  Or they learned databases in school, and they've never gone back to see all of the stuff they missed.
They learn the bare minimum SQL to get by, and don't realize all of the different extensions that different RDBMSes offer.
On one project, I'd love to have materialized views ... but I'm using Postgres.  I'd love to use spatial data types for another project, but I'm going to have to do a hack, or change databases to deal with mySQL's insistance that they be not null.  I've even had to figure out how to disable Oracle's transactional consistency to deal with long-running queries on an OLTP that would've been no problem in mySQL.
I can normally code around the shortcomings of the database for a given problem, but part of the problem is in selecting the right tool for the job -- on a current project, we've wasted man-months on data replication because we're using Postgres, and they decided on Slony-1 before they actually knew all of what we'd be replicating.
... I view this question as being like 'why don't more people use feature x in language y' -- if they're not an expert in language y they might not know feature x exists.
(and don't take this as support for getting DBA certification ... I've known some Oracle DBAs that couldn't program their way out of a wet sack;  I've taken all of the courses in the 8i days, but refused to take the tests as I didn't want to be lumped in with that group)

A: Because stored procedures:

*

*add another development language, increasing complexity and potentially redundant code (logic written in both languages);

*generally have worse tooling, monitoring and debugging capabilities than PHP, C#, Java, Python, etc;

*are generally less capable than most middle tier languages;

*only have an advantage with high volume data transformation (where you avoid the server roundtrip), which tends to only be a minimum of actual usage.

That being said, it's a common methodology on C# ASP.NET applications.
As Jeff Atwood put it, stored procedures are the assembly language of databases and people don't tend to code in assembly language unless they need to.
I've frequently used materialized views and sometimes used CONNECT BY in Oracle, neither of which I believe exist in MySQL.
I don't tend to use XML/XSLT in the database because, well, that means I'm using XML and XSLT.
As for geographical or spatial data structures, the reason there is probably that they're hard to just "pick up". It's a fairly specialist area. I've read the MySQL manual on spatial data structures and I'm sure it makes sense to someone with extensive GIS experience but to me and my limited needs (which tend to be around marking the latitude/longitude of a point) it just doesn't seem worth the time investment to figure it out.
Another issue is that if you go beyond ANSI SQL (much) then you've just tied yourself somewhat to a particular database vendor and possibly to a specific version. For that reason you'll often find application developers will tend to treat their databases at the lowest common denominator, which means treating them as a dumping ground for relational data.

A: Scalability. The more work you give to the database server, the greater a bottleneck it becomes. It's more scalable to have a whole farm of load-balanced application servers processing the data, and just use the database as a persistence store.

A: I think the biggest reason that overshadows all the rest is that relational database systems become dramatically more important when multiple applications are sharing the same data. Codd's famous paper is titled "A Relational Model of Data for Large Shared Data Banks" (emphasis mine).
People have a tendency to think that the application they are writing now will always be controlled by their team; and that it will always satisfy all of the needs of people interested in the data generated by the application. If a new need arises, that would be satisfied by adding a new feature to an existing application, not creating a new application.
But in many cases (not all, of course; every situation is different), that development model doesn't work very well in the long term. As the data generated by the application accumulates and becomes more important to the business, different people will have interesting ideas about how to use the data. When that happens, if you don't have a relational database management system, you are in for a big challenge.

A: I have been in too many situations where corporate politics ("we arent allowed access to the SQL Server so lets install a lesser powerful DBMS like Access to process millions of rows and join that with millions of rows in another table, and lets automate that import..") or even the technical politics that can happen ("I know Access can handle that amount of data and even if it doesnt we can split the MDB into several MDBs and reference them.....")
UGH.  Corporate politics and technical politics or even ignorance have prevented me from using many features.
Another example - I see no reason to not use stored procedures in a 100% Microsoft shop where SQL Server is the DBMS of choice. But, because the IT guy who was eventually going to own the solution was "light" on SPs, I had to resort to other measures.  I mean, there is a perfect example of why some that "feature" went ignored by them at their shop.
I know another shop that still uses DOS Foxpro 2 because their sole IT guy wrote the existing system that way and that is how all new stuff will be developed.  Why?   Cant we move along with the times?  Many of the marketing people over there have several DOS prompts open at once, with Foxpro "jobs" running in them to produce the most ugly reports I've ever seen.  But it works - I will give them that.  It works -- they have 12 million rows in their main table and 50+ other tables that they 'join' with that main table (not all 50 at once obviously) but man... its well past 1991!  They dont even want to discuss one item from that bullet list you provided in your question.
Stuff like this is why I guess.

A: I would say the biggest reason is that most people don't know about them.  Once someone has figured out a solution to a problem, that becomes the default solution to similar ones.  SELECT * FROM table has worked for a lot of people for a long time, so they don't bother looking at new approaches to old problems.
The other reason is that sometimes writing it in code is much easier than using a database.  Its the same idea as rolling your own vs. buying an off the shelf component.  Using a pre-written feature can solve your problems many times, but every once in a while, you need to do something which is outside of the capabilities of what the pre-written components can perform.

A: Nice question, and good discussion.
Another way to put it is "why haven't object DBs caught on?" which is the other side of the coin. DBs continue to be an annoying abstraction that still leaks its way into every app out there, but they're incompatible with the OO logic of modern applications.
It is indeed a strange state of affairs that we hide and duplicate the functionality of DBs in ActiveRecord, Hibernate, and other middlewares. But this is what happens to paradigms at the point of breakage (the "Object-relational impedance mismatch"). Will we ever transition to database technologies that are similar to our OO apps (e.g., object DBs)?
The answer is "not for a long time" and in the meantime, expect the DB to be ignored and squashed down and used for just row storage in many cases, as the middle-tier grows in functionality to bridge the gap.
Another question is "why would I do it in the DB if the middle-tier can do it?" The middle-tier is familiar and gaining ground in speed and functionality all the time. Again, we use the middle tier to avoid the OO-RDMS mismatch.

A: To advance on what Christian said, about scalability.
Simply, RDBMs are being used more as pure data stores, while the logic has been migrating in to the Application Servers. The extra tier of the AS give developers more flexibility than using the RDBMS as an Application Server.
Before, in the classic days of Fat Apps and Client Server, the DB and Application Server were basically the same thing. You had application logic either embedded in your fat client code, or you pushed it back in to the RDBMS. But back then, the primary form of communication was SQL directly to the database.
Nowadays, other application protocols are more common (CORBA, DCOM, Remote EJB, and more and more common today XML/JSON/HTTP-RPC style protocols over HTTP). Most databases don't respond to those protocols directly, so an Application layer is interjected to intercept those calls, and that layer calls the database.
But as we've learned we now get a lot more flexibility putting logic in to this layer. Wider choice of tools, more flexibility over caching, or failover, or, even database technology (RDMBS, OODBMS, Document stores like CouchDB). That "new", 3rd tier, despite the added complexity, adds more flexibility and power than the complexity it introduces.
When your app tier is a very thin veneer on top of Stored Procedures, it's valid to question why it's even there at all.
Leveraging the database and all of its features is a valid application strategy, even today. SQL Server, Oracle, etc, are terribly powerful pieces of software.
Even then, though, the third tier is enormously helpful in adding flexibility to a modern system.

A: Because developers don't know about SQL. They rely on DDL and DML generated by tools like Hibernate and language level constructs like JPA annotations. Developers don't care if these are horribly inefficient because they are mercifully hidden by normal log levels and because DBAs are not part of development teams.
That's why I like tools iBATIS. They make you write and understand SQL, including DBMS specific features.

A: For me, the reason is not only my applications being database agnostic, but a database best preforms the basic CRUD functions.  Yeah, databases are highly optimized, and might be able to make an HTTP callout, but why would you do it?  A webservice / web application is optimized for HTTP calls, not a database.  Just like an application is not designed to connect directly to a datafile and retrieve the data.  Can it be done? Yes, but why?  That is not what your application EXCELLS at.
I personally feel that everything you mentioned, out side of stored procedures belongs in the application.  If you know your architecture is X then take advantage of X's features, hand load off to the DB server when appropriate, etc...  If it could be X or Y (or Z), then your application should be agnostic, unless you are trying to create job security by ensuring that you might have to refactor the application :).  I think a little bit of laziness, combined with comfortablity might have something to do with it.  I know I would rather do it in C# than SQL if I can . . . my C# skills are just better.

A: First off: any developer using an ORM is naive if S/he thinks using an ORM negates having to have SQL skills. Most ORMs that generate SQL vary the SQL emitted depending on how the object queries are constructed. The developer will need to analyze the SQL to see if they should change any of the object queries.
Short answer: A lot of those features aren't practical for OO development. I know that DBAs don't like to hear that but, it's the truth. Those features are good for edge cases and most good ORMs such as N/Hibernate allow you to provide SQL for those edge cases.
When it comes to being mostly delegated to CRUD:
Long answer: I think the RDBMS world is going through maturity growing pains, and is finding it's place in the world. Truth: OOP is older than RDBMS. OOP is just getting out of it's growing pains and maturing. I think SQL as a language is very mature, but the idea of what a RDBMS should handle is just getting settled. The RDBMS was the business logic holder for most web apps until Java and C# came around. I think we are just starting to feel this correction now.
That being said, I don't think any ORM designer is going to tell you that the quality of the sql statements fed to the RDBMS don't matter.
When it comes to non-CRUD
I don't have an answer here. Most shops I know of still use the DB for ETL/etc...

A:
I guess one reason is the fear of vendor lockin.

This doesn't get said all that often, but the benefits of using vendor-specific features need to be weighed against the cost. Mainly the cost of having to rewrite the parts that rely on vendor-specific features for every database you want to support. There is also a performance cost if you implement something in a general purpose way when the vendor provides a better way.
I'll bring up this example: one might find the "lockin" of SQL Server to be more acceptable once one realizes all of the things Analysis Services, Reporting Services, and so on can do for your application. For major commercial database systems, it is not "just" the SQL database engine that needs to be taken into account.

A: There are not enough developers knowing all those features at a level that would really make the difference to a normal 'middle tier' programmer, when it comes to implementing the same logic into DB or middle tier. Maybe the single people that really have in-depth knowledge of that features are DBAs. And those focus on other problems than development. There are more 'normal' developers out there than DBAs. So it would be very difficult and costly to find the right people for your team.
Another point is, that you will normally only gather the in-depth knowledge about one database system, and not all of them. So you can have SQL Server experts or Oracle experts, but not both. This leads (to an extent) to narrow application fields where high specialization counts. Then, the market for such applications isn't that big, even if it's there.

A: "Why are database features being ignored".
Because lots of so-called developers are completely ignorant about data management, and what's worse, they're completely ignorant of their ignorance too.  "Unskilled and unaware of it", for whom this rings a bell.

A: If your software runs on your client's hardware then any change to the database (new Stored Procedures, updated views, etc) will require DB administrator rights. This is nearly always a problem for clients. Involving the DB group complicates any updates you need to do. There are a lot of great reasons presented here, but this is the only one I need to avoid putting code in the database like the plague.

A: I guess one reason is the fear of vendor lockin. These DBMS features are not standardized - for example, stored procedures are very DB specific, and if you implemented stuff using stored procedures (instead of, say, web services exposed via a middle tier), then you are forever stuck with the DBMS first chosen, (that is, unless you're willing to spend time/money to re-implement it in another DBMS if you wanted to change DBMS).

A: I think the reason is a combination of vendor lock-in and lack of knowledge on the part of most RDBM users.  SQL is a programming language, and it's much harder to master both the language you're calling SQL from and SQL than to master one or the other, especially since SQL is a particularly unique language.
The solution, I think, is to abstract your database functionality into a utility class, and give ownership of the class to a few users who know what they are doing with SQL.  This minimizes the risk of vendor lockin (if you switch vendors, the only thing that gets rewritten is the class).  This also gives the developers who aren't experts in SQL an abstracted-out interface so they don't have to deal with the database directly.

A: I have always worked on systems that are sold to many clients and runs on the client's hardware.  This leads to:

*

*You don't know what version of the database software the client will be running.

*The customers may not be willing to update the database software when you wish due to licence costs or there IT policy.

*Even basic features like materialized views are only in some "editions" of the database software, the smaller customers are often not willing to pay for the high end edition of the database.

*Sooner or later one of your sales people will agree to your software being used with a different vendor's RDBMS.

*Choosing between writing the logic once in the middle tier, or at least PL-SQL and TSQL in the database is an easy choose!

*Any change to the database (new Stored Procedures, updated views, etc) will require DB administrator rights; this can be a lot harder on some customers site then just updating your software.

*Writing a script to update the database is always harder than installing a new version of the application's dlls.  (Most build systems these days output MSI files as part of every build)

*It is harder to unit test code in a database then a middle tier.

*It is harder to debug stored procs than C#.

*Just because it works on your database does not mean it will work on the customer's database, RDBMS have too many switches that change how they work – customers always tend to set them in different ways.

So given all the above, the gain from using a database feature must be great before it is worth the long term pain.

A: One concern I have seen with leveraging increased database functionality is scaling. It seems to be a much more difficult proposition to scale your database load vs web/application server load.
Your options are limited, scaling-up with bigger faster hardware (with sometimes much higher licensing costs), or complicated, scaling-out with read-only copies, etc.
If there are performance issues, I want them to be at the web server application level. At least then one of my options is to add another web server and distribute load.
I am not arguing against database level code to minimize the amount of network traffic (records) sent between the web server and database server. I am arguing against other features, eg. extensive business logic processing at the database level.

A: A few posts note that it is cheaper to scale at the application layer than at the db layer.
Another consideration is composite applications that access multiple data stores.  Much easier to write and maintain platform agnostic query language in the app tier than separate platform specific queries in the the db layer.

A: Because writing object-oriented software, in the host language, with native host-language objects, beats writing procedural software.