Delete all files from folder older than a specified amount of time with custom function

Question: I am trying to delete all files from a folder that are older than x hours (current example is for one hour). But it doesn't respect the condition, the script delete all the files from the folder, doesn't matter if they are older than 1 hour or newer than 1 hour.
<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 'on');

  function destroy($dir) {
    $mydir = opendir($dir);
    while($file = readdir($mydir)) {
      if($file != "." && $file != "..") {
        chmod($dir.$file, 0777);
        if(is_dir($dir.$file)) {
          chdir('.');
          while($dir.$file) {
            if(date("U",filectime($file)) >= time() - 3600) {
                unlink($dir.$file);
        echo $file.' had been deleted';
            }
          }
        } else
          unlink($dir.$file) or DIE("couldn't delete $dir$file
");
      }
    }
    closedir($mydir);
  }

  $docroot = $_SERVER['DOCUMENT_ROOT'];
  $docroot = $docroot.'/scrapers/thumbnails/';
  destroy($docroot);
?>

Comment: I don't know PHP, but if you are getting the age of the file in seconds since 1 Jan 1970, an older file (relative to today) will have an age that is a smaller number of seconds (since it will be nearer 1970), not larger.
Comment: @MarkSetchell I see.Hmm.
Answer: try:
function destroy($dir) {
    $mydir = opendir($dir);
    while($file = readdir($mydir)) {
        if($file != "." && $file != "..") {
            chmod($dir.$file, 0777);
            if(is_dir($dir.$file)) {
                chdir('.');
                while($dir.$file) {
                    if((time() -  filemtime($file)) > 3600) {
                        unlink($dir.$file);
                        echo $file.' had been deleted';
                    }
                }
            } else
                if((time() -  filemtime($file)) > 3600) {
                    unlink($dir.$file) or DIE("couldn't delete $dir$file
");
                }
        }
    }
    closedir($mydir);
}

Comment: Still deletes the new files (all files), newer than 1 hour, and also echo's `Warning: filemtime(): stat failed for 1395644972173331.png in`
Comment: this is maybe then a problem with the realpath of the file. What is in your `$dir`? Try `filemtime($dir . '/' . $file)`


Gui won't start start dist-upgrade

Question: I did a fresh install, set up everything all day yesterday, did a dist-upgrade and autoremove, boom. Tried to reinstall desktop, no luck... Any help please?
some package mismatch
gui not starting
Comment: You took a photo of the text, thus can login. You can pastebin the text from terminal, copy it to a file & send the file somewhere, or login remotely (`ssh` or a text login) & then use another system to copy & paste with a GUI tool if you're not familiar with terminal commands. There are many ways; but I'd ask whomever took for the photo you pasted as they do have access to the text.
Comment: Pictures of text on a screen is much harder to read than text placed in your question, but you've no doubt added some 3rd party package to your system to is conflicting with your desktop package thus the problem.  (*You've given few details; and I can't copy from a picture (unlike text in a question) thus can't easily do some searching of potential issues; though I suspect the problem relates to installs prior to your `apt autoremove`*)
Comment: I did check for held packages. There are none. So the link didn't help me. Only other source I added is multiverse. I would've copied text but how am I supposed to if I have no access to it?
Comment: Nvm, I had to downgrade libgbm1 to 22.04.1 since the dependencies are not yet available in the latest version apparently. Instead of complaining about the format other people actually tried to help me.
Answer: I had to downgrade libgbm1 to 22.04.1 since some packages aren't available in 22.04.2 yet apparently. Reddit helped me far more than people here.
Comment: `libgbm1 | 22.2.5-0ubuntu0.1~22.04.1 | jammy-updates   | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x` is the correct 22.04.2 package currently; there is `libgbm1 | 22.2.5-0ubuntu0.1~22.04.2 | jammy-proposed  | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x` in proposed; but you shouldn't need that yet; if you do you have a sources or 3rd party package issue from earlier.

Gui won't start start dist-upgrade


Sort barplot columns ggplot

Question: I have this R code code to generate the following barplot:
d <- data.frame(case = c(1,2,3,4),
                var=c('foo', 'foo', 'foo', 'foo','bar', 'bar', 'bar', 'bar'),
                val=c(9,2,2,4,6,1,2,3))
d$var <- as.factor(d$var)
d$case <- as.factor(d$case)
ggplot(d, aes(x = case, y = val, fill = var)) + scale_x_discrete() + geom_bar(position="dodge")

How can I sort the bars by the value of 'bar'?
Disclaimer: this might be a duplicate of https://stackoverflow.com/questions/10746342/sorting-ggplot2-box-plot-by-2-columns but this was not answered, so...
Comment: @Arun I think you just need to modify your answer to sort the levels of `case` by `val` within `foo`, but I agree that this wasn't terribly clear from the question.
Comment: @Arun, thanks for the answer, what I really ment is that I would like to sort the columns not per case but across cases. In my example, if I 'sort the bars by the value of bar', I would like the cases to be displayed in this order: 1, 4, 3, 2
Comment: Arun has basically shown you the way, even though he misread how you wanted it sorted. Just specify the levels of `case` in the desired order.
Comment: Okay after enough trials, now, I think I got it right. Thanks @joran for clarifying the question.
Answer: Use order to get the columns ordered by values for bar and replicate it in foo as well. Then use this column for x.
d$case <- match(d$val[d$var == "bar"], sort(d$val[d$var == "bar"]))
d$case <- factor(d$case, levels=1:4)
# now use this:
ggplot(d, aes(x = case, y = val, fill = var)) +
         geom_bar(position="dodge", stat="identity")

(or equivalently)
 ggplot(d, aes( x= order, fill = var)) + geom_bar(aes(weights=val), position="dodge")

Sort barplot columns ggplot


Are these studs actually structural?

Question: First question on here so apologies if getting it wrong.  I have removed old lath and plaster wall from under stairs to install cupboards but there is a lot of wood that appears to be structural support for the stairs.  One stringer appears to be nailed to the wall but the top does not appear to have vertical support from the beam.  Any thoughts?
Structural support or plaster battens?

Just check under floorboards.  No beam underneath so just resting on boards mid way between 13 inch flooring support beams.
Back of the stringer

Top of Stringer

Stud under stringer
Comment: Those uprights are more for holding the plaster than the stairs, so I doubt if they give the stairs much support.  Probably the other way the stairs hold the top of the wall in place.
Comment: Thanks - my thoughts too but not really ready to knock them out just yet :)
Comment: the wall might be supporting the top end pf the stringer,  you could use a bracket or hanger there instead to support the stringer from the floor joist.
Answer: In many cases, studs that are sitting directly on the subfloor are not structural. Perhaps the only exception, and this would be only in homes built before 1955, before the building codes were introduced. If there is a joist directly under the stud bottoms, they may be bearing.
The main concern for wall removal would be to be certain to maintain a good connection/support at the base of the stairs. In my opinion, this should be no problem, since to add cupboards all the way to the lowest end of the stairs would seem impractical. Keeping the 1 short stud there will do all needs to be done for anchoring/support, should it need it to begin with. Another thing to look at is the stringer that the studs connect to. If there is the equivalent of a 2X6 left over after the notches are cut to set the treads on, there is enough "meat" there to handle the span that is left over from my suggestions.
The last thing to look at is the connection at the top. if you take out 3 studs, leaving the last one intact at the top of the stairs, it may offer you a 4' wide area for a cupboard. Depending what the studs do beyond the camera, you may be able to get over a 5' set of cupboards.
These suggestions are the simplest way to accommodate what you ask. There are framing anchors that can be used at the top to aid in removing even more studs potentially, but that would require more info on what you have.
Comment: If you could upload a clearer picture of the back of the stringer (as it's covered with a decorative piece on the front) and more clearly showing how the studs are joined to the stringer it may help to resolve some of the questions in this answer.  In the existing fuzzy picture it looks like maybe one of the studs is cut into the stringer but the others are not.  May just be odd pixelation.
Comment: Thanks Jack - have got some more photos to show studs sitting beneath the stringer, the back of the stringer with  tape measure and the top of the stringer also.  Will add photos in the original post
Comment: Thanks jay613 also :)
Comment: The additional photos seem to support everything in this answer.  It all appears to be framing for the plaster, added after the stairs were built.
Comment: How wide will the cupboards be per your original idea? There can be a type of hanger that could support the top of the carriage. If you plan on removing the stud at the top, I would insist the proper hanger be added first, before removing the stud. The stud does help hold that carriage in place, since it is deeply notched at the top to go around the gray/white beam
Comment: Thanks Jack - will talk to cupboard company about it

Are these studs actually structural?


Use a HTML page like a button

Question: I have a HTML page and I want to use the page like a button, for example when I click anywhere on the page, something happens just like a button, any way?
Comment: Perhaps, have an element with `100% width` and `height`, and wrap `a` tag around the element...
Comment: see fiddle http://jsfiddle.net/nagq8/
Answer: Bind a click event handler to the document object.
document.addEventListener('click', function (evt) {
    alert('click');
});

Comment: yeah, thanks, just 1 other problem, except this method, I used a button too. but when I click the button, the function works twice, once because of clicking on the button and once because of using this method , how to solve this?
Comment: https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation
Comment: how to use stopPropagation ?
Comment: To quote the page I linked to: See Example 5: Event Propagation in the Examples chapter for a more detailed example of this method and event propagation in the DOM.
Answer: You could use the following function to trigger actions when the mouse is clicked anywhere on the page:
document.body.onmousedown = function() {
     // enter your code here
}

Comment: yeah, thanks, just 1 other problem, except this method, I used a button too. but when I click the button, the function works twice, once because of clicking on the button and once because of using .body.onmousedown , how to solve this?

Use a HTML page like a button


Why is this airduct twitching and making a noise?

