Browse folders and files using the Places menu

Question: I love the Places extension and the menu it provides. However, usually, I use the file browser to open one file, and rarely use it more than a few seconds (navigate, select file, bang enter, done), and I find it a waste to open and close the file browser each time I want to open, say a paper I downloaded. Is there a way I can expand the Places, such that I can navigate subfolders right there, and click on the file to open it (kind of like the directory tree packaged with any decent code editor)?
The pain point is the Files app that Gnome now ships with also does not have a decent looking directory tree.
Answer: You can try two options:

install and switch to the GNOME FlashBack session with sudo apt-get install gnome-session-flashback gnome-panel.
install and switch to the MATE DE with sudo apt-get install ubuntu-mate-desktop^.


C# How to access a class member by Binding

Question: I want to access a class member by binding, but without any UI nor XAML code.
class Foo {
    public int Value { get; set; }
}

class Bar {
    public Foo foo { get; set; }
}

Bar bar = new Bar() {
    foo = new Foo() {
        Value = 2
    }
}

Binding b = new System.Windows.Data.Binding("foo.Value");
b.Source = bar;

// Now I want a method which returns bar.foo.Value, would be like that:
int value = b.GET_VALUE(); // this method would return 2

Is there such a method ?
Comment: Have you read up on the [documentation](https://msdn.microsoft.com/en-us/library/cc838207(v=vs.95).aspx)?
Comment: Yes, but the documentation is with XAML or user interface element (TextBlock)
Answer: I found the answer, thanks to:
How to get class members values having string of their names?
No need of Binding class:
public static class Extensions
{
    public static object GetPropertyValue(this object Obj, string PropertyName)
    {
        object Value = Obj;

        foreach (string Property in PropertyName.Split('.'))
        {
            if (Value == null)
                break;

            Value = Value.GetType().GetProperty(Property).GetValue(Value, null);
        }

        return Value;
    }
}

Usage:
class Foo {
    public int Value { get; set; }
}

class Bar {
    public Foo foo { get; set; }
}

Bar bar = new Bar() {
    foo = new Foo() {
        Value = 2
    }
}

bar.GetPropertyValue("foo.Value"); // 2

bar.foo = null;
bar.GetPropertyValue("foo.Value"); // null


bijective continuous map and the preimage of a convergent sequence

Question: At first my question

Let $X,Y$ are metric spaces with $X$ compact also let $T : X \to Y$ be a bijective continuous map and $(y_n)_{n=1}^{\infty}$ a sequence of $Y$. Is it true the following fact? $$(y_n) \text{ convergent } \implies (T^{-1} y_n) \text{ Cauchy }$$
Or the more general? $$(y_n) \text{ Cauchy } \implies (T^{-1} y_n) \text{ Cauchy }$$
Is the assumption that $X$ is a compact space necessary?

And now the story behind
I came across the following problem about compact metric spaces

Let $X,Y$ are metric spaces and moreover $X$ is compact, also let $T : X \to Y$ be a bijective continuous map.
Prove that $T^{-1}$ is continuous

I am aware of the proof by contradiction. However a tried to make a direct proof but I got stuck.
my attempt

The map $T^{-1}$ is continuous if for every convergent sequence $(y_n) \subseteq Y$, with $\lim y_n=y$, it follows that $\lim T^{-1}y_n=T^{-1}y$
Let $(y_n)$ be a sequence of $Y$ such that $\lim y_n=y$
The fact that $X$ is compact and $T$ continuous implies that there is a subsequence, $(T^{-1} y_{k_n})$ , of $(T^{-1}y_n)$ such that $$\lim T^{-1} y_{k_n}=T^{-1} y$$

This is where a got stuck.
If a prove that $(T^{-1}y_n)$ is a Cauchy sequence.Then the fact that it has a convergent subsequence implies that $(T^{-1}y_n)$ and moreover $\lim T^{-1} y_{k_n}=\lim T^{-1} y$
Thank you for your time
Comment: Oh there are several problems that you are asking. So the main problem is proving inverse is also continuous? Do you know continuous image of compact set is compact then?
Comment: Do you know that if $f$ is uniformly continuous, $(x_n)$ Cauchy, then $f(x_n)$ is also cauchy?
Comment: no, but  i think that i can prove it. How is this related to my qeustion?
Comment: Continuity on compact space means uniform continuity. So it follows that $T^{-1}$ of cauchy sequence is also cauchy
Comment: Well I am just keep throwing out propositions. So which you are going to prove first? Feel free to ask if you have doubts…
Comment: @LiChunMin my main quastion is if $T^{-1}$ of a Cauchy seqeunce is Cauchy, when T is continuous and $X$ compact. And moreover if compactness of $X$ is necessary.

I tried to make clear how this question came up, but it seems that all the other stuff that I wrote are missleading.
Comment: Well I think you did a great job. I didn't go that far and just blindly follow the proofs when I studied analysis just last semester…I think compactness is nessesary to ensure that the inverse is uniformly continuous. If we take away compactness, what kind of domain do you want to have?
Answer: The answer to both questions is "yes", and the assumption that $X$ is compact is necessary for both. Foobaz John has already provided an elegant proof for the first question, but here is another: since $X$ is compact, it suffices to show that $T^{-1}y$ is the only limit point of $\{T^{-1}y_n\}$ where $y=\lim_{n\to\infty}y_n$. But if $T^{-1}y_{n_k}\to x_0$, by continuity of $T$ we have $y_{n_k}\to Tx_0$, so $y=Tx_0$, i.e. $x_0=T^{-1}y$. This completes the proof.
For the second question: since $X$ is compact and $Y=T(X)$, with $T$ continuous, we know $Y$ is also compact. In particular, $Y$ is complete, so $\{y_n\}$ Cauchy implies $\{y_n\}$ convergent. Now we can just defer to the first question.
To see compactness is necessary as an assumption, consider $X=[0,1)$, $Y=\{z\in\mathbb C:|z|=1\}$ and $T(x)=e^{2\pi i x}$. Then $T$ is continuous and bijective, but $T^{-1}$ is not continuous. Moreover, even if we knew $T^{-1}$ was continuous, this would not necessarily mean $\{y_n\}$ Cauchy implies $\{T^{-1}y_n\}$ Cauchy; for that we would need uniform continuity (which is automatic in compact spaces, providing another proof for the second question).
Answer: It suffices to prove that the map $T$ is closed in order to show that $T$ is a homeomoprhism. To this end, let $E$ be a closed subset of $X$. Since $X$ is compact, it follows that $E$ is compact. Since $T$ is continuous, the continuous image of a compact set is compact and hence $T(E)$ is compact. But compact sets are closed (since $Y$ is a metric space); hence, $T(E)$ is closed as desired.
For your first question, since $T:X\to Y$ is a homeomorphism (as we have shown), it follows that $y_n\to y$ implies that $T^{-1}(y_n)\to T^{-1}(y)$ so that $T^{-1}(y_n)$ is Cauchy (as convergent sequences are clearly cauchy). The second question is similar since $T(X)$ is compact and hence complete. Thus if $\{y_n\}$ is Cauchy in $Y$, then it converges and we can use the answer of the previous question. The assumption that $X$ is compact is necessary as there exist continuous bijective maps which are not homeomorphisms (for example, the map $f:[0,1)\to S^1$ given by $f(x)=(\cos2\pi x,\sin 2\pi x)$.
Comment: @ karhas The map $T$ is closed means that if $E$ is closed in$ X$, then $T(E)$ is closed in Y. It is equivalent to showing that the preimage of closed sets under $T^{-1}$ is closed because $T$ is a bijection..
Comment: what it means for a map to be closed?


Is there a way to set hotkeys to locations in StarCraft 2?

Question: I thought that I remembered the ability to assign a hotkey to a location in SC1, but I don't see anything listed in the hotkeys for SC2 for such a thing. I'd like to be able to immediately switch the view to a particular location (like Backspace does for your base).
I thought I saw something in the key assignments that sounded like it for ctrl-F7 through F10 or something, but when I tried to set them and then use them it looked like they were set to do something else entirely.
Answer: If you go to options, hotkeys you can assign it to whatever you want. It is called camera-save. By default though some menus take up f9 - f12, so ctrl+f8 is the only one that works for camera saving with the default profile. You either need to pick different keys or take the menus off of those hotkeys to get the other ones to work.
Comment: Awesome thanks! So it looks like I had the right option, but why would Blizzard make the defaults unusable?!? Very odd.


Is it possible to create a PHP Switch which check the url for a specific string?

Question: Is it possible to create a PHP switch, which checks a URL's for a specific string? I'm using $_GET to customize the URL'S of specific pages depending on various situations. I want to trim down the Url and check it against several cases. Here is the code I have so far.
Here is the an example of the URL:

www.example.com/page/resource/view.php?id=417&module=1&menuid=4&module=1&page=4
<?php

// Grabs the page URL
$url = curPageURL();
var_dump($url);

$trimURL = trim($url);
var_dump($trimmed);

$trimmed = trim($text, "resource/view.php?id=417&module=1& || &module=1&page=4");
var_dump($trimmed);

// The Switch
switch ($trimmed) {
case "menuid=1":
    echo "Menu ID  1";
    break;
case "menuid=2":
    echo "Menu ID 2";
    break;
case "menuid=2":
    echo "Menu ID 3";
    break;
default:
echo "No Menu Number Detected.";
}
?>

Comment: Is there a specific reason you can't just use `$_GET["menuid"]` in the `switch` statement without the other trimming?
Comment: You really don't want to do things that way! You're hard coding a lot of stuff, whenever there is a new menu ID you've got to update your code, that's not good programming! You want to solve this in a generic way.
Comment: If that is the easiest solution. Then I have no problem using that
Comment: @Nick - that's the only solution that makes sense in this situation.
Comment: @markus-tharkun I know, but there is no way around it. It how it was done before I was here.
Comment: @markus-tharkun I don't have that kind of resources. Thanks.
Comment: You don't have less resources, hm, interesting...
Answer: switch($_GET["menuid"]) {
    case "1":
        echo "Menu ID  1";
    break;
    case "2":
        echo "Menu ID 2";
    break;
}


Is the World 4 version of Hunt impossible without doing something else first?

Question: I'm stuck on the World 4 version of Hunt. I don't want a walkthrough; I don't even want a hint. (Please don't offer a hint.) I just want to know whether it's impossible without doing something else first to alter the puzzle, because it sure looks impossible to me: as far as I can tell, the rightmost guy will always be alive when you get to the gate. Just kidding; I got it.
Comment: @Kotsu yeah that occurs to me now as well, I'm quite certain that is the *only* instance though.
Comment: @Wipqozn As far as puzzle pieces are concerned, it's the only instance, yes.
Comment: @Wipqozn while it is possible to beat every level without doing something else, OP is referring to grabbing the puzzle piece in the level. Some puzzle pieces in the game cannot be obtained the first pass through (the specific example that comes to mind for me is early on in the game, world not disclosed to avoid spoilers).
Comment: It's possible to beat *all* the levels without doing something else first.
Comment: @Kotsu: if you're thinking of the example I'm thinking of, that's what had me worried.
Answer: No, this is completely possible to do without doing anything else outside the level. I was skeptical at first as well, but you just have to think about it a bit.
As requested, no hint has been given.
Comment: If this was a sufficient answer to your question, an "accept" would be appreciated ;).
Comment: If an answer is accepted, it means it has been useful, and thus could be considered a hint. Shall we agree to disagree?


