Collection class that maintains sorted order based on particular property? I'm looking for a collection class that will automatically insert elements in sorted order based on a property (namely "Priority"), so that when I iterate over it later, I'll get back the elements in this order.     seems to sort by keys, which is not what I want.
Is there a sorted collection type in .NET? I'm looking for a container that keeps all its items in order.  I looked at SortedList, but that requires a separate key, and does not allow duplicate keys.  I could also just use an unsorted container and explicitly sort it after each insert.  Usage:   Occasional insert Frequent traversal in order Ideally not working with keys separate from the actual object, using a compare function to sort. Stable sorting for equivalent objects is desired, but not required.  Random access is not required.   I realize I can just build myself a balanced tree structure, I was just wondering if the framework already contains such a beast.
Removing control chars (including console codes / colours) from script output I can use the "script" command to record an interactive session at the command line.  However, this includes all control characters and colour codes.  I can remove control characters (like backspace) with "col -b", but I can't find a simple way to remove the colour codes.  Note that I want to use the command line in the normal way, so don't want to disable colours there - I just want to remove them from the script output.  Also, I know can play around and try find a regexp to fix things up, but I am hoping there is a simpler (and more reliable - what if there's a code I don't know about when I develop the regexp?) solution.  To show the problem:   spl62 tmp: script Script started, file is typescript spl62 lepl: ls add-licence.sed  build-example.sh  commit-test         push-docs.sh add-licence.sh   build.sh          delete-licence.sed  setup.py asn              build-test.sh     delete-licence.sh   src build-doc.sh     clean             doc-src             test.ini spl62 lepl: exit Script done, file is typescript spl62 tmp: cat -v typescript Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls^M ^[[0m^[[00madd-licence.sed^[[0m  ^[[00;32mbuild-example.sh^[[0m  ^[[00mcommit-test^[[0m         ^[[00;32mpush-docs.sh^[[0m^M ^[[00;32madd-licence.sh^[[0m   ^[[00;32mbuild.sh^[[0m          ^[[00mdelete-licence.sed^[[0m  ^[[00msetup.py^[[0m^M ^[[01;34masn^[[0m              ^[[00;32mbuild-test.sh^[[0m     ^[[00;32mdelete-licence.sh^[[0m   ^[[01;34msrc^[[0m^M ^[[00;32mbuild-doc.sh^[[0m     ^[[00;32mclean^[[0m             ^[[01;34mdoc-src^[[0m             ^[[00mtest.ini^[[0m^M spl62 lepl: exit^M  Script done on Thu 09 Jun 2011 09:47:29 AM CLT spl62 tmp: col -b &lt; typescript  Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls 0m00madd-licence.sed0m  00;32mbuild-example.sh0m  00mcommit-test0m         00;32mpush-docs.sh0m 00;32madd-licence.sh0m   00;32mbuild.sh0m          00mdelete-licence.sed0m  00msetup.py0m 01;34masn0m              00;32mbuild-test.sh0m     00;32mdelete-licence.sh0m   01;34msrc0m 00;32mbuild-doc.sh0m     00;32mclean0m             01;34mdoc-src0m             00mtest.ini0m spl62 lepl: exit  Script done on Thu 09 Jun 2011 09:47:29 AM CLT This is how I'm approaching it: let $R$ be a finite integral domain and I'm trying to show every element in $R$ has an inverse:   let $R-\{0\}=\{x_1,x_2,\ldots,x_k\}$,  then as $R$ is closed under multiplication $\prod_{n=1}^k\ x_i=x_j$,  therefore by canceling $x_j$ we get $x_1x_2\cdots x_{j-1}x_{j+1}\cdots x_k=1 $,  by commuting any of these elements to the front we find an inverse for first term, e.g. for $x_m$ we have $x_m(x_1\cdots x_{m-1}x_{m+1}\cdots x_{j-1}x_{j+1}\cdots x_k)=1$, where $(x_m)^{-1}=x_1\cdots x_{m-1}x_{m+1}\cdots x_{j-1}x_{j+1}\cdots x_k$.   As far as I can see this is correct, so we have found inverses for all $x_i\in R$ apart from $x_j$ if I am right so far. How would we find $(x_{j})^{-1}$? How to avoid the 'not properly formatted as code' alert In .NET why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision. Python: [Errno 2] No such file or directory: 'lines.txt' What is the meaning of p values and t values in statistical tests? Ubuntu 16.04 LTS Virtualbox 5.0.40 ubuntu r 115130  Today after upgrading to kernel 4.13.0-26 guest vbox machines started to crash whole ubuntu. just hard poweroff is working.  If I startup with kernel 4.10.0-42 everything works fine.  what may be the problem ? Accessing inherited variable from templated parent class Consider the following code:  template&lt;class T&gt; class Foo { public:   Foo() { a = 1; }  protected:   int a; };  template&lt;class T&gt; class Bar : public Foo&lt;T&gt; { public:   Bar() { b = 4; };    int Perna(int u);  protected:   int b;  };  template&lt;class T&gt; int Bar&lt;T&gt;::Perna(int u)  {    int c = Foo&lt;T&gt;::a * 4; // This works   return (a + b) * u;    // This doesn't }   g++ 3.4.6, 4.3.2 and 4.1.2 give error   test.cpp: In member function `int Bar&lt;T&gt;::Perna(int)': test.cpp:25: error: `a' was not declared in this scope   g++ 2.96 and MSVC 6, 7, 7.1, 8 and 9 accept it, as do (at least) older Intel and SGI c++ compilers.   Do the new Gnu C++ compiler obey the standard or not? If they do, what is the rationale behind that inheriting class is not able to see a protected inherited member variable?  Also, if there's  int A() { return a; }    in Foo, I get error  test.cpp:25: error: there are no arguments to A that depend on a template parameter, so a declaration of A must be available test.cpp:25: error: (if you use -fpermissiveâ, G++ will accept your code, but allowing the use of an undeclared name is deprecated)   when I try to use it in a member function of Bar. I find that curious as well: Bar inherits Foo, so I think it's obvious that A() in scope of Bar is Foo::A(). Suppose $G=\{a_1,...,a_n\}$ is a finite abelian group, and let $x=a_1a_2\dotsm a_n$.   Prove that if there is more than one element of order $2$ then $x=e$.   What I've done so far: (#1 is just for illustration, There should be at least $3$ such elements)   $G$ has an even number of elements with order $&gt;2$ (They are paired so: $(a,a^{-1})$ ). And then there are $e$ and $\{b|o(b)=2\}$. Also, if $G$ has at least one element of order 2 then $|G|$ is even (Lagrange). Thus $|\{b|o(b)=2\}|$ must be odd. If there is exactly one element $b$ of order $2$ then $x=b$. That's because $G$ is abelian, and we can write: $x=e\cdot b\cdot(a_1 a_{1}^{-1}\dotsm a_n a_{n}^{-1})=b\cdot(e\dotsm e)=b$. If there are exactly $3$ such elements $a,b,c\in G$, then, as shown above, $x=abc$ and thus $x=e$ (That's because $(abc)^2=a^2b^2c^2=e$ which means $abc\in \{a,b,c,e\}$. If $abc=a$ then $b=c^{-1}=c$ which is false, same goes for $abc=b,abc=c$.)   I haven't managed to find a reason why the claim must hold for $5, 7, ...$ (i.e. All other odd integers). Does anyone have an idea?  Thanks in advance. Please excuse my English.  edit: Not a canonical answer but a simple one (if such even exists). These days, the standard way to present differential calculus is by introducing the Cauchy-Weierstrass definition of the limit. One then defines the derivative as a limit, proves results like the Leibniz and chain rules, and uses this machinery to differentiate some simple functions such as polynomials. The purpose of my question is to see what creative alternatives people can describe to this approach. The nature of the question is that there is not going to be a single best answer. I have several methods that I've collected which I'll put in as answers to my own question.  It's not reasonable to expect answers to include an entire introductory textbook treatment of differentiation, nor would anyone want to read answers that were that lengthy. A sketch is fine. Lack of rigor is fine. Well known notation and terminology can be assumed. It would be nice to develop things to the point where one can differentiate a polynomial, since that would help to illustrate how your method works and demonstrate that it's usable. For this purpose, it suffices to prove that if $n&gt;0$ is an integer, the derivative of $x^n$ equals $0$ at $0$ and equals $n$ at $1$; the result at other nonzero values of $x$ follows by scaling. Doing this for $n=2$ is fine if the generalization to $n&gt;2$ is obvious. Why is "union" an exception to the "a/an" rule? CASE WHEN with GROUP BY I have a table that looks like this (oversimplified case of the actual case to make my point)  CREATE TABLE sales (    id int,    currency VARCHAR(5),    price int    shop_id int );   Now I need to make a query that will give me something like this table, grouping by shops yet giving sum of sales per currency My problem is when I make currency column non aggregate it fails because my query becomes non standard. When I add currency to group by then each currency creates new row, something I don't want. I have run out of option and would appreciate any help or pointer to the right direction.  I use MySQL but would appreciate if I would get the solution that works with more databases (PostGreSQL being at the top of the list after MySQL)  Query that works with undesired results  SELECT   shop_id,           (CASE WHEN currency= "GBP" THEN SUM(price) ELSE 0 END) AS POUND,           (CASE WHEN currency= "USD" THEN SUM(price) ELSE 0 END) AS USDOLLAR GROUP BY shop_id, currency   The data that should be produced by the query  shop_id     |   POUND   |   USDOLLAR     -----------------------------------------     1       |   400     |   300 -----------------------------------------     2       |   250     |   100 -----------------------------------------     3       |   400     |   100 ----------------------------------------- Airbnb housing gone electrifyingly bad I am staying at a place booked via Airbnb. Something happened and there is no electricity from Friday! The house-owner has provided a super noisy generator, which is inconsistent, meaning that it "randomly" supplies power to some parts of the house, so you cannot rely on it.  Is there any rule/law in SF, CA, USA to describe the compensation one should get from such kind a situation?    The owner owns the whole building. On the ground floor there is a restaurant. On the 1st floor there are the apartments. Something happened in the restaurant, which made the electricity go off, but she didn't give more details, she said "there was an emergency and the power went off". Take the following class as an example:  class Sometype {     int someValue;      public Sometype(int someValue)     {         this.someValue = someValue;     } }   I then want to create an instance of this type using reflection:  Type t = typeof(Sometype); object o = Activator.CreateInstance(t);   Normally this will work, however because SomeType has not defined a parameterless constructor, the call to Activator.CreateInstance will throw an exception of type MissingMethodException with the message "No parameterless constructor defined for this object." Is there an alternative way to still create an instance of this type? It'd be kinda sucky to add parameterless constructors to all my classes. Why shouldn't I care what model/make/year my bicycle is? Switching between one and two monitors When running my MBP, I attach an external monitor, a keyboard and trackpad to it so I have two separate desktops which are contiguous; like it's a "fancy" desktop.   Back in the day on Mavericks, it behaved properly: when I unplugged the external monitor to, say, take the laptop into a meeting, it would just put all of the desktops separately on the built in display, roughly preserving which window stayed on which desktop so all you'd have to use was a run a restore tool like Display Maid to restore your window positions when you plug your external monitor back in. This was handy because you didn't have to manually clean up your desktop when done.   Now, with El Cap, it would seem that when you unplug the external monitor, it used the monitor count of whichever screen had the most desktops and merges the windows from the two "combined desktops" into one desktop in a way that seemed to be random, which is clumsy.   Worse, setting back Display Maid to restore the original configuration automatic doesn't work like it used to - previously it saved positions on all desktops in one action, but now it does it one screen at a time and forcing you restore eech desktop separately, which is tedious. It would seem that Display Maid is not great software anymore.  Is there some other utility out there that must work better so you can restore how your windows and desktop setup was as it was before you unplugged the external monitor. Any ideas? Is there is any way to prove the Faraday's law of induction? I want to know if there is any way to prove the Faraday's law or is it just an experimental observed phenomena?  More specifically, is there any reason why the proportionality constant is 1? How did Faraday discover it? I also heard that we can prove Faraday's law using the principle of least action, but is that true? How to pass parameters to function in a bash script? I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable but that wouldn't make my code much more readable as far as I can see.  Intended usage example:  #!/bin/bash #myscript.sh var1=$1 var2=$2 var3=$3 var4=$4  add(){ result=$para1 + $para2 }  add $var1 $var2 add $var3 $var4 # end of the script  ./myscript.sh 1 2 3 4   I tried using $1 and such in the function, but then it just takes the global one the whole script was called from. Basically what I'm looking for is something like $1, $2 and so on but in the local context of a function. Like you know, functions work in any proper language. I live in a town where fresh or whole milk is not readily available. I was wondering if I could make cheese from UHT Milk. If so, what kind of cheese and what method I should use? Or rather, Should I? How can I create that glitter tears effect and the sparkles?