Question: I have an air duct in my basement. It leads from my furnace (I think?) to the outside world.
However, as you can see from this video, it is "twitching".
Every second or so it jerks slightly and makes a noise.
https://youtu.be/u-WKaxWBnw4
The portion of the duct shown in this video is the end of the duct that terminates outside the house. The rightmost portion of this duct leads to an opening on the exterior wall of the house.
When the furnace switches on, the twitching stops. What's going on?
Do I have an alien living in my air-duct?
Update: The end of the duct is not connected to the furnace. It is connected to a clothes dryer. But I still don't know why it is clicking like this.
Comment: Sounds like something switching back and forth. What is on both ends of the duct or in the line somewhere?
Comment: Update: The end of the duct is not connected to the furnace. It is connected to a clothes dryer. But I still don't know why it is clicking like this.
Comment: My answer still pertains (although I changed "furnace" to "dryer"). Go find the flapper, and it'll be clicking. Hold it either open or shut, and the clicking (and the duct throbbing) will stop.
Answer: The outside end of the duct has a flapper to prevent air (and critters) from coming into the house when the dryer is off. However, even with the dryer off, there can still be a small amount of airflow through the duct, e.g. from inside/outside air pressure differences. It seems that in your case there isn't enough airflow to keep the flapper open, so it swings closed, making a "click". Then, as the (small amount of) pressure builds up, the flapper pops open to let a burst of air through. The changing air pressure causes the flexible duct to throb. Repeat twice a second, and bingo: alien living in your vent duct.
Answer: Is this air duct part of a fresh air intake? Is it connected to an active damper which controls how much air flows through it? If so, the damper may be switching on and off when the HVAC circulating fan is off.
Alternatively, wind blowing across the vent on the exterior may be setting up oscillations when the HVAC fan is off.


Centre overflowing element around non-centre point

Question: I have an element E that is 1000px wide, that is within a parent container P.
Of E's 1000 pixels of width, the columns x position 600–800px are more important than the others, so as its parent element gets narrower, I'd like to position E within P so that these pixels are visible and centred within P (until this is no longer possible).
So, if P can fit the entire width of E, no problem! Just centre E within P:
             ┌──────────────────────────────────────────────────────────────┐
             │P                                                             │
             │      ┌─────────────────────────┬──────────────┬───────┐      │
             │      │E                        │Important█████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      │                         │██████████████│       │      │
             │      └─────────────────────────┴──────────────┴───────┘      │
             │                                                              │
             └──────────────────────────────────────────────────────────────┘

However, if the parent is resized to be e.g. 250px wide, E should be centred around x=700px:
                                         ┌───────────────────────────┐
                                         │P                          │
                     ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼─────┬──────────────┬──────│
                       E                 │     │Important█████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     │                   │     │██████████████│      │
                                         │     │██████████████│      ││
                     └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼─────┴──────────────┴──────│
                                         │                           │
                                         └───────────────────────────┘

Is this possible to achive with CSS? (Maybe using calc()?)
Bonus: Is it possible to have the overflow be scrollable? (If so, I guess JS is needed?)
Comment: Is the content in `E` an image or text?
Comment: @veesar It's a `div` with a fixed height and width.
Answer: You could do this with absolute positioning. For larger screens, position the #Important div absolutely 200px from the right-end of E. For smaller screens, position the div absolutely from the left (e.g., 50px from the left).
See this CodePen for the solution.
With this method, the contents of #Important div will overlap the contents of E which I'm assuming is what you want based on the visuals in your question.


Prove that $g \circ f$ is a one-to-one function

Question: Let $f$ and $g$ be one-to-one functions such that the domain of $f$ is $A$, the range of
$f$ is $B$, the domain of of $g$ is $B$, and the range of $g$ is $C$.

Prove that $g \circ f$ is a one-to-one function.
Prove that $f^{−1} \circ g^{−1}$ is the inverse of $g \circ f$.

Not sure if I should be letting $f(x)$ and $g(x)$ be actual functions here then proving it, or what's going on..
Comment: Well, what is a one-to-one function, precisely?
Comment: @Berci http://en.m.wikipedia.org/wiki/Injective_function
Comment: A function $h$ is injective if and only if given $h(x_1) = h(x_2)$, then $x_1 = x_2$; (or the equivalent given $x_1 \neq x_2$, then $h(x_1)\neq h(x_2)$).
Comment: The first part is addressed here:
http://math.stackexchange.com/questions/237883/functions-and-injection-bijection-surjection-of-composition
Comment: The second part is discussed (although not entirely answered) here: http://math.stackexchange.com/questions/190138/a-question-about-composition-of-functions
Answer: Here's a simple proof for part 1:
Suppose $h(x)=g(f(x))$
Since we know $f,g$ are two (equal or distinct) one-to-one functions, for all $x\ne y \in A$,
$f(x) \neq f(y)$ (by definition of one-to-one).
Now, we are given that $f(x), f(y) \in B$, which is also the domain of $g$.
Also, we now know that $g(f(x)) \neq g(f(y))$, since we know that $g$ is also a one-to-one function.
But we have $h(x)=g(f(x)), h(y) =g(f(y)) \implies h(x) \neq h(y)$, which is the definition of a one-to-one function.
This proves our theorem, since $h(x) =g(f(x)) = g\circ f$.
Answer: The goal: We can prove $g∘f$ is one-to-one by using the hypothesis to shows that $g(f(x)) = g(f(y)) \implies f(x) = f(y)$
The hypotheses are:
$ f: A \to B$ and $f$ is injective. (injective mean one-to-one)
$ g: B \to C$ and $g$ is injective.
Proof: Let $f$ and $g$ be an injective function. Assume there exist two elements x and y in A such that $x \neq y$, then $f(x) \neq f(y)$ because $f$ is injective. So $f(x)$ and $f(y)$ are two distinct elements in B. Thus, $g(f(x)) \neq g(f(y))$ are two distinct elements in $C$ because g is injective. We have shown that: $$f(x) \neq f(y) \implies g(f(x)) \neq g(f(y))$$
which equivalent to:
$$g(f(x)) = g(f(y)) \implies f(x) = f(y)$$
$\therefore g\circ{f}$ is a one-to-one function.
$$\tag*{$\blacksquare$}$$
If you struggle, comment the part that you don't understand about this proof.


Complex number - sum of imaginary part

Question: Question:

Let $z = \cos \theta + i \sin \theta$. Then what is the value of $$\sum^{15}_{m=1}\text{Im}(z^{2m-1})$$ at $\theta = 2^o$

Not sure how I should attempt this question. Obviously, as it's only the sum of the imaginary part, it will simply be:
$$\sin \theta + \sin 3\theta + \sin 5\theta + ... + \sin 29\theta$$
Not sure how to proceed from here though.
Comment: Hint: Compute the (complex) sum $\sum\limits_{m=1}^{15}z^{2m-1}$, and only after that, consider its imaginary part.
Comment: @Did Thanks, got that now. I made the mistake of trying to sum the imaginary part from the starting/
Comment: Yes. **Motto to remember:** $e^{i\theta}$ is easier to deal with than $\sin\theta$ (or $\cos\theta$).
Comment: @Did Yes. I see that now. We can apply sum of GP and stuff to $e^{i \theta}$... Much easier. Thanks!
Answer: We can write $$z=\cos \theta+i\sin \theta = e^{i\theta}$$
Now we have to calculate $\Im(S)$ where $$S=\sum^{15}_{m=1}z^{2m-1} =  \sum^{15}_{m=1}e^{i(2m-1)\theta}$$
Now Let $$\displaystyle S=e^{i\theta}+e^{3i\theta}+...........+e^{29i\theta}..................(1)\times e^{2i\theta}$$
So $$S\cdot e^{2i\theta} = e^{i3\theta}+............+e^{i29\theta}+e^{i31\theta}.....(2)$$
So we get $$\displaystyle S = \frac{e^{i\theta}-e^{i31\theta}}{1-e^{i\theta}} = \frac{1-e^{i30\theta}}{e^{-i\theta}-e^{i\theta}}$$
Now Using $$\bullet\; \cos \theta +i\sin \theta = e^{i\theta}$$ and $$\bullet\; \cos \theta -i\sin \theta = e^{-i\theta}$$
and $$\displaystyle \bullet\;  e^{in\theta} = \cos n\theta+i\sin n\theta.$$
We get $$\displaystyle e^{-i\theta}-e^{i\theta}=-2i\sin \theta$$
So we get $$\displaystyle S = -\left[\frac{1-(\cos 30\theta+i\sin 30\theta)}{2i\sin \theta}\right]=i\left(\frac{1-\cos 30\theta}{2\sin \theta}\right)-\frac{\sin 30\theta}{2\sin \theta}$$
Now We have To Calculate $\Im(S)$  Which is $$\displaystyle \left(\frac{1-\cos 30\theta}{2\sin \theta}\right)$$
Now at $\theta = 2^0\;,$ We get $$\displaystyle \Im(S) = \left(\frac{1-\cos 60^0\theta}{2\sin 2^0}\right)=\frac{1}{4\sin 2^0}$$
Comment: Aha..... So you basically used sum of a GP?
Comment: Yes  Gummy bears .
Comment: Ahh.... Don't know how I missed that. Thanks for the help.
Comment: Welcome   Gummy bears .
Answer: Let $C=\cos\theta+\cos3\theta+\cos5\theta+...+\cos29\theta$
$S=\sin\theta+\sin3\theta+\sin5\theta+...+\sin29\theta$
$C+iS=(\cos\theta+i\sin\theta)+(\cos3\theta+i\sin3\theta)+...+(\cos29\theta+i\sin29\theta)$
$C+iS=e^{i\theta}+e^{3i\theta}+e^{5i\theta}+...+e^{29i\theta}$
$C+iS=\left\{\frac{e^{i\theta}(e^{30i\theta}-1)}{e^{2i\theta}-1}\right\}=\left\{\frac{(e^{30i\theta}-1)}{e^{i\theta}-e^{-i\theta}}\right\}=\left(\frac{\cos30\theta+i\sin30\theta-1}{2i\sin\theta}\right)$
Compare real and imaginary parts on both sides:$S=\left(\frac{1-\cos30\theta}{2\sin\theta}\right)$
Put $\theta=2^0$ and you get $S=(1-1/2)/(\sin2^0)=1/(4\sin2^0)$