How to assign a value to a variable after each interval?

Question: I would like to run a script that repeats 100 times.
With each repetition it should be in order
Take the names from an array or list and pass them to my variable. How can I do this ?
I created this as an example and think about how I can install a function there. I've read and tried a few things. But somehow I'm not ready yet

var TestNames = ["test1", "test2", "test3", "test4", "test5"]
var n = TestNames[0]
interval = setInterval(function() {
  var Username = n;
  console.log(Username);
  // here is some code
}, 2000);
setTimeout(function() {
  clearInterval(interval)
}, 10000);
Comment: What is the logic to pick a name in each iteration? Is it random or by order? Does [`var Username = TestNames.shift();`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) suffice? What happens when all names are iterated over?
Answer: Aassuming the setTimeout is calculcated by the amount of names (10000/2000), you can omit it entirely.

const TestNames = ["test1", "test2", "test3", "test4", "test5"];

//REM: https://developer.mozilla.org/en-US/docs/Web/API/setInterval
//REM: Passing a copy of TestNames to not alter the original
const interval = setInterval(function(listOfNames){
  if(listOfNames.length){
    //REM: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
    const Username = listOfNames.shift();
    console.log('Current name:', Username);
    console.log(TestNames.length - listOfNames.length, ' names done.');
    console.log(listOfNames.length % TestNames.length, ' names left.')
  }
  else{
    //REM: Cancel the interval, if listOfNames has no more items
    clearInterval(interval);
    console.log('No names left.')
  }
}, 2000, Array.from(TestNames));

Take the names from an array or list and pass them to my variable. How
can I do this ?

That depends on your requirements.

Do you need to keep TestNames?
Do you pick a random name?
Do you just pick the next name in order?

In my example I pass a copy of TestNames to the interval as listOfNames. On each iteration I remove the first item from listOfNames by using shift which also returns that removed item and assign it to Username. If listOfNames has no more items, the interval gets cleared.
Comment: Not my downvote. I prefer this one since it has no timeout and no pesky counter.
Comment: @Gelegen the usernames are not random, I will set them myself. Which are then called up one after the other.  TestNames was a example,can be changed
Comment: Added *count of done* and *count of left*.
Answer:

const TestNames = ["test1", "test2", "test3", "test4", "test5"]

let index = 0

const interval = setInterval(function() {

  const Username = TestNames[index];

  console.log(Username);
  index += 1
}, 2000);

setTimeout(function() {
  clearInterval(interval)
}, 10000);
Comment: I disagree to teach beginners poor syntax. += is as difficult, Why not index = index + 1 if you want to be really simple?
Comment: Please: `index++` and what when it is manages to get to more than 4 before the clear?
Comment: @mplungjan `index++` is very complicated for beginners
Comment: Thanks for the many replies, I'll get to work right away and test them all :-)
Comment: But here's another question, would
++, +=, +1

does everything work?

What is bad syntax?
Comment: @Jeffrey https://stackoverflow.com/questions/17241877/difference-between-and-1-in-javascript
Answer: If you want to write a username for each iteration, I suggest this. Also note the use of const and let

const testNames = ["test1", "test2", "test3", "test4", "test5"]; // JS arrays starts at 0
const numberOfNames = testNames.length;
let counter = 0;
let interval = setInterval(function() {
  if (counter >= numberOfNames) return; // don't continue
  let Username = testNames[counter];
  console.log(counter,Username);
  counter++; // point at the next or perhaps beyond - shorthand for counter = counter + 1 or counter += 1.  ++ increments

  // here is some code
}, 2000);
let tId = setTimeout(function() {
  clearInterval(interval)
}, 10000);
Comment: Thanks again to everyone who helped :-)

For my purposes, the code of "Gelegen" works best. Since I can always enlarge my array. So I don't need to know how many names are in it to calculate setTimeout.
I like the counter function of "mplungJan". In the end I would know how many names I have without counting them myself. Now I'll try to see if I, as a beginner, can integrate the counter function in "Gelegen" his code :-)
Comment: Is there any reason for `interval` to be `let` and to assign `setTimeout` to `tId`? Just curious about the choice.
Comment: Using `++` is an antipattern for me. `testNames[counter++]` would make more sense. When you use `++` you imply that you care about the current value, but you want to increment it after.
Comment: @Konrad while that is a stance to take, I entirely disagree. I totally dislike those **assign and use variable in same statement**. It is like using `testNames[index += 1]` in your snippet (if you start at -1). Also it may work in this case, yet it might not work generally if `counter` has more uses.
Comment: @JavaScript I always assign setInterval and setTimeout to separate variables. And I always assign them to a variable to be sure I can clear them if needed.
Comment: I was contemplating the [counter++] but I prefer to set it explicitly. In this case even more important because I wanted show the counter in the console.log BEFORE incrementing to teach SO that the JS Arrays started a 0. Also I ALWAYS use ++ when adding one to anything


Lucene Net Search fail if term is too short

Question: I am new to Lucene, so maybe this is a techical limit i dont understand.
I have indexed few text and the try to fetch the content.
If i query this text open-source reciprocal productivity with the query source i get a match.
If i sue the query sour i also gret a match. But if i use the query sou then i don't get any match.
I am using Lucene .Net version 4.8
Here the code i am using to creating index :
using (var dir = FSDirectory.Open(targetDirectory))
{
    Analyzer analyzer = metadata.GetAnalyzer() ; //return new StandardAnalyzer(LuceneVersion.LUCENE_48);

    var indexConfig = new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer);

    using (IndexWriter writer = new IndexWriter(dir, indexConfig))
    {
        long entryNumber = csvRecords.Count();
        long index = 0;
        long lastPercentage = 0;
        foreach (dynamic csvEntry in csvRecords)
        {
            Document doc = new Document();
            IDictionary<string, object> dynamicCsvEntry = (IDictionary<string, object>)csvEntry;
            var indexedMetadataFiled = metadata.IdexedFields;

            foreach (string headField in header)
            {
                if (indexedMetadataFiled.ContainsKey(headField) == false || (indexedMetadataFiled[headField].NeedToBeIndexed == false && indexedMetadataFiled[headField].NeedToBeStored == false))
                    continue;

                var field = new Field(headField,
                                        ((string)dynamicCsvEntry[headField] ?? string.Empty).ToLower(),
                                        indexedMetadataFiled[headField].NeedToBeStored ? Field.Store.YES : Field.Store.NO, //YES
                                        indexedMetadataFiled[headField].NeedToBeIndexed ? Field.Index.ANALYZED : Field.Index.NO //YES
                                      );

                doc.Add(field);
            }

            long percentage = (long)(((decimal)index / (decimal)entryNumber) * 100m);
            if ( percentage > lastPercentage && percentage % 10 == 0)
            {
                _consoleLogger.Information($"..indexing {percentage}%..");
                lastPercentage = percentage;
            }

            writer.AddDocument(doc);
            index++;
        }

        writer.Commit();
    }
}

And here the code i sue to query the index :
var tokens = Regex.Split(query.Trim(), @"\W+");

BooleanQuery composedQuery = new BooleanQuery();
foreach (var field in luceneHint.FieldsToSearch)
{

    foreach (string word in tokens)
    {
        if (string.IsNullOrWhiteSpace(word))
            continue;

        var termQuery = new FuzzyQuery(new Term(field.FieldName, word.ToLower() ));
        termQuery.Boost = (float)field.Weight;
        composedQuery.Add(termQuery, Occur.SHOULD);
    }
}

var indexManager = IndexManager.Instance;
ReferenceManager<IndexSearcher> index = indexManager.Read(boundle);

