text:
Q: Crash During Update Deleted ALL panels; can't open terminal; can't see icons
Possible Duplicate:
Recover the package manager after crash during update

So I was upgrading Ubuntu from 11.10 to 12.04 in the terminal after recovering my system from a previous crash, and then I go through a power outage during the second time trying to update. NOW, my screen is white, only the time shows up in the top right corner, no icons show up, no apps show up, AND terminal is NOT opening. I can still use the internet somehow, and Ctrl+Alt+F2 opens what I think is a back-up terminal? NEED HELP to recover what is lost.

A: If you get a live CD, you will be able to access to the content of your computer. In this case, you can still backup what can be saved, (re)install Ubuntu 12.04 from scratch and then put your backup on this fresh (and clean) install.
What you can see by typing Ctrl + Alt + F2 is a command line interface. With this, you can only access to terminal functionnalities. You can attempt to launch the graphical UI by typing the startx command.
You can also do your backup like I explained below with the CLI but a basic knowledge of Linux commands is required - commands for moving (mv), copying (cp), deleting files and folders (rm), changing the current directories (cd) and seeing what is inside a directory (ls). If you do not feel confident with the CLI, consider using the live CD which is much more user friendly and which will not enable you to due errors due to the big power of commands.


text:
Q: Splitting a fraction into two I have the following question: How do they go from step (2) to step (3)?
They split a fraction and somehow make $ x^3_n $ into $ \frac{x_n}{3}$  as well and I don't follow ... It's a take on Newtons Method.

A: Isn't it just the fact that $$-\left( \dfrac {a-b}c \right )=-\left(\dfrac ac -\dfrac bc\right) =-\dfrac ac +\dfrac bc$$

redpajama_set_name: RedPajamaStackExchange


text:
Q: Why won't Android Eclipse project update graphics? After a month of development, my project has suddenly decide to refuse to update my button graphic. I took my existing 9patch button and brightened it a little, saved it, and now it won't update on my device. Eclipse shows the new graphic (eventually) but the device rendition is the old button. I have to manually Clean, but in doing so my 9patch has broken and doesn't scale. I've read my 9 Patch Image stopped working and included the jar, but still the 9patch I'm trying to change won't update on my device, or it updates as a standard fixed-sized image with the black 9patch markings showing. If I delete the 9patch from resources and replace it with another button, it works.
Basically it's as if my project has gotten hokey. I've used Clean... and resource Refresh repeatedly, but it's not playing well. Once it even said I had manually edited the R.java file after a Clean... Is there some super cleanup reset thing I can do?
tldr; When I change graphic, the new graphic isn't updated on device. I use refresh and Project/Clean but that breaks the 9patch. What's wrong?


text:
Q: Use Typescript into Angular 1.5 Using Angular 1.5.5, I try to use Typescript so I configured gulp tasks successfully ; now I try to make a service in typescript with this code in SampleService.ts:
module app {
    class SampleService {
        constructor() {
        }

        public toto() :void {
            console.log('test');
        }
    }
    angular.module("app").service("SampleService", [SampleService]);
}