Complex number - sum of imaginary part


Share a piece of data between several Android apps

Question: I am writing an SDK for Android that will be used by many different apps. Each app needs to know if there is a previous installation of another app that uses the SDK; the first one will create a random id (a cookie) and store it, all later apps have to read it and reuse it. Note that the cookie will be created anew for every device.
I have searched for a long time for the answer; please read thoroughly before answering because I have read lots of different StackOverflow answers and have scoured the internet reading random blogs; I have tried a lot of things but none worked (I will save you the links).

A ContentProvider is definitely overkill. Also it needs to intrude an app's AndroidManifest.xml, something I am trying to avoid.
Likewise for a service: needs to be defined in the AndroidManifest.xml, which I do not control and do not want to require changes to.
Using external storage would perhaps be an option, but I don't want to require additional permissions.
Using SharedPreferences directly with getSharedPreferences() does not work because apps can only access their own preferences.
I can get a common preferences object using createPackageContext(package, MODE).getSharedPreferences(). This would work beautifully if I had a main package and many clients of the data, but in fact I don't know the package of the app that will be installed first -- it can be any of them. I don't even have a list of package names to search. Passing a package name which has not been installed fails.
Following the approach above, I have tried to piggyback on some standard Android app which I can count on, and store my preferences there -- say:
createPackageContext(
    "com.android.browser",
    Context.CONTEXT_RESTRICTED)
    .getSharedPreferences(
        "GLOBAL_PREFS",
        Context.MODE_WORLD_READABLE);

but it does not work: the error reads
Couldn't create directory for SharedPreferences file
  /data/data/com.android.browser/shared_prefs/GLOBAL_PREFS.xml

So, to recap: I need to store a piece of data (a short string) in some standard location, so that any other app can go there and read it if present, and it should work if at all possible without doing any magic in the AndroidManifest.xml or requesting any permissions.
There probably isn't any perfect answer, so perhaps the best solution is to write to external storage; then so be it. To put things into context, apparently it is trivial to do this on iOS using a keychain, designed to store secure data.
Comment: i just want to add, for the benefit of anyone else who may come across this, that calling getSharedPreferences(..) on the context of another package is a Very Bad Idea.  android uses a cache of SharedPreferences objects that is keyed only by the preferences file name and does not take into account the package.  in other words, there is absolutely no guarantee that the SharedPreferences you get back actually corresponds to the package context you are calling against, unless you never use any context other than your own.
Answer: Unfortunately there really isn't a great answer for this that I know of. You've come up with a pretty good outline of your options and the best way may well be with external storage.
Just to throw something out there, I suppose it's possible you could use a flat file with a fixed name and world readable (and possibly writable) permissions. You'd have to then iterate through all applications' directories and check for this known-named file in each folder and attempt to open it.
While this might work theoretically, consider the case where the app that contains the "cookie" is uninstalled. Then you're left cookie-less. You might want to create the cookie in every app, copying over the value of the previous cookies to new cookies.
I haven't actually tried this, but I imagine it should work.


What should I modify to prevent deadlock on c++ thread

Question: Here is my source code:
#include "stdio.h"
#include <stdlib.h>
#include <string.h>
#include "thread"
#include "mutex"

int count0=0 ,count1 =0;
std::mutex main_thread;
std::unique_lock<std::mutex> lck(main_thread, std::defer_lock);

void Function00(long millisecond){

    while (true){

        lck.lock();
        count1++;
        printf("count0:%d count1:%d \n",count0,count1);
        lck.unlock();
        std::this_thread::sleep_for(std::chrono::milliseconds(millisecond));

    }
}

void Function01(){

    std::thread th(Function00, 1000);//count per 1 s

    do{
        lck.lock();
        count0++;
        lck.unlock();
        std::this_thread::sleep_for(std::chrono::milliseconds(500));//count per 0.5 s
    } while (1);

}

int main(int argc, char *argv[])
{
    Function01();

    return 0;
}

I then use the command to build my .o file:

g++ -std=c++11 -pthread testa.cpp -o a.o

However, it shows the error:
terminate called after throwing an instance of 'std::system_error'
  what():  Resource deadlock avoided
Aborted

I feel confuse and no idea to solve it, so i try in Microsoft VS2013, and it runs with no error... I feel confuse to it. Is it the problem in linux? What should i modify to prevent the deadlock?
Comment: You're locking `lck` twice. You definitely shouldn't be doing this
Comment: do you mean i need to create another thread?
Comment: what if i use a function to create thread everytime it run, will it come to deadlock?
Comment: I think you don't need this locking at all, just modify values and print them. Or must these values be modified in some particular way?
Comment: get rid of uniquelock and just use plain mutex with your current logic..it will work
Comment: i am sorry, what is rid? how to use it?
Answer: unique_lock cannot be locked twice, if you want to lock a mutex on two threads so that one of them will block, you need to use two unique_locks.
void Function00(long millisecond){

    while (true){

        {
            std::unique_lock<std::mutex> lck(main_thread);
            count1++;
            printf("count0:%d count1:%d \n",count0,count1);
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(millisecond));

    }
}

void Function01(){

    std::thread th(Function00, 1000);//count per 1 s

    do{
        {
            std::unique_lock<std::mutex> lck(main_thread);
            count0++;
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(500));//count per 0.5 s
    } while (1);

}

Comment: @Question-erXDD: no, you just need a `unique_lock` per thread.
Comment: @Question-erXDD: `lock_guard` Can only be locked by the constructor and unlocked in destruction, `unique_lock` can be locked and unlocked at any time.
Comment: @Question-erXDD: allocate the unique_lock on the stack, each thread will have one of its own.
Comment: I am sorry that i am the beginner of it, so i need to create two thread?
Comment: what if there are multiple functions(eg >4) work concurrently, can one thread do this for all?
Comment: @Dani isn't `std::lock_guard` enough for this?
Comment: @Question-erXDD: How would you have 4 functions concurrently with one thread?
Comment: wt are the different between std::lock_guard & std::unique_lock ?
Comment: @Dani: I mean each function has its own count like one count score, one count time, one is display thread and one one is create_thread_for_another_counter
Comment: @Question-erXDD: I don't understand the problem
Comment: Ops sorry for my poor presentation. give an example, if we have a server, it will keep listen if there is an client. assume client A comes, server will create a new thread to keep the connection with client A while the original thread(maybe main thread) will keep on listen. so if we only have a unique (which only handle 2 thread?), how to handle the new thread created?


How does one construct a 3D file format from pixels and vertices?

Question: I have searched around in a lot of places but I have yet to find some place that explains 3D file formats in a way that aligns with the model I have right now. I have a simple problem (I think) but it's hard to get through all the file format documentation and to understand what the data actually resembles.
Let's say one would have the following raw data in a data structure that resembles the below:

A index list, of numbers

int[]

A list of objects containing vertices for a mesh, with their normals and texture coordinates

{vertices: vec3[], normals: vec3[], UV: {u: float, v: float}}[]

A list of pixels

float[]

How would one go about turning this data structure into a popular file format? I don't know where to begin. GlTF would have my preference if that's doable/possible.
Comment: What does any of that data *mean*? Like, what does this "list of pixels" actually *do*? It's hard to know what "aligns with the model I have right now" when we don't know what that "model" even is.
Answer: The list of pixels would typically be encoded as one of the popular image formats like ktx if it is going to be consumed by other rendering programs, or jpg if it is just for viewing. The vertices, normals and UV values would be formatted into whatever file format you desire to output.
This means picking a file format, like obj which is a nice simple format.
Basically a program would output the "pixels" as texture data, the other data formatted to the file type chosen and the file would "refer" to the texture data.
On the other hand some formats include the "pixels" directly in the format.
There are libraries out there that can help, or you can write your own encoder.
As Nicol Bolas pointed out it is difficult to give a more complete answer without knowing more details about the data and the file format.
Are you coding this up or is it from one of the popular rendering programs out there?
Answer: Here is an overview of how you would go about producing an glTF asset from your data.
First, write your index and vertex data arrays into files.

They can be all the same file, but for the conceptually simplest case, make them separate files.
You write the integers or floats as raw bytes, not text or any other format, with no metadata. This is just like you would pass the same data to a GPU buffer, except that they must be little endian integers (that is, swap the order of the bytes in each integer if your program is compiled for a big-endian processor; this is rare but possible).