int resultLimit = luceneHint?.Top ?? RESULT_LIMIT;
var results = new List<JObject>();
var searcher = index.Acquire();
try
{
    Dictionary<string, FieldDescriptor> filedToRead = (luceneHint?.FieldsToRead?.Any() ?? false) ?
                                                            luceneHint.FieldsToRead.ToDictionary(item => item.FieldName, item => item) :
                                                            new Dictionary<string, FieldDescriptor>();

    bool fetchEveryField = filedToRead.Count == 0;

    TopScoreDocCollector collector = TopScoreDocCollector.Create(resultLimit, true);
    int startPageIndex = pageIndex * itemsPerPage;

    searcher.Search(composedQuery, collector);

    //TopDocs topDocs = searcher.Search(composedQuery, luceneHint?.Top ?? 100);
    TopDocs topDocs = collector.GetTopDocs(startPageIndex, itemsPerPage);
    foreach (var scoreDoc in topDocs.ScoreDocs)
    {
        Document doc = searcher.Doc(scoreDoc.Doc);
        dynamic result = new JObject();
        foreach (var field in doc.Fields)
            if (fetchEveryField || filedToRead.ContainsKey(field.Name))
                result[field.Name] = field.GetStringValue();

        results.Add(result);
    }
}
finally
{
    if ( searcher != null )
        index.Release(searcher);
}

return results;

I am confused, is the fact the i cant get resoult for sou query relate to the fact that the StandardAnalyzer that is used to build the index, use a some stop-word that prevent my query term to be found in the index? (the index stop ad source and sour because those are both english words)
Ps : here the explain plot, even if i don't know how to use it :

searcher.Explain(composedQuery,6) {0 = (NON-MATCH) sum of: }
Description: "sum of:"
IsMatch: false
Match: false
Value: 0
Answer: The documentation for FuzzyQuery points out that it uses the default minimumSimilarity value of 0.5: https://lucenenet.apache.org/docs/3.0.3/d0/db9/class_lucene_1_1_net_1_1_search_1_1_fuzzy_query.html

minimumSimilarity - a value between 0 and 1 to set the required similarity between the query term and the matching terms. For example, for a minimumSimilarity of 0.5 a term of the same length as the query term is considered similar to the query term if the edit distance between both terms is less than length(term) * 0.5

So, it matches "source" when the query is "sour", because removing "ce" requires two edits, the edit distance is 2, and that's <= than length("sour") * 0.5. However, matching "source" to "sou" would need 3 edits, and so it's not a match.
You should be able to see the same document matching even if you search for something like "bounce" or "sauce", since those are also within two edits from "source".
Comment: you are right, and i like the fact that even not perfect match will produce result, but how may i increase the maxEdits value? If i try to set a greater value in the cosntructor i get a runtime error. By now i work arround the issue adding two Query for each term, a FuzzyQuery to match misspelled term, and a WildCardQuery to match contains.  May be this a good solution?
Comment: What are you trying to achieve here? Are you trying to make it so that the word matches by any variation of it?
Comment: I have indexed many documents (no common schema) that are basically few json with many string properties. I receive a query that tell me in which property do a search and for wich word. I need to find variation of the word and also perform a "contains" search in  each string
Comment: Ok, got it! In that case it feels like a combination of FuzzyQuery and WildCardQuery as you described above should be the best way to achieve that!


Download .vbs inside of xampp server instead of displaying the code

Question: We have in our company a VBS script that users need to donwload, it's pretty simple.
But, here in the SERVER we have to run another applications in PHP we are trying to put this VBS there to users download. But when they enter in the link it displays the code of VBS and don't download.
Have something I can do to fix that?
SOLVED
Using this link, if someone want to: http://php.net/manual/en/function.readfile.php
Comment: Put the code, are you trying this using `header()` ?
Answer: If your webserver is apache, you could create a .htaccess file in the directory with the vbs files you want users to download with the following contents:
<FilesMatch "\.(vbs)$">
  Header set Content-Disposition attachment
</FilesMatch>

This will cause all vbs files in that directory to show a "save file as" dialog instead of showing the code directly in the browser.
Alternatively, since you mentioned PHP, you could create a new php file with the following code in the directory with the vbs file:
<?php
header("Content-Disposition: attachment");
readfile("yourfile.vbs");
?>

And then just point to the php file instead of the vbs file
Comment: Hi @Andrew! Thanks for your reply. I've tried the 2 things. So, I have here a XAMPP running APACHE. Tried to put a .htaccess file in the htdocs folder and also scripts folder where vbs is and didn't worked, still opening the vbs (XAMPP already config without module commented). The second one, download a PHP with the content of VBS. Could you help me with that?
Comment: Hey @RodrigoBRF. First of all, check the httpd.conf file in the xampp folder (c:\xampp\apache\conf in windows) and look for a line that says `AllowOverride None` and change it to `AllowOverride All` to allow htaccess to override settings (If you are using virtual hosts, you might have to do the same thing in the httpd-vhosts.conf file). Then try the htaccess solution again but this time **restart apache after creating the htaccess file**. Restarting apache is an important step that I forgot to mention.
Comment: I'm not sure if you tried the PHP solution or not but I think it should work too. Just create a php file like **download.php** with the code from my answer (replacing yourfile.vbs with the actual vbs file name) and stick it in the same directory as the vbs file. Then when you want to link to it, you would do something like `Download`
Comment: Hi Andrew! Tried the .htaccess as you mentioned, didn't work. The PHP file I'm having the problem as I said, when you hit link to 'download.php' it downloads, but downloads a .PHP with the code of VBS inside of it, it doesn't download as a .vbs file! Look my code:
Comment: Friend, I solved it using the code in this link: http://php.net/manual/en/function.readfile.php thank you so much!
Comment: Perfect. Glad I could help.


How do you install chntpw on Ubuntu 17.04?

Question: I downloaded the tar.gz off of the Ubuntu Package website and have tried following 3 different tutorials, and every time I try to do something terminal tells me I can't. I haven't made any progress.
Comment: Why is your title and body of the question sooo different?!!
Answer: chntpw is in the default repositories of Ubuntu 17.04 and all currently supported versions of Ubuntu. To install chntpw open the terminal and type:
<code>sudo apt update
sudo apt install chntpw
</code>
Comment: Check in *Software & Updates* -> *Ubuntu Software* tab that the first four software sources in the list are checked by check marks. Don't try to install the chntpw .tar.gz file you downloaded. Use apt to install chntpw and apt will download and install chtpw for you.
Comment: Hey. It worked. I just needed you there to hold my hand. Thanks.
Comment: Yeah, I did try this. For some reason it returns an error saying Unable to locate package.


Mongoid embedded document parent not set in after_initialize callback

Question: I'm trying to reference the parent object of an embedded document from within an after_initialize callback.
Here's a mockup of my setup:
require 'mongo'
require 'mongoid'

connection = Mongo::Connection.new
Mongoid.database = connection.db('playground')

class Person
  include Mongoid::Document

  embeds_many :posts
end

class Post
  include Mongoid::Document

  after_initialize :callback_one

  embedded_in :person, :inverse_of => :post

  def callback_one
    puts "in callback"
    p self.person
  end
end

This will cause the behavior I don't want:
a = Person.new
a.posts.build
puts "after callback"
p a.posts.first.person

which spits out:
[d][Moe:~]$ ruby test.rb
in callback
nil
after callback
#<Person _id: 4e57b0ecba81fe9527000001, _type: nil>

To get the desired behavior, I can manually do this:
b = Person.new
c = Post.new(person: b)
puts "after callback"
p c.person

which gives me:
d][Moe:~]$ ruby test.rb
in callback
#<Person _id: 4e57b386ba81fe9593000001, _type: nil>
after callback
#<Person _id: 4e57b386ba81fe9593000001, _type: nil>

the only problem with that being that it doesn't work whenever an object is being loaded from the DB, in which case one would think that person would already be set, because it's being loaded from the person, but it's not.
Does anyone know if this is the desired behavior, and if it is can you tell me why?
If this isn't the desired behavior, can anyone tell me a workaround?
Comment: This problem seems to persist in Mongoid 3 as well.
Answer: There are several issues for this problem on GitHub: #613, #815 and #900.
Mongoid v2.2.0 has been released yesterday, but still doesn't include the patch from #900. So there's no simple way to do this.
Depending on your use case, lazy loading might already be enough:
class Post
  include Mongoid::Document

  embedded_in :person, :inverse_of => :post

  # This won't work yet.
  #
  # after_build :init
  #
  # def init
  #  @xyz = person.xyz
  # end

  def xyz
    @xyz ||= person.xyz
  end

  def do_something
    xyz.do_some_magic
  end
end

Comment: Thanks for the workaround, I haven't tried the lazy loading yet, I think I'll wait for #900.


'save link as' / 'open with' / 'launch application' window

Question: When I want to open any file or even when I want to do "save link as" in mozilla there is a pop up window with the title launch application which I should choose an application to open that file. What is it? And how I can configure it to not open for mozilla or if it is not possible how to delete it?
Answer: As discussed in the comments, it turned out the real issue was somewhere else - I may try to integrate the useful part here.