Otherwhere I have :
angular.module('app',
[ 'ngMaterial',
  'ngAnimate',
 ....

In order to declares routes:
$stateProvider
    .state('myapp', {
        url: '',
        controller: 'MainController as vm',
        templateUrl: 'app/views/main.html',
        abstract: true
    })
    .state('myapp.search', {
        url: '/',
        controller: 'SearchController as vm',
        templateUrl: 'app/views/partials/search.html'
    })

Without this service declaration, everything is working fine. Now with SampleService declared this way, I get:
Error: [ng:areq] Argument 'MainController' is not a function, got undefined
http://errors.angularjs.org/1.5.5/ng/areq?p0=MainController&p1=not%20a%20function%2C%20got%20undefined
minErr/<@http://localhost:3000/bower_components/angular/angular.js:68:12
assertArg@http://localhost:3000/bower_components/angular/angular.js:1880:11

Even if the service is not injected, it seems to break my application. Any idea of what wrong I did?

A: There is a working plunker
Just register controller as you did with a service:
module app {
    class SampleService {
        constructor() {
        }

        public toto() :void {
            console.log('test');
        }
    }
    angular.module("app").service("SampleService", [SampleService]);

    class MainController  {

        static $inject = ["$scope", "SampleService"];
        constructor(
            protected $scope,
            protected SampleService: SampleService) {

            this.init();
        }

        public init() :void {
            this.SampleService.toto();
        }
    }
    angular.module("app").controller("MainController", MainController);
}

and states as they are (just I do prefer some url, other then string empty)
.state('myapp', {
    url: '/myapp',
    controller: 'MainController as vm',
    templateUrl: 'app/views/main.html',
    abstract: true
})
.state('myapp.search', {
    url: '/search',
    controller: 'SearchController as vm',
    templateUrl: 'app/views/partials/search.html'
})

and this will work:
<a ui-sref="myapp.search">

Check it here in action


text:
Q: Workflow error in Sharepoint Online I am having this error in Sharepoint Online when I run a workflow to create an Enterprise Project from a list The details of the error was

Retrying last request. Next attempt scheduled in less than one minute.
  Details of last request: HTTP Forbidden to
  https://xxxxxxxxxxxxxx/sites/pwa/_api/ProjectServer/WorkflowActivities/CreateProjectFromListItem(webId='923e34ac-7127-4707-b6e1-83ac3235ef67',listId='a352ed9d-3b99-4405-b2a3-2fc3c2678335',itemId='2',eptId='09fa52b4-059b-4527-926e-99f9be96437a')
  Correlation Id: f9d2736f-8a66-4425-a5cc-cb30adf980ff Instance Id:
  3e7695ad-5913-4bb0-b6c8-cbf29e4e877a
PJClientCallableException: GeneralSecurityAccessDenied
  GeneralSecurityAccessDenied

I tried changing my workflow to just send an email to check whether there is something wrong with the workflow but emailing work I suspect it has something to do with the workflow engine service user (if there is such a thing) trying to create and Enterprise Project.
I and the admin so I have the full access but for some reason the workflow is running as a different user on my behalf.
It is a simple workflow and it looks like this

And the list looks like this with its mapping with the Project Web App Fields

Any reasons why this is happening? How do I resolve the issue? If its a workflow service user what is the user that I can give full access to creating Enterprise Projects


text:
Q: Form String From .txt file without using System.IO Class in VB I would like to know whether there is a way to convert the text from a .txt file to a string without using the System.IO Class in VB 2010. Thank you.

A: If you are just after a quick way to read in a file, try:
Dim strJunk As String = My.Computer.FileSystem.ReadAllText("C:\Junk\Junk.txt")


text:
Q: Right approach writing a Dockerfile with Node as backend I am writing a simple angular app which uses node as back-end for file upload. My project folder is as such:

To run this in Angular, I do

*

*ng serve

*Simultaneously run "nodemon server" in another command line in same folder and I am good to go. I tried doing this in Dockerfile with below instructions:

#Getting Base Image
FROM node:latest AS builder

#CMD ["echo", "Docker Image for eOTA Index Page!"]

WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH

#add app
COPY . /app

#install and app dependencies

COPY server.js /app/server.js

COPY package.json /app/package.json

RUN npm install

RUN npm install -g @angular/cli

#RUN npm install rxjs-compat --save

RUN npm install rxjs

#RUN npm install bootstrap --save

RUN npm install bootstrap

#RUN npm install ng2-file-upload --save

RUN npm install ng2-file-upload

RUN npm install -g @angular/material

#RUN npm install express multer body-parser dotenv --save

RUN npm install express multer body-parser dotenv

#RUN npm install nodemon --save-dev

RUN npm install -g nodemon

RUN npm run build --prod

#RUN npm nodemon server

CMD ["nodemon", "/app/server.js"]

FROM nginx:latest

COPY --from=builder /app/dist/ng8fileupload /usr/share/nginx/html

I am able to run the angular project however can never run server.js. App upload breaks. If i try running nodemon server via command line everything works. What am I doing wrong while running nodmon?

A: I would suggest you to modularize your code into frontend and backend components.
So, your backend code will live in the backend folder and frontend code will live in the frontend folder.
There will be separate Dockerfile for each in frontend and backend folder.
Now, to assemble the containers use Docker compose file which will live in root directory of your project.
Check the example here https://github.com/wkrzywiec/kanban-board/blob/master/docker-compose.yml


text:
Q: Vector application A rigid body rotates about an axis through the origin with angular velocity $10\sqrt{3} $ rad/sec. If $\overrightarrow{\omega}$ points in the direction of $\ \hat{i} + \hat j + \hat k$, then what is the equation to the locus of the points having tangential speed $20\ $ m/sec?
I have no idea about this problem. Please help.

A: If a rigid body rotates around an axis with angular velocity $\overrightarrow \omega$ then :
$$\overrightarrow \omega = |\omega|\space \widehat \omega\space \text{rad/sec}$$ where $|\omega|$ is the magnitude and $\widehat \omega$ is the direction of rotation or the axis of rotation. According to the problem,
$$\overrightarrow \omega = 10 \sqrt{3} \space \frac{(\widehat i + \widehat j + \widehat k)}{(\sqrt{3})}\space \text{rad/sec} = 10 (\widehat i + \widehat j + \widehat k)\space \text{rad/sec} $$
Now the particle rotates around this axis with a tangential speed of $v_T=20\space m/sec$, so the perpendicular distance between the axis of rotation and the axis is :
$$v_T=|\omega|r$$ giving $r=\frac{2}{\sqrt{3}}m$. The locus of a point having a tangential speed of $v_T$ and rotating around the axis is definitely a circle in 2 D and a cylinder in 3 D.

To find the equation of cylinder, the axis given is the line passing through the origin(mentioned in the question), so find the equation of a line which passes through $(0,0,0)$ and is in the direction of $\widehat i + \widehat j + \widehat k$.
Find the direction cosines and apply the equation of line.
Such a line is :
$$\frac{x-0}{\frac{1}{\sqrt{3}}}=\frac{y-0}{\frac{1}{\sqrt{3}}}=\frac{z-0}{\frac{1}{\sqrt{3}}}=t$$
Now consider a point $P(h,k,l)$ which is the rigid body location, this point is always transalting a path in which the point is always maintaing a tangential speed of $v_T=20 \space m/sec$ The trajectory of all such points is the locus. If we visualize it, we see the set of all points that are at a particular distance from the rotation axis line.
To find the equation of the cylinder just apply the fact that the line joining the axis and the point $P$ are perpendicular to each other and at a distance of $\frac{2}{\sqrt3} m$.

Direction cosines of the lines OX and HX will follow the relation:
$$t(h-t)+t(k-t)+t(l-t)=0$$
so either $t=0$ or $$h+k+l=3t$$
Now the distance HX = $\frac{2}{\sqrt 3}$. So:
$$HX^2=(h-t)^2+(k-t)^2+(l-t)^2=\frac{4}{3}$$
From Pythagoras theorem, $OX^2+HX^2=OH^2$
Solving the last two equations you can get:
$$h^2+k^2+l^2=\frac{4}{3}+3t^2$$
Now put back the value of $t$ as $\frac{h+k+l}{3}$ to get:
$$h^2+k^2+l^2-hk-kl-lh=2$$
Hope this helps...


text:
Q: (SWING) Menu bar actions and state keeping I'm writing a client app that's a bit similar to MS Excel - It has one menu bar , and you have several inner frames , each frame is a file in one of several states.
The basic flow is this : After opening a file , you can click on build , and after the build is  completed you can export/save it (others scenarios are more complex).
What I'm interested in is how to change the state of the menu buttons every time you switch between frames: if you haven't pressed the "build" yet , the "export" should be disabled , but if you switch to a window where you've already pressed the "build" button and it's built , the "export"
button should be enabled.
Is there a design pattern for handling something like this? Any Best Known Methods?

A: Add an InternalFrameListener to every internal frame you create, and listen for internalFrameActivated events. The event contains the frame which has been activated. Ask this internal frame its state, to know if it has been built, and enable/disable the menu items accordingly.


text:
Q: Problem with fonts in okular in kubuntu 20.04 I am having a problem with fonts substitutions in kubuntu 20.04 using okular or evince (both). The file has some embedded fonts as in
------------------------------------ ----------------- ---------------- --- --- --- ---------
ABCDEE+Calibri                       TrueType          WinAnsi          yes yes no       5  0
Arial                                TrueType          WinAnsi          no  no  no      12  0
Arial,Bold                           TrueType          WinAnsi          no  no  no      14  0
Arial                                CID TrueType      Identity-H       yes no  yes     16  0
Arial,BoldItalic                     TrueType          WinAnsi          no  no  no      21  0
Arial,BoldItalic                     CID TrueType      Identity-H       yes no  yes     23  0
Arial,Italic                         CID TrueType      Identity-H       yes no  yes     29  0
ABCDEE+Calibri,Italic                TrueType          WinAnsi          yes yes no      34  0
ABCDEE+Century Schoolbook,Bold       TrueType          WinAnsi          yes yes no      36  0

an image of how it looks is attached. It seems a problem with fixed width fonts and any help trying to solve it would be appreciated.

as you can see the rendering is very poor


text:
Q: Docker compose doesn't get picked up by reverse proxy I have a docker-compose that creates a container with a http server that doesn't get picked up by jwilder's nginx reverse proxy but it works wen instantiated by hand.
version: '2'
services:
    mongo:
        image: tutum/mongodb
        expose:
            - "27017"
        environment:
            - AUTH=no

    backend:
        build:
            context: "./instance"
        hostname: instance
        ports:
            - "1080:8080"
        expose:
            - "8080"
        links:
            - mongo

    frontend:
        build:
            context: "./instancegui"
        ports:
            - "80"
        environment:
            - VIRTUAL_HOST=some.host.com
            - LETSENCRYPT_HOST=some.host.com
            - LETSENCRYPT_EMAIL=someone@somewhere.com

the config file generated by the reverse proxy says upstream{...DOWN}
but the container runs fine when instantiated like so
docker run --name group_frontend_1 -p 80 -e "VIRTUAL_HOST=some.host.com" -e "LETSENCRYPT_HOST=some.host.com" -e "LETSENCRYPT_EMAIL=someone@somewhere.com" -d db70e6003db9

A: Ok found the solution
the problem is that the contained is not in a network watched by the proxy container, the most direct way is to set the contained in bridge mode
network_mode: "bridge"

and ports 80 is overkill its only needed expose
expose:
        - "80"

sources:
https://github.com/jwilder/nginx-proxy/issues/552
https://github.com/docker/compose/issues/3012

A: Why not use a plain and simple nginx image like this. Docker already does DNS for you.


text:
Q: Why push method works on with object? Why does "push method" works with object? How that mechanism works underhood?
function MyArray() { }
MyArray.prototype = [];

var arr = new MyArray();
arr.push(1, 2, 3);
console.log(arr); // [1, 2, 3]  in Chrome

sorry for my english. Thanks!

A: MyArray returns an object, even in Chrome, and uses the methods of Array, via assigned prototypal inheritance. The result of an instance of MyArray is still an object, not an array.

function MyArray() { }
MyArray.prototype = [];

var arr = new MyArray();
arr.push(1, 2, 3);
console.log(arr);                    // { 0: 1, 1: 2, 2: 3, length: 3 }
console.log(typeof arr);             // object
console.log(Array.isArray(arr));     // false
console.log(arr instanceof Array);   // true
console.log(arr instanceof MyArray); // true


text:
Q: Why use reverse nibbled in decimal-octets in SMS PDUs? I am studying for SMS PDU.
However, I do not know why the SMS PDU transmits the phone number and the like by reverse nibbled. (012345 to 103254)
Why does it work like this?

A: Noone knows excactly :)
But in telco within SS7 protocol, almost all numbers are reversed (vlr,hlr,imsi etc.)
In older days on slow networking, every bit matters, thats why SS7 is so optimized.
I believe it has to do with a speed when number has odd length.
In newer protocols (like Volte) there is no such thing anymore.


text:
Q: how to configure mysql workbench (mac version) not to append the @localhost in the mysql login After specify mysql user name, workbench (6.0.9.11421 build 1170) will always append the "@localhost". Is there any way to let workbench just use the configured user name to login?
The issue is  the user@localhost & user@% are two totally independent users. I don't need this xxx@localhost
MySQL config: (use "root" instead of "'root'@'172.31.5.133'" will got same issue, mysql server query will return "root@localhost" as the connected user)

Connection User from MySQL:

Another tool, Sequel pro, works perfectly without the above issue
Connection config:

Connection User from query:

A: When you ssh and mysql, you are connecting to the MySQL database from the ssh. That is why the @localhost appears. If you were to directly connect to it without sshing, the localhost will disappear.

A: MySQL Workbench will not always append "@localhost". It uses the host setting you specified in the connection settings.
Update:
The host can be set in the connection management wizard which you can reach, for instance, by right clicking on a tile and selecting "Edit Connection...":


text:
Q: Connection on the cotangent bundle I'm reading "Differential forms and connections" by R. Darling and I must have made a mistake in problem 4 in section 9.4. It states:

Prove that $\nabla_X \omega := \iota_X\, d\omega$ is not a connection on the cotangent bundle.

But it's additive in both arguments and $\nabla_{hX} \omega = \iota_{hX}\, d\omega = h\iota_{X}\, d\omega=h\nabla_X \omega$. The only problem can be the Leibniz rule:
$$\nabla_X (h\omega) = \iota_X\, d(h\omega)=\iota_X\, (dh\, \wedge\, \omega + h\,d\omega)=X(h)\, \omega + h\, \iota_x\,d\omega = h\nabla_X\omega + X(h)\omega,$$
so it's seems to work as well. Where did I make a mistake?

A: There's a missing term in the penultimate expression in your display equation.
Since $\iota_X$ is an antiderivation and $dh$ is a $1$-from, expanding the quantity $$\iota_X (\color{#df0000}{dh \wedge \omega} + \color{#0000df}{h \,d\omega})$$ gives
$$\color{#df0000}{(\iota_X dh) \wedge \omega - dh \wedge \iota_X d\omega} + \color{#0000df}{h \iota_X d\omega}.$$
By definition the first term is $X(h) \omega$ and the last is $h \nabla_X \omega$.


text:
Q: Show five digits after decimal point in c++ but if there are 0 after decimal point don't print them The number must be displayed with exactly five digits after the decimal. If the number is 0 to display only 0 instead of 0.00000. If the number has zeros in his decimal recording only show numbers other than zero, for example 0.08500 instead of outputting 0.085
//s0 is my variable
if (s0==) cout<<"0"
else cout<<setiosflags(ios::fixed)<<setprecision(5)<<s0;

A: Try:
std::cout << std::setprecision(5) << s0;

In your version setiosflags(ios::fixed) is forcing trailing zeros.

A: It seems obvious, but could you use printf?
#include <stdio.h>

int main(){

    printf("%5.3f", 0.8500000000);
    return 0;
}

A: You can't easily do it in C++ with the streams and << operator, because 0 is a special case.
Write a function
 std::string tonice(double x)
 {
    char buff[64];
    if(x == 0)
       sprintf(Buff, "0");
    else
       sprintf(buff, "%5.3f", x);
    return std;string(buff);

  }

Then
 cout << "The data is " << tonice(x) << " other bits and bats";

A: std::cout << std::setprecision(5) << s0;
This is the best method for setting precision.


text:
Q: rsync - copy contents of the directory only if a certain file doesn't exist We want to migrate contents of an old server to a new one but rather than coping everything, we want to exclude any directory that has a .swf file in it. We are aware of the --exclude flag but it will only exclude the file(s), not the parent directory (and it's contents), if there is a .swf file
If this cannot be done with rsync, is there a bash script we can use to copy files from one server to another, with this condition?

A: You could generate a list of directories which contain *.swf files, and then convert that list into an exclude file for rsync.
e.g.
find /path/to/topdir/ -iname '*.swf' -printf "%h\n" |
    sort -u |
    sed -e 's/^/- /; s:$:/**:' > rsync-exclude.txt

output will look something like this, which can be used with rsync's --exclude-from=FILE option:
- /path/to/topdir/directory1/**
- /path/to/topdir/directory2/**
- /path/to/topdir/directory3/**
- /path/to/topdir/directory5/subdir1/**

Note that rsync's include and exclude options can be difficult to master, they do not work quite like either globs or regular expressions.  You will  want to practice with --dry-run and --verbose first until you get the patterns exactly right.


text:
Q: How to create a function that scores ngrams before unigrams in Python? Let's assume I would like to score text with a dictionary called dictionary:
text = "I would like to reduce carbon emissions"

dictionary = pd.DataFrame({'text': ["like","reduce","carbon","emissions","reduce carbon emissions"],'score': [1,-1,-1,-1,1]})

I would like to write a function that adds up every term in dictionary that is in text. However, such a rule must have a nuance: prioritizing ngrams over unigrams.
Concretely, if I sum up the unigrams in dictionary that are in text, I get: 1+(-1)+(-1)+(-1)=-2 since like =1, reduce=-1, carbon =-1,emissions=-1. This is not what I want. The function must say the following things:

*

*consider first ngrams (reduce carbon emissions in the example), if there the set of ngrams is not empty, then attribute the corresponding value to it, otherwise if the the set of ngrams is empty then consider unigrams;

*if the set of ngrams is non-empty, ignore those single words (unigrams) that are in the selected ngrams (e.g. ignore "reduce", "carbon" and "emissions" that are already in "reduce carbon emissions").

Such a function should give me this output: +2 since like =1 + reduce carbon emissions = 1.
I am pretty new  to Python and I am stuck. Can anyone help me with this?
Thanks!

A: I would sort the keywords descendingly by length, so it's guarantee that re would match ngrams before one-gram:
import re

pat = '|'.join(sorted(dictionary.text, key=len, reverse=True))

found = re.findall(fr'\b({pat})\b', text)

Output:
['like', 'reduce carbon emissions']

To get the expected output:
scores = dictionary.set_index('text')['score']

scores.re_index(found).sum()


text: Q: How to scrape a web page using python for numbers from 1 to 500 that maybe present on the page? I have been looking to make a program for scraping a webpage to see if it contains any number from 1 to 500, I found many ways to this on the internet, but the thing is all of them open a new webpage in the beginning, I dont want that to happen but for it to switch to a tab that I have already opened. Is there any code that will switch to a tab on a webpage that I have already opened, then execute a list of commands(basic clicking stuff), and finally scrape the webpage for numbers from 1 to 500?


text:
Q:  can't post values in laravel Hi I'm new to laravel and I create a form then when I tried to post values with textarea it didn't work and this is my code for form:

<form class="form-vertical" role="form" method="post" id="contactForm" action="{{route('newPage')}}">

        موضوع:
        <input type="text" name="title" class="form-control" id="username"
        value="{{ Request::old('title') ?: ''}}">
        @if ($errors->has('title'))
          وارد کردن موضوع ضروری است
        @endif

        سرفصل مربوطه به انگلیسی:
        <input type="text" name="related_subject" class="form-control" id="username"
        value="{{ Request::old('related_subject') ?: ''}}">

        @if ($errors->has('related_subject'))
           وارد کردن سرفصل ضروری است
        @endif

        شرح مطلب:

        <textarea type="text" rows="10" cols="100" name="contents"
           class=
          "form-control" id="message" style="resize:none"></textarea>

        @if ($errors->has('contents'))
           وارد کردن سرفصل ضروری است
        @endif

        <button type="submit" class="btn btn-primary">Sign up</button>

        <input type="hidden" name="_token" value="{{Session::token()}}">
    </form>

but it works when I use input instead of textarea! I mean when I deleted text area and use an input it works correctly!
How can I solve it?

A: You have issue in your textarea syntax
your code
<textarea type="text" rows="10" cols="100" name="contents"
       class=
      "form-control" id="message" style="resize:none"></textarea>

normal code for textarea
<textarea rows="10" cols="100" name="contents"
       class=
      "form-control" id="message" style="resize:none"></textarea>

textarea has no type for more detail you can visit
-W3School html textarea section give you more detail

A: I think you have submitted form use javascript with form's id.
So you should add [form] attribute that same id of form to textarea.
example:
<form name="frmA" id="frmA" action="/" method="post">
 <textarea form="frmA"></textarea>
</form>


text:
Q: Defining multiple rows based on data subset in a vectorized manner Suppose I have the following dataframe:
data <- data.frame(
    row_idx = 1:120,
    value = runif(120, min = 0, max = 1)
)
data$index <- rep(seq_len(nrow(data) / 4), each = 4)

data$value[data$row_idx %% 4 != 0] <- NA

Which should give me something along:
  row_idx     value index
1       1        NA     1
2       2        NA     1
3       3        NA     1
4       4 0.1463743     1
5       5        NA     2
6       6        NA     2
7       7        NA     2
8       8 0.2197675     2
...

I know this may look silly, I'm just trying to reproduce the problem.
The issue in question is: How can I, for each index group (1, 1, 1, 1; 2, 2, 2, 2; ...), make the value column equal to its single non-NA value divided by 4 and then replicated across the NA rows?
The expected output would be, for example:
# desired output
  row_idx value index
1       1 0.03659358     1
2       2 0.03659358     1
3       3 0.03659358     1
4       4 0.03659358     1
5       5 0.05494188     2
6       6 0.05494188     2
7       7 0.05494188     2
8       8 0.05494188     2
...

Notice how the first four values are simply 0.1463743 / 4.
I know this can be solved by using loops, apply functions and such, but is there a vectorized way of doing this? A one, two liner tops?

A: do this
library(tidyverse)

data$value <- data$value /4
data %>% group_by(index) %>%
  fill(value, .direction = "up")

Check
set.seed(123)
data <- data.frame(row_idx = 1:120,
  value = runif(120, min = 0, max = 1))
data$index <- rep(seq_len(nrow(data) / 4), each = 4)

data$value[data$row_idx %% 4 != 0] <- NA

data$value <- data$value /4
data %>% group_by(index) %>%
  fill(value, .direction = "up")

# A tibble: 120 x 3
# Groups:   index [30]
   row_idx value index
     <int> <dbl> <int>
 1       1 0.221     1
 2       2 0.221     1
 3       3 0.221     1
 4       4 0.221     1
 5       5 0.223     2
 6       6 0.223     2
 7       7 0.223     2
 8       8 0.223     2
 9       9 0.113     3
10      10 0.113     3
# ... with 110 more rows

If you don't want to use pipes, use simply this
data <- fill(data, value, .direction = "up")

*

*Another option

data$value <- rev(zoo::na.locf(rev(data$value/4)))

    row_idx      value index
1         1 0.22075435     1
2         2 0.22075435     1
3         3 0.22075435     1
4         4 0.22075435     1
5         5 0.22310476     2
6         6 0.22310476     2
7         7 0.22310476     2
8         8 0.22310476     2
9         9 0.11333354     3
10       10 0.11333354     3
11       11 0.11333354     3
12       12 0.11333354     3
13       13 0.22495624     4
14       14 0.22495624     4
15       15 0.22495624     4
16       16 0.22495624     4
17       17 0.23862591     5
18       18 0.23862591     5
19       19 0.23862591     5
20       20 0.23862591     5
21       21 0.24856744     6
22       22 0.24856744     6
23       23 0.24856744     6
24       24 0.24856744     6
25       25 0.14853551     7
26       26 0.14853551     7
27       27 0.14853551     7
28       28 0.14853551     7
29       29 0.22557476     8
30       30 0.22557476     8
31       31 0.22557476     8
32       32 0.22557476     8
33       33 0.11944899     9
34       34 0.11944899     9
35       35 0.11944899     9
36       36 0.11944899     9
37       37 0.05790645    10
38       38 0.05790645    10
39       39 0.05790645    10
40       40 0.05790645    10
41       41 0.09221136    11
42       42 0.09221136    11
43       43 0.09221136    11
44       44 0.09221136    11
45       45 0.11649061    12
46       46 0.11649061    12
47       47 0.11649061    12
48       48 0.11649061    12
49       49 0.11055002    13
50       50 0.11055002    13
51       51 0.11055002    13
52       52 0.11055002    13
53       53 0.05163285    14
54       54 0.05163285    14
55       55 0.05163285    14
56       56 0.05163285    14
57       57 0.09361569    15
58       58 0.09361569    15
59       59 0.09361569    15
60       60 0.09361569    15
61       61 0.06859591    16
62       62 0.06859591    16
63       63 0.06859591    16
64       64 0.06859591    16
65       65 0.20309738    17
66       66 0.20309738    17
67       67 0.20309738    17
68       68 0.20309738    17
69       69 0.15730528    18
70       70 0.15730528    18
71       71 0.15730528    18
72       72 0.15730528    18
73       73 0.05502972    19
74       74 0.05502972    19
75       75 0.05502972    19
76       76 0.05502972    19
77       77 0.02778386    20
78       78 0.02778386    20
79       79 0.02778386    20
80       80 0.02778386    20
81       81 0.19704896    21
82       82 0.19704896    21
83       83 0.19704896    21
84       84 0.19704896    21
85       85 0.22326278    22
86       86 0.22326278    22
87       87 0.22326278    22
88       88 0.22326278    22
89       89 0.16327548    23
90       90 0.16327548    23
91       91 0.16327548    23
92       92 0.16327548    23
93       93 0.04692278    24
94       94 0.04692278    24
95       95 0.04692278    24
96       96 0.04692278    24
97       97 0.12787636    25
98       98 0.12787636    25
99       99 0.12787636    25
100     100 0.12787636    25
101     101 0.23861846    26
102     102 0.23861846    26
103     103 0.23861846    26
104     104 0.23861846    26
105     105 0.15218375    27
106     106 0.15218375    27
107     107 0.15218375    27
108     108 0.15218375    27
109     109 0.07530722    28
110     110 0.07530722    28
111     111 0.07530722    28
112     112 0.07530722    28
113     113 0.03557357    29
114     114 0.03557357    29
115     115 0.03557357    29
116     116 0.03557357    29
117     117 0.10112757    30
118     118 0.10112757    30
119     119 0.10112757    30
120     120 0.10112757    30

A: You can try ave from base R:
data$newcol <- ave(data$value, data$index ,  FUN=function(x)sum(x, na.rm=TRUE)/NROW(x))


text:
Q: Apache Spark - org.apache.spark.SparkException: Task not serializable When attempting to run my method:
    def doGD() = {
       allRatings.foreach(rating => gradientDescent(rating));
    }

I get the error: org.apache.spark.SparkException: Task not serialisable
I understand that my method of Gradient Descent is not going to parallelise because each step depends upon the previous step - so working in parallel is not an option. However, from the Console if I do this:
    val gd = new GradientDescent()
    gd.doGD();

I get the error as mentioned.
However, if in the Console I do this:
    val gd = new GradientDescent()
    gd.allRatings.foreach(rating => gradientDescent(rating))

It works perfectly fine. As you may have noticed what works in the 2nd example is the same code as in the first example except instead of a method I just take the code out of the method and call it directly.
Why does the one work and the other does not? I'm bemused.
(Additional note: Class GradientDescent extends Serializable ).
The gradientDescent method:
def gradientDescent(rating : Rating) = {

var userVector = userFactors.get(rating.user).get
var itemVector = itemFactors.get(rating.product).get

userFactors.map(x => if(x._1 == rating.user)(x._1, x._2 += 0.02 * (calculatePredictionError(rating.rating, userVector, itemVector) * itemVector)))
userVector = userFactors.get(rating.user).get // updated user vector

itemFactors.map(x => if(x._1 == rating.product)(x._1, x._2 += 0.02 * (calculatePredictionError(rating.rating, userVector, itemVector) * itemVector)))
}

I know I'm using 2 vars stored on the master - userFactors and itemFactors - and as the process is sequential parallelising is not possible. But this doesn't explain why calling the method from the Console does not work but re-writing the inners of the method in the Console does.

A: Hard to tell without full source of GradientDescent class, but you're probably capturing an unserializable value. When running the method, it needs to serialize the full object and send it to the workers, while inlined version doesn't.


text:
Q: Automated emails from a Google Sheet I was looking for a solution to send automated emails from a Google Sheet connected to a Google Form, so I found Google Scripts. I never worked with it (or other scripts) before, so it's all new to me. I did find a lot of information on the internet, but I still have some questions.
Let's explain the situation. So I'm selling two different products in a Google Form, they both have a different price, so I was looking for a solution to send mails to the customers with the total price and some extra information. I have a Google Sheet where all the answers are put in automatically.
So I have 12 columns, as you can see in a copy of my sheet. https://docs.google.com/spreadsheets/d/1CrA9cNAwsUdLyaxzFiJrtXxu-0eiIMiA3IEaEaIYlZo/edit?usp=sharing
The script I use is added as a picture.
The problems:

*

*The script should prevent Google from sending duplicates, but that doesn't work

*I used a formula to fill the total amount in the sheet (column L) but I can't add it in the text of the script to send it in the mail

What I want:

*

*Automated mails, can I add the script as a add-on or how do I automate it in the sheet? Now I need to press the "play script" button every time

*I want the duplicate tracker to work, so no-one gets 2 mails

*I want the script to scan enough rows, so everyone gets a mail

*I want the total amount in the text of the mail

That's it I guess, thanks for helping!

    // This constant is written in column C for rows for which an email
// has been sent successfully.
let EMAIL_SENT = 'EMAIL_SENT';

/**
 * Sends non-duplicate emails with data from the current spreadsheet.
 */
function sendNonDuplicateEmails() {
  try{
    // Get the active sheet in spreadsheet
    const sheet = SpreadsheetApp.getActiveSheet();
    let startRow = 3; // First row of data to process
    let numRows = 3; // Number of rows to process
    // Fetch the range of cells A2:B3
    const dataRange = sheet.getRange(startRow, 1, numRows, 300);
    // Fetch values for each row in the Range.
    const data = dataRange.getValues();
    for (let i = 0; i < data.length; ++i) {
      const row = data[i];
      const emailAddress = row[1]; // Second column
      const message = 'Beste ' + row[4] + '\n\nBedankt voor uw bestelling, we hebben deze succesvol ontvangen!' + '\n\nU bestelde ' + row[2] + ' pakjes droge worsten en ' + row[3] + ' pakjes pannenkoeken.' + '\nDit vormt dus ' + row[2] + ' x €6 en ' + row[3] + ' x €6,5.' + '\nIn totaal komt dit op ' + ' euro.' + '\n\nDe bestelling is pas officieel na overschrijving van bovenstaand bedrag op het rekeningnummer BE04 7755 8091 4631 met als mededeling: ' + row[2] + ' DW en ' + row[3] + ' PK.' + '\n\nBij vragen of opmerkingen kunt u ons altijd een mailtje sturen via info@chirozedelgemdorp.be.' + '\n\nChiro Zedelgem Dorp dankt u, laat het u smaken!';
      const emailSent = row[11]; // Elfde kolom
      if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
        let subject = 'Worst- en pannenkoekenverkoop | Chiro Zedelgem Dorp';
        // Send emails to emailAddresses which are presents in First column
        MailApp.sendEmail(emailAddress, subject, message);
        sheet.getRange(startRow + i, 11).setValue(EMAIL_SENT);
        // Make sure the cell is updated right away in case the script is interrupted
        SpreadsheetApp.flush();
      }
    }
  }
  catch(err){
    Logger.log(err)
  }
}


text:
Q: Output redirection fails when using Start-Process to launch CMD with START /B This is my test.ps1:
Start-Process -FilePath 'CMD.EXE' -NoNewWindow -ArgumentList '/C START /B PING.EXE google.com -t > logfile.txt 2>&1'
echo "Finished."

The test is an infinite ping to google, which is a good test for the conditions that I need to check:

*

*Open the process in a new detached thread (= see the 'Finished' printed out + see PING.EXE alive in the process list + CTRL+C not killing PING.exe) [OK]

*Collect the ping progress (that is: redirect standard input and standard error) to logfile.txt [FAILS] <= this solution does not seem to work on my test, logfile.txt stays at 0 bytes

It is a convoluted solution, even though my final goal is relatively simple. What I finally want is to reproduce this linux cmd in powershell:
ASPNETCORE_ENVIRONMENT=Production ASPNETCORE_URLS=http://*:5000 dotnet run > ${LOGFILE_PATH}.txt 2>&1 &

The difficult part in Windows seems to be to "really detach the process". START /B is the only windows functionality that I have found that really does that. But then I have the "output redirection" problem. And since I need it in a .ps1 file, I need to wrap it in Start-Process.

A: You might be searching for one or more of the following
Start-Process
parameters:

-RedirectStandardOutput
Specifies a file. This cmdlet sends the output generated by the
  process to a file that you specify. Enter the path and filename. By
  default, the output is displayed in the console.
-NoNewWindow
Start the new process in the current console window. By default
  PowerShell opens a new window.


text:
Q: How to change the border color of an image frequently by Javascript? How to change the border color of an image frequently by Javascript?

A: With this you can change the border every set interval from what you are saying, all you have to do is modify the 100 in the setTimeout method to any millesecond time.
And anytime you want to change the color set globalColor equal to a hexidecimal color.  This will every 100ms or what ever you change it to set the border to globalColor.

var globalColor;

function setColor(color) {
  img1.style.borderColor = "#" + color;
}

var imageTimeout = setTimeout(function() {
  setColor(globalColor);
}, 100);
img#img1 {
  border-width: 4px;
  border-style: solid;
}


text:
Q: Chaining requests with scrapy Now I can see that scrapy downloads all pages concurrently, but what I need is to chain people and extract_person methods, so that when I get list of persons urls in method people I follow all of them and scrape all info I need and only after that I continue with another page people urls. How can I do that?
def people(self, response):
    sel = Selector(response)
    urls = sel.xpath(XPATHS.URLS).extract()
    for url in urls:
        yield Request(
            url=BASE_URL+url,
            callback=self.extract_person,
        )

def extract_person(self, response):
    sel = Selector(response)
    name = sel.xpath(XPATHS.NAME).extract()[0]
    person = PersonItem(name=name)
    yield student

A: You can control the priority of the requests:

priority (int) – the priority of this request (defaults to 0). The priority
  is used by the scheduler to define the order used to process requests.
  Requests with a higher priority value will execute earlier. Negative
  values are allowed in order to indicate relatively low-priority.

Setting the priority for person requests to 1 will let Scrapy know to process them first:
for url in student_urls:
    yield Request(
        url=BASE_URL+url,
        callback=self.extract_person,
        priority=1
    )


text:
Q: Clickable li but another li not clickable I'm trying to figure this out, but for the life of me I'm confused. I have this:

HEADER

    Links

 Another Link

   Multilevel

Link in level 2

Link in level 2

and my javascript:
var hash = window.location.hash.substr(1);
var href = $('.sidebar-menu li a').each(function(){
    var href = $(this).attr('href');
    if(hash==href.substr(0,href.length-10)){
        var toLoad = hash+'.php #content';
        $('#content').load(toLoad)
    }
});

$('.sidebar-menu li a > .treeview li a').click(function(){

and I'm having trouble with this line:
$('.sidebar-menu li a > .treeview li a').click(function(){

I want the sidebar-menu menu clickable for all li's with a tags however when I click on the treeview menu, it fires up as an href link. I don't want that clickable.
Am I using the greater than less than symbols correctly in my JavaScript?

A: use this to prevent default href action
$(your selector).click(function(e) {
  e.preventDefault();
  // e for event
  // preventDefault will stop default href action
});

edit: or you can handle all # links with this selector and preventDefault
$('.sidebar-menu a[href="#"]').click(function(e){
  e.preventDefault();
});

selector a[href="#"] will select only A-tags with param href == "#", then just use preventDefault() on them to stop default href action

A: If you want only elements directly under your selector, use >.
This will select only a tags directly in the li tags that are directly in the sidebar-menu:
$('.sidebar-menu > li > a')

Your first onclick can look like this:
var href = $('.sidebar-menu > li > a').each(function(){
    var href = $(this).attr('href');
    if(hash==href.substr(0,href.length-10)){
        var toLoad = hash+'.php #content';
        $('#content').load(toLoad)
    }
});

Your second one can just look like this:
$('.treeview li a').click(function(){
    // do stuff.
});

It depends on how much nesting you'll do, but this will apply to all a tags in your treeview, regardless of nesting level.
EDIT:
I see you didn't want the tree clickable at all.  In that case, you shouldn't use the a tag at all.  Use something like a span with styling that makes it look like a link. Links (a) go somewhere. If you aren't going somewhere, don't use the a.
fiddle: https://jsfiddle.net/6njj7L9g/2/
snippet:

$(document).ready(function() {

 var hash = window.location.hash.substr(1);
 var href = $('.sidebar-menu li a').each(function(){
  var href = $(this).attr('href');
  if(hash==href.substr(0,href.length-10)){
   var toLoad = hash+'.php #content';
   $('#content').load(toLoad)
  }
 });

 $('.sidebar-menu > li > a').click(function(){

  var toLoad = $(this).attr('href')+' #content';
  $('#content').hide('fast',loadContent);
  $('#load').remove();
  $('#wrapper').append('LOADING...');
  $('#load').fadeIn('normal');
  window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
  function loadContent() {
   $('#content').load(toLoad,'',showNewContent())
  }
  function showNewContent() {
   $('#content').show('normal',hideLoader());
  }
  function hideLoader() {
   $('#load').fadeOut('normal');
  }
  return false;

 });

});
.treeLink{
    text-decoration: underline;
    color: blue;
    cursor: pointer;
}

HEADER

    Links

 Another Link

   Multilevel

Link in level 2

Link in level 2

A: Make href="" and not href="#" if you don't want it to be click-able.


text:
Q: Solving $2\sin(x) + 3\sin(2x) = 0$ Solve for x:

$$2\sin(x) + 3\sin(2x) = 0 $$
$$2\sin(x)(1 + 3\cos(x)) = 0$$

Stuck here. The solution mentions some arccos function, but I need a detailed explanation on this one.

A: If you have that
$$2\sin{(x)}(1+3\cos{(x)})=0$$
then one or both of the factors must be equal to zero, hence either
$$2\sin{(x)}=0$$
$$\sin{(x)}=0$$
$$x=\pi k $$
or
$$1+3\cos{(x)}=0$$
$$\cos{(x)}=-\frac13$$
$$x=\pm\arccos{\left(-\frac13\right)}+2\pi k$$
where $k$ is an arbitrary integer. The function $\arccos{(x)}$ gives the value of $y\in\left[0,\pi\right]$ such that $\cos{(y)}=x$.

A: Hint: if the product of two numbers is $0$, at least one of them is $0$.


text:
Q: How can I make trailing spaces visible within rotated text in Excel? I'm creating a spreadsheet which contains text that's rotated at 90 degrees within some of the cells, which form part of a diagram. The diagram is symmetrical, where the cells at the top of the diagram are aligned to the bottom (thus the text is effectively left-aligned), and the cells at the bottom of the diagram are aligned to the top (thus the text is right-aligned).
In order to make the diagram clearer, I have inserted leading spaces to the cells at the top of the diagram, and trailing spaces to the cells at the bottom of the diagram. I've set the cell formats to text to ensure that numbers are treated as such. However, the trailing spaces aren't appearing within the bottom cells for some reason (although they are present within the values as they appear within the formula bar). The values within the cells with the leading spaces are successfully being indented.
Please can someone point me to a solution to this problem?

A: Okay, I found a workaround that does the job. Instead of adding a trailing "space", I use character U+00A0; this successfully indents the rotated, right-aligned text. I'm still wondering why it doesn't do it with a normal space though?


text:
Q: Remove elements from an array matching patterns from a file I'm trying to build a function that:

*

*Gets arguments and assigns them to an array.

*Removes all the elements that match the Exclude file.

Exclude file is a text file that contains a list of strings to exclude separated by lines.
For example:
The Exclude file is: list.txt.
It contains:

value1
value2

Let's assume we call the function with these arguments:
Function value1 value2 value3

The desired output would be:

value3

So far I tried to iterate through the list.txt and overwrite the array with array minus the String from the file. But it seems that it doesn't overwrite the array and instead it appends the values.
The output I get right now is:

value3 value2 value3

My code is:
function Function {
    argsArr=( "$@" )
    while read p; do
        argsArr="${argsArr[@]//$p*/}"
    done <list.txt
    echo "${argsArr[@]}"
}

A: A simple grep check would suffice:
$ cat list.txt
value1
value2
$ function Function
> {
> for i in "$@"
> do
> fgrep -q "$i" list.txt || echo "$i"
> done
> }
$ Function value1 value2 value3
value3
$

We just iterate through the parameters passed to function and grep for that parameter in list.txt(Exclude file), if exit code is non-0 i.e not present we then just print it out.
If you want the result in array, declare it at start of function using array=(), just append the parameter to an array like this: fgrep -q "$i" list.txt || array+=("$i") and at the end of function just do echo ${array[@]}
Edit 1: just using an array
$ function Function
> {
> declare -a array=()
> for i in "$@"
> do
> fgrep -q "$i" list.txt || array+=("$i")
> done
> echo "${array[@]}"
> }
$ Function value1 value2 value3
value3
$

A: Check out line 4:
function Function {

    argsArr=( "$@" )
    while read p; do
        argsArr=(${argsArr[@]/$p*/})
    done <list.txt
    echo "${argsArr[@]}"
}


text:
Q: How to POST with AFNetworking and send parameters as POST Data? I'm trying to make a POST on the Instagram API to change a user's relationship but I'm having trouble getting the call to work. I've done some research and one guy says to put the action=follow part in the POST Data. I searched this further and still cannot get my requests to go through.
let request = NSMutableURLRequest(URL: NSURL(string: "https://api.instagram.com/v1/users/\(user.id)/relationship?access_token=\(account.accessToken)")!)
        let key = "action=follow"
        let mastData = key.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!
        let mastLength = "\(mastData.length)"

        request.HTTPMethod = "POST"
        request.HTTPBody = mastData
        request.addValue(mastLength, forHTTPHeaderField: "Content-Length")
        request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

        let operation = AFHTTPRequestOperation(request: request)
        operation.responseSerializer = AFJSONResponseSerializer()
        operation.setCompletionBlockWithSuccess({ (_, result) -> Void in
                        let result = result as! NSDictionary
                        let data = result["data"] as! NSDictionary

                        completion(true)
            }) { (_, error) -> Void in
                completion(false)
        }

Also, I know the user.id is valid and the account.accessToken is valid also because I'm using them successfully in other parts of the app.


text:
Q: "Automatic" and timely method JS I want to build an account class on JavaScript where you have a savings modality that you get a fixed amount of interest (juros in this code) to your current balance on that modality. And there's also a special account that inherits from the normal one but the interests you get from the savings modality is doubled.
I want the interests value to be added every 30 days from the creation of the account. I thought on the following code:
class Conta {
    constructor (saldoCorrente, saldoPoupanca, addJuros, jurosPoup) {
        this.saldoCorrente = saldoCorrente
        this.saldoPoupanca = saldoPoupanca
        this.jurosPoup = 0.5
        this.addJuros = function() {
            let dia = new Date(day)
            if (dia == 30) {
                this.saldoPoupanca += saldoPoupanca * jurosPoup
            }
        }
    }
    depCorrente = (valor) => this.saldoCorrente += valor
    depPoupanca = (valor) => this.saldoPoupanca += valor
    transPoupToCorr(valor) {
        this.saldoPoupanca -= valor
        this.saldoCorrente += valor
    }

    }

    class Especial extends Conta {
        constructor(jurosPoup) {
            super(jurosPoup, 1)
        }
            }

I specially ask to revise my constructor function/method on the "if day == 30" that I KNOW it is wrong (lol) and also a way to make this function/method automatized. I read somewhere that if it is on the class constructor then it'll be called automatically, but I'm not sure.
Thanks!


text:
Q: Angular Universal does not render data from API Requests My Angular Universal application is only rendering the HTML in the template, but not any variables or data that is loaded from API requests.
I created a very simple test component:
HTML:

ObjectID: #{{user?.id}}

Typescript:
export class TestComponent implements OnInit {

  user: User
  constructor(private userService: UserService) { }

  ngOnInit() {
    this.userService.getUser(1).subscribe(user => this.user = user)
  }
}

The results from this if I look in the source of my page will be
ObjectID: #
. I'm using the Universal Starter. Isn't the Angular Universal server suppose to wait for the ngOnInit() to finish loading?

A: The issue was that I was serving my Angular app and my API app from 2 separate Docker containers, and the Server-Side-Rendered NodeJS app was trying to do the HTTP calls to the public url of the API container -- the problem with this is that a Docker container does not know the public url (e.g. 0.0.0.0:8000) of the other containers, it only knows the container names (e.g. http://backend).
This is only an issue during development, not during production because then it uses a real public domain.
The solution I did was to add a alias in my etc/hosts file on my local computer to 0.0.0.0, and then also adding the same alias in my docker-compose.yml file. So both my browser, and the container, can access the API on a custom hostname.
etc/hosts on local machine
0.0.0.0 api.local

docker-compose.yml
services:
  ...
  backend:
    ...
    networks:
      default:
        aliases:
          - "api.local"

All HTTP calls during development from both the client and the server side rendered app is done to http://api.local/


text:
Q: The fastest way pandas can compile numerous dataframes I am compiling some dataframes with pandas at the moment, currently 99 workbooks with around 200,000 rows of data and a few columns. The exercise is filtering one of these columns and getting a combined workbook of all of the filtered data.
Initially I used a list to append all the filtered data to one dataframe and then write out a the resultant csv, below:
appended_data=[]
for fname in os.listdir(readpath):
    if 'xlsx' in fname:
        ex_wbk = os.path.join(readpath + fname)
        try:
            fName = os.path.join(readpath + "\\" + fname)
            fBase = os.path.basename(fName)
            df = pd.read_excel(fName, index = False, index_col=None, na_values='')
            df.drop(df.iloc[:, 2:4], inplace = True, axis = 1)
            df.dropna(subset=['Data Line'], inplace=True)
            appended_data.append(df)
            errorbook = ex_wbk
        except OSError:
            print(str(errorbook) + " Workbook in use")
            pass

appended_data = pd.concat(appended_data, sort=True)
appended_data.to_excel(home, header=False, index=False)

This took 789 seconds to run

Then, I thought about making a csv file of each workbook with only the filtered data and compiling all of those. As below,
for filename in os.listdir(homedir):
    if filename.endswith(".xlsx"):
        fName = os.path.join(homedir + "\\" + filename)
        fBase = os.path.basename(fName)
        fRaw = os.path.splitext(fBase)[0]
        df = pd.read_excel(fName, index = False)
        df.drop(df.iloc[:, 2:4], inplace = True, axis = 1)
        df.dropna(subset=['Data Line'], inplace=True)
        df.to_csv(path_or_buf=home, header=True, index=False)

all_files = glob.glob(homedir + "/*.csv")
df = pd.concat((pd.read_csv(f) for f in all_files))
os.path.join(path, "*.csv")
df.to_csv ("D:\\Users\\cdoyle\\Desktop\\short\\combined_csv.csv", index=False, encoding='utf-8-sig')

This took 610 seconds to run

Is there a faster way than the above?

A: Have you ever profiled your code? Without it, you won't really know where you'll get the most benefits and it's hard to make good guesses.
Still, I notice that you're reading a spreadsheet and only after it's loaded in memory discarding a couple of columns. You'll likely get some improvement if you already delegate that earlier, to the reader:
column_indices_to_preserve = […]
pd.read_excel(…, usecols=column_indices_to_preserve)

This will prevent you from doing at least one extra pass over the data, which is desirable. It will also reduce the memory footprint of each data structure.


text:
Q: How can I create a div with maximize and minimize functionality using angular How can I create a div with maximize and minimize functionality using angular.
There is a maximize icon on default, on clicking that button the div should be maximize and icon should changed to minimize. on clicking minimize icon it should minimize and the icon reverted to maximize.

A: Define a variable toogle in your ts
toogle:boolean=false;

And
<button (click)="toogle=!toogle">{{toogle?'v':'^'}}</button>

  lorem ipsum

You can use also [style.min-height]
Update You can also

  <button (click)="toogle=!toogle">{{toogle?'v':'^'}}
  </button>
  lorem ipsum

Update 2
If we defined two styles in .ts
  toogle:boolean=true;
  minimize= {height:'1.5rem',position:'fixed',bottom:0,overflow:'hidden'}
  maximize={height:'100vh'}

We can use:

  <button (click)="toogle=!toogle">{{toogle?'v':'^'}}</button>lorem ipsum


text:
Q: java: how jna callback function works I'm using a native library coded in C or C++, after a lot of multiple tests i successed to make it work, but i'm not sure if what i do correspond to the correct coding rules, and some parts are not clear for me.
So my question is : could you confirm and complete what i understood.
Thanks
the C prototype function is:
typedef void (*pfHook) (const char *pText);

and the function to set the callback function is:
short LogHookEx(void (*pfHook) (const char*));

So i created an interface for my native dll like that:
So if i understood "interface pfHookCallback" correspond to the C prototype function and "sCscSetApiLogHookEx" is a classic method from my native dll.
public interface Reader extends Library {

    Reader INSTANCE = (Reader) Native.load((Platform.isWindows() ? "ReaderDll" : "c"),
                    Reader.class);
interface pfHookCallback extends Callback {
        void invoke(String pText);
    }

    short LogHookEx(pfHookCallback pfHook);
}

The part that i understand less, is the part that i include in my "main":
public class Principal {

    public static void main(String[] args) {

        Reader.pfHookCallback pfHook = new Reader.pfHookCallback() {
            public void invoke(String pText) {
                System.out.println(pText);
            }
        };

        res = Reader.INSTANCE.LogHookEx(pfHook);

To be more clear this callback function is used for tracing from an hardware device.
As described above, it's working, but it's not cleat for me.
And another question is , the goal of my code is to save the logs (so the pText string) into a file. Is there a best practice to do that, because if i create buffered writer, i don't know if it's good or not to do something like that:
public class Principal {

    public static void main(String[] args) {

        Reader.pfHookCallback pfHook = new Reader.pfHookCallback() {
            public void invoke(String pText) {
                bw.write(pText);

                bw.close;
            }
        };

        res = Reader.INSTANCE.LogHookEx(pfHook);

My question is i don't know if it's really good to open and close a file very quickly every time there is a log to be saved ?


text:
Q: Duplicating and arranging a list I have a list,
{a,b,c,d,...,z}

And I want to duplicate that list n times such that,
{a,a,a,b,b,b,c,c,c,....z,z,z}.

I have found the Table function can create duplicates by appending to the end of the list. Is this the way to go and then reordering? If so, how?
Any help would be appreciated.

A: f1 = Flatten@Transpose@ConstantArray@## &;
f2 = With[{ls = #}, Flatten[Transpose@Array[ls &, #2]]] &;
f3 = Flatten@Transpose[Table[#, {#2}]] &;
f4 = Flatten[ArrayPad[List /@ #, {{0, 0}, {0, #2 - 1}}, "Fixed"]] &;

lst = {a, b, c, d};

f1[lst, 3]

{a, a, a, b, b, b, c, c, c, d, d, d}

 Equal @@ (#[lst, 3] & /@ {f1, f2, f3, f4})

True

Timings:
list = RandomReal[{0, 1}, 1000000];
n = 3;
{t1, r1} = f1[list, n] // AbsoluteTiming;
{t2, r2} = f2[list, n] // AbsoluteTiming;
{t3, r3} = f3[list, n] // AbsoluteTiming;
{t4, r4} = f4[list, n] // AbsoluteTiming;
{t5, r5} = Flatten[ConstantArray[#, n] & /@ list] // AbsoluteTiming;
{t6, r6} = Sequence @@ ConstantArray[#, n] & /@ list // AbsoluteTiming;
{t7, r7} = Flatten@Replace[list, a_ :> Table[a, {n}], 1] // AbsoluteTiming;
{t8, r8} = Flatten[NestList[# &, #, 2] & /@ list] // AbsoluteTiming;

{t1, t2, t3, t4, t5, t6, t7, t8}

{0.044306, 0.034579, 0.021672, 0.111301, 0.558783, 2.088776, 1.020894, 0.369900}

Equal @@ {r1, r2, r3, r4, r5, r6, r7, r8}

True

A: You can use Map (or its shorthand /@) together with Sequence over the list:
list = {a, b, c}
Sequence[#, #, #] & /@ list
(* {a, a, a, b, b, b, c, c, c} *)

For larger amounts of repetition, that gets annoying. In that case, you can use ConstantArray and the remove the List head:
list = {a, b, c}
n = 5
Sequence @@ ConstantArray[#, n] & /@ list
(* {a, a, a, a, a, b, b, b, b, b, c, c, c, c, c} *)

As J. M. mentions you can also use Flatten (or even Join) instead of Sequence:
Flatten[ConstantArray[#, n] & /@ list]
Join @@ (ConstantArray[#, n] &) /@ list

A: This one is just for fun,
list = ToExpression /@ Alphabet[]
Most@Fold[Riffle[#1, list, #2] &, list~Join~{dummy}, Range[2, 5]]

(* {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t,
u, v, w, x, y, z} *)

(* {a, a, a, a, a, b, b, b, b, b, c, c, c, c, c, d, d, d, d, d,
e, e, e, e, e, f, f, f, f, f, g, g, g, g, g, h, h, h, h, h, i, i, i,
i, i, j, j, j, j, j, k, k, k, k, k, l, l, l, l, l, m, m, m, m, m, n,
n, n, n, n, o, o, o, o, o, p, p, p, p, p, q, q, q, q, q, r, r, r, r,
r, s, s, s, s, s, t, t, t, t, t, u, u, u, u, u, v, v, v, v, v, w, w,
w, w, w, x, x, x, x, x, y, y, y, y, y, z, z, z, z, z} *)

You need the dummy variable or else Riffle won't put any extra zs on the end.

A: A replacement version:
lst = {a, b, c, d};
Replace[lst, a_ :> Sequence[a, a, a], 1]
(* {a, a, a, b, b, b, c, c, c, d, d, d} *)

or
Replace[lst, a_ :> Sequence @@ Table[a, {5}], 1]
(* {a, a, a, a, a, b, b, b, b, b, c, c, c, c, c, d, d, d, d, d} *)

or, slightly faster,
Flatten@Replace[lst, a_ :> Table[a, {5}], 1]


text:
Q: Why actions can not be done on match groups when using replace operator in powershell? Why when I execute following script:
'abc abc abc' -replace '\w+', '$0 abc'.ToUpper()

I get abc ABC abc ABC abc ABC instead of ABC ABC ABC ABC ABC ABC?
Moreover, if I execute
'abc abc abc' -replace '\w+', '$0 abc'.ToCharArray()

I get $ 0   a b c $ 0   a b c $ 0   a b c
Is this possible to make some actions with match groups?

A: As Lee_Daily points out, the .ToUpper() call is executed before the string is passed to -replace.
If you want programmatic access to each substitute, use [regex]::Replace() directly:
[regex]::Replace('abc abc abc', '\w+', {"$($args[0].Value) abc".ToUpper()})

... or, if you're using PowerShell 6.1 or newer, -replace also supports a scriptblock for substitute evaluation:
'abc abc abc' -replace '\w+', {"$($_.Value) abc".ToUpper()}


text:
Q: PHP: Unsure How to Model a Database Relationship In my database I have a table 'favorites' and a table 'activity'. I am using the Zend Framework and I have a class modeling both tables. Now, when someone favorites an article then I have to add a row in the activity table.
The most obvious way to do this would be to create the methods addActivity and addFavorite in the respective table classes, and whenever an article is favorited I would call then addActivity method. Although this is very straightforward, it doesn't seem natural to me.
Do you have any suggestions on a better way to do this?

A: I had faced the same problem in the past. I had it solved, using your ontology, with a static method in the activity table the call was something like:
Activity::addNew($favouriteID, Activity::FAVOURITE);

and yes it looks un-natural.
You are talking about Aspect Orientation here, I'm afraid...
Another way to do it (but did not choose it for other reasons), would be by adding a trigger to the database, which would populate
activity, each time a favourite was added. I did not want to go there because it is overstated in the literature that triggers soon
get out of control. This depends on how much application logic you want to have on database level...


text:
Q: Erlang application exit,, but vm is still running My Erlang applicaation processed crashed and then exited, but found that the erlang VM is still running.
I could recieve pong when ping this "suspended node"
Types regs() and the results show below, there is not my app process.
(hub@192.168.1.140)4> regs().

** Registered procs on node 'hub@192.168.1.140' **
Name                  Pid          Initial Call                      Reds Msgs
application_controlle <0.7.0>      erlang:apply/2                30258442 1390
auth                  <0.20.0>     auth:init/1                        189    0
code_server           <0.26.0>     erlang:apply/2                 1194028    0
erl_epmd              <0.19.0>     erl_epmd:init/1                    138    0
erl_prim_loader       <0.3.0>      erlang:apply/2                 2914236    0
error_logger          <0.6.0>      gen_event:init_it/6           49983527    0
file_server_2         <0.25.0>     file_server:init/1            16185407    0
global_group          <0.24.0>     global_group:init/1                107    0
global_name_server    <0.13.0>     global:init/1                     1385    0
gr_counter_sup        <0.43.0>     supervisor:gr_counter_sup          253    0
gr_lager_default_trac <0.70.0>     gr_counter:init/1                  121    0
gr_lager_default_trac <0.72.0>     gr_manager:init/1                   46    0
gr_lager_default_trac <0.69.0>     gr_param:init/1                    117    0
gr_lager_default_trac <0.71.0>     gr_manager:init/1                   46    0
gr_manager_sup        <0.45.0>     supervisor:gr_manager_sup          484    0
gr_param_sup          <0.44.0>     supervisor:gr_param_sup/1          253    0
gr_sup                <0.42.0>     supervisor:gr_sup/1                237    0
inet_db               <0.16.0>     inet_db:init/1                     749    0
inet_gethost_native   <0.176.0>    inet_gethost_native:serve      4698517    0
inet_gethost_native_s <0.175.0>    supervisor_bridge:inet_ge           41    0
init                  <0.0.0>      otp_ring0:start/2             30799457    0
kernel_safe_sup       <0.35.0>     supervisor:kernel/1                278    0
kernel_sup            <0.11.0>     supervisor:kernel/1              47618    0
lager_crash_log       <0.52.0>     lager_crash_log:init/1        97712230    0
lager_event           <0.50.0>     gen_event:init_it/6         1813660437    0
lager_handler_watcher <0.51.0>     supervisor:lager_handler_          358    0
lager_sup             <0.49.0>     supervisor:lager_sup/1             327    0
net_kernel            <0.21.0>     net_kernel:init/1            110769667    0
net_sup               <0.18.0>     supervisor:erl_distributi          313    0
os_cmd_port_creator   <0.582.0>    erlang:apply/2                      81    0
rex                   <0.12.0>     rpc:init/1                    15653480    0
standard_error        <0.28.0>     erlang:apply/2                       9    0
standard_error_sup    <0.27.0>     supervisor_bridge:standar           41    0
timer_server          <0.100.0>    timer:init/1                  59356077    0
user                  <0.31.0>     group:server/3                23837008    0
user_drv              <0.30.0>     user_drv:server/2             12239455    0

** Registered ports on node 'hub@192.168.1.140' **
Name                  Id              Command
ok

It rarely occurs, but anyone explains it?

System: CentOS 5.8
Erlang: R15B03


text:
Q: ES6 Modules: Sustainability of TypeScript internal modules & Bundles Full names of classes in TypeScript
TypeScript 1.X allows the developer to use internal modules as namespaces.
module MyProject.MySubProject {
    export class A {
    }
    export function f() {
        var a1 = new A(); // valid
        var a2 = new MySubProject.A(); // valid too
        var a3 = new MyProject.MySubProject.A(); // valid too, again
    }
}
MyProject.MySubProject.f();
var a4 = new MyProject.MySubProject.A(); // ... and valid

When transpiled to ES5, this code creates an object MyProject that contains an object MySubProject that contains two functions A and f.
From inside the module, a class can be designed with a relative name (A, MySubProject.A) or the full name (MyProject.MySubProject.A). From outside the module, the exported class is used with the full name.
But nested modules no longer exists in ES6. And TypeScript is going to align to the ES6 modules.
Are the full names of classes (MyModule1.MyModule2.MyClass) compatible to ES6?
If we want to use namespaces in the old way, can we declare an ES6 class in a closure or an object?
Bundles and ES6 modules
Here is a similar code in the ES6 way:
//------ MyProject/MySubProject.js ------
export class A {
}
export function f() {
    var a1 = new A(); // valid
}

//------ main.js ------
import { A, f } from 'MyProject/MySubProject';
f();
var a2 = new A();

After concatenation of the two JavaScript files into a single minified file, how to operate the import?

A: TypeScript is only going to align with ES6 modules as a new sytanx based on TypeScript external modules. This is based off of what work is being done on GitHub. Current internal modules do not conflict with the new syntax and therefore will continue to work as is.


text:
Q: I'm building a WordPress theme and noticed that the 404 page template runs along with the corresponding templates for each page. Any idea why? function debug($message){

   error_log($message, 3, get_template_directory() . '/debug.log');

}

I added the above function to each of the templates.
For example, front-page.php includes a line that goes like this: debug("front-page.php \n");
I use tail -f debug.log in the terminal to determine which templates are being used by a particular page.
Here is the result.

A: I used the following function to retrieve the URLs of each page.
  function template_debug($filename = null) {
        $url = home_url($_SERVER['REQUEST_URI']);
        debug("Called from: $filename using URL $url \n");
    }

Then I inspected the front page which triggered the 404 template along with the front-page template. The Network Monitor tab showed the error, which was an incorrect folder name included in the CSS file.
After making the necessary changes, the 404 template isn't being triggered anymore.


text:
Q: Creating pandas dataframe with tuples per row but with missing columns I have an operation that outputs a series of tuples like
[('a',1.0), ('c', 2.5)]. It does this for a lot of inputs, so the outputs would look like
[('a',1.0), ('c', 2.5)]
[('b',1.5), ('c', 2.5)]
[('a', 5.0), ('b',1.5), ('c', 2.75)]

which should output a dataframe that looks like
>>> df
     a     b     c
0    1.0   NaN   2.5
1    NaN   1.5   2.5
2    5.0   1.5   2.75

However, the column names are not known beforehand, so at some point the data generation, I could end up with some ('z',12.0).
I think the simplest way would be to create a dataframe for each row and concatenate the dataframes:
df_list = []
for row in rows:
     tuple_result = f(row)
     df_list.append(pd.DataFrame(...)) # generate a single-row dataframe
df = pd.concat(df_list, axis=0, ignore_index=True)

and this will take care of all the NaNs and column names. However, I will be doing this for several rows and I think this approach will be unnecessarily memory-intensive.
Is there a better way to do this?

A: Your can use a list comprehension, converting each row of tuples into a dictionary.
my_data = [
    [('a',1.0), ('c', 2.5)],
    [('b',1.5), ('c', 2.5)],
    [('a', 5.0), ('b',1.5), ('c', 2.75)]
]

>>> pd.DataFrame([dict(row) for row in my_data])
     a    b     c
0  1.0  NaN  2.50
1  NaN  1.5  2.50
2  5.0  1.5  2.75

Timings
%timeit pd.DataFrame([dict(row) for row in my_data * 100000])
# 559 ms ± 92 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

%timeit pd.DataFrame(map(dict, my_data * 100000))
# 438 ms ± 25.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

%%timeit
df_list = []
for row in my_data * 100000:
     df_list.append(pd.DataFrame(dict(row), index=[0]))
df = pd.concat(df_list, axis=0, ignore_index=True, sort=False)
# 6min 11s ± 1min 54s per loop (mean ± std. dev. of 7 runs, 1 loop each)


text:
Q: How can I download an image that contains Arabic characters in the name? Here is my code:
WebClient client = new WebClient();
client.DownloadFile("http://bazdeh.org/wp-content/uploads/2016/05/%D8%A8%D8%A7%D8%B2%D8%AF%D9%87-%D8%B1%D9%88%DB%8C.jpg", Server.MapPath("/Image/holoo3.jpg"));
// original url (not encoded): http://bazdeh.org/wp-content/uploads/2016/05/بازده-روی.jpg

Code about downloads an image which is break and doesn't get open (I mean, the windows image viewer throws):

Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or is too large.

Noted that I've encoded/decoded it like this but still doesn't work and says "invalid URL format":
HttpUtility.UrlEncode(Uri.UnescapeDataString(url)));

Anyidea how can I do that?

A: I find my answer. the problem was my internet speed that was very low.
I test my code with high speed internet and get result OK. And is problem dont related with Arabic character in file name.
When try with low speed internet speed, image downloaded Incomplete.


text:
Q: NoSQL solution with fast Map/Reduce There are 3 high load sites (>400k unique visitors per day), they all are tightly connected, have same admin interface, sharing user accounts etc... Sites have following statistics items: visitors, unique visitors, user path, referer, time on site, on page, region, country and browser. Statistics is aggregated and processed by 3rd party service, but this service can't provide cross-site statistics in a convinient manner (lots of manual checks and tracking of users) so I want to build a statistics solution which will provide functionality described above and also provide cross-site statistics. And now I'm in doubt: what should I use for storage? First I've tried to use good old MySQL and that totally failed: performance and scalability issues were killing whole idea. So I've started to look at NoSQL solutions, but I don't have much experience with them and I'm seeking for advice which solution should I use that will fit following requirements:

*

*Non-blocking map/reduce. Map/Reduce shouldn't block collection for writing (so when admin requests some statistics data sites would be still able to add visitor records)

*Easily scalable.

*Users are counted on the beginning of request lifecycle, so response from database should be really fast

Any ideas?

A: While grabbing a few freebies from a conference in the Spring, I spent a few min's sitting through a presentation that covered several mongoDB use cases, one that appears applicable is the case of ServerDensity. Their blog entry describes a similar high volume logging system, along with the reasoning behind their decision to move from mySQL to MongoDB, and in particular why mongoDB rather than the competition. There are other presentations along similar lines kicking around e.g. Eventbrite, Yotta, Devmash
There's also a chapter (5 - Web Analytics using MongoDB), of PHP and MongoDB Web Development Beginner's Guide, By Rubayeet Islam, that covers building such a system.


text:
Q: Spark structured streaming multiple applications joined by Kafka I have two Spark structured streaming applications. The first makes some windowing aggregations and outputs to Kafka in "update" mode. The second reads this Kafka stream and does some further processing and again outputs in "update" mode.
Will the second application reading the Kafka stream read in the most up to date data?


text:
Q: How to remove background noise in image without damaging text? I am processing images for tesseract's ocr. I need help to get rid of the background noise without damaging the text.
Example input image

I have tried median blurring and removing small connected components (How do I remove the dots / noise without damaging the text?). The problem with connected components is that the noise can have larger connections and I cannot get rid of it without also removing the minus sign. Any suggestion how to move forward?

A: Since your image is only black/white, you can do simple thresholding and morphological transformations to filter the image. If your image input was not black and white, you could do blurring techniques such as cv2.medianBlur() or cv2.GaussianBlur() to smooth the image as a preprocessing step. Then you could perform morphological operations with various kernel sizes or construct custom kernels with cv2.getStructuringElement(). Generally, a larger kernel size (7x7 or 9x9) will remove more noise but also remove the desired details as opposed to a smaller kernel (3x3 or 5x5). There is a trade off depending on how much noise you want to remove while balancing the amount of details to preserve. Take a look at this answer for colored captchas.

Threshold

Morph close

Invert image for Tesseract

Result

-63 164

import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image = cv2.imread('1.png',0)
thresh = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY_INV)[1]

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)

result = 255 - opening
cv2.imshow('thresh', thresh)
cv2.imshow('opening', opening)
cv2.imshow('result', result)

print(pytesseract.image_to_string(result))
cv2.waitKey()