Your "pixels" — a texture for the object, I assume — should be written into a image file (PNG, JPEG, or a compressed texture format specified in a glTF extension).
Then, you create the glTF file itself, which is a JSON structure that describes how to use the contents of the above binary files.
The glTF file will specify that the indices are indices, and which one of the files contains vertex positions and which one contains normals, using "attributes" and "accessors", and put them together into a "mesh". It may also contain "node", "scene", "camera", and "animation" objects, describing more about what to do with the mesh, but these are all optional.
There are a lot of details to glTF, but this is fundamentally all there is to it: write out your numerical data to binary files, then write out the glTF that describes the structure of those files. (It's also possible to pack all the data into a single .glb file.)
Now that I've given you the big picture, I hope you will be able to able to figure out all the concrete details by following the glTF specification and checking your work with a glTF scene viewer and a validator. When I was doing this, I found the glTF Tools Extension for Visual Studio Code very useful — it does both preview and validation.


Ubuntu 14.04 prevent screen turning off in lock screen

Question: Every time when I am in lock screen, the screen will automatically turn off. I have tried to change the setting in Brightness and lock turn screen off when inactive to never. It will not turn off my screen when I am logged into the Desktop view but it will still turn off my screen when I am in lock screen.
How to prevent it to turn off the screen in lock screen?
Answer: My experience: I tried setting the option "turn off screen" to never and "lock screen" to 30 seconds, but the computer never locks automatically.
It seems like the time to lock the screen its only after the screen turns off, in that case the "lock screen" option should be grayed out when "turn off screen" its set to never.


Simil Bernoulli inequality for induction

Question:
Prove that $(1+x)^n \ge nx, \forall n \in \mathbb{N}, \forall x>-1 $

My work:
If $-1<x \le 0$ it's trivial because $RHS \le 0$ and $LHS \ge 0$, $\forall n \in \mathbb{N}$
Start with the induction. If $n=0$ we have $1>0$, so suppose true for all $m<n+1$ and proof for $m=n+1$:
$$(1+x)^{(n+1)}=(1+x)(1+x)^n \ge (1+x)nx$$
So i have to proof that $(1+x)nx \ge (n+1)x$ that it means that
$$nx+nx^2 \ge nx+x \longrightarrow nx \ge 1$$
but this is not even true (e.g. $n=1,x=10^{-2}$).
Where is the mistake?
Thanks
Comment: The usual form of Bernoulli is $(1+x)^n\ge1+nx$
Comment: @AnginaSeng yes. But I can't use Bernoulli inequality to prove this. I have to do it for induction.
Answer: Let $ x \geq 0$. If you are keen on using induction prove the stronger inequality $(1+x)^{n} \geq 1+nx$. Here induction works fine and the required inequality follows from this.
[$(1+x)(1+nx) =1+x+nx+nx^{2} \geq 1+(n+1)x$].
Comment: @Skills You did not read my answer correctly. I did not use Bernoulli's inequality. I used induction. But I use a small trick to change the given inequality to something stronger. The original inequality does not follow directly by induction as you have noticed.
Comment: Thanks, but the purpose of the exercise is to use the induction principle. I must not use the Bernoulli inequality.
Comment: You're right. I didn't read after editing. Thanks.
Answer: Lets prove a stronger inequality, $(1+x)^n\geq 1+nx > nx$.
We want to show  that $(1+x)^n\geq 1+nx$ for all natural numbers $n$ and for all $x>-1$.
Since $x>-1$, then $x+1>0$, so $(x+1)^n>0$. That handles the condition that $x>-1$.
Now, we want to induct on $n$.
Base cases, $n=0$ and $n=1$: $$(1+x)^0=1\geq 1+0\cdot x=1$$ $$(1+x)^1=1+x\geq 1+ 1\cdot x =1+x$$ Both are true, so our base cases are complete.
Inductive hypothesis: Suppose $(1+x)^n\geq 1+nx $ for some natural number $n$. We wish to show that this is true for $n+1$.
$$\begin{align}(1+x)^{n+1}&=(1+x)(1+x)^n\\&\geq(1+x)(1+nx)\\&=1+(n+1)x+nx^2\\&\geq 1+(n+1)x\end{align} $$
Since we have now shown that for all natural numbers $n$, $$(1+x)^n\geq 1+nx $$ with equality at $n=0,n=1$, then it follows that $$(1+x)^n\geq 1+nx > nx\geq 0\geq -n$$ and we are done by induction.


Proof of Cauchy integral theorem on any simply connected set

Question: I am trying to find a reference for a proof of Cauchy integral theorem, ie the fact that given a simply connected open subset $U$ of the complex plane, a rectifiable loop $\gamma$ contained in $U$ and a function $f$ holomorphic on $U$, then :
$$\int_\gamma f(z)dz=0$$
Is it only true for specific (convex, starred) simply-connected subsets ? I've found proof for a disk or a keyhole from "Goursat's Lemma" in Elias M. Stein and Rami Shakarchi book on complex analysis, but I've struggled to find one that applies to any (simply connected) set. Does it require advanced knowledge on other topics, regarding homotopy for example ?
Comment: It's not really clear what you mean by "any set." If the set isn't simply connected, then either it isn't path connected (in which case $\gamma$ makes no sense as it might live in two disjoint sets), or it has holes, in which case $f$ might analytically extend to a function with a singularity in one of the holes, so the residue theorem would apply instead. Otherwise, as long as you can embed a simply connected set in your "any set" that also contains your curve $\gamma$, it should be fine.
Comment: Yes, sorry, I was talking about any simply connected subset, without any convexity or additional conditions.
Comment: This is essentially in Stein and Shakarchi's book: Section 5 of ch.3 proves that if $\gamma_0$ and $\gamma_1$ are homotopic in a domain $\Omega$ on which $f$ is holomorphic then $\int_{\gamma_0} f(z)dz = \int_{\gamma_1} f(z)dz$. But if $\Omega$ is simply-connected, any closed path $\gamma$ is homotopic to the constant path $c(t)=z_0=\gamma(0)$, and clearly $\int_{c} f(z)dz =0$, so $\int_{\gamma}f(z)dz =0$.    Appendix B of that book also discusses simply-connected domains in $\mathbb C$, proving, e.g., that a bounded domain D is sim-conn. if and only if $\mathbb C_{\infty}$\D is connected.
Answer: You will find a proof in Richard A. Silverman's Introductory Complex Analysis, §36.


Iphone ASIHTTP setDidFinishSelector issue

Question: i have the following code:
<code>  - (void)imageDownloaded:(ASIHTTPRequest *) request idDisco:(NSNumber *)iddisco
    NSLog(@"%d",[idPlace intValue]);
  }
</code>
And
<code>   NSURL *url = [NSURL URLWithString:[item objectForKey:@"image"]];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request setDidFinishSelector:[self performSelector:@selector(imageDownloaded:idDisco:)withObject:request withObject:disco.id_disco]];
</code>
But the compiler tells me that "passing argument 1 of setDidFinishSelector from incompatible pointe type"
It works fine but i don't know what i'm doing wrong.
Thanks
Answer: You have to pass @selector(someMethod:) there:
And the signature of the method should be
<code>- (void)methodName:(ASIHTTPRequest *)request;
</code>
Look at this example:
<code>- (IBAction)grabURLInTheBackground:(id)sender
{
   if (![self queue]) {
      [self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
   }

   NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request setDidFinishSelector:@selector(requestDone:)];
   [request setDidFailSelector:@selector(requestWentWrong:)];
   [[self queue] addOperation:request]; //queue is an NSOperationQueue
}

- (void)requestDone:(ASIHTTPRequest *)request
{
   NSString *response = [request responseString];
}

- (void)requestWentWrong:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}
</code>
Comment: sorry i edit my question because i need a selector with two arguments
Comment: The signature of the expected method is not configurable(Unless you modify ASIHTTPRequest.m) so you will have to store the id of the image somewhere else.


Apache - virtualhost - works only one

Question: I need a couple of virtualhosts on my local dev machine.
Unfortunately it needs to be windows.
httpd-vhost.conf
<VirtualHost *:80>
  ServerAdmin email@example.com
  DocumentRoot "C:/xampp/htdocs"
  ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   ServerAdmin email@example.com
   DocumentRoot "C:/xampp/htdocs/manadom.local/public"
   ServerName manadom.local
   ErrorLog "logs/manadom.local-error.log"
   CustomLog "logs/manadom.local-access.log" combined
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin firstname.lastname@example.com
  DocumentRoot "C:/xampp/htdocs/galeriabiznesu"
  ServerName gb.loc
  ErrorLog "logs/gb.loc-error.log"
  CustomLog "logs/gb.loc-access.log" combined
</VirtualHost>

And hosts file:
127.0.0.1 localhost
127.0.0.1 manadom.local
127.0.0.1 gb.loc

The problem is:
localhost points to
C:/xampp/htdocs/manadom.local/public

manadom.local points to
C:/xampp/htdocs/manadom.local/public too

gb.loc points to
C:/xampp/htdocs/manadom.local/public

I can't idea what's wrong?
Please help me, i'm not an admin but i read about it lot and i don't know what possibly i can do wrong.
Comment: Did you restart the Apache after changing configuration files?
Comment: Yes. [some text to make it 12 characters]
Comment: Check if you file is included in httpd.conf - look for a line:

    Include conf/httpd-vhost.conf
Comment: Dev-machine setup is off-topic for ServerFault, I'm afraid.
Answer: For named virtual hosts you have to set "NamedVirtualHosts" directive. Please look at the manual -> http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost
Answer: Yes, as said,  before virtual hosts directives you should have:
NameVirtualHost *:80

Apache - virtualhost - works only one


DIV float:right with no text wrapping

Question: I'm trying to create a pseudo table of three columns in CSS/HTML:
Columns:

Long text field, text-align:left
Variable text field, text-align: right
Fixed text field, text-align: right

With short text everything displays correctly.. but if the first column or the second column get too big the text is wrapped:

What I want is for the first row to overflow with an ellipse so that it appears like this:

But I can't seem to get the CSS right. Here is what I have so far:
HTML:

First column with some short text

Download

[Some attributes]

First column with some more short text

Download

[Some attributes]

Last row with longer text should be clipped but is not being

Download

[Attributes, Are, Different]

CSS:
div
{
    font-family: arial;
}

.row
{
    width: 600px;
    background-color: red;
    margin-bottom: 10px;
    white-space: nowrap;
    padding: 5px;
}

.row div
{
    display: inline-block;
}

.filename
{
    white-space: nowrap;
    overflow: hidden;
    text-overflow:ellipsis;
}

.attributes
{
    float: right;
}

.download
{
    float: right;
}

.attributes,
.download
{
    padding-left: 5px;
}

JSFiddle:
http://jsfiddle.net/nLACS/8/
Can anyone suggest the best way of making the first column overflow so that the second two columns do not wrap down below keeping in mind that the second column can also be variable length as well?
Comment: do you want to implement this using divs only or can you use table structure as well?
Comment: I'd prefer DIV if possible but table would be OK
Comment: I think the problem with table would be that all rows would be clipped at the same point.. where ideally rows with different attributes should be clipped at different points depending on the length of the attributes column
Answer: How about flex solution? The only concern is browser support, but if no need for outdated browsers, you can use this nice feature.

CSS:
.row
{
    width: 600px;
    background-color: red;
    margin-bottom: 10px;
    white-space: nowrap;
    padding: 5px;
    display: -moz-flex;
    display: flex;
}

.filename
{
    white-space: nowrap;
    overflow: hidden;
    flex-grow: 1;
    flex-shrink: 1;
    max-width: 400px;
    white-space: nowrap;
    padding: 5px;
    border: 1px dotted white;
    margin: 2px;
}