It is a dialog window of firefox asking you which application to use to open a speciffic kind of file.
The choice will be saved for that file type,
but it will ask for each file type at the first use.
Comment: How can I disable it?
Comment: You mean to not open programs for files?
Comment: No. But when I want to download adobe from its site there are some options that are unable to download that. I just need mozilla to download it with its downloader.(thanks for your replys)
Comment: Oh, if it's about this special case, the problem may be very different (an X-Y-problem). So you want to download and run a downloader for some adobe software? The only step where firefox could help would be downloading the downloader program, and you run it?
Comment: What's the actual problem you're trying to solve - eg something like "install Adobe Foo version 42.e"?
Comment: sites like adobe don't let downloaders to download their files. Only browsers can do that. But How can I choose the browser as a way to download that file?
Comment: Normally, "Save Llink As..." in the context menu should work. Does it work on other links for you? Try to save the question page using Save link as... on  the question title.
Comment: I think your link may be special or somehow broken or non-standard at least. I have never seen that Save link as... does not work...
Comment: The save link as open that launch application box that I should choose a program.
Comment: You mean, if used on the question title?
Comment: this is the link http://get.adobe.com/flashplayer/
Comment: Ah, the link on that yellow button? That's very special indeed - technically, it's not even a link! On that page, if I choose `apt` format to the left, the software center opens... strange. Now I see what you mean. Do you have the problem on any other links?
Comment: I haven't faced the same problem yet.
Comment: Ok, so it's more or less speciffic to downloading software in packages from Adobe - but part of the issue is in firefox, or some firefox extension from ubuntu. The special Adobe link makes it just harder to understand and solve. _Now we have found the **real problem** we want to solve. And can start looking for a **solution**!_ :)
Comment: :) Yeah. You are right.
Comment: It seems it is possible to download it from software centre. Thanks a lot for your helps. Anyway if you find a solution to this problem, I would be happy to here that.
Comment: I have my own issue to debug for now - rewrite/edit the question and title if you like. By the way, are you sure you need the absolute latest flash plugin version? Did you try `adobe-flashplugin` from the Ubuntu partner repository?
Comment: Oh, that version in software center is exactly the one I just asked - the one I use. And I was thinking you try hard to get the newest version - the really absolutely newest version! So, another X-Y-problem! Take a look at that - can help to save lots of your time! http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem


configure tor to use only US proxies

Question: Can anybody tell how I can configure my tor to use only US proxies?
Answer: Vidalia, open Settings→Advanced
and add this to your torrc file:
ExcludeNodes {be},{pl},{ca},{za},{vn},{uz},{ua},{tw},{tr},{th}, {sk},{sg},{se},{sd},{sa},{ru},{ro},{pt},{ph},{pa}, {nz},{np},{no},{my},{mx},{md},{lv},{lu},{kr},{jp}, {it},{ir},{il},{ie},{id},{hr},{hk},{gr},{gi},{gb}, {fi},{es},{ee},{dk},{cz},{cy},{cr},{co},{cn},{cl}, {ci},{ch},{by},{br},{bg},{au},{at},{ar},{aq},{ao}, {ae},{nl},{de},{fr}

Answer: Add this to your torrc file:
ExitNodes {US}
StrictNodes 1

configure tor to use only US proxies


Select a row in a SQL table only if a value is in the next few rows of the table?

Question: How do I select rows from a SQL table with a specific column value, but only if one of two specific column values are in the next five rows?
For example I have a table that looks like the following:
id | name     | action
-----------------------
 1 | New York |  1
 2 | Boston   |  3
 3 | Dallas   |  2
 4 | Boston   |  4
 5 | New York |  2
 6 | Chicago  |  5
 7 | Dallas   |  6

I want to select the rows where action=1, if and only if there is in a row in the next five rows of the table where action = 4 or action = 6.  In the above table this would return the first row (id=1, New York), only because of row id=4 (Boston, action=4) but not because of row id=7 (Dallas, action=6)
Answer: One method uses window funtions:
select t.*
from (select t.*,
             count(*) filter (where action in (4, 6)) over (order by id rows between current row and 5 following) as cnt_action_4_6
      from t
     ) t
where action = 1 and cnt_action_4_6 > 0

Answer: Use window functions:
select *
from (
    select t.*,
        count(*) filter(where action in (4, 6)) over(order by id rows between 1 following and 5 following) cnt
    from mytable t
) t
where action = 1 and cnt > 0


Ubuntu 18.04 stuck at purple loading screen after new update

Question: Today I switched on my laptop and ubuntu 18.04 stuck on the purple loading screen after boot. As I have another ubuntu boot on my drive, I boot into it and everything was working normally.
it boots on recovery mode.
How do I solve it?
I tried:

Boot into recovery mode and edit /etc/gdm3/custom.conf WaylandEnable=false

Problem keeps the same.
Ubuntu 18.04
Comment: @H.sanati can you please share your solution?
Comment: See here: https://askubuntu.com/questions/613582/terminal-wont-launch-after-upgrading
Comment: @Hamad , it is stuck on boot
Comment: talk to me I think i can help you because i had the same issue and after struggling for 5 days I fixed it
Comment: @Abbas i posted the answer. tell me if it works
Answer: This issue can have two reasons:
1- your system has Nvidia graphics card and its driver is not installed.
for this you should follow these steps:
When you start your system you can see the grub menu that has options like Ubuntu, Advanced options for Ubuntu and ...( I have a Asus laptop that I must press Esc on to see the grub menu) select Ubuntu but don't press Enter, press E instead.
You will see boot parameters for Ubuntu. In this step we are going to use an open source graphics instead of Nvidia temporarily to install the right graphics driver. In the line which starts with linux add this at the end of the line: nouveau.modeset=0 after ... quiet splash like this: quiet splash nouveau.modeset=0
Now you can press F10 to continue booting and you should see the login page and it won't be stuck. (don't do the second reasons solution if you logged in successfully. follow the final step)
2- your display manager has a problem.
When you upgrade to 18.04, Ubuntu uses gdm as a default display manager that has more code complexity than lightdm. so you should change it to lightdm (even if your Ubuntu uses lightdm do it anyway because maybe lightdm is broken)
Go to recovery mode and bring up the shell (with networking enabled) as root now type these commands:
 sudo apt-get update
 sudo apt-get install --reinstall lightdm
 sudo dpkg-reconfigure lightdm

Select lightdm as default display manager and reboot you should see the login page.
I recommend you to do both solutions at the same time if you are not sure which to use.
Final Step
Now after logging in you should install the right version of Nvidia graphics on your system.
Type the following commands:
sudo apt-get purge nvidia*
sudo ubuntu-drivers devices

Now you can see the drivers available for you Nvidia graphic card install the recommended version like this (the version can be different on your system but mine is 390):
sudo apt-get install nvidia-390

Warning: don't add any PPA for Nvidia
After installation is complete reboot your system normally and it must work.
Comment: There is a typo in `nauveau.modeset=0`. It is spelled `nouveau.modeset=0`, right?
Comment: I had exactly the same issue as Steve reported in another answer. step1 in this answer made no difference, but step2 worked :)
Comment: Tried the 2nd solution first and it worked like a charm.  I'd do +100 if I could.
Comment: Very useful to fix ATI X1600 problem on IMac late 2006, with Ubuntu upgraded from 16.04 to 18.04. Log in screen was like broken and logging in to the desktop results in black windowed aplications (totally black), like Firefox or even the software updater. At least the terminal could be seen nicely and I could apply the second fix, going back to lightdm. Now Perfect!!! Thank you.
Comment: @CorinFletcher I'm glad it worked :)


What do I do if there are no new missions in Jetpack Joyride and I'm still missing one star to be able to level up?