.attributes
{
    flex-grow: 1;
    flex-shrink: 1;
    text-align: right;
    display: -moz-flex-inline-block;
    display: flex-inline-block;
    white-space: nowrap;
    padding: 5px;
    border: 1px dotted white;
    margin: 2px;
    overflow: hidden;
}

.download
{
    flex-grow: 1;
    flex-shrink: 1;
    display: -moz-flex-inline-block;
    display: flex-inline-block;
    text-align: right;
    white-space: nowrap;
    padding: 5px;
    border: 1px dotted white;
    margin: 2px;
    overflow: hidden;
}

http://jsfiddle.net/nLACS/10/
Margins, paddings, borders are thre just for demo.
Comment: You're welcome! It's a really good doc to check:
http://css-tricks.com/snippets/css/a-guide-to-flexbox/
Comment: fantastic, just what I needed. I have not seen these flex-grow attributes before :)
Comment: Please, if you're going to be posting Flexbox solutions, *at least get the prefixes right*.  Also, there's no `flex-inline-block` property.
Answer: I suggest to go with display:table and table-cell as following:
html

First column with some short text

Download

[Some attributes]

First column with some more short text

Download

[Some attributes]

Last row with longer text should be clipped but i...

Download

[Attributes, Are, Different]

css
div
{
    font-family: arial;
}

.row
{
    width: 600px;
    background-color: red;
    margin-bottom: 10px;
    white-space: nowrap;
    padding: 5px;
    display:table;
}

.filename
{
   display:table-cell;
    width:50%;
    max-width: 250px;
    overflow:hidden !important;
    float:left;
}
.tabletow{
    display:table;
    width:50%;
    float:right;
}

.tabletow > div{
    max-width:100px;
    overflow:hidden;
}

.download{
    width:25%;
}

.attributes,
.download
{
    display:table-cell;
}

fiddle
Answer: Hi as I had commented earlier I have implemented in table elements in the fiddle
HTML

        First column with some short sdsadakjsdhajdhjkashdajskdhajskdhkatext

        Download

        [Some attributes]

        First column with some short sdsadakjsdhajdhjkashdajskdhajskdhkatext

        Download

        [Some attributes]

        First column with some short sdsadakjsdhajdhjkashdajskdhajskdhkatext

        Download

        [Some attributes]

CSS:
table {
   border-collapse: collapse;
}
tr {
   border: solid;
   border-color:white;
   border-width: 5px 0;
}
.column1,.column3 {
   width:25%;
   padding-bottom: 1em;
}
.column1{
   width:50%;
}

.rows{
   background-color: red;
}

UPDATED FIDDLE
Comment: seems to be wrapping in Chrome.. the idea is that the columns overflow without wrapping.
Comment: Hi added an updated fiddle so you have the old and the new fiddle in the same answer. Hope that helps

DIV float:right with no text wrapping


Can I get a list of helpful hints during the load screen for Path of the Exile

Question: Can someone please list all the tips that appear during the loading screen?
I saw one about skill gems last night that I wanted to read but disappeared to quickly
Answer: Here is a list of all of the loading screen tips:

Remember to use flasks (1-5 on the keyboard).
You can remove a {Skill Gem} from an item by right clicking on it.
Put a # before your chat message to talk globally.
Instances reset after being empty for 15 minutes.
Drop an item in the chat box to link it to other players.
Players in the same party will join the same instances.
Right click on a player or message them in chat to invite them to your party.
Support gems need to be placed in linked sockets to affect another gem.
Hold {Shift} to attack from your current location.
You can access your stash in town.
Waypoints can be used to travel quickly between some areas.
Flasks on your belt refill as you kill enemies.
Remember to allocate your passive skill points on the passives screen.
To reach the next difficulty level, find the exit at the end of the current difficulty.
To use a {scroll} or {orb}, right click it then left click the target item.
Hold {Shift} and click a stack of items to unstack them.
Never tell anyone your password.
Some items need to be {identified} with a {Scroll of Wisdom} before they can be used.
Cruel, Ruthless and Merciless difficulties incur an experience penalty on death.
{Skill Gems} gain experience as you do while they are equipped.
{Bosses} and {rare} monsters are more likely to drop powerful equipment.
If you cannot use a gem, placing it in an item will stop you from using the item.
Partying with other players makes enemies harder and rewards better.
Don't let enemies surround you.
You can change your key bindings in the {Options} menu.
You can move the minimap around using the {arrow keys}.
Your stash can be used to move items between your characters.
Being polite will get you invited back to play with people again!
There will be bugs.
You can only remove or place Flasks in your belt while your inventory is open.
Some chests have a better chance of dropping items than others.
Monsters that deal cold damage can freeze you.
Lightning damage can shock you, increasing damage taken.
Fire damage can ignite targets, causing them to burn for extra damage.
Holding Alt will show items on the ground, and pressing Z will toggle always displaying
items and sockets.
Some containers can be opened by attacking them.
Monsters with the very rare "Wealth" mod drop a huge number of items.
Activating a new {Waypoint} is a way of saving your exploration through Wraeclast.
At vendors, you can trade an Iron Ring and a Skill Gem for a resistance ring.


$location.path is not redirecting to page in Angular JS

Question: Here is the code.In URL it is redirecting to #!/dashboard but it is not displaying anything.
var app = angular.module("myapp", ["ngRoute"]);
app.config(function ($routeProvider) {
    $routeProvider.when("/", {
        templateUrl: "Login.html"
    }).when("/dashboard", {
        tepmlateUrl: "Dasu.html"
    });
});

app.controller("LoginCtrl", function ($rootScope, $location, $scope) {
    $scope.submit = function()
    {
        debugger;
        if($scope.userid == 'admin' && $scope.password == 'admin')
         {
            $rootScope.LoggedIn = true;

            $location.path('/dashboard');

         }
    }
});

Comment: Is that... client side authentication...?
Comment: Yes,it is client side authentication.
Comment: Not related to the question, but I assume this is only for testing out things?
Comment: Yes.It is related to testing.
Comment: I see for the dashboard route config you have 'tepmlateUrl', should be templateUrl. Not sure if it's just a typo?
Answer: You have a typeo in your $routeProvider config
.when("/dashboard", {
        tepmlateUrl: "Dasu.html"
});

Should be
.when("/dashboard", {
        templateUrl: "Dasu.html"
});


What are the different levels of the Poké Finder?

Question: As you know, Pokémon Sun & Moon feature a Poké Finder, which upgrades as you gain likes for your photos.
I'm currently level 4.
So far, the improvements are :

lvl2 : Zoom
lvl3 : Better Zoom
lvl4 : Maximum Zoom.

What happens starting at the fifth level?
Thank you!
Answer: Level 5 gives you the ability to press a button to call the Pokemon closer to you. There are no levels higher than level 5.
Source: https://www.reddit.com/r/pokemon/comments/5dx1dt/so_i_spent_a_few_hours_grinding_out_the_v5_pok%C3%A9/
Comment: The source you're thinking of is [here](https://www.reddit.com/r/pokemon/comments/5dx1dt/so_i_spent_a_few_hours_grinding_out_the_v5_pok%C3%A9/).


How to determine the transformation matrix from given initial and transformed co-ordinates?

Question: How to determine transformation matrix for an object given a graph?
This is a problem indeed similar to this one. And I've approached it in the same way like there.
Given:
A line AB A(0,0),B(1,1).
It is transformed to
A'(0,-1),B'(-1,0)
Now, I need to find the transformation matrix.
I begin
TM.A=B
Where TM=Transformation Matrix
A=given coordinates
B=transformed coordinates
Comment: So, what is your questions, specifically? Surely $TM\times A$ will not yield $B$ here. I think this actually requires a translation vector, which will not fit in a 2D matrix. You need 3D matrix (homogeneous coordinates), unless you are discussing transformation around point $(1/2, -1/2)$/
Comment: @Enigmatisms I know I did wrong because when I take a look at it and reverse multiply, I don't get the coordinates that I should be getting after getting transformed. Can you guide me just the matrix required?
Answer: I am not sure whether this is what you need, hope it helps:
To transform from one line to the other, one can try to use the homogeneous coordinates, which will incorporate the potential translation of the line. So we can formulate the problem in the following way. Notice that the length of the line stays the same, therefore we don't need to consider scaling. Thus, this case can be modeled as rigid body transformation:
$$
\begin{pmatrix}
\cos\theta & -\sin\theta & t_x\\
\sin\theta & \cos\theta & t_y\\
0 & 0 & 1\\
\end{pmatrix}
\begin{pmatrix}
0 & 1\\
0 & 1\\
1 & 1\\
\end{pmatrix}
=
\begin{pmatrix}
0 & -1\\
-1 & 0\\
1 & 1\\
\end{pmatrix}
$$
Solving the above linear equations yields:
$\cos\theta = 0, \sin\theta = 1, t_x = 0, t_y = -1$. So this tells us:

Line AB is first rotated around $(0, 0)$ by 90$\deg$ (counter-clockwise), we have: CD $(0, 0)\rightarrow(-1, 1)$.
Then we apply translation: CD -> A'B', moving the line down the y-axis by 1: $(0, -1)\rightarrow(-1, 0)$.

So basically, if you know it is gonna be rigid body transformation, then approach the problem in the above way. A more general 2D transformation will be (given in homogeneous coordinate system):
$$
\begin{pmatrix}
a & b & c\\
d & e & f\\
0 & 0 & 1\\
\end{pmatrix}
$$
which takes translation, shearing, scaling and rotation into account. Since this representation has more unknown variables, it requires more information to solve the whole system.
Comment: Thanks for the support.


Where do I collect revenue?

Question: As I was running through the first or second memory in Constantinople, I received a notification saying "Revenue Deposit made: xxxx V in the bank vault.
Where do I collect this revenue? I looked around the Assassin HQ and found some chests, but nothing that appeared to be a vault.
Answer: You'll need to renovate one of the banks in the city to be able to collect.  Once in your control, just go to the bank and withdraw your money.
To be able to renovate the bank, you need to be in control of the zone first.  If necessary, you'll have to liberate the templar-held zone first.  The ones in Galata should be available to you in the beginning.  Just examine the sign and pay the required amount.  As you start off, it will cost in the mid-1000's.  But the more renovations you make, the more it will cost.
Comment: And remember that any time you renovate a building it adds about 20% to your awareness meter.  Don't go nuts!

Where do I collect revenue?


How do I "power slide"?

Question: To get the "Blue Sparks" challenge I need to "power slide" into enemies to kill them. Since I've successfully completed the game without ever killing a single enemy in this way, I apparently don't know how to do it.
I have (I think) killed several enemies with the Boost ability in cars and I've got plenty of progress in the run-stuff-over challenge, so what's the trick for this one?
Comment: Granted the fact that I always take gunner seat drastically limits my roadkill stats...
Answer: Apply the brake while in a turn to power slide.  That's the right bumper on a 360 controller.
This causes the wheels to lose traction, and the vehicle to move sideways.
Power sliding over an enemy - very difficult.

"Blue Sparks" is a reference to Mario Kart Wii, where power sliding builds up blue sparks.  These sparks cause you to boost after the power slide is finished.
Power sliding (aka drifting) in other racing games (such as the Burnout series) allows you to corner more sharply.
Comment: Default key is 'G' on PC.
Comment: It is actually possible to power slide while turning only slightly, and not letting go of accelerator, which makes hitting enemies much easier. Still, the best way to farm the challenge is to massively overlevel skags to kill them with one hit.
Comment: Ahah. Yeah, that's not something I would have thought to do.
Comment: Maintaining forward (or reverse) motion was what I was missing.  On the PS3 it's the left joystick that's the accelerator, just keep that pressed forward or pulled back while you simultaneously turn and brake with the right joystick and trigger.  And as Orc JMR said, aim for skags, as they're the easiest prey on playthrough 1.
Answer: there's a video tutorial that tells you how to do it
Comment: This would be a better answer if you summarized the process right here in the question.
Comment: See my comment to @AmyB's answer for PS3 tips.

How do I "power slide"?


About the true ending of Bravely Default

Question: I'm at the final chapter, fighting the penultimate boss. I'm having a hard time beating her.
I've been reading online, and from what I gather is a true and false ending.
Apparently, if you follow the story, awaken all the crystals several times, and beat the boss, you will fight the ultimate real boss and get the true ending.
If you destroy a crystal, uh, the battle with the penultimate boss will be easier? I don't quite get it:

What exactly happens when you destroy a crystal? Do I not get to fight the ultimate real boss?
Can you destroy a crystal before the final chapter?
If I get the false ending, can I get the true one later? And viceversa.
Answer: If you destroy a crystal, you do not get to fight the real ultimate boss, nor the final form of the penultimate boss.
You can destroy a crystal as early as Chapter 5. You do not have to wait until Chapter 8.
If you get the false ending, saving your game after the ending and loading it will put you back before you destroyed the crystal, so you can then proceed to get the true one later. Getting the true ending will put you back on the final chapter with all four crystals not yet awakened so you can then proceed to get the false one later (and this also makes Genome Abilities related to the crystal bosses always obtainable).
Comment: It's also worth mentioning that if you destroy a crystal, you will not get to fight the final form of the penultimate boss, in addition to not facing the ultimate boss.
Comment: Right. Just keep tapping the button. I did it on Chapter 7 when I got the false ending, personally.
Comment: You can destroy them early?! I swear I tried to do it once (you just keep on praying right?) and nothing happened so I kept going lol.


Reason behind the condition for multiplication of matrices

Question: Why is the product of two matrices defined only when the number of columns in $A$ is equal to the number of rows in $B$?
Comment: This is immediately answered once you understand (or look up) that matrices are just linear maps.
Comment: The product $C = AB$ of matrices $A$ and $B$ is defined as that $A(Bx) = Cx$ for all column vectors $x$ (of appropriate dimension). This equation only makes sense if the number of rows of $B$ is equal to the number of columns of $A$.
Comment: Oh so let's take the following (hypothetical) example, One matrix is of the order 2×3 and another matrix B is of the order 4×5.
Comment: In that case neither $AB$ nor $BA$ is defined as a product of matrices.
Answer: The answer provided by Winged Reptile is well done ($+1$). But allow me to say something more.
Sometimes, in a Linear Algebra course, ones starts by studying the algebra of matrices, before studying what a linear transformation is (as it was in my case).
Of course that when one starts to study linear transformations, all becomes clearer. But if you haven't yet study linear transformations, you can think as follows.
Given two vectors of dimension $n$, you can compute the inner product of those two vectors. For example, if $u = (u_1,u_2,\dots,u_n)$ and $v=(v_1,v_2,\dots,v_n)$, with the usual inner product, you get
\begin{align*}
u \cdot v = u_1 v_1 + u_2 v_2 + \dots + u_n v_n = \sum_{i=1}^n u_iv_i.
\end{align*}
Hence, you can think of the product of two matrices as a generalization of this inner product. The ideia is that one should compute the inner product of the rows vectors of the first matrix with the column vectors of the second matrix.
Since the inner product is only defined for vector with the same dimensions, we require that the number of columns of the first matrix to be equal to the number of rows of the second matrix.
Once again, I point that the explanation is given by the fact that in this way, we can compute the composition of two linear transformations by multiplying the two matrices associated to those linear transformations. But if you haven't yet hear about linear transformations, this is a nice way to get a sense of the definition of product of matrices.
Comment: I once taught a Linear Algebra class where linear transformations were introduced before matrices.  It was a disaster!
My conclusion is that, for beginners, it is much easier to swallow what looks like a random choice of products  and
additions (i.e. matrix multiplication),  than the notion of a linear transformation.
Comment: @Ruy that happens to be true. Starting with linear transformations may not be the best approach for beginners, although it is the most logical one
Answer: The product of matrices $BA$ is only well defined when the number of columns of $A$ equals the number of rows of $B$ because that is how matrix multiplication is defined. The real question is then why is matrix multiplication defined this way?
If we have a $n \times m$ matrix $A$ (with entries in $\mathbb{R}$) then we can define a linear transformation $T: \mathbb{R}^m \rightarrow \mathbb{R}^n$ by $T(\textbf{x}) = A\textbf{x}$.
Likewise, if we have a $m \times l$ matrix $B$ then we can define a linear transformation $S: \mathbb{R}^m \rightarrow \mathbb{R}^l$ by $S(\textbf{x}) = B\textbf{x}$.
Of course, we can compose these linear transformations to get another linear transformation $S \circ T: \mathbb{R}^m \rightarrow \mathbb{R}^l$. This map is only well defined because the codomain of $T$ equals the domain of $S$.
But $S \circ T(\textbf{x})=S(A\textbf{x})=B(A\textbf{x})=(BA)\textbf{x}$.
We can now see that $S \circ T$ is only a well defined linear transformation when the number of columns of $A$ (the codomain of $T$) equals the number of rows of $B$ (the domain of $S$).
Matrix multiplication was defined in the way it is specifically so that composition of the corresponding linear transformations corresponds to matrix multiplication.


Characterization of closed map by sequences/nets

Question: I'm interested in characterizing closed maps in terms of nets.
Since a map is closed iff $\overline{f(V)} \subseteq f(\overline{V})$ for all subsets $V$, I believe one possible such characterization is

$f$ is closed iff for each net $x_\alpha$ such that $f(x_\alpha) \to
 y$, we have that $x_\alpha$ converges to the set $f^{-1}({y})$.

By convergence to a set I mean that for any neighborhood $V$ of $f^{-1}({y})$, $x_\alpha$ is eventually in $V$.

In case anyone's interested, I came to this question trying to show that

$X$ is compact $\iff$ the map $X \to \{*\}$ is universally closed.

I know a proof, but I thought a proof in terms of nets could be more elucidatory.
Comment: Does that also mean that $f\left( \lim_{\alpha\to\infty} x_{\alpha}\right) = f(f^{-1}(y))=y= \lim_{\alpha\to\infty} f\left(  x_{\alpha}\right)$? However, closed mapping need not be necessarily be continuous, right? What am I missing?
Answer: It seems the following.
You belief is right and we can prove a
Proposition. Let $X,Y$ be topological spaces and $f:X\to Y$ be a map. The map $f$ is closed iff for each net $\{x_\alpha\}$ such that $\{f(x_\alpha)\}$ converges to a point $y$, we have that the net $\{x_\alpha\}$ converges to a set $f^{-1}({y})$.
Necessity. Suppose that the map $f$ is closed. Let $\{x_\alpha:\alpha\in A\}$ be a net such that $\{f(x_\alpha)\}$ converges to a point $y\in Y$. Assume that the net $\{x_\alpha\}$ does not converge to a set $f^{-1}({y})$. Therefore there exists an open neighborhood $U$ of the set $f^{-1}({y})$ such that for any index $\beta\in A$ there exists an index $\alpha\in A$, $\alpha\ge\beta$ and $x_\alpha\not\in U$. Put $V=\{x_\alpha: x_\alpha\not\in U\}$. Since the map $f$ is closed, $\overline{f(V)} \subset f(\overline{V})$. Since $\overline{V}\subset X\setminus U\subset X\setminus f^{-1}({y})$, $y\not\in f(\overline{V}) $. But, since $y$ is a limit point of the net $\{f(x_\alpha)\}$, $y\in \overline{f(V)}$, a contradiction.
Sufficiency. Assume that the map $f$ is not closed. Then there exists a (necessarily non-empty) set $V\subset X$ such that $\overline{f(V)}\not\subset f(\overline{V})$. Let $y\in \overline{f(V)}\setminus f(\overline{V})$ be an arbitrary point. Let $A$ be a family of all open neighborhoods of the point $y$. For any neighborhood $U\in A$ pick an arbitrary point $y_U\in f(V)\cap U$ and an arbitrary point $x_U\in V\cap f^{-1}(y_U)$. Then a net $\{x_U: U\in A \}$ converges to a set $f^{-1}(y)$. Since $y\not\in f(\overline{V})$, $f^{-1}(y)\cap \overline{V}=\varnothing$. Thus $X\setminus \overline{V}$ is an open neighborhood of the set $f^{-1}(y)$, which has no points from the set $V$, and, therefore, no points from the net $\{x_U\}$, a contradiction.
Comment: What about a characterization of closed maps in terms of filters, as follows: A map $f: X \to Y$ is closed iff the following condition holds: for any filter $\mathcal{F}$ in $f(X)$ with cluster point $y$, the set $f^{-1}(\{y\})$ is a subset of the cluster points of $f^{-1}(\mathcal{F})$?