Question: I just finished another set of missions for Jetpack Joyride , but oddly I'm still missing one more star to be able to complete the set to level up. I have no new missions, so I guess I'm stuck. What do I do?
Answer: Basic troubleshooting:
Quit the app, double tap home, hold on Jetpack Joyride, and delete it. (This will not delete the game itself; it just stops running it) and then open it again and see what happens.
Otherwise I'd say un-install and re-install; this shouldn't lose your progress if it is connected to something like Game Center.
Comment: @Merx, if this answers your question, accept it as an answer, and consider upvoting it.
Comment: It worked! Uninstalling and reinstalling the game... Thanks
Comment: It didn't work for me... i just un-installed and re-installed and play until lvl 12 with 14,000 coins, then i quit and later play it again and i just had 4,000 coins... :( it's the thirth time :(


Lenovo thinkpad E460 keyboard issue after skype call

Question: I have Lenovo thinkpad E460 model laptop with Ubuntu 18.04. Whenever I do a skype call just after disconnect skype call my keyboard behaves strange. To fix this I have to attach external keyboard and kill skype from terminal. My skype version is -184.108.40.206 Does anyone knows any fix for this.
Comment: I am having the exact same issue here with Thinkpad L580, ubuntu 19.10, skype 184.108.40.206. Exiting skype from the toolbar menu (with the mouse) temporarily solved the problem for me.
Comment: Yes same with me. In my case I have to lock the screen once and then open terminal somehow and kill the skype. If you find any solution let me know
Comment: Yes, facing same issue after 1:1 call. Everything works fine if I am on a group call.
Answer: It's fixed in the recent versions of skypeforlinux. Upgrade Skype to 126.96.36.199 or a newer version.


Can I use separate circuits for Light / Ceiling fan combo for future backup power integration?

Question: I am in the process of rewiring my 100 year old house.
I would like to use 14/3 wire from the breaker box to run 2 separate circuits, one side will be just lights, the other side will be just for the ceiling fans. Both sides together will be about 1200 watts if all fans are on high and all the lights are on and if I use incandescent bulbs (but who does that anymore).
My thinking is this, some day I would like to put in a backup/alternative power source, I don't want everything to run off the backup power source, just lights and a few other select circuits. In trying to keep the demand on my backup power low.
Anyways is it an option to run those 2 circuits on a single 14/3?
Answer: No, you need to keep neutrals separate.
YOU CANNOT RUN SEPARATE CIRCUITS ON 14/3
That thing you're thinking of, is called a "multi-wire branch circuit" (singular).  It is one circuit.  Note that they share a neutral, and that's what makes them one circuit.
The only way you could conceivably ham-bone 2 circuits onto 14/3 is by using the ground wire as the second circuit's neutral, but that's so outrageously reckless that I mention it only to assassinate it.
Actually, you have a bigger prob^H^H^H^H challenge
Speaking of assassinating, I am assuming you will NOT be using one of those atrocious 6-8-10 circuit transfer switches that cost a fortune, aren't well built, are by shabby suppliers like FPE->Republic, cost 4 times as much, and have spaghetti wiring. Their only virtue is ease of retrofit, and that's no virtue at all on a ground-up rewire.
Generally the way smart people do it, is with a separate subpanel for  the circuits to be switched between sources. Then you have a simple 2- or 3-pole transfer switch or interlock; this can be as simple as a $25 strap that ties together 2 backfed breakers in the panel. That, with a

And another alternative is DC power.  For a modest "lights, refrigerator, few other things" supply, it may be better to "stay" in DC power, if your auxiliary source is battery plus solar/wind/microhydro/simple-gen.   This avoids the significant energy overhead of an inverter running 24x7 merely to run loads that can work on DC.  You can still use mains wiring and mains panels, however, the challenge I'm about to mention will become even bigger, because these systems must be rigidly separated from Mains.
The challenge
When you are in auxiliary-power mode, or when switched to it, you will have two separately-derived power sources, and certainly, two separate panels.  Because of this, wiring must be carefully separated, in particular, neutrals cannot cross. That means things like the 14/3 MWBC trick are right out.
In fact, you'll need a fan-light which has two separate neutral wires: one for fan and one for light.
Low voltage would need to be in different boxes or with listed partitions, and separate cables.  If both sides are mains power, even if they're separate panels or sources, they can commingle in the same box or even the same cable. But still, neutrals need to be separated.   And there's the trick. You need some way to "mark" which cable is coming from which service.
For instance, you could do a really diligent job of marking cables with colored tape (and leaving a bit past the cable clamp). (in particular, tape panel 2's white wires with gray tape).  Or you could wire the alternate service in UF or MC cable instead of NM.  Anything like that would be acceptable, but you'll need to do it, or you'll lose your mind trying to work inside boxes.   I work in conduit and have as many as 4 circuits in a conduit at a time, and you have to color-code or you will make mistakes!
Comment: @Kris you can't serve one leg of an MWBC out of a different panel than the other leg.  Wouldn't matter if they were separately derived, but, think about a shared neutral utility and generator connection with one MWBC leg on each,  what happens to neutral, when power is at a slightly different frequency (they drift in and out of phase)....
Comment: Yep, this guy knows his MWBC and the nightmare scenario created by generators and aux power when dealing with them. In my mind a MWBC should be the last available option and only used when you can't wire them properly without ripping out walls and floors, every other option should be analyzed and attempted first.
Comment: They are dangerous and they're usually installed incorrectly (my current rental with an open ground and a MWBC in the kitchen with no GFCI). Sharing the neutrals between circuits means you can't separate them, one single misplaced splice and your entire circuit becomes a dangerous potential to feed current through the grounds across into the actual grounds... Now there's a current carrying conductor attached to the wall plate screws and the metal chassis of everything plugged in. Reverse the polarity of an outlet and now the live isn't switched and the metal toaster becomes a death trap...
Comment: @bob the builder, they are permitted per code so not sure why you think they are dangerous.
Comment: Yeah, the MWBC is going to cause *serious* issues here if he wants to set up to use a standby generator "out of the box", as that requires a *switched neutral* transfer switch, which will *not* play nicely with a "half standby" MWBC
Comment: It would only be a problem for separately derived systems.  These setups are rare in my experience.
Comment: @Harper can't or shouldn't? :) Those are two entirely different things. :) With a separately derived system the neutral is physically broken so it would be impossible whereas with a non separately derived system the neutrals is not broken.  Interesting comment about frequency affecting the phases. I think that would only be a concern for separately  derived systems where the mains power and emergency power are running simultaneously.
Comment: When you're in the planning stages you eliminate the bad outcomes and potential problems which will arise later. Installing a MWBC into any new installation should be the last option in a renovation type scenario where ripping out walls would be required to run new wiring. It's an old concept and is illogical to use now, especially considering the planned use of a generator or split power system. I've never encountered a MWBC that didn't create problems, it's basically a half ass attempt to create a circuit with less materials simply to save running the proper wiring.
Comment: @kris can't.  You can't serve 1 circuit out of 2 different panels.  An MWBC is one circuit. Also not least, MWBCs must be handle-tied, precisely to keep them from having phasing problems. That again forces you into 1 service source.
Comment: @Harper can't is a big word. What is stopping someone from running the red of a MWBC into a non-separately derived emergency panel through a piece of conduit, while keeping the black in the mains panel ? Notta.
Comment: @Kris but how do you handle-tie the breakers?  How do you assure they are placed on opposite poles/phases even after subsequent maintenance of the panel?  Of course it can be done...I mean it can't be done to Code.
Answer: Yes, it's possible.  The 14 gauge wire will handle 1200W (about 10A) but check your fan wiring closely. Most ceiling fans I've seen have separate hot wires for the fan and light but a common neutral. Running the fan from the house wiring and the light from emergency power (e.g. a generator) could energize the house neutral, relative to ground, which is unsafe for electrical workers. You'll probably need a whole house shutoff to keep from back feeding the grid when you're on emergency power.
Comment: The disconnect from the main or whole house shutoff is a requirement for generators weather it is a transfer switch or a mechanical lockout of the main that allows the panel to be fed by a breaker. The listed mechanical lockouts are the least expensive route but not automatic like some transfer switches, some of the breakers usually need to be turned off in this case so the generator is not overloaded.
Answer: Multi-wire branch circuit "MWBC" is technically the term.
They are generally only preferred to cut cost on materials and labor.
They require a double pole ( more than certain a AFCI type in your case ) breaker to de-energize the ungrounded conductors.
What you're trying to do is a lot of work for nothing much when all you need to do is make sure the fan motors are in the off mode when using the back up power.
Comment: A MWBC is only permitted under very strict circumstances and if they are intending to split the loads to be supplied by another source then a MWBC is the last thing you want to deal with due to the shared neutrals. The breakers would be required to be common trip and you couldn't supply only one half of the branch, this is horrible advice.
Comment: No bad advise was given. . Also, cite a code reference to the "strict requirements".


How to install the same host operating system in virtualbox?

Question: I am using ubuntu-13.04 and want to install this same OS in Oracle-virtual box. I don't have the ISO image and don't want do download the big image file.
Is there any way to directly install it on Vbox?
Comment: You can make a _copy_ of the host, by using `dd`: **either** boot a Live CD, then pipe `dd` into `nc` (netcat) which connects to a Live CD-booted virtual machine that pipes `nc` into `dd` to write on the virtual disk; **or** boot a Live CD, create a virtual disk that gives the VM raw disk access (see the VirtualBox User Manual, it's online) to the host partition, then `dd` in the VM from the raw disk to another virtual disk that will store the copy. Both methods will return an exact copy of the host, so you might wish to reconfigure `/etc/fstab`, `/etc/network/interfaces/`, etc.
Comment: ... and, both methods **must** be done when the host OS is not booted (because you can't safely `dd` a mounted partition, which is because part of the data that is to be written to the filesystem is cached in RAM, which means that `dd` might copy an inconsistent f.s.).
Comment: Also if the virtual box hard disk file exists on the same partition as the one you are dd'ing then you're asking for trouble.  1) it won't fit. 2) it's changing as you're writing it!
Answer: No. The ISO carries packages that are unpacked into the target. When you install Ubuntu, you do not get the original packages but only unpacked functional versions. They are not available to Ubiquity and must be downloaded again.
However, if you do have a CD, you can create a new VM and instruct Virtualbox to use the physical CD drive as that of the VM for installation.


What do the tour groups want?

Question: In Oh! Edo Towns, tour groups come and stay at your inns. How do you unlock more tour groups, and what does each group need in order to accomplish their task?
Answer: How do you unlock more tour groups?
The best answer I could find is from this blog and seems to have been copy-pasted all over the web. However, the author admits that these may not be completely accurate.

Elementary School Trip – available from start
Heartbreak Club – available from start
Ogre Vanquishing Tour – available from start
Nation-Wide Tour – unlocked when the Komon Combo is created?
Govt. Inspection Tour – unlocked when total Yield is greater than 50,000? (Maybe between 50,000 – 60,000?)
Ako Clan Samurai – 30,000 Yield and unlock the Samurai House.
Friendship Alliance – unlocked after Edomae Combo is created?
Prince's Secret Tour – ???
Pumpkin Products PR – unlocked from Traveler combo?
Gas Survey Tour – unlocked after obtaining the option to research the Elekiter Shop?
New Home Search Team – Have a total of 3 Zoos (anywhere on the map).
Kairobot's Journey – unlocked after placing all 46 unique combos on the map and reaching 50 years.

What do they need to accomplish their task?
My experience has been that their percentage complete rises over time as the group visits shops and spends money.
I found one guide that claimed "Having crafts and combos through building placements will attract more visitors," but it's not clear how they arrived at that conclusion, so I'd take it with a grain of salt.

What do the tour groups want?


How can i load nested folders for FreeMarker template using spring org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean

Question: Hi I have requirement to create ftl for different entities,
I want to load ftl's from nested folders, Like all A realted ftl's should be insite A folder then all the Macro's live into Macro folder.
<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath" value="classpath:freemarker/Account/"/>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

this is not working.Using spring 4
<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath">
        <value> "classpath:freemarker/Account/" , "classpath:freemarker/Macro/"</value>
    </property>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

Also after debugging the spring class
public void setTemplateLoaderPath(String templateLoaderPath) {
    this.templateLoaderPaths = new String[] {templateLoaderPath};
}

Instead of an array , templateLoaderPath behaves like single string.
Answer: You need to set the templateLoaderPaths property (note the s at the end), not templateLoaderPath.
I believe the Spring syntax for that will be (haven't tested it...):
<property name="templateLoaderPaths"
          values="classpath:freemarker/Account/,classpath:freemarker/Macro/"
/>

or the longer form:
<property name="templateLoaderPaths">
  <array>
    <value>classpath:freemarker/Account/</value>
    <value>classpath:freemarker/Macro/</value>
  </array>
</property>

Comment: (Mark it as an answer then.)


Android EditText Link to Button

Question: Not sure how this should be implemented.  I have an activity with an Edit Text and Button (a text field to specify search parameters, and a button to execute the search).  Right now the user has to enter text in the field and then press the Search button.  How can I make that button the default action, or someone configure the edit text field to click that button when the user presses enter?
Currently with the default behavior, when I select that edit text field, there is no return key shown on the virtual keyboard.
Any ideas?
Answer: Found the documentation item for this shortly after posting the question.
<code> <EditText android:id="@+id/edtInput"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
        android:imeOptions="actionSend|flagNoEnterAction"
        android:maxLines="4"
        android:maxLength="2000"
        android:hint="@string/compose_hint"/>
</code>
See http://developer.android.com/resources/articles/on-screen-inputs.html

Android EditText Link to Button


Is it worth comparing CSP headers with HSTS headers?

Question: I am working on a project to add HSTS header to web application. As a prework for that, I have added CSP header in report mode only with default-src https directive. The intent is to assess the violations and decide if adding HSTS header is going to break any usecase.
Questions:

Is it a worthy approach?
What are the scenarios that we will miss for HSTS with this approach?
What are recommended approaches, if they are different from what the one I have described above?
Answer: I would have thought it was pretty obvious if you are using https only on you server. Do you have https set up? Do you have a redirect set up to force all http requests to be redirected to https? These are questions that should be easy to answer by looking at your server config and I don't think you need CSP to answer them. And if the answer to both is not "Yes", then why are you considering HSTS?
CSP support is not universal (though admittedly neither is HSTS) and, with these things, it's usually the older, less common browsers that will break as you'll presumably test the common ones so whether your approach will give you the confidence you need to proceed is debatable.
The one thing you should be aware of is if you are using includeSubDomains flag. This can cause problems if it affects more servers than you intend it to, but CSP will not help as you will presumably only set up CSP on the servers you think will be affected. More info here: https://serverfault.com/questions/665234/problems-using-hsts-header-at-top-level-domain-with-includesubdomains.
Also be aware that, once HSTS is implemented, certificate errors cannot be bypassed in the browser anymore. Not that you should do this, but just another intentional  effect of this flag that not everyone knows about.
Note that the only way to resolve HSTS issues (e.g. If you discover you need http after all), other than to remove the header and wait for the policy to expire, is to set the max age back to zero and hope people visit your site with https to pick up this new HSTS policy and override the previous one. With Chrome it is possible to manually view and remove the policy, but that's not practical if you have any volume of visitors and also not aware of any way to do this with the other browsers short of a full reinstall.
The best approach is to be fully aware of what HSTS is, and the caveats above, and then start with a low expiry, and build it up slowly as long as you do not experience any issues.
There is also the preload list but I would stay well away from that until you've been running this for at least 6 months with no issues.
Comment: In that case HSTS will not break your site as you are already on https only (taking note of the includeSubDomains issue I mentioned above for any subdomains). However even http links will automatically be redirected so CSP will not report anything - except if you are loading 3rd party content on your site over http which will cause you other errors and which HSTS won't help with (except for the small use case of fully qualified http links back to your own site). HSTS takes care of requests. CSP takes care content loaded on the page. Two different uses cases with little overlap.
Comment: The answer to both of your questions is yes.
Let me try to rephrase my question. Is it good to evaluate HSTS using CSP by applying CSP policies where header looks something like:
Content-Security-Policy-Report-Only: default-src https:; script-src https: 'unsafe-inline' 'unsafe-eval'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri

I will look into the point you have mentioned - related to certificate error.


What should I consider when designing a simple bookcase that will be built without power tools?

Question: I'd like to build a bookcase using pine (or meranti) planks of dimension 22mm/220mm/3m that my local hardware store stocks. They offer the service of cutting to length, but I have no power tools (well, maybe a drill and countersink bit), so will have to have it all cut beforehand.
What should I consider when designing it, in particular:

joint type
stiffening the shelves in the middle
allowing for unusual dimensions such as wide and low
I'd prefer something with interesting look

A design I can look at and alter would be the ideal solution
Comment: Look at some kits that are pre-designed and go together with cam screws and only tool needed is a screwdriver. Ikea?
Comment: Boards + something to act as supports...bricks...cement blocks...chunks of logs...
Comment: I agree with shirlock.  You are unlikely to be able to buy raw materials for less than it costs for a kit.  I only build from scratch one I have exhausted all kit possibilities - and I already have tools and fasteners, etc.
Comment: For insight into wall-mounted vs free-standing shelving, you might want to read [my answer here](http://diy.stackexchange.com/a/21336/7001).  Remember that books are very dense (they hardly float in water) - they are the densest item I ever store in my home.  Accordingly, you might want to work out how much weight you'll actually be storing and make sure your proposed shelving will actually support it.
Answer: The solution when I was in college was to use cinder blocks as the uprights. No tools at all required. This is a long time ago granted, but I believe gravity has not changed much. Cheap and common, cinder blocks are about 8 inches square by 16 long. Two stacked for each end of a shelf makes room for common book sizes. We would call 22 mm 3/4inch here and I would comfortably make a four foot shelf for books without worrying about bracing provided it is solid wood, which it sounds like it is. The advantage of the cinder block approach is ready availability and quick installation. It is not pretty, though, you would have to call it utilitarian, which went well with the wire spool table and orange crate record storage. This is, or was, a common approach to furnishing your first apartment in the States. They do make cinder blocks in 8 inch cubes also if your shelves are narrower.
Comment: In earthquake country, I'd expect a little application of Liquid Nails so it was more or less permanently connected together. Also doesn't survive an enthusiastic German Shepherd crashing into it! That's another story...
Comment: That brings back memories, my parents used the decorative square blocks that are used for wall openings. They have a kind of floral pattern to the center structure and so were a little more decorative than the usual 8"x16" wall blocks.
Comment: Memories? I still possess similar blocks as your parents (but just open, no floral bit) that supported my audio equipment until just 2 years ago! Lasted much longer than you would expect flat pack furniture to last.
Comment: I remember the square blocks, too. They were about 4 inches thick and would have made for unstable shelving here in earthquake country. Hence the use of wider blocks. Pufferfish might be able to use them, though. They would take up less of the shelf.
Comment: @bcworkz - Choose your lumber correctly and they make fairly impervious plant shelves as well. Try doing that with the chipboard or MDF you find in a flat pack!


Why can't I reload?

Question: Sometimes during a game in Overwatch, no matter the hero (except Reinhardt and Mech D.Va) when I have fired a few shots and hit the R button to reload, my hero will not reload.
This usually goes away after a short while (Around 5-10 second or so, but sometimes longer), and occasionally the hero will begin to reload, then stop, and refuse to reload for the duration of this glitch. It doesn't impact my character automatically reloading on an empty clip, but it is very inconvenient when trying to keep my clip topped up between fights.
I do have some performance lag sometimes on my machine, but my connection is fairly stable.  Could my performance lag be the problem, or is this a known bug?
Comment: I play Overwatch on PS4, and I notice that if I start to lag, even slightly, occasionally the game will either not get my signal to reload, or will start but the animation fails, and I have to press reload again. What is your down and up speeds? Are you hardwired or wireless?
Comment: Make sure to enable the "show performances..." in the options menu (can't remember the exact name right now), and monitor your ping.
Comment: Make sure that the key to reload is really R in your Keyboard settings.
Comment: Were you trying to melee someone? I often find that I fail to reload in close combat while trying to use a the melee attack, it can interrupt reloading.
Comment: Does it look like your character starts the reload, then decides against it? I experience that a fair amount (start reloading the Peacemaker, then McCree being all "Nah bruh, I only need 1 bullet"). I also see this with what look like double taps when I shoot (I click once, I see two distinct weapon trails going out, one affected by recoil. Only 1 ammo is consumed and it appears as though the second/recoiled shot is the one that actually has a projectile. The trail that went where I was aiming is a ghost).
Comment: @Karlyr Yes, reloading with R usually does work, and most of the time I will, when doing nothing else, reload a partially-used gun to make sure it's topped up.
Comment: @D.Va No, at the given time of reloading, I was only walking around, and my ability to reload was halted for several seconds, far beyond the time it would take for a melee to end.
Comment: @KizTrap Yes, it is occasionally like that, though it lasts a bit longer than just the initial attempt to reload.
Comment: @Zibbobz Yeah, sounds exactly like my problem. It sounds like it's lag attributed, where your client assumes the reload command will be sent and starts the animation, then gets the "failed to send command" style response from the game's attempt to send and stops it.
Answer: This is definitely due to packet loss.
Overwatch handles everything server-side, and has to make sure that happens on its server is consistent with what happens on everyone's client. The server keeps track of every player's health, ammo, shots fired, ult charge, and so on, for various reasons, such as preventing cheating. When you want to reload, your client announces that to the server, which updates its ammo count for you; meanwhile, the client is playing the reload animation and only actually reloads when it receives confirmation from the server.
Now I'm not exactly sure what kind of information loss prevention mechanisms Overwatch uses, but if enough messages are lost, any action such as firing your weapon, activating an ability, or indeed reloading can be lost, and for some reason it seems to happen most often with reloading.
Comment: Sometimes, the server even thinks you're moving very quickly to the left. *Very.* *Quickly.*
Comment: @Zibbobz No, it shouldn't work like that. Just spam your reload key/button.
Comment: So it's possible that if I just fire one additional time, the Server Client will pick up the fact that I've fired my weapon, and allow me to reload?

Why can't I reload?


How to build the "sed" command, in Linux Bash (Ubuntu)

Question: I'm struggling to create a command line to replace "00-59/1 * * * *" with "11-11/1 * * * *". Actually, both value will be passed through variables, once those values change according to the user behavior.
var1="00-59/1 * * * *"
var2="11-11/1 * * * *"
As you can see, those values belong to crontab. This is a script to change the schedule value on crontab.
I do know that the big issue here is because there is "/" caracter inside, but I couldn't figure out how to make it works.
Any idea?
Thanks in advance!
Comment: Welcome to stack overflow, please add expected output to post with code tags.
Answer: Here is a example input.
$ cat input
00-59/1 * * * * TASK1
* * * * * TASK2
00 1 * * * TASK3
1 1 1 1 1 TASK4

# Escaping `#` and `\` before substitute.
# For BSD Sed
$ var1="$(echo "00-59/1 * * * *" | sed -E 's/([/*])/\\\1/g')"
$ var2="$(echo "11-11/1 * * * *" | sed -E 's/([/*])/\\\1/g')"

# For GNU Sed
$ var1="$(echo "00-59/1 * * * *" | sed -r 's/([/*])/\\\1/g')"
$ var2="$(echo "11-11/1 * * * *" | sed -r 's/([/*])/\\\1/g')"

# Don't forget to use double quotes. :)
$ cat input | sed "s/${var1}/${var2}/"
11-11/1 * * * * TASK1
* * * * * TASK2
00 1 * * * TASK3
1 1 1 1 1 TASK4


How do create an http redirect an http request coming in on port 80 to https on port 443?

Question: I'd like to create a status 301 redirect from a url like http://whatever.com/whatever?whatever to https://whatever.com/whatever?whatever . I'm using node.js but I doubt the answer is node-specific.
I know you can write the "Location" header with a url like this:
response.writeHead(301, {
   'Location': request.url
});
response.end();

But how do I specify that i want the redirect to go to https?
Answer: It is common to use a 301 permanent redirect for this purpose. To change protocols, you need to include the protocol and host in the Location header:
var server = http.createServer(function(request, response){
    var newUrl = 'https://' + request.headers.host + request.url;
    response.writeHead(301, {
       'Location': newUrl
    });
    response.end();
});

The standard Node HTTP package doesn't automatically parse the hostname and port, so if you need compatibility with nonstandard ports you should use a package like Express to easily grab req.hostname.
Comment: Thats it! Just needed a way to get the host. I found it somewhere else, so its pretty trippy to see that you wrote essentially verbatim what i already have in my code. But correct answer so you get the check, thanks!


How to disable IPv6 ping echo reply in Ubuntu 18.04

Question: I want to disable IPv4/6 ping echo reply on my Ubuntu 18.04.
For IPv4 I can do it with net.ipv4.icmp_echo_ignore_all=1 in /etc/sysctl.conf.
What is the IPv6 equivalent?
Here is my ip6tables -nvL:
root@localhost:~# sudo ip6tables -nvL
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
 1990  130K ufw6-before-logging-input  all      *      *       ::/0                 ::/0
 1990  130K ufw6-before-input  all      *      *       ::/0                 ::/0
    0     0 ufw6-after-input  all      *      *       ::/0                 ::/0
    0     0 ufw6-after-logging-input  all      *      *       ::/0                 ::/0
    0     0 ufw6-reject-input  all      *      *       ::/0                 ::/0
    0     0 ufw6-track-input  all      *      *       ::/0                 ::/0
    0     0 DROP       icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 128

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ufw6-before-logging-forward  all      *      *       ::/0                 ::/0
    0     0 ufw6-before-forward  all      *      *       ::/0                 ::/0
    0     0 ufw6-after-forward  all      *      *       ::/0                 ::/0
    0     0 ufw6-after-logging-forward  all      *      *       ::/0                 ::/0
    0     0 ufw6-reject-forward  all      *      *       ::/0                 ::/0
    0     0 ufw6-track-forward  all      *      *       ::/0                 ::/0

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
  283 21372 ufw6-before-logging-output  all      *      *       ::/0                 ::/0
  283 21372 ufw6-before-output  all      *      *       ::/0                 ::/0
   39  3884 ufw6-after-output  all      *      *       ::/0                 ::/0
   39  3884 ufw6-after-logging-output  all      *      *       ::/0                 ::/0
   39  3884 ufw6-reject-output  all      *      *       ::/0                 ::/0
   39  3884 ufw6-track-output  all      *      *       ::/0                 ::/0

Chain ufw6-after-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-after-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ufw6-skip-to-policy-input  udp      *      *       ::/0                 ::/0                 udp dpt:137
    0     0 ufw6-skip-to-policy-input  udp      *      *       ::/0                 ::/0                 udp dpt:138
    0     0 ufw6-skip-to-policy-input  tcp      *      *       ::/0                 ::/0                 tcp dpt:139
    0     0 ufw6-skip-to-policy-input  tcp      *      *       ::/0                 ::/0                 tcp dpt:445
    0     0 ufw6-skip-to-policy-input  udp      *      *       ::/0                 ::/0                 udp dpt:546
    0     0 ufw6-skip-to-policy-input  udp      *      *       ::/0                 ::/0                 udp dpt:547

Chain ufw6-after-logging-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-after-logging-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all      *      *       ::/0                 ::/0                 limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw6-after-logging-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-after-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-before-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all      *      *       ::/0                 ::/0                 rt type:0
    0     0 ACCEPT     all      *      *       ::/0                 ::/0                 ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 1
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 2
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 3
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 4
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 128
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 129
    0     0 ufw6-user-forward  all      *      *       ::/0                 ::/0

Chain ufw6-before-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all      lo     *       ::/0                 ::/0
    0     0 DROP       all      *      *       ::/0                 ::/0                 rt type:0
   14  1152 ACCEPT     all      *      *       ::/0                 ::/0                 ctstate RELATED,ESTABLISHED
    0     0 ufw6-logging-deny  all      *      *       ::/0                 ::/0                 ctstate INVALID
    0     0 DROP       all      *      *       ::/0                 ::/0                 ctstate INVALID
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 1
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 2
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 3
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 4
    4   320 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 128
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 129
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 133 HL match HL == 255
   89  5696 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 134 HL match HL == 255
    6   432 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 135 HL match HL == 255
   11   704 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 136 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 141 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 142 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 130
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 131
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 132
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 143
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 148 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 149 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 151 HL match HL == 1
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 152 HL match HL == 1
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 153 HL match HL == 1
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 144
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 145
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 146
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 147
    0     0 ACCEPT     udp      *      *       fe80::/10            fe80::/10            udp spt:547 dpt:546
    0     0 ACCEPT     udp      *      *       ::/0                 ff02::fb             udp dpt:5353
    0     0 ACCEPT     udp      *      *       ::/0                 ff02::f              udp dpt:1900
    0     0 ufw6-user-input  all      *      *       ::/0                 ::/0

Chain ufw6-before-logging-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-before-logging-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-before-logging-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-before-output (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all      *      lo      ::/0                 ::/0
    0     0 DROP       all      *      *       ::/0                 ::/0                 rt type:0
   16  1280 ACCEPT     all      *      *       ::/0                 ::/0                 ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 1
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 2
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 3
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 4
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 128
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 129
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 133 HL match HL == 255
    6   384 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 136 HL match HL == 255
   11   792 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 135 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 134 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 141 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 142 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 130
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 131
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 132
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 143
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 148 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       ::/0                 ::/0                 ipv6-icmptype 149 HL match HL == 255
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 151 HL match HL == 1
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 152 HL match HL == 1
    0     0 ACCEPT     icmpv6    *      *       fe80::/10            ::/0                 ipv6-icmptype 153 HL match HL == 1
    2   192 ufw6-user-output  all      *      *       ::/0                 ::/0

Chain ufw6-logging-allow (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all      *      *       ::/0                 ::/0                 limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW ALLOW] "

Chain ufw6-logging-deny (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all      *      *       ::/0                 ::/0                 ctstate INVALID limit: avg 3/min burst 10
    0     0 LOG        all      *      *       ::/0                 ::/0                 limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw6-reject-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-reject-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-reject-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-skip-to-policy-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all      *      *       ::/0                 ::/0

Chain ufw6-skip-to-policy-input (6 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all      *      *       ::/0                 ::/0

Chain ufw6-skip-to-policy-output (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all      *      *       ::/0                 ::/0

Chain ufw6-track-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp      *      *       ::/0                 ::/0                 ctstate NEW
    0     0 ACCEPT     udp      *      *       ::/0                 ::/0                 ctstate NEW

Chain ufw6-track-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-track-output (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp      *      *       ::/0                 ::/0                 ctstate NEW
    2   192 ACCEPT     udp      *      *       ::/0                 ::/0                 ctstate NEW

Chain ufw6-user-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-user-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
.....
.....
.....

Chain ufw6-user-limit (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all      *      *       ::/0                 ::/0                 limit: avg 3/min burst 5 LOG flags 0 level 4 prefix "[UFW LIMIT BLOCK] "
    0     0 REJECT     all      *      *       ::/0                 ::/0                 reject-with icmp6-port-unreachable

Chain ufw6-user-limit-accept (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all      *      *       ::/0                 ::/0

Chain ufw6-user-logging-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-user-logging-input (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-user-logging-output (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw6-user-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Comment: Don't do that. ICMPv6 echo requests are useful for debugging. They are also absolutely required for your service to be reachable for Teredo clients. Filtering those packets won't solve any problems but it will make problems harder to debug and introduce problems on its own. And if you make any mistake in the filter configuration you may end up filtering ICMPv6 packets which are even more important than echo requests.
Answer: Because you use ufw, you have to edit file /etc/ufw/before6.rules and add a line:
-A ufw6-before-input -p icmpv6 --icmpv6-type echo-request -j DROP

Then sudo service ufw restart
For "clean ip6tables" solution:
sudo ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-request -j DROP

It will ignore every echo request packet. But be aware, that VPS provider may use echo-request/echo-reply to determine if your server is running.
Comment: this is not working. i can ping6 my vps anyway. and even it would ... how can i make this permanent? i'm using ufw ... should i write this in the /etc/ufw/before.rules?
Comment: Show us the current ip6tables configuration `sudo ip6tables -nvL`. For making it permament just install iptables-persistent package.
Comment: i edited the question above to add the output
Comment: ahh now it is working. i found the entrys in the /etc/ufw/before6.rules and changed the --icmpv6-type echo-request and echo-reply to DROP in the INPUT section. thank you


Screen turns black when plugging in a second monitor

Question: I'm running 11.04 on a 2011 13" mackbook pro (intel hd 3000 gpu).
Previously everything had been fine, but today when I plug in an external monitor (17" Acer being plugged in via a mini display port to VGA adapter) the laptop immediately recognizes the monitor, but the screen turns black. It seems that everything is still responsive. I can see the cursor and I can see it change as it moves over things like text boxes or the edges of open windows. But even after unplugging the monitor, I can't get anything but a black screen until I restart gdm.
Yesterday I was using the laptop with a 22" Asus monitor using a mini display port to DVI adapter and everything was fine. This same monitor was also working fine last week when I was running OS X, and on an older HP laptop without an adapter (straight to VGA).
How can I fix this?
Comment: Found any solution? Happening to me too in an Asus u35jc-a1, external monitor Samsung T220. At first I thought it was related to Unity, but it's happening in Gnome 2 as well.
Answer: Just found the official bug page, with possible workarounds such as installing other kernel versions: https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/745112
For the time being, it seems we have to wait or play with other kernels...
EDIT: I've just installed and tried kernel linux-headers-2.6.39-020639rc4 and works like a charm - at least in this regard. I hope it's as stable as the previous one as well!
Comment: BTW, everything is working fine now on a 3.0 kernel. I also had it working on a 2.39 kernel.
Comment: where did you get that kernel??
Comment: ok, i found that kernel. I tried it and it works ... better .... it doesn't cause my main screen to go blank. But on the external monitor, it's completely black except for the unity panel thing (not sure what to call it) at the top and the cursor. (this kernel: http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.39-rc4-natty/)
Comment: the kernel here: http://kernel.ubuntu.com/~kernel-ppa/mainline/drm-intel-next-proposed/ exhibits the same behavior as the one I previously mentioned.
Answer: Installing a new 2.6.39 kernel solved a problem in my case. Here are step by step instructions for less experienced users: http://blog.lome.pl/blog/ubuntu-11-4-black-screen-problem-solved/
Comment: as mentioned in the comments on Seb's answer, no dice. The laptop monitor works fine with the newer kernels, but the external one is still a black screen.
Comment: Did you try the one from here: https://launchpad.net/~kernel-ppa/+archive/ppa/+packages ? It's 2.6.39-rc5 not 2.6.39-rc4 so maybe it will work better... and it actually did work for me.
Answer: I am running Ubuntu 11.04 with both a Nvidia and an integrated Intel AGP in my laptop.
I am using an external monitor connected through a mini DisplayPort wired to the Intel card. It has been working since I installed Ubuntu 11.04 a month a go, today the external monitor stopped responding:

The external monitor reports no sync
System > Preferences > Monitors reports the external monitor as attached and operational.
Print Screen includes the image of the external monitor
The laptop primary monitor works as expected.

After double checking the cables, connections and the external monitor I booted back in the previous Kernel (I suppose yesterday I got an kernel update) and the external monitor came back to life. I did the test forth an back a couple times and the behavior was consistent.
The offending Kernel is 2.6.38-11-generic.
Last known good Kernel is 2.6.38-10-generic.
So far I am sticking to the previous Kernel while using an external monitor.
Following are my graphics device info:
anibal@collar-de-bolas:~ $ lspci | grep -i VGA
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)

anibal@collar-de-bolas:~ $ sudo lshw -C video
[sudo] password for anibal:
  *-display
       description: VGA compatible controller
       product: nVidia Corporation
       vendor: nVidia Corporation
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nouveau latency=0
       resources: irq:16 memory:f0000000-f0ffffff memory:c0000000-cfffffff memory:d0000000-d1ffffff ioport:3000(size=128) memory:f1000000-f107ffff
  *-display
       description: VGA compatible controller
       product: 2nd Generation Core Processor Family Integrated Graphics Controller
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 09
       width: 64 bits
       clock: 33MHz
       capabilities: msi pm vga_controller bus_master cap_list rom
       configuration: driver=i915 latency=0
       resources: irq:54 memory:f1400000-f17fffff memory:e0000000-efffffff ioport:4000(size=64)

Comment: Just filled a Kernel bug for this: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/838181 please go an check it if it aplies to you.
Answer: As a workaround to be able to continue work, look here
Transcript:
You need to go to a tty shell (with no ui) by using, for example, ctrl+alt+F2.
In the tty shell, you need to login and find any compiz process, using the command
ps -ef | grep compix

Then, kill all the compiz processes:
kill -9 <processes ids separated using space>

Then run unity to initialize the UI:
unity&

Give it a moment to load and go back to the 'UI shell', using ctrl+alt+F8, to see the UI being initialized.
Answer: I had this problem with a DVI monitor plugged into a dock, using Ubuntu 11.10. I solved it by deleting the file ~/.config/monitors.xml


Finding two points from an univariate function

Question: I'm quite puzzled by the following problem.
Problem
Let
$f\left(a,b\right)=\int _a^b\:\left(2-x-x^2\right)dx$
Find $a$ and $b$ such that $a\le b$ and $f(a,b)$ is local maximum.
My doubts came by the form of
$\int _a^b\:\left(2-x-x^2\right)dx$
it's a single variable integral, and $f(a,b)$ it's for a multivariate.
and for that reason I'm extremely sure that the first dumbest thing that came through my brain was looking
$\int _a^b\:f\left(x\right)dx,\:a\le b$
and maximizing $f(x)$ but I'm entirely sure that that's the wrong step to take, so I'm puzzled for the notation and want the problem asks.
If someone could explain to me the nature of the problem it would be fantastic.
Comment: Well, to begin with, the function $f$ is not defined.
Comment: Is $f : (a,b) \in \mathbb{R}^2 \mapsto \int_a^b (2-x-x^2) \, \mathrm{d}x$?
Comment: Do you have the following result available to you?  Let $D = \dfrac{\partial^2 f}{\partial a^2}\dfrac{\partial^2 f}{\partial b^2} - \left[\dfrac{\partial^2 f}{\partial a\text{ }\partial b}\right]^2$. Then if $D(c, d) > 0$ and $\dfrac{\partial^2 f}{\partial a^2}(c, d) < 0$, there is a relative maximum at $(c, d)$.
Comment: The second partial derivative test, right? yes it did not came through my mind. Thanks
Answer: hint
Let $ c\in(a,b)$.
$$
f(a,b) =\int_a^b(2-x-x^2) dx$$
$$=\int_a^cg(x)dx+\int_c^bg(x)dx$$
$$\frac{\partial f}{\partial a}=-g(a)=a^2+a-2$$
Comment: Si si, il peut calculer les dérivées partielles sans avoir calculé l'integrale comme dans la reponse ci-dessus.
Comment: Ok now I agree with you.
Answer: $f\left(a,b\right)=\int _a^b\:\left(2-x-x^2\right)dx$
$f\left(a,b\right)=\big [2x-\frac{x^2}2-\frac{x^3}3 \big ]^b_a$
$f\left(a,b\right)=\frac {12b-12a-3b^2+3a^2-2b^3+2a^3}{6}$
$\frac {\partial f}{\partial a}=\frac{-12+6a+6a^2}{6}$
Maximum  means $\frac {\partial f}{\partial a}=0 \Rightarrow -12+6a+6a^2=0$
$(a-1)(a+2)=0 \Rightarrow a=-2$ or $a=1$
Similarly get $b=-2$ or $b=1$
Since $a<b$ must be $a=-2, b=1$
etc...
Comment: (+1) Although, there are some things I disagree with: maximum does not _mean_ $\frac {\partial f}{\partial a}=0$. You made a mistake, $a^2+a-2 = (a-1)(a-2)$.
Answer: Define
$$ f(x,y)=\int_y^x(2-t-t^2)\,dt=G(x)-G(y) $$
Then $f_x(x,y)=G^\prime(x)=2-x-x^2=-(x+2)(x-1)=0$ and
$f_y(x,y)=-G^\prime(y)=-2+y+y^2=(y+2)(y-1)=0$ and
$f_{xx}=-1-2x,\,f_{yy}=1+2y,\,f_{xx}=f_{yy}=0$ so $D(x,y)=-(1+2x)(1+2y)$
Since $D(1,1)=D(-2,-2)=-9<0$ $f$ has saddle points there.
But $D(-2,1)=9$ and $f_{x,x}(-2,1)=3>0$, $f$ has a local minimum there.
And, since $D(1,-2)=9$ and $f_{xx}(1,-2)=-3<0$, then $f$ has a local maximum there.
Thus, $f(1,-2)=\int_{-2}^1(2-t-t^2)\,dx=4.5$ is the value at the local maximum.