Changing loft bed's beam to diagonal braces?

Question: We have an IKEA loft bed for our 12 yr old.
One of the beams that prevent legs going apart, is messing up with access to his chest of drawers.
I want to change that beam to diagonal braces like these:

What would be a good way to attach them to the bed frame to ensure legs don't come apart? The legs are 6x6 cm, and the horizontal frame part is 2x10 cm. The diagonal braces I want to use would be 7x4x40cm.
Comment: That frame looks pretty unstable already.
Comment: Can the legs be screwed to the floor?  If the room is carpeted, the answer is probably yes.  Screw holes in carpet can disappear with a simple brushing of the carpet.
Comment: Note that IKEA furniture works under the realm of that you won't be abusive to it and you generally put it against walls.   If I put that bed in the middle of one of my kids' room it would be in pieces in a matter of a few months.   The only saving feature is - it really is made out of nothing so unless your kids are 4 or under they will probably live fine in collapse.   IKEA does make some crap (yes we have their crap in my house too).
Answer: I'm really concerned about the stability/safety of what you're proposing. The diagonals seem under-sized to me but even with heavier diagonals I don't think the bed verticals would hold up. A 12 year old clambering up and down that ladder is going to put a lot of lateral stress on those vertical supports without the horizontal strut..
Have you considered moving the horizontal strut on the left of the picture all the way to the floor? That would give the stability you will need.
Also if there is a way to attach the verticals to the back wall - better yet.
Edit
Your idea of moving it up instead of removing it is much better. I would keep it as close to the center of the verticals as you can. Again - if you can attach it at the top to the back wall would be best. If you did that I think the diagonals properly attached would work well.
Second edit
If you want to do diagonal struts I would through bolt them with no more than 1/4 inch diameter bolt and washers. With only 6 cm width to work with you don't want anything larger than that.
However, I strongly urge you to attach the posts and/or preferably the bed frame to the wall and not rely on diagonal struts. That's the solution you need. Put wood spacers between the frame and wall and attach it into the studs with  Timberlok screws. All you need is two attach points through the frame. They are easy to install and remove and when you get rid of the bed at some point you only have two 3/16" holes to patch in the drywall.
Comment: Yup, that was my reaction too.  That cross brace has a very important job to hold the verticals at spacing so they hold square (or at least parallelogram) and don't trapezoid.  That works when the verticals are only untied for 0.6m.  The brace will leave the vertical untied for about 1.3m from the look of it.  IKEA manufactures to close precision, and definitely made the vertical not strong enough for that.
Comment: yes, I considered moving it down, but I am afraid it will then be the stumbling place for the kids. how about if I move it higher, instead of lower? At around the height I imagined my braces? it will be eye height and much harder to miss than something under your feet.
Comment: I can secure at least one of the two legs against the wall; assuming I go for it, what would then be a good way to fix the braces to the struts, as per the original question?
Answer: The lateral support on your bed mostly comes from the two connections at the top creating what is called a moment connection (think of lifting a long stick with both hands). The middle members do provide some additional support but consider that there is NOT one on the front and this should make it obvious that they are not absolutely necessary to keep the bed from falling over.
The middle brace is more about keeping the relatively thin and tall posts in place. In particular, the BOTTOM of the post. The braces are located in the middle for reasons such as aesthetics, to prevent toe stubbing (if the middle piece was not there then people would walk through and hit the bottom piece). They do provide some additional support against buckling but that is minor, again note that front piece does not exist.
My suggestion is to prevent the bottom of the posts from moving. If you have carpet then it's probably fine as it is as long as no one tries to move it. If hardwood floors or for the case of people relocating the post or bed, you can place a cross member in a different location, perhaps at one of the shelves so that it is not in the way, or at the bottom of the post, even under the posts, though you would need to rise the other end the same amount or cut down the posts in question
Comment: +1, except for the carpet suggestion.  "As long as no one tries to move it" + "I have a pre-teen boy" = "Those legs will get moved"
Answer: Your plan is basically sound. Long screws, counterbored through the braces, should hold well.
If you can move the removed beam right down to the floor to tie the posts together, that might help.
If you can attach the posts to the wall, that will help some.
And if you discover the bed is still wobbly, a wide plank where the braces are would be my next step.
Answer: I built a very similar bed but without any of the lower braces.
I anchored the top bed frame to the wall on two corners (diagonally opposite).
This means that there is no side to side movement of the bed frame.
So the posts are simply bearing vertical (gravity) load.
Its been rock solid for a year.
Comment: Even if you attach the bed against one wall, you already constrain quite a few degrees of movement. The fundamental goal is to make sure that the front legs carry only weight.
Answer: When I built my grand kids bunk beds I used 3/4 inch plywood at the foot and head of the beds. In your case, you could put a panel of plywood that went as far down as possible under the top bunk. And it could go up as far as you want past the top. That is what I did so I could add a book and toy shelf to the bed.
In this case just attach with standard #8 screws (drywall, or woodworking).


Ubuntu 20.04 Booting is 3 times longer than Windows 10

Question: Windows 10 booting requires 12/15 seconds while Ubuntu 20.04 one requires 40/45 seconds.
Both OSs are installed in SSD Samsung 840 EVO.
I've provided you in advance outputs of some commands (but please suggest me other useful ones).
Thanks in advance.
Here is the log from systemd-analyze chain:
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.

graphical.target @10.465s
└─multi-user.target @10.465s
  └─kerneloops.service @8.657s +10ms
    └─network-online.target @8.651s
      └─NetworkManager-wait-online.service @3.343s +5.308s
        └─NetworkManager.service @3.171s +170ms
          └─dbus.service @3.169s
            └─basic.target @3.159s
              └─sockets.target @3.159s
                └─snapd.socket @3.158s +673us
                  └─sysinit.target @3.153s
                    └─snapd.apparmor.service @2.779s +106ms
                      └─apparmor.service @2.660s +118ms
                        └─local-fs.target @2.659s
                          └─run-user-125-gvfs.mount @3.864s
                            └─run-user-125.mount @3.651s
                              └─local-fs-pre.target @343ms
                                └─systemd-tmpfiles-setup-dev.service @311ms +31ms
                                  └─systemd-sysusers.service @284ms +26ms
                                    └─systemd-remount-fs.service @269ms +12ms
                                      └─systemd-journald.socket @260ms
                                        └─-.mount @257ms
                                          └─system.slice @257ms
                                            └─-.slice @257ms

Here is the log from systemd-analyze blame:
7.103s plymouth-quit-wait.service
5.308s NetworkManager-wait-online.service
2.302s snap-core20-975.mount
2.262s snap-snapd-11841.mount
2.256s snap-youtube\x2ddl-3805.mount
2.187s snap-skype-173.mount
2.124s snap-snap\x2dstore-518.mount
2.080s dev-sda2.device
2.060s snap-pdftk-9.mount
1.952s snap-snap\x2dstore-498.mount
1.947s snap-spotify-46.mount
1.862s snap-telegram\x2ddesktop-2637.mount
1.825s snap-gtk\x2dcommon\x2dthemes-1514.mount
1.805s snap-spotify-45.mount
1.780s snap-gnome\x2d3\x2d34\x2d1804-60.mount
1.631s snap-gnome\x2d3\x2d34\x2d1804-66.mount
1.620s snap-pinta\x2djames\x2dcarroll-8.mount
1.619s snap-snapd-11588.mount
1.617s snap-skype-172.mount
1.573s snap-gnome\x2d3\x2d28\x2d1804-145.mount
1.565s snap-intellij\x2didea\x2dultimate-295.mount
1.546s snap-telegram\x2ddesktop-2619.mount
1.446s dev-loop2.device
1.370s dev-loop3.device
1.346s snap-postman-132.mount
1.336s snap-core18-1997.mount
1.336s dev-loop4.device
1.310s snap-postman-133.mount
1.220s snap-kde\x2dframeworks\x2d5\x2dqt\x2d5\x2d14\x2dcore18-4.mount
1.217s snap-pinta\x2djames\x2dcarroll-6.mount
1.158s snapd.service
1.144s snap-acestreamplayer-11.mount
1.131s snap-datagrip-107.mount
1.122s systemd-backlight@backlight:intel_backlight.service
1.118s dev-loop5.device
1.097s dev-loop0.device
1.051s dev-loop8.device
1.003s dev-loop1.device
 999ms dev-loop6.device
 978ms dev-loop7.device
 908ms dev-loop9.device
 855ms dev-loop11.device
 852ms dev-loop10.device
 814ms fwupd.service
 615ms dev-loop12.device
 555ms snap-intellij\x2didea\x2dultimate-289.mount
 552ms snap-kde\x2dframeworks\x2d5\x2dqt\x2d5\x2d15\x2dcore20-14.mount
 518ms networkd-dispatcher.service
 491ms plymouth-read-write.service
 488ms dev-loop14.device
 483ms snap-code-64.mount
 476ms snap-core20-1026.mount
 440ms snap-gtk\x2dcommon\x2dthemes-1515.mount
 437ms udisks2.service
 435ms snapd.seeded.service
 431ms snap-code-65.mount
 415ms snap-gtk2\x2dcommon\x2dthemes-13.mount
 395ms upower.service
 360ms dev-loop16.device
 349ms snap-datagrip-106.mount
 342ms systemd-logind.service
 322ms snap-core-11081.mount
 291ms systemd-rfkill.service
 283ms dev-loop17.device
 276ms dev-loop20.device
 229ms accounts-daemon.service
 223ms systemd-fsck@dev-disk-by\x2duuid-8732e59a\x2d2720\x2d48f9\x2dafaf\x2d206471a8ed59.service
 223ms systemd-journal-flush.service
 218ms systemd-udevd.service
 196ms dev-loop25.device
 194ms dev-loop13.device
 192ms systemd-resolved.service
 192ms dev-loop15.device
 192ms dev-loop19.device
 171ms avahi-daemon.service
 170ms NetworkManager.service
 170ms bluetooth.service
 165ms polkit.service
 165ms dev-loop31.device
 161ms snap-core18-2066.mount
 157ms dev-loop30.device
 155ms systemd-timesyncd.service
 146ms switcheroo-control.service
 141ms thermald.service
 139ms wpa_supplicant.service
 137ms dev-loop27.device
 134ms dev-loop26.device
 133ms dev-loop18.device
 127ms systemd-journald.service
 124ms systemd-udev-trigger.service
 118ms apparmor.service
 114ms firstname.lastname@example.com
 113ms gpu-manager.service
 112ms email@example.com
 109ms snap-core-10958.mount
 106ms snapd.apparmor.service
 103ms dev-loop33.device
 102ms dev-loop24.device
  98ms apt-daily-upgrade.service
  96ms dev-loop28.device
  92ms apache2.service
  88ms geoclue.service
  81ms grub-common.service
  74ms ModemManager.service
  73ms keyboard-setup.service
  70ms apport.service
  69ms dev-loop32.device
  59ms dev-loop23.device
  56ms systemd-fsck@dev-disk-by\x2duuid-DD37\x2dA40E.service
  55ms dev-loop22.device
  55ms dev-loop21.device
  53ms systemd-random-seed.service
  51ms e2scrub_reap.service
  47ms systemd-sysctl.service
  41ms rsyslog.service
  40ms colord.service
  39ms grub-initrd-fallback.service
  39ms gdm.service
  34ms systemd-tmpfiles-clean.service
  31ms systemd-tmpfiles-setup-dev.service
  30ms dev-loop35.device
  26ms systemd-tmpfiles-setup.service
  26ms systemd-sysusers.service
  23ms systemd-modules-load.service
  21ms plymouth-start.service
  19ms home.mount
  19ms firstname.lastname@example.com
  17ms nvidia-persistenced.service
  15ms firstname.lastname@example.com
  14ms pppd-dns.service
  14ms email@example.com
  13ms dev-hugepages.mount
  12ms systemd-remount-fs.service
  12ms dev-mqueue.mount
  11ms sys-kernel-debug.mount
  11ms sys-kernel-tracing.mount
  10ms kerneloops.service
  10ms boot-efi.mount
   9ms alsa-restore.service
   8ms systemd-update-utmp.service
   8ms kmod-static-nodes.service
   8ms systemd-user-sessions.service
   7ms systemd-update-utmp-runlevel.service
   5ms openvpn.service
   5ms dev-loop36.device
   4ms console-setup.service
   3ms rtkit-daemon.service
   3ms sys-fs-fuse-connections.mount
   3ms ufw.service
   2ms setvtrgb.service
   2ms sys-kernel-config.mount
   1ms dev-loop29.device
 673us snapd.socket

Here is the log from systemd-analyse
Startup finished in 3.289s (firmware) + 7.828s (loader) + 35.232s (kernel) + 12.593s (userspace) = 58.943s
graphical.target reached after 12.583s in userspace

Kernel Log (dmesg):
https://drive.google.com/file/d/1Rxr-TZuYXvwSyRz-PQkBW4iiNf5dKUL3/view?usp=sharing
Comment: There are too many `snap` services, according to your output of `systemd-analyze blame`. You can consider replacing them with their .deb counterparts.
Comment: *Should I always prefer using apt-get install* -- That is your personal choice.  Nowadays "Ubuntu Software" often defaults to snap over apt. While snap is a great way to get the newest version of certain apps, they are sometimes not as fast as native apps. However, this is not a complete answer to the question (that is why I commented instead of answering). Someone else may be able to provide a better answer regarding other services which can be safely disabled.
Comment: @ArchismanPanigrahi Thanks for your answer. Do snap packages come from using "Ubuntu Software" for installations? Should I always prefer using apt-get install ?
Comment: Is your Windows boot time from cold? If you start up from one of the suspended states it's not really a valid comparison.
Comment: @PonJar I've disabled fast boot.
Comment: This will not be due to snap. Added delays by added snap packages are some microseconds at most. Indeed, fair comparison would be if also Windows would be cold booted (so no fast start enabled, and after fully shutting it down). Still, I find 40 s quite long for a system booting from SSD.
Comment: What is the output of `systemd-analyse` without arguments? What you reported is time in userspace, and that actually looks quite normal.
Comment: @vanadium I've just posted ouput of systemd-analyse
Comment: It is the kernel that is stuck. Once it is past there, all is normal. You should inspect kernel logs.
Comment: @vanadium Should I try with dmesg?
Comment: There are system and boot logs, but, like you, I would need to search how to retrieve them.
Comment: @vanadium I've just posted kernel logs by submitting dmesg.
Comment: In kernel log, you can see that strange thing happens between 1053rd row and 1054th row.
Comment: Do I have to format in order to solve the problem (I have already an home partition so I won't loose personal data). Or can I try other things?
Comment: Some things to review. I think I boot a bit fast since Kubuntu, not Ubuntu. https://askubuntu.com/questions/1284302/is-it-possible-to-make-ubuntu-20-04-boot-faster
Answer: As some of the commenters, I suggest you replace all snaps with their .deb variants. This should boost your boot time significantly. You don't really need to use sudo apt install for that.
Perhaps as yourself, I prefer the graphical installation through the Ubuntu Software. Whenever you want to install something from there, check the upper right corner. There should be a drop-down menu with words such as "ubuntu-focal-SOMETHING" or "latest/stable". If its the former, you're good to go: the .deb package will be installed. If it's the latter, then this is a Snap package, and I suggest you choose whatever "ubuntu-focal-SOMETHING" option there is.
If there is only the Snap option in Ubuntu Software, you can always go to your preferred software's website page and download a .deb package directly from there. Installing this package will also connect you to the official PPA of that app which will enable automatic updates. This is how you can get the .deb packages for Skype and Spotify apps. Telegram is available as a .deb in Ubuntu Software. You can check Pinta yourself. As for the YouTube app, it's probably just the website in a desktop wrapper, so you may consider simply watching YouTube in Firefox, or get a website wrapper app .deb package. But that's a different question.
Hope this helps!
Comment: Not the solution. It is the kernel that takes a long time. Moreover, easy enough to test: remove all snaps, see that the boottime has not decreased and reinstall the snaps again.
Comment: @Igor Thanks for the clarification about snap vs deb
Comment: No problem!

@vanadium I don't mean to say that this is THE solution, for there may be other issues. But the snaps do take long to boot, especially autostarting ones such as Skype and Telegram, so this will help to an extent.


Does background noise play a part in the Alien being able to hear you?

Question: If there is already a lot of background noise, due to machinery or an alarm for example, will walking or running, (instead of crouching), still give me away?
Answer: No... it is my understanding that the same ongoing noises do not have an effect an the xenomorph's senses, no matter how loud they are, however any thing activated by you or inevitably triggered by the level design will alert the xenomorph to your location... Also FYI... your motion tracker also alerts the xeno when he's close by so use it sparingly :D


Send a post request through an API

Question: I am starting to use a Payment API and I'm following their jsfiddle example. They are posting to the website requestbin in the fiddle. However, how do I make it post to my server instead? I am using balanced payments, rails and HAML.
In the first line of code var THEPOSTTOLINK = 'http://requestb.in/1hkphb71'; The example shows where to post to but how do I do that in Rails? I can't just write localhost:3000  or www.mysite.user/account.
Javascript
var THEPOSTTOLINK = 'http://requestb.in/1hkphb71';

var marketplaceUri = '/v1/marketplaces/TEST-MPg9bCIQUZMBoiPMnvWkQJW';
balanced.init(marketplaceUri);
function responseCallbackHandler(response) {
   switch (response.status) {
     case 400:
         console.log(response.error);
         break;
     case 404:
         console.log(response.error);
         break;
     case 201:
         var $form = $("#bank-account-form");
         var bank_account_uri = response.data['uri'];
         $('<input>').attr({
            type: 'hidden',
            value: bank_account_uri,
            name: 'balancedBankAccountURI'
         }).appendTo($form);
         $form.attr({action: THEPOSTTOLINK});
         $form.get(0).submit();
     }
 }
var tokenizeInstrument = function(e) {
     e.preventDefault();

     var $form = $('#bank-account-form');
     var bankAccountData = {
         name: $form.find('.ba-name').val(),
         account_number: $form.find('.ba-an').val(),
         bank_code: $form.find('.ba-rn').val(),
         type: $form.find('select').val()
     };
     balanced.bankAccount.create(bankAccountData, responseCallbackHandler);
 };
$('#bank-account-form').submit(tokenizeInstrument);

Bank account form
%form#bank-account-form{:action => "#", :method => "POST"}
  = label_tag :bank_name, "Account Holder's Name"
  = text_field_tag :bank_name, nil, name: nil, :value => "John Q. TaxPayer", class: "ba-name"
  %p
  = label_tag :route_num, "Routing Number"
  = text_field_tag :route_num, nil, name: nil, :value => "121000358", class: "ba-rn"
  %p
  = label_tag :acct_num, "Account Number"
  = text_field_tag :acct_num, nil, name: nil, :value => "9900000001", class: "ba-an"
  %p
  %button.btn{:type => "submit"}
    tokenize

Answer: As we discussed in #balanced on IRC, here's a rough example on how to accomplish what you're looking for. https://gist.github.com/remear/7f6d7e6f24aa7e63fd2b
Comment: While this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference.

Send a post request through an API