Ubuntu 13.04 does not recognize wireless adapter (14e4:4365)

Question: I replaced Windows 8 on my laptop with Ubuntu and neglected to check if my wifi adapter (14e4:4365) would work. I've tried a few solutions to make it work, but I can't seem to make it happen. I don't have access to internet on the computer-I'm at a hotel on a business trip-but I can transfer files from a laptop with internet to the one with the issue.
Result running lspci -nn | grep 0280:
07:00.0 Network controller [0280]: Broadcom Corporation Device [14e4:4365] (rev 01)

Comment: RTL8111/8168B is your wired ethernet adapter, not wireless. Please edit your question to add the result of this command from the terminal: lspci -nn | grep 0280
Comment: possible duplicate of [Installing Broadcom Wireless Drivers](http://askubuntu.com/questions/55868/installing-broadcom-wireless-drivers)
Answer: With a temporary wired ethernet connection, please open a terminal and do:
sudo apt-get install bcmwl-kernel-source

Detach the ethernet. After a reboot, your wireless should be working.
Comment: Or use USB tethering.
Comment: I was getting unable to locate package bcmwl-kernel-source. I had to do sudo apt update first.


How did I get +12 reputation for my up voted Answer?

Question: I know reputation score goes up to +10 when others vote up our questions. But today I notice, I get +12 for my answer.
How did I get +12 reputation instead of +10. Any Idea?
Answer: It's actually two events:

A up-vote
A un-down-vote

The latter means a user took off their down-vote, and you gained back the 2 points you lost when you got down-voted.


Rails .map produces unwanted ["\n"]

Question: I got the following lines in my view:

<%= @runnings_past.map do |f| %>
      <%= f.title %>
  <% end %>

which works just fine in the console --> output:
2.1.2 :076 > @runnings_past.map do |f|
2.1.2 :077 >     f.title
2.1.2 :078?>   end
 => ["Murtenlauf"]
2.1.2 :079 >

But when I use it in the view as seen above, I get an expression like this:
Murtenlauf ["\n"]

Where does the ["\n"] come from?
Comment: not quite understood, that is this `Murtenlauf ["\n"] `?
Answer: <%= @runnings_past.map do |f| %>
   <%= f.title %>
<% end %>

Should actually be
<% @runnings_past.each do |f| %>
   <%= f.title %>
<% end %>

Notice the lack of = (in addition, I changed map to each because you're just iterating through the array)
<%= means evaluate the code and insert the result into the html structure.  So what you were doing was evaluating the .map and putting the result into your html.  So you would iterate through the @runnings_past code, place the f.first into the html (which is what you want) but then when you were done with that, you were placing the result of the mapping (which apparently was an array with a string return character) into the html afterwards.
Comment: I need to use map since otherwise i'm just printing the activerecord:relation but the lack of the '=' did the trick! thanks a lot!!
Comment: You actually don't need the `map` and there will be a performance hit by using it.  [`.map`](http://www.ruby-doc.org/core-2.1.5/Array.html#method-i-map) will iterate through the array and whatever the returns from the block will be placed in the current index of that array.  `each` however simply iterates over the array.  Unless there is something else you are doing @runnings_past afterwards where you want it to be an array of return characters, you should really be using `each`
Answer: You are using the wrong iterator. You want to use each instead of map. Map creates a new array where each element is the result of each iteration in the block. While each simply calls the given block once for each element in the array.
In addition, as pointed out by @JTG, you want to remove the =. You only need = for showing output. You don't need it for logic.

Rails .map produces unwanted ["\n"]


How to verify if I am subscribed or not and execute an action? in Selenium c#

Question: I need to execute an action if I am subscribed to a YouTube channel or another if I am not
I know that the path of the button without being subscribed is this
driver.FindElement(By.XPath("//*[@id=\"subscribe-button\"]/ytd-subscribe-button-renderer/paper-button/yt-formatted-string")).Click();

I have written this pseudocode so that they understand better
If button subscribe is enabled
click on subscribe
else (If I am subscribed)
continue with the code normally

Before Subscribe:

<yt-formatted-string class="style-scope ytd-subscribe-button-renderer">Subscribe 157K</yt-formatted-string>

<paper-button noink="" class="style-scope ytd-subscribe-button-renderer" role="button" tabindex="0" animated="" aria-disabled="false" elevation="0" aria-label="Subscribe to EminemMusic.">
      <yt-formatted-string class="style-scope ytd-subscribe-button-renderer">Subscribe 37M</yt-formatted-string>
    <paper-ripple class="style-scope paper-button">

  </paper-ripple></paper-button>

After Subscribe:

<yt-formatted-string class="style-scope ytd-subscribe-button-renderer">Subscribed 157K</yt-formatted-string>

<paper-button noink="" class="style-scope ytd-subscribe-button-renderer" role="button" tabindex="0" animated="" aria-disabled="false" elevation="0" aria-label="Unsubscribe from EminemMusic." subscribed="">
      <yt-formatted-string class="style-scope ytd-subscribe-button-renderer">Subscribed 37M</yt-formatted-string>
    <paper-ripple class="style-scope paper-button">

  </paper-ripple></paper-button>

But how do I verify if it is already subscribed?
I do not speak English, sorry if I write badly.
Comment: Can't you just check the text of the button?
Comment: Does the `Subscribe` button disabled if you are already subscribed? If yes, then you can check the button status as verification of the subscription.
Comment: @supputuri the button changes to gray https://i.stack.imgur.com/nEJdS.png
Comment: I tried with `driver.FindElement(By.LinkText("Subscribe")).Click();` but no found
Comment: Edit your question and post the relevant HTML of the SUBSCRIBE and SUBSCRIBED buttons.
Comment: Done, I've already edited the publication.
Comment: I need help, I keep trying but I can not do the code.
Comment: @Gexur check my updated answer and let me know how it goes
Answer: Here is the simple solution. (Took the aria label as base because the aria-label starts with Subscribe to when not subscribed, if already subscribed it will be Unsubscribe from.
if (driver.FindElements(By.XPath("//paper-button[contains(@aria-label,'Subscribe to')]")).size() > 0){
    driver.FindElement(By.XPath("//paper-button[contains(@aria-label,'Subscribe to')]")).click();
}

You dont need the else as you will continue the script if already subscribed or subscribed as part of above step.
Comment: No worries, Glad it was helpful.
Comment: @supputuri Hello, thanks for helping me. When I place the code, I receive this IWebElement warning that does not contain a definition of 'Size'.
Comment: Try with "Count" or "Size" without the '()'
Comment: Works, but the code after "if" he skip if `(driver.FindElements(By.XPath("//paper-button[contains(@aria-label,'Suscribirme a')]")).Count > 0)
                {
                    driver.FindElement(By.XPath("//paper-button[contains(@aria-label,'Suscribirme a')]")).Click();
                }
 //code after if skips` :S
Comment: @Gexur Sorry I did not get your commnet, Do you mean the code after `if{}` not running?
Comment: yes, https://i.imgur.com/1tvPtik.png after the if do not run the "blue" part  and goes straight to the orange color line. (see image to understand)
Comment: wrapp the 'blue' part in the `else` part.
Comment: I need it to work regardless of whether it is `true` or `false`. without `else`
Comment: I changed  `driver.SwitchTo().Window(mainWindow);` for `driver.SwitchTo().Window(driver.WindowHandles.First());` and works fine, thanks for the help!, and sorry for my english xD
Answer: Just verify the button text.
if (subscribeBtn.Text.ToUpper().Contains("SUBSCRIBE"))
{
    subscribeBtn.Click();
}//else
//{
//    Your code here
//}

Hope it helps.


Why is the inequality sign reversed here?

Question: I am tasked to find the values of $x$ that satisfy $y<5$ for the equation$$y=\frac{x-2}{x+1}$$
I took the following steps:
$$\frac{x-2}{x+1}<5$$
$$x-2<5x+5$$
$$-4x<7$$
Dividing on both sides by -4 hence changing equality signs yields:
$$x>-\frac{7}{4}$$
And since there is a discontinuity at $x=-1$
$$x<-1$$
However the correct answer given in the textbook is $$-1<x<-\frac{7}{4}$$ Why is this so, have I made an error in my working or is there a lapse in my knowledge?
Comment: That cannot be the correct answer because $\{x \mid -1<x<-\frac{7}{4} \}$ is an empty set.
Comment: @Filthyscrub The answer in your book is wrong. Try $x=0$.
Answer: Because $x+1$ may be negative.
The right solution is the following:
$$\frac{x-2}{x+1}<5$$ it's
$$\frac{-4x-7}{x+1}<0,$$ which gives $$x>-1$$ or $$x<-\frac{7}{4}.$$
Answer: Avoid cross multiplication in inequations. If you want to do it then make cases:
Case 1: $x+1>0~~~~(1)$ $$\implies (x-2)<5(x+1) \implies -4x <7 \implies x>-7/4~~~(2).$$
The overlap of (1) and (2) is $x>-1.~~~(3)$
Case 2: $x+1<0~~~~(4)$ $$\implies (x-2) >5(x+1) \implies x<-7/4~~~(5)$$
The overlap of (4) and (5) is $x<-7/4~~~(6)$
The final answer is the union of these two cases (3), (6): $x<-7/4$ or $x>-1$, Equivalently $x\in (-\infty, -7/4)\cup (-1, \infty).$
Note: When you multiply an inequation by a negative factor as declared  in Case 2 above,the sign of the inequation changes.
Answer: A variant solution: rewrite the function first
$$\frac{x-2}{x+1}=1-\frac3{x+1},$$
so the inequation can be rewritten as
$\;\dfrac 3{x+1}>-4$.
Two cases:

either $x>-1$: the l.h.s. is positive, so the inequation is satisfied by any of these $x$;
or $x<-1$. We have
$$-4<\frac3{x+1}<0\iff \frac{x+1}3<-\frac14\iff x< -\frac34-1=-\frac74,$$
so the set of solutions is $\:\bigl(-\infty,-\frac74\bigr)\cup\bigl(-1,+\infty\bigr)$.


Prove an odd group's subgroup is normal

Question: let $H$ be a subgroup of a finite group $G$. Assume that $G$ is odd and $|G|=3|H|$  Prove that $H$ is normal in $G$
An hint is given for the solution as follows:
let $\ a \in G\ s.t. a \not\in H$
Define $\phi:H\rightarrow \mathbb{Z}_2\ s.t.\ \phi(h)=0$ if $\ haH=aH$, $\phi(h)=1$ if $\ haH=a^2H$
Then $\phi(H)=\{0\}$ so $\phi(H)=\{0\}=Ker(\phi)$ so $H$ is normal.
My misunderstanding:
Previously I had shown that if $a \not\in H$, there are 3 unique cosets of $H$ in $G$ ($H,aH,a^2H$). So if $h \in H$, and $\phi(h)=0$
$$(*)\implies haH=aH\implies h\in aH \implies H\cap aH\neq \emptyset\implies aH=H$$
Which is obviously a contradiction. Could help me understand

Why is statement $(*)$ not true? (Edit: this has been made clear to me now)
How would I show that $\phi(h)=0\ \forall h \in H$ ?
Comment: $haH = aH$ does not imply $h \in aH$. It implies $ha \in aH$, which means $h \in aHa^{-1}$.
Comment: Correct, $aH$ is not a group unless $a \in H$, so that property does not apply. Regarding your second question, have you shown that $\phi$ is a homomorphism? If so, note that $\phi(H)$ must be a subgroup of $\mathbb Z_2$, and there are only two possibilities since $\mathbb Z_2$ only has two subgroups.
Comment: You assume $|G|=3|H|$ and you have to prove it?
Comment: My mistake! edited
Comment: but it is a property of cosets that $aH=H\ iff\ a \in H$. If it doesn't apply, is that because $aH$ is not necessarily a group?
Comment: Yeah, I've shown $\phi$ is a homomorphism. So $phi(H)\subset \mathbb{Z}_2$ and $phi(H) = \{0,1\}\ or\ \{0\}$. but $|\phi(H)|$ divides $|H|$ so $phi(H) = \{0\}$. Thanks for the help
Comment: No, $\phi(H)$ is a subgroup of $\mathbb Z_2$, so $|\phi(H)|$ divides $|\mathbb Z_2| = 2$. What can you say about $|H / \text{ker}(\phi)|$?
Comment: Suppose $\phi :G \rightarrow G'$ and $H$ is a subgroup of G. let $\phi_H$ denote teh restriction of $\phi$ to the elements of $H$. Then $\phi_H$ is a homomorphism of $H$ onto $\phi(H)$. Suppose $|Ker\phi_H|=t \implies \phi $ is a $t$-to-1 mapping so $|\phi (H)|t =|H|$ This is true in general, not just for this specific case of $H, \phi$.
Comment: Sorry, I misinterpreted what you were saying. Indeed, $|H| = |\ker(\phi)| \cdot |\text{im}(\phi)| = |\ker(\phi)| \cdot |\phi(H)|$, hence $|\phi(H)|$ is odd, essentially the same as what I wrote in the answer.
Answer: Assuming you have verified that $\phi$ is a homomorphism, recall that $H / \ker(\phi) \cong \text{im}(\phi)$, so $|H| / |\ker(\phi)| = |\text{im}(\phi)|$. Now $|G|$ is odd, so $|H|$ is odd, so $|H| / |\ker(\phi)|$ is odd, which means that $|\text{im}(\phi)|$ is odd. Since $\text{im}(\phi)$ is a subgroup of $\mathbb Z_2$, its order must be $1$ or $2$, and of these possibilities, only $1$ is odd. Therefore $|\text{im}(\phi)| = 1$, so $|\ker(\phi)| = |H|$, so $\ker(\phi) = H$.

Prove an odd group's subgroup is normal


How can I add a single divider after a few items to seperate a group in RecyclerView?

Question: I've got a problem. I want to use a single divider in my Recyclerview navigation drawer. How can I do this? Right now I've got a DividerItemDecoration.java with after each item a divider and that's not what I want. I want to set a single divider after a specific item. Here's the DividerItemDecoration.java code:
package com.***********.************;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public class DividerItemDecoration extends RecyclerView.ItemDecoration {

private static final int[] ATTRS = new int[]{
        android.R.attr.listDivider
};

public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;

public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;

private Drawable mDivider;

private int mOrientation;

public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}

public void setOrientation(int orientation) {
    if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
        throw new IllegalArgumentException("invalid orientation");
    }
    mOrientation = orientation;
}

@Override
public void onDraw(Canvas c, RecyclerView parent) {
    if (mOrientation == VERTICAL_LIST) {
        drawVertical(c, parent);
    } else {
        drawHorizontal(c, parent);
    }
}

public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}

@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    if (mOrientation == VERTICAL_LIST) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}

And this is the onCreateView of the NavigatonDrawerFragment.java:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
    mDrawerList = (RecyclerView) view.findViewById(R.id.drawerList);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mDrawerList.setLayoutManager(layoutManager);
    mDrawerList.setHasFixedSize(true);
    mDrawerList.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    mDrawerList.setItemAnimator(new DefaultItemAnimator());

    final List<NavigationItem> navigationItems = getMenu();
    NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(navigationItems);
    adapter.setNavigationDrawerCallbacks(this);
    mDrawerList.setAdapter(adapter);
    selectItem(mCurrentSelectedPosition);
    return view;
}

Answer: Simple solution https://pastebin.com/4J7sPaCF
public class SingleDividerDecoration extends DividerItemDecoration {

    private final int height;
    private int position = -1;

    public SingleDividerDecoration(Context context, @DrawableRes int dividerId) {
        super(context, LinearLayout.VERTICAL);
        Drawable divider = ContextCompat.getDrawable(context, dividerId);
        this.height = divider.getIntrinsicHeight();
        setDrawable(divider);
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int viewPosition = parent.getChildAdapterPosition(view);
        int dividerHeight = viewPosition == position ? height : 0;
        outRect.set(0, 0, 0, dividerHeight);
    }
}


Why run the same phase twice to a series of outlet?

Question: Just found the setup in the photos below. This circuit was run with 3 wires + ground. White is neutral, Black and Red are on the same phase. There's a single pole 15 amps breaker feeding it. This is not a MWBC.
Each outlet has the neutral bridged between the two plugs, but each plug is fed by either the Red or black wire.
Why would someone install it this way ? Is there any upside I'm missing ?
The downsides I see are:

having two wires on the same screw connector.
using 3 wires were 2 would do.

The upside ?

Would this make it easier to separate this into two circuits in the future?

I'm looking for a rationale as to why the original installer might have done this, and whether there's any further downsides. If this is standard practice, I'd also be happy to learn about it.
Edit, from question:

neither the Red or Black are switched anywhere. Last point I see them they go into the wall and as far as I can tell they must simply be connected at the breaker panel.
they are indeed bridged on the neutral side and split on the hot side.

Edit:

breaker connection showing the red and black together at the breaker: (this setup was done twice by the same guy, only consider the top one. The bottom one goes to another room)

whole panel, although I fear the pros will have much to comment on:

original images:
Comment: It looks as if the outlets are only bridged on the neutral side. The doubling on the screws was apparently done to continue the circuit to another receptacle without using a pigtail or a wirenut. Go figure!
Comment: With a multi-meter or 120V/240V "twin probe tester" you can confirm whether the red and black at the receptacle are different phases. Red to black will be 0V or 240V.
Comment: Have you checked whether there's a switch on the wall somewhere that turns power on and off to either the red or the black half of these receptacles?
Comment: no switch for either red or black, and yes, bridged on the neutral side but split on the hot side
Comment: Does the single pole 15 amp breaker that this is fed from have both a red and a black wire connected to the single terminal?
Comment: How about a picture of the panel showing the breakers where this mess is connected? That would help clear up how to fix this. Also, if that was a licensed electrician who installed it, he should have his license pulled. As @isherwood noted, two wires wrapped around a screw like that is illegal.
Comment: @FreeMan see edits.
Comment: And... two wires under the screw on the breaker like that is illegal, too. Yikes! I'm no electrician, but I cannot fathom what they were trying to accomplish.
Comment: what's not clear to me whether the two reds at the receptacle correspond to the two reds at the panel. I am guessing they don't (or you'd be shorting across the two phases) so you have this double wiring at two different circuits, and the second red at the receptacle is leading to a further receptacle on the same circuit. Did you check the red-to-black voltage at the receptacle?
Comment: If you want MWBC you can replace the two with one 240V breaker and run one black and one red to your desired receptacle(s), or just cap off the reds as you suggested earlier, and use a single phase receptacle.
Answer: The question is "why".  I'm going to guess ... since that's all we can really do.    Useless MWBCs that were poorly conceived, poorly executed, and never useful, were combined at the panel to gain back a couple of spaces.
Someone thought it would be cool to run two circuits to lots of outlets using MWBC.  Just to have the capability all over the house to use one outlet for two big things.  If it were done properly with pigtails this would be perfectly fine, even if I can't think of any great applications right now.
Later, someone needed space in the panel (the clue is, it's full) and realized having these twin-circuit outlets all over the house was not that useful after all.   Maybe the couples hair drying sessions were fun but didn't need to be done in every room?  Maybe as it turned out nobody ever needed to vacuum while microwaving in the kids bedroom?   So they were combined onto one breaker as an easy way to gain back a couple of spaces without losing any functionality upstairs.
Answer:
Just found the setup in the photos below. This circuit was run with 3 wires + ground. White is neutral, Black and Red are on the same phase. There's a single pole 15 amps breaker feeding it. This is not a MWBC.

Then they are both on the same breaker.
If they are different breakers then they are an MWBC which is dangerously misfired, and should be promptly placed on a 2-pole 240V breaker. (not a tandem).

Each outlet has the neutral bridged between the two plugs, but each plug is fed by either the Red or black wire.

Code requires a light switch in each room to operate a light.  An exception allows a switched receptacle instead, presuming you'll plug in a floor lamp and that will be the room light.
Such wiring is typically done like this. Black is "always-hot" and red is "switched-hot".  Each receptacle is connected either to black-only, or the tab is broken and one socket is connected to each, making one of the sockets switched with the switch.
The wiring in this socket is appropriate either for that, or a MWBC.
The deciding factor is -- Is there a switch in this room which seemingly does nothing? If so, most likely this is a switched circuit for the light, but some nitwit defeated the switch by wiring a receptacle just like the above but failing to "break off the tab".  The improper tab is bypassing the switch, rendering it inoperative.  Find that tab and break it.

Why would someone install it this way ? Is there any upside I'm missing ?
... having two wires on the same screw connector.

You can't ever do that. That's just amateur hour / "saving your way to the graveyard".  2 wires on a screw is just illegal and stupid. (unless the device's UL-approved instructions say otherwise).  The right way to do this is either

Pigtail. Join the two to a third pigtail on a wire nut...  then land the third on the screw.
Use receptacles listed for 2 wires per screw, and that means almost any "spec grade" receptacle (cost $3, come in a box instead of loose in a bin). Their instructions specify how to fit 2 wires per screw.

Note that if this is a multi-wire branch circuit (MWBC) then the neutral wire must be a pigtail -- it cannot cannot splice on the receptacle, because it must remain continuous if the receptacle is removed.  (just like ground).

Would this make it easier to separate this into two circuits in the future?

No, installers never do things "for the future" unless Code requirements put a gun to their head (neutral in switch loops).  They're generally wiring new houses by the dozen, profit margins are paper thin, they don't spare anything.
What you can use it for is entirely decided by where the /3 cables go right now. If to a switch, you can use it for switched receptacles.  If to the panel, you can use it for a (corrected) MWBC.
Comment: _What you can use it for_ ... or replace the outlets with ones with intact bridges, cap the red wires in each box, use wire nuts and leave everything on a simple neutral-white and black-hot setup, right?  There is a separate light fixture on the ceiling, so no, switched outlets have no value.
Comment: If the red and black wire are on different breakers, they should not use the same neutral wire either, it could get double the amps that the breakers are supposed to limit the system to.
Comment: Unless it's a _proper_ MWBC setup, @Orbit.
Comment: @FreeMan: Indeed, but then the powered lines would be on different phases.
Comment: Super useful info. Added the breaker panel pic after confirming they were indeed joined there.
Comment: It's possible this was done by a DIY while upgrading the receptacle to a "decora" style and who didn't know about MWBC, shorted a few times with all sorts of configurations until this one set in replacing the MWCB breaker with two independent 15A breakers. There could be another set of chained receptacles with the same problem.
Comment: @Jeffrey that's great news.  It was wired as a *multi-wire branch circuit* and then the MWBC was decommissioned for some reason, what P2000 says, or desire to use a 120V generator.  /cringe the breakers... I think the BR may be listed for double tapping (maybe that's why they didn't use Murray/Siemens?). Oher than alien breakers, the panel doesn't look so bad.  Most wires have some extra length (GOOD!) so you can move breakers around.
Comment: @Harper-ReinstateMonica -- pretty sure BR never was listed for doubletaps
Comment: @Jeffrey -- that's possible too


Trying to activate Netgear WNDA3100 N600 WiFi Dual Band Adapter

Question: I am very new to Ubuntu and am having trouble setting up my new wireless adapter. I'm running Ubuntu 14.04. I've added some more info about the adapter.
<code>th0      no wireless extensions.
lo        no wireless extensions.
Bus 003 Device 003: ID 0846:9011 NetGear, Inc. WNDA3100v2 802.11abgn [Broadcom BCM4323]
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 003: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 004 Device 002: ID 046d:c05a Logitech, Inc. M90/M100 Optical Mouse
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 009 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
</code>
Answer: I know this an older post but here goes.
You have to use the windows driver provider with the device. It's a .inf and a .sys file. Use ndisgtk [ndiswrapper gui] on the .inf file and in some cases need a reboot. Should be working then. In my case to get it to connect o my WAP2 security router I had to run "ps auxwww" which for whatever reason decided to make it play nice. If you have an open wifi router you're connecting to or something that uses WEP security you should be fine.


Ubuntu Server live cd rescue mode can't run fsck

Question: I have an ubuntu server virtual machine that crashed and I was forced to reset the virtual machine. When I booted, it did an automatic fsck, but I want to make sure that the filesystem is ok. I have searched for instructions on how to run fsck from an ubuntu live cd, but none of the instructions work!
The version of the ubuntu server live cd is 10.04.2 and when the live cd menu appears I chose "Rescue mode". I then went through the questions (similar to those during installation) and the final prompt asks you to choose a "device to use as root file system". I read online that I shouldn't mount the root file system if I want to run fsck, so I chose the option "do not use a root file system". Next option I selected was "execute a shell in the installer environment". I now get a command prompt, but when I try to run fsck /dev/sda1 I get "fsck not found".
I'm completely lost and even the "Official Ubuntu Server 2nd edition" book doesn't explain the procedure properly.
I hope someone more knowledgeable can help me out! Thanks.
Answer: For anyone not seeing the disk devices (/dev/sda1 etc.), be sure to run "Load installer components from CD" from the main menu; say "Do not use a root file system" when prompted.
To run the actual fsck: You are correct that a generic fsck (which on other systems automatically calls the correct filesystem-specific fsck) does not exist. However, a range of filesystem-specific fsck are available, such as fsck.ext4. To see a list, type fsck without hitting enter and press tab twice -- the shell will display a list of possible completions. Pick the one that's appropriate for your file system (ext4 and ext3 are popular). I'm pretty sure that if you pick the wrong one, it will abort with an error message without causing any harm. Example:
fsck.ext4 -f /dev/sda1

This runs the ext4 fsck utility on the first partition of the first SCSI disk. -f forces a full check even if the file system is marked clean.
Comment: You might also want to add `-y` to avoid considerable amount of "yes" answers.
Answer: You will have to use the desktop cd (iso). You would boot the live iso with your VM, and run fsck from a terminal.
The server CD, as you can see, has a very limited "live" environment, and is used primarily for installation.
Comment: That's very interesting! I assumed I needed the **server** CD to fix a server OS installation. I will try this immediately cause the VM needs to be up an running ASAP.
Comment: I was able to run fsck from the **desktop** ISO and it reported that the filesystem was clean. I'm still surprised that I used the **desktop** version, but happy that it turned out ok. Thanks for your help.
Comment: You can actually run `fsck` from the server CD. See my answer.


Reverse wiring basement lights

Question: Can existing basement lights wired in succession from the main electric panel, with the last light on a switch be reverse wired so that all of the lights can be controlled by the switch?
Answer: Can you elaborate on what you mean by "reverse wired?"
If you're saying you want to put the switch at the far end, near the last light,the most straightforward way to do that is to pull power into that switch box, then feed the lights from there (don't feed the lights directly from the panel).
Or, I suppose you could pull 3-rope all the way through from the first light to the last light. You'd run 2-rope from the panel to the first light.
EDIT: a commentor pointed out that code now requires a neutral in all switch boxes. So run 3-rope from the last light fixture to the switch box, use the red and black for your switch leg, and cap the neutral for future use (presence-detecting switches and so on).
Connect the black wire straight through all the light fixture boxes. Then connect the switch leg (the 3-rope running from the last light fixture to the switch) to the black and red wires. At each light fixture, pigtail and connect the red (hot) and white (neutral) to each light fixture. Or you could switch black and red (wire red straight through, wire black to each fixture)--doesn't matter.
You always want to switch the hot wire, not the neutral. Otherwise, you end up with power at the fixtures even when the switch is off and it's a shock hazard.
I'm not sure why I feel compelled to say this, but if the lights in question are all on the same circuit, they should be wired in parallel (not in series), so the hot and neutral wires need to be pigtailed in the box at each light fixture to connect to each light, but also run directly to the next light (not wired through each light to the next).
Comment: This 3-wire setup is exactly what I have in my basement, as wired by the builder. The same cable supplies power from the main panel at the other end of the basement, feeds several lights, goes to a switch at the entry point, *and* feeds a few outlets, too. Been in place for a few years, and hasn't failed yet.
Comment: Note that Code now requires a neutral at all switches, so a 2-rope to the switch from the last light doesn't comply. Run a 3-rope and leave the neutral capped for possible future smart switch use.
Comment: Ah, good point.  Yep, run 3-rope to the switch. Thanks!
Comment: Where the heck does referring to conductors as "rope" come from?? I've never heard that before, either on this site or from any actual contractor or electrician I've worked with.
Comment: @gregmac Wires bundled up in a sheath (like NM cable) is a cable. Cables have traditionally been called rope, going way back. I did some work for my electrician uncle when I was young and he and others referred to it that way, so that's what's in my head. 2 rope would be NM/Romex cable with two conductors (plus ground), 3 rope would be the cable with 3 conductors.
Comment: Although technically, of course, it's 14/2 or 12/2 (or whatever gauge) NM cable, or 14/3 or 12/3 MC or whatever. Which of course is more technically accurate.
Answer: The standard solution would be to either run power and neutral to the switch and then run switched power and neutral back to the lights, or to run power/neutral to a box, run a "switch loop" from there to the switch and back, and then run switched power and neutral from box to lights.
It sounds like you want to do something different ... which may or may not work electrically (I don't understand your idea well enough to answer than)  but may not meet code.
Comment: Switches are for the "hot" conductors in regular AC applications. No switching neutrals.
Comment: Uhm.... didn't say anything about switching neutrals, just running neutral to complete the circuit. Or at least that was my intent;  it is Sunday night after all.

Reverse wiring basement lights


Any reason why one would call hide() before show()?

Question: Why would one want to call hide() before show() ? I'd like to know this before i optimize this with method chaining..
function ShowSomething() {
  jQuery("something").hide();
  jQuery("something").show();
}

Comment: I'd call hide before fadeIn()
Comment: because only hidden elements can be shown.
Answer: When calling hide() the initial value of that element's display is stored for when show() is called, that initial value is put back in place. If no initial value is set, then show() will set display:block.
So, if an element was originally display:inline, but (let's say) .css("display","none") was called on that element, it would be hidden with no initial property saved. When we show() this element again it will be given display:block - not it's initial value of inline which is what it would be given if we'd used hide().
To summarize: hide() will preserve the original display value ready for show() to use
Source: The jQuery hide() documentation
Comment: Where does this come from? Experience or documentation? I'm curious.
Answer: There's no difference in the output if that was chained, other than jQuery will actually perform the DOM lookup twice on the non-chained version.
In terms of performance, non-chaining is actually 24% slower, as shown below:

See my JSPerf
Answer: .hide will

.hide() is fired immediately and will override the animation queue if
  no duration or a duration of 0 is specified.

So, if the animation was already in the queue it would be removed, and then inserted with .show(). It can also be useful (visually) for certain animations where you go from non-existance to existance. You can chain them together, it will make no difference.
Answer: This usually comes up when you have a series of elements that need to be shown one at a time. First, you hide all elements with a certain class, then you show the one you want.


two dimensional heat equation

Question: Please I really need some help for this exercise, I can't solve it for any ways...

I need to prove the maximum principle for the two dimensional heat equation with zero boundary data. Really I need help for this...
The book (Asmar) state without prove the maximum principle for one dimension and is this:
Comment: As your book states, the solution of the two dimensional heat equation with homogeneous boundary conditions is based on the separation of variables technique and follows step by step the solution of the two dimensional wave equation (§ 3.7 pag. 155) and the details are shown in Project Problem 17 (pag. 163). The proof of maximum principle is presented in the Appendix at the end of the section (i.e. pag. 190).
Comment: Can you state the maximum principle you are to show?  There are "weak maximum principle"s and "strong maximum principle"s and it's hard to guess which you mean.  Also, do you, for instance, have a maximum principle for a similar system, like the Laplace equation?
Comment: Yes, the book don't give a principle just state the principle for the heat equation in one dimension
Comment: I really need to understand this problem... Pls
Answer: Anytime you see a finite domain, standard heat equation, think separation of variables.  Try to use $u(x,y,t) = T(t)X(x)Y(y),$ and you'll get 3 ODE's to solve, something along the lines of
\begin{align}
T'(t) + c^2(\lambda_x + \lambda_y)T(t) &= 0\\
X'' - \lambda_x X &=0\\
Y'' - \lambda_y Y &=0.
\end{align}
This should be the motivated approach by seeing the form of the solution, namely 3 functions, each of a single variable, multiplied together.  Try it and see how it goes.

A little intuition behind why $m \leq u(x,t) \leq M$ is as follows,
The solution form is exponentially decaying in time, and the trig functions are bounded, so for $t$ growing, the solution relaxes (Show this rigorously by bounding the size of your solution). When $t$ is zero, the solution satisfies the boundary conditions, and those are bounded as well.  It is not hard to translate this into a mathematical statement.
Comment: I found the solution by separating variables but I don't how to prove the maximum principle as one dimension

two dimensional heat equation


How can I fix Teamviewer sharing when sharer can see your screen but mouse doesn't work?

Question: I am trying to let someone share my screen by using teamviewer. He is able to log on to my machine but he is unable to move the mouse around to actually be able to do anything. Has anyone has this problem in the past or know where I should look to try and solve the problem. I am using ubuntu 23.04.
Answer: I have used ubuntu + teamviewer and there was a prompt that appeared whenever I remote accessed it. I had to enable allow control or something in that prompt and then share
Comment: Thanks. I'll give it another shot and try that. It's appreciated.


Changes are persistent on a bootable USB flash drive?

Question: I consider to create a bootable pendrive with Ubuntu 12.04 LTS. I wonder if all changes that will be made are persistent? If I install an application, will it be also available after OS reboot? Will my files stay intact?
Answer: Your files and programs will remain intact after reboot as long as you choose "Stored in reserved extra space" bellow "When starting from this disk, documents and settings will be:" on startup disk creator.
Answer: If you install Ubuntu to the flash drive (as if it was a normal hard drive), any changes you make to the installed Ubuntu and files are indeed persistent. It is exactly like a normal Ubuntu installation, except that it is highly portable.
If you turn your flash drive into a bootable Ubuntu installer (called a Live USB), then the flash drive is just like a Live CD. All changes made during the Live session are lost upon reboot, unless you enabled persistence when you created the Live USB. This would effectively make "customisations such as keyboard layout, numlock, preferences, additional packages" survive reboots. (Source)
Comment: Live USB supports persistence.
Comment: I installed ubuntu on USB (using Live CD) and it wont boot. I am sure that grub was also installed on mem stick. Tried both methods: GRUB on SDB (memstick) and on SDB1 (first partition with mountpoint "/"). Now, I am very confused :( In my opinion it should works well.
Comment: Ah! That's a different issue. I would recommend you start a new question with this problem.


Can't get skydome image to appear

Question: In compiz, when I select an image for the skydome it doesn't appear when I rotate the cube. I have JPEG enabled, and the skydome box is checked, but when I go to rotate the cube it's just the default blue and white background. How can I fix this?
Answer: First, make sure that the image path is valid, and it is in the JPEG format. If it is, then first if you are using unity, log out of it, and use another desktop session (such as unity 2D). If compiz is the window manager for that session, temporarily use another one (such as xfwm4 or metacity). Then run the following commands in a terminal window:
<code>rm -rf ~/.gconf/apps/compiz*
rm -rf ~/.cache/compizconfig-1/
rm -rf ~/.config/compiz-1/
rm -rf ~/.compiz*
</code>
And then log out and log back in. See if this helps!
Source: http://ubuntuforums.org/showpost.php?p=11436939&postcount=12

Can't get skydome image to appear


can we use vertex degree to detect hamilton path and hamilton circuit?

Question: Hamilton path: goes through every node/vertex exactly once.
Hamilton circuit: goes through every vertex exactly one and ends at the starting node/vertex.
So i am wondering is possible to use degree to detect if a graph have hamilton paths or circuits. Like we do with eulers circuit , if every vertex  in the graph have a even degree then we know that eulers circuit exists.
Answer: Check the theorems of Ore and Dirac.
According to the theorem of Ore:
Let $G$ be a (finite and simple) graph with $n ≥ 3$ vertices. We denote by $\deg (v)$ the degree of a vertex $v$ in $G$, i.e. the number of incident edges in $G$ to $v$. Then, Ore's theorem states that if
$\deg (v) + \deg (w) ≥$ $n$ for every pair of non-adjacent vertices $v$ and $w$ of $G$
then $G$ is Hamiltonian.
According to the theorem of Dirac:
A simple graph with $n$ vertices $(n ≥ 3)$ is Hamiltonian if every vertex has degree $n / 2$ or greater.
Comment: What do you mean by Hamiltonian? path or circuit
Comment: Dirac = circuit.
Ore = path
Comment: alright, for Ore do i just pick a random pair of non-adjacent vertices ? do i have to check for every possible pair of vertices , or isit enough with one random pair of non-adjacent vertices ?
Comment: Every pair of non-adjacent vertices.
Comment: alright, thanks


List of sources can not be read Ubuntu 16.04

Question: I am trying to update my packages put I keep getting an error saying,
E: Malformed entry 52 in list file /etc/apt/sources.list (Component)
E: The list of sources could not be read

When I run
sudo nano /etc/apt/sources.list

I get these lines of code on line 52
deb http://cran.rstudio.com/bin/linux/ubuntu xenial

deb http://cran.rstudio.com/bin/linux/ubuntu xenial
Anyone have any ideas, I tried to write xenial partner but to no avail. Any help would be very much appreciated. Thanks
Comment: Are both on the same line `52`?
Comment: More accurately, a dupe of http://askubuntu.com/questions/880355/malformed-entry-63-in-list-file-after-upgrading-to-gnome-16-04-01
Comment: Your line is missing a repo name like `main, universe, restricted` after it! Put it like this `deb http://cran.rstudio.com/bin/linux/ubuntu   xenial   contrib` and try again
Answer: According to UBUNTU PACKAGES FOR R the correct deb entry for the cran repository for the xenial release is (note the trailing slash /)
deb http://cran.rstudio.com/bin/linux/ubuntu xenial/

This seems to be a rather obscure point of syntax: the general form for such entries is
deb [ option1=value1 option2=value2 ] uri suite [component1] [component2] [...]

however from man sources.list:
   The URI for the deb type must specify the base of the Debian
   distribution, from which APT will find the information it needs.  suite
   can specify an exact path, in which case the components must be omitted
   and suite must end with a slash (/). This is useful for the case when
   only a particular sub-directory of the archive denoted by the URI is of
   interest. If suite does not specify an exact path, at least one
   component must be present.
which is the case here.
Comment: Aka trivial repos: https://wiki.debian.org/HowToSetupADebianRepository


If cookie exists read and set it's value to a variable in Woocommerce

Question: I've created two custom functions in my Woocommerce store. The idea is to limit a certain type of product to a maximum of 3. I want to set a cookie for one week to prevent more of the same type of product being purchased by the same customer. So if the customer buys 1 today, then for the next 6 days they could still purchase up to another 2 until the cookie expires. But 3 would always be the maximum.
The function works in that it will set a limit if more than 3 items are added to the basket in one session, and the cookie still exists after checkout. My hunch is it's not being read at the right time, or passed to the function which checks if it exists.
<code>    function filter_woocommerce_add_to_cart_validation( $true, $product_id, $request_quantity, $variation_id = '', $request_variation = '' ) {
        // holds checks for all products in cart to see if they're in our category
        $lpc_cookie = $_COOKIE['lpc'];

        if ( isset( $lpc_cookie ) ) {
            $category_checks = $lpc_cookie;
        } else {
            $category_checks = 0;
        }

        $limited_product_count = 4;
        $limited_slug = 'instant-print'; //replace 'instant-print' with your category's slug

        // check each cart item for our category
        if( ! is_admin() ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                $product = $cart_item['data'];

                if ( has_term( $limited_slug, 'product_cat', $product->id ) ) {
                    $category_checks += $cart_item['quantity'];
                }
            }
        }

        // We also check the item that the user is trying to add to cart
        if ( has_term( $limited_slug, 'product_cat', $product_id ) ) {
            $category_checks += $request_quantity;
        }

        if ($category_checks >= $limited_product_count) {
            $notice = 'Sorry, you have reached the maximum amount for this type of product that you can purchase during this period.';
            wc_add_notice( __( $notice, 'textdomain' ), 'error' );
            return false;
        }

        return $true;
    };

    add_filter( 'woocommerce_add_to_cart_validation', 'filter_woocommerce_add_to_cart_validation', 10, 3 );

    function set_cookie_for_limited_products () {
        $limited_slug = 'instant-print'; //replace 'instant-print' with your category's slug
        // check each cart item for our category
        if( ! is_admin() ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                $product = $cart_item['data'];

                if ( has_term( $limited_slug, 'product_cat', $product->id ) ) {
                    $category_checks += $cart_item['quantity'];
                }
            }
        }

        // $expire = time() + 60 * 60 * 24 * 7; // expires in one week
        $expire = time() + 60 * 60; // expires in one hour
        setcookie('lpc', $category_checks, $expire);
    }

    add_filter( 'woocommerce_before_checkout_form', 'set_cookie_for_limited_products' );
</code>
I hope this is something obvious. Initially I was trying to echo and var_dump variables, but I found that was causing other stuff to break.
Comment: Why put this in cookies ??? what about if the user decide just to open an other browser or use the "New Private window" ? why not insert in a DB the purchases related to the user, and check if user purchased via DB query....
Comment: @lharby The customer must be registered in the store? If so, you should implement that this is stored with the user, if you force the client to be registered, I can help you, using cookies is not a good idea
Comment: @DanielRiera this is my current setup, https://imgur.com/m5DAs0G so you are saying I should disable guest checkout? I don't want to put people off ordering. I know that cookies are flawed but I also don't know how to read or write any db queries.
Comment: @lharby check my answer :)
Comment: Oh I prefer the idea of using both options. I will try and check this later and get back to you. Thank you.
Answer: It's easy, I can give you an example, but if guests can make purchases, you won't be able to save that information, it's an example that takes into account the two possible situations.
<code>function filter_woocommerce_add_to_cart_validation( $true, $product_id, $request_quantity, $variation_id = '', $request_variation = '' ) {
        // holds checks for all products in cart to see if they're in our category

        $limited_product_count = 4;
        $limited_slug = 'instant-print'; //replace 'instant-print' with your category's slug

        if(is_user_logged_in()) {
            //Using database
            $user_id = get_current_user_id();
            $lpc_cookie = get_user_meta( $user_id, $limited_slug, true );
            $expire = get_user_meta( $user_id, $limited_slug . '_expire', true );
        }else{
            //Using cookie
            $lpc_cookie = $_COOKIE['lpc'];
        }

        //Check lpc_cookie and expire value
        if ( isset( $lpc_cookie ) && $expire > time() ) {
            $category_checks = $lpc_cookie;
        } else {
            $category_checks = 0;
        }

        // check each cart item for our category
        if( ! is_admin() ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                $product = $cart_item['data'];

                if ( has_term( $limited_slug, 'product_cat', $product->id ) ) {
                    $category_checks += $cart_item['quantity'];
                }
            }
        }

        // We also check the item that the user is trying to add to cart
        if ( has_term( $limited_slug, 'product_cat', $product_id ) ) {
            $category_checks += $request_quantity;
        }

        if ($category_checks >= $limited_product_count) {
            $notice = 'Sorry, you have reached the maximum amount for this type of product that you can purchase during this period.';
            wc_add_notice( __( $notice, 'textdomain' ), 'error' );
            return false;
        }

        return $true;
    };

    add_filter( 'woocommerce_add_to_cart_validation', 'filter_woocommerce_add_to_cart_validation', 10, 3 );

    function set_cookie_for_limited_products () {
        $limited_slug = 'instant-print'; //replace 'instant-print' with your category's slug
        // check each cart item for our category
        if( ! is_admin() ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                $product = $cart_item['data'];

                if ( has_term( $limited_slug, 'product_cat', $product->id ) ) {
                    $category_checks += $cart_item['quantity'];
                }
            }
        }

        // $expire = time() + 60 * 60 * 24 * 7; // expires in one week
        $expire = time() + 60 * 60; // expires in one hour

        if(is_user_logged_in()) {
            //Using database
            $user_id = get_current_user_id();
            update_user_meta( $user_id, $limited_slug, $category_checks );
            update_user_meta( $user_id, $limited_slug . '_expire', $expire );
        }else{
            //Using cookie
            setcookie('lpc', $category_checks, $expire);
        }
    }

    add_filter( 'woocommerce_before_checkout_form', 'set_cookie_for_limited_products' );
</code>
Comment: Hmm, this is the direction I want to go in. My issue is the same as above. To replicate it, I signed out of WP. Purchased two items and checked out. Then came back to a new session. In my mind this means now I can only add 1 more item from the limited category to my cart, as the cookie (or the get_user_meta) should be set to 2, but it is not being read on the store pages. So this is never being set `$category_checks = $lpc_cookie;` and I don't know how to solve that, also testing this seems to be quite difficult.
Comment: Maybe I need a different function than `filter_woocommerce_add_to_cart_validation` in order to check if the cookie/db value exists across all store pages (although to my mind this should be enough right)
Comment: Check your database if prefix_usermeta exist  instant-print meta_key on your user ID
Comment: Yes it does exist, see https://imgur.com/0SOXvwU but either way it's not being passed to `$category_checks` via db value or cookie value.
Comment: Hmm, I may have logged out at this point and then gone through checkout using the cookie method, but I would have expected this to be set via one method or the other. And on a new session it would let me add another 3 products to the basket despite db and/or cookie being set. I was going to suggest continuing in a chat but I don't seem to have that option. https://chat.stackoverflow.com/?tab=site&host=stackoverflow.com
Comment: Is possible synchronize $_COOKIES <-> DATABASE... but i need time :) where talk about this?
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229555/discussion-between-lharby-and-daniel-riera).


Read logs from log4net like in Elmah?

Question: Is there any tool for reading logs from log4net files like Elmah?
Answer: Have a look at http://logjoint.codeplex.com/ this is a tool in which you can define your own rules to read your log file.
Answer: Take a look at chainsaw

Chainsaw v2 is a companion application to Log4j written by members of
  the Log4j development community. Like a number of Open Source
  projects, this new version was built upon inspirations, ideas and
  creations of others. Chainsaw v2 has it's roots from the original
  Chainsaw utility written by Oliver Burn, and with inspiration from the
  Log Factor 5 utility contributed by ThoughtWorks Inc.

It works well with log4net too
Comment: Chainsaw can read regular text log files, try the latest developer snapshot, the setup GUI is much improved and there are a ton of new features: http://people.apache.org/~sdeboy

Read logs from log4net like in Elmah?


How is Lord DeRosso immortal?

Question: If you explore Vampire Castle, you'll ultimately learn that Lord DeRosso gained his immortality while burning in his own castle's flames - when some dark voice offered him power everlasting.
During the final battle, Lord DeRosso makes an appearance: before sacrificing himself against Lord Ouroboros, he recites the same words as the dark voice - then he fuses with Ouroboros' core.
But, this still doesn't quite explain Lord DeRosso's immortality - nor is it very clear why did he recite those words (obviously he's the dark voice his past self heard, but I still don't see the point).
So, what exactly makes Lord DeRosso immortal?
Comment: He's probably immortal by the power of that unknown "dark voice". Reciting the words may just have been a way to "strip" himself of his immortality the same way he obtained it (?). I've not found anything that hints at how or why he's immortal.
Answer: I actually don't recall directly either; and I'm not sure it was ever clearly explained.
It's an interesting chain of events I can't get straight in my head:

DeRosso becomes immortal when he sets his home ablaze and hears the voice
The voice is actually DeRosso speaking during the final battle (beginning the bootstrap paradox)
During the battle with Sage (1800 years prior to the story's events); he's given a task by the angel only he can complete due to being an immortal

So I guess he somehow was able to make himself immortal?
I'm pulling this from the final fantasy wiki:

Forced to watch the innocents trapped in his manor suffer a lingering
  death by starvation, DeRosso set his home on fire with the intent to
  go down with it. Just as he was about to die, beginning to come to the
  realization that his persecution is unwarranted and that those
  responsible must pay, DeRosso heard a voice call out to him: "Accept
  me and I shall grant life everlasting. Though it shall be filled with
  grief, thou shalt have all eternity to wreak vengeance upon thine
  enemies". While the voice's identity was unknown to him at the time,
  DeRosso became an immortal and left the ruins of his home. Demonized
  as a vampire by the Orthodoxy, deciding to make use their propaganda
  by giving himself the look, DeRosso gathered many followers who shared
  his malice towards the Orthodoxy.
In the final world, with Ouroboros's arrival into his reality, DeRosso
  carries out his promise to the angel by merging into the monster's
  core. Using his own immortality to negate Ouroboros's regeneration,
  DeRosso dies with the monster when he is finally destroyed. But prior
  to his sacrifice, as the Infernal Realm transcends time and space,
  DeRosso begins a bootstrap paradox by saying the very words he heard
  long ago so that a past version of himself would hear it.
Comment: Maybe he gave his old self Ouroboros's immortality, assuming it had to go somewhere? But yea, they don't really explain it.

How is Lord DeRosso immortal?


Is there a way to set conditions for end parameter in python?

Question: I'm new to programming, just going through a wee online course, but I've hit a stumbling block on one of the tasks.
The task is to print the coordinates in the format of an 8 by 8 grid. So A1 to H1 is on the first line, A2 to H2 on the second, etc. The task is to be done using nested list comprehension where possible.
So far I have this, which puts all coordinates on the same line separated by a space:
let=["A","B","C","D","E","F","G","H"]
num=[1,2,3,4,5,6,7,8]

[print(i,j,sep="",end=" ") for j in num for i in let]

I've tried some daft things that definitely do not work, such as:
let=["A","B","C","D","E","F","G","H"]
num=[1,2,3,4,5,6,7,8]

[print(i,j,sep="",end=" " if i!=H) for j in num for i in let]

Is there a way to do this in a single line without typing out full "for" loops?
Comment: List comprehensions are meant to *build lists*, and should not be used for side effects (like printing, as you do here). Use normal loops.
Comment: And if you absolutely have to use list comprehensions, use them to build a list of sublists that you will `join`, and print the final result.
Answer: try
let=["A","B","C","D","E","F","G","H"]
num=[1,2,3,4,5,6,7,8]

[print(i,j,sep="",end=" ") if i!='H' else print(end='') for j in num for i in let]

but as the comment said, try using loop instead when you want to print things
Answer: I think there is no way to do this in one line because it will print all the coordinates in one line, so you will need extra lines to arrange them in a grid but you can use this code :
let=["A","B","C","D","E","F","G","H"]
num=[1,2,3,4,5,6,7,8]

for i in num:
    x=""
    for k in let:
        x+=k+str(i)+" "
    print(x)

Answer: I think some compromises need to be taken... single line + "print comprehension"... is quite unpythonic. The main problem to your question, to impose conditions on print parameters, is a bit hard because the parameters are not callables.... Here just some examples of usage.
Construct a single string with \n and without optional print parameters.
let=["A","B","C","D","E","F","G","H"]
num=[1,2,3,4,5,6,7,8]

# for layout
col_sep, coords_sep = ' ', ''

print('\n'.join(col_sep.join(f'{i}{coords_sep}{j}' for i in let) for j in num))

Construct a list of strings, with optional print parameters
lst = [col_sep.join(f'{i}{coords_sep}{j}' for i in let) for j in num]
print(*lst, sep='\n')

With conditions on print parameters
The result should be properly design to make use of a "conditional" end parameter: construct out of the two given lists a flat list and then use modulo-arithmetic:
lst = ' '.join(col_sep.join(f'{i}{j}' for i in let) for j in num).split()
[print(term, end=(lambda x: ' ' if i % len(num) else '\n')(i)) for i, term in enumerate(lst, 1)]

lambda-part can be also replaced with end=' ' if i % len(num) else '\n'


Ubuntu for netbooks

Question: I just bought a new toy an Asus EEE 1015PN. I have no experience with ubuntu but I wish to learn to use it. I wish to hear your advice.
optional & off-topic: I didn't dig the subject, but is android a valid choice for me?
Answer: As it's a netbook, I suggest you to try the Ubuntu Netbook edition. The page I'm linking to has a detailed guide with screenshots on installing it. All you need is a spare USB stick with at least 2GB space.
I suggest you to Try ubuntu before actually installing it. In that way, you can see if it really fits your need.
Answer: Since the askubuntu site is for objective questions and answers, you should get more advices at a forum like this http://ubuntuforums.org/
At FAQ you can read what kind of questions are expected here:

You should only ask practical,
  answerable questions based on actual
  problems that you face. Chatty,
  open-ended questions diminish the
  usefulness of our site and push other
  questions off the front page. To
  prevent your question from being
  flagged and possibly removed, avoid
  asking subjective questions where …
Answer: Go for it Dole! I own a very similar netbook (Asus EeePC 1005PE), and Ubuntu Netbook Edition (10.04 LTS) was my first experience with Linux. It was love at first sight with its amazing netbook-oriented interface.  You will see how great it optimizes space, and how superior it is when comparing to Windows when it comes to small 10" screens.
I have mine dual-booting with factory-installed Windows 7 Starter... but... to be honest, in 10 months using it i may have booted Windows like 5 times only.
And remember that with Ubuntu, you dont have a limited, "starter" edition. You a full fledged OS, complete with all software including an (Open-)Office Suite.
I would suggest 10.04 Lucid Lynx over 10.10 Maverick Merrkat on 2 reasons:

10.04 is an LTS (Long-Term Support) version. Meaning support and updates for it will last longer (3 years) than the regular version 10.10 (1.5 years). Also, it (usually) have more stable packages, less experimental software. Its built to last longer and be more trouble-free.
10.10 lanched a whole new revamped interface. Some loved it, some hated it. But all agree that its very different from what most people are used to. So, coming from Windows world, i guess you might feel more "confortable"  with the more "traditional" 10.04 laucher.

Both have amazing hardware suppport for Asus EeePCs. You will find that most (if not all) FN+Keys will be working out-ot-the-box. So as Wireless, LAN, Sound, 3d-Video, Webcam, Microphone, etc. And the greatest: no need to install ANY driver! No more "go to device website and download or install setup CDs" anymore!
For netbooks, specially Asus EeePC ones, its a great choice, one I recommended whole-heartedly.
That said, here it is:
http://www.ubuntu.com/netbook

Ubuntu for netbooks


How do I acquire more convoys?

Question: In Assassin's Creed 3, you have the option of sending out convoys loaded with goods for sale.
I'm lead to believe that this should be your primary means of income as you roam the frontier and kill defenseless animals for the sake of profit. I've seen this question about what to do when a convoy is under attack, but it doesn't indicate what to do after the fact.
Unfortunately, I was unable to make it to my convoy in time to prevent the attack, and now my convoy is completely lost. A look at my ledger shows that I currently have no convoys available. This has put me in a bit of a financial bind.
How can I get more convoys if, and when, I lose the one(s) I currently have?
Comment: Not an answer but I found that convoys felt like a waste of time. The ship convoys seemed to be more profitable (especially with the low risk once you'd done the naval missions) since the value of items seemed very high when selling that way but the land convoys seemed to be not that much return on investment (price of sale not much more than price of production). I found hunting and skinning (getting perfect pelts of course) to be a much better way to make money but it may be because I enjoyed hunting animals.
Comment: @Chris Don't you have to convoy to sell those pelts? Or can I just go to any store?
Comment: any store will buy them direct. Though no idea of the difference in profits by convoying them vs selling direct.
Answer: You can build more convoys once you get access the the estate ledger.
At the accounting book , you can craft another caravan. Cheaply. First, go to your stock pile. You should see a list with categories on the right, and one of them will be labeled "forest." Buy 1 oak lumber and 1 oak bark, and then go to the crafting menu.
You will see something that says recipies. Press it, and it will lead you to another list. Go to the category that says "special items." From there, if you scroll right, you will eventually find an item that says land convoy. Then, just craft it.
You can have a maximum of three convoys at any time.
Comment: You also build the naval convoys this way though I'm not 100% sure when they open up (I suspect I didn't see them for some time). I suspect it may just be when you get access to naval stuff.
Answer: It's very easy to make another convoy. Just go to the guy that's taking care of you, and he will help you with supplies and a few men, but the rest would be on your own.
Comment: "with supplies and a few men" what?  Also Achilles only sets you up with your first convoy.  If it gets destroyed you have to build another..

How do I acquire more convoys?


Let $S$ be a subgroup of the group $\mathbb{Z}$. Then $S = \{ 0 \}$, else $S = \mathbb{Z}a$ with $a = \min\{ j \in S : j \in \mathbb{Z}^{+} \}.$

Question: I was reading Group Theory and I got this theorem. This is my proof:

$\blacksquare~$Theorem: Let $S$ be a subgroup of the group $\mathbb{Z}$. Then

Either $S$ is the trivial subgroup $\{ 0 \}$,

or else,

it has the form $ \mathbb{Z} a $, where $a$ is the smallest positive integer in $S$.

$\blacksquare~$Proof: We can break the problem into two cases.

Case I: When  $0 \in S $ and $\{0\}~$ is the only element of $S$ .

Proof: We can easily solve the issue as $\{0\}$ is the trivial subgroup of any additive group.

Case II: When $o( S ) < \infty $ but it contains other elements except $\{0\}$ too.

Proof: Let  $n$ $\in$ $ S $ , then $ (- n) $ $\in$ $ S $.
Again, $ a \in S$ and $a$ is the smallest positive integer to be in $S$.

$\circ \circ~$ Let us prove at first, $\mathbb{Z}a$ $ \subseteq $ $ S $.
Then, we take an element $ n \in \mathbb{Z}a$. Therefore the element $ n $ has a form like $ n = ka $ for some $ k \in \mathbb{Z}$. Now, $ ka = \underbrace{a + a + a + \cdots + a}_k $.
Therefore, we have our result, by inducton, as $ a \in S$ $\Rightarrow$ $ ka \in S $ $\Rightarrow$ $ ( -ka ) \in  S.$
Therefore we have, $ \forall $ $ n \in \mathbb{Z}a $, $ n \in S $, from which we have shown, $\mathbb{Z}a$ $\subseteq$ $ S $.
$\circ \circ~$ Let us then show the reverse one, i.e. $ S $ $ \subseteq $ $\mathbb{Z}a$.
For this case let us take $ m \in S$. Therefore, by Euclidian Algorithm, we have the following ,
\begin{equation*}
    m = qa + r \quad [ 0 \leqslant r < a ]
\end{equation*}
Again, we know that, $\mathbb{Z}a$ $\subseteq$ $ S $. Then, we have, $qa \in S$.
Therefore , we obtain the follwing -
\begin{equation*}
    r = m - qa
\end{equation*}
And  $ m , qa \in S $ . Then , we have that , $ ( m - qa ) \in S $ implying, $ r \in S $ contradicting the fact $ a \in S$ and $a$ is the smallest positive integer to be in $S$. Therefore $ r = 0 $, which tells us that, $ m = qa $.
Therefore we have proved that, $ S $ $ \subseteq $ $\mathbb{Z}a$ .
Therefore, we have from our two results,  $ S $ $ = $ $\mathbb{Z}a$ . And hence we are done!
We need to see the following example and understand some of our elementary number theory problems in light of group theory!

$\S .$ Extension of the Theorem:
$\bullet~$Proposition: Let $a , b$ be both integers and not both zero, and let the subgroup $S$ = $ \mathbb{Z}a + \mathbb{Z}b$ generated by $a$ and $b$ , and from previous theorem we know that, the subgroup $S $ can be represented as $\mathbb{Z}d $ where $d = \text{gcd} (a, b) $. Then-

a) $d$ divides $ a  ~\&~  b $.

b) If any $ e \in S $ divides both $ a ~\&~ b $ , then it must divide $ d $ also.

c) The integer $ d $ , can be written as -
\begin{equation*}
    d = ra + sb
\end{equation*}
for some $ r , s \in \mathbb{Z}$ [ Bezout's Theorem in Elementary Number Theory ].

$\bullet~$Proof: We see that, if $S$ is not the trivial subgroup of $\mathbb{Z}^{+}$ then, we can construct an additive group $\mathbb{Z}d$ generated by $d$ such that,
\begin{equation*}
    \mathbb{Z}d = \mathbb{Z}a + \mathbb{Z}b
\end{equation*}
Again we know that, $a \in S$ and $b \in S$ and $S = \mathbb{Z}d $. Which directly implies that, $d | a  $ and $d | b  \quad \quad  \cdots \cdots$ (a)
Again, if $ e \in S $, then, we have from (c)
\begin{align*}
    d = ka + sb,
\end{align*}
which implies $e \lvert d$.

Are there any glitches in the respective proofs?
Thanks
Comment: I was using Dummit and Foote and Artin.
Comment: Which textbook are you using?
Comment: Certainly you mean $S$ is a subgroup of $\mathbb{Z}$, and $a \in \mathbb{Z}^+$?
Comment: I'm not sure what $\mathbb Z^+$ is, but if it's the positive integers, then it is certainly not an additive group, as there are neither inverses nor an identity element.
Comment: Yeah! I edited it @Carlo
Comment: I am not sure what $o(S)$ is, but otherwise, it looks fine.
Comment: @Carlo $o(g)$ is the order of the element $g$. And similarly, $o(S)$ is the order of the group $S.$ I know it's also denoted by $\lvert S \rvert$. :)
Answer: You can do it faster. If $S$ isn't the trivial group (i.e. $S \neq \{ 0 \}$) then if $a = \min(S \cap \Bbb{Z}^+)$, clearly $S \supseteq \Bbb{Z}a$. (We know a nontrivial additive subgroup of the integers must contain a positive number because it is closed under additive inverses.) If there exists $b \in S, b \not \in \Bbb{Z}a$ then as you say, $S$ contains the positive number $c = \gcd(a, |b|) < a$, contradicting the fact that $a$ is the smallest positive element of $S$. QED.
Answer: A group presentation for $\Bbb Z$ is
$$\langle r\mid \varnothing\rangle.$$
This is because $\Bbb Z$ is cyclic, infinite, and generated by $1$, so all integer multiples (or, as in the presentation, all powers) of $1$ are in $\Bbb Z$ (or of $r$); presentations are usually multiplicative, but, here, by abuse of notation, we can consider $r=1$.
Let $S\le G$. Then $S\neq\varnothing$, since $0\in S$.
The trivial group is always (isomorphic to a copy of) a subgroup of any group, so let's suppose there is some $s\in S$ such that $s\neq 0$. Since $\Bbb Z$ is cyclic, $s$ is an integer multiple (or "power") of $r$, say, $s=rk$ for some $k\in \Bbb Z$. But the order of $r$ is infinite and, by closure of $S$, all multiples of $s$ are in $S$; and if some multiple $\ell$ of $s$ is the identity $0$, then $\ell=r(kt)$ for some $t\in\Bbb Z$, so that
$$\underbrace{r+\dots+r}_{kt \,\text{ times}}=0,$$
a contradiction.
Thus the order of $S$ cannot be finite (unless it is trivial).

Lemma: All subgroups of a cyclic group are cyclic.

Proof: (See here.) "$\square$".
Thus $S$ is infinite and cyclic. Hence $S\cong \Bbb Z$.
Such a subgroup $S$ of $\Bbb Z$ is necessarily, then, a group of all multiples of some multiple $s$ of $r$, using the notation above; that is, $$S=\Bbb Zs:=\{zs\mid z\in\Bbb Z\}$$ under addition. WLOG, as you have shown, we may assume $s>0$. Suppose, further, that $s$ is not the minimal positive multiple of $r$ in $S$, that, instead, there exists some $x\in S$ with $0<x<s$. But then, since $S=\Bbb Zs$, we have $x=ys$ for some $y\in\Bbb N$, which cannot be done as $0<ys<s$ implies $0<y<1$.
The result follows.

Your proof of the proposition is flawed, since $(c)$ is not proven.
Comment: Ah, right, I understand now.
Comment: Your proof that $S=\mathbb{Z}s$ seems cyclic (you say "since $S=\mathbb{Z}s$...". Also, it would be more clear if you stated that $s$ is the generator of $S$ (this is implicit in what you said, but is worth making explicit).
Comment: Thank you for the feedback, @user1729. My use of "since $S=\Bbb Z s$  . . ." is not in proving $S=\Bbb Z$; I had already stated that $S$ is necessarily the set of all multiples/powers of $r$. What I was aiming to prove is that $s$ is minimal.


Using transform:rotate in % animation css

Question: I have an animation which should rotate 360 degrees 50% into the animation, but it's not working.
.w11 {
top:9px; font-
size:50px; color: black; opacity: 0.5;}

.w11 {animation: movefirst
12s linear infinite;
animation-direction:
alternate-reverse;
position: relative;}

@keyframes movefirst {0%
{left:23px;}50%
{transform:rotateX(3
60deg);}
100%{left:200px;}}

e

Answer: It works, you just had some extra space typos in your code.

.w11 {
  position: relative;
  top: 9px;
  font-size:50px;
  opacity: 0.5;
  animation: movefirst 12s linear infinite;
  animation-direction: alternate-reverse;
}

@keyframes movefirst {
  0% {
    left: 23px;
  }
  50% {
    transform: rotateX(360deg);
  }
  100% {
    left: 200px;
  }
}

e


difficulty in building ffmpeg for windows

Question: I am making an app in which i want to use ffmpeg library.I have successfully compiled the library in windows,but i have not seen the ffmpeg.so,but i got the ffmpeg.exe file.Can you please tell me how to do it?
Comment: "for windows" and "android" tag + .so? Clean this mess up a bit please
Comment: Any help will be appreciated.
Answer: You can use ffmpeg.exe path. If you are creating video image through ffmpeg then use this code:
    function create_video_image_only($v_file,$thumb) {
$cmd = 'C:\inetpub\vhosts\domain-name\httpdocs\ffmpeg\bin\ffmpeg.exe -itsoffset -4 -i "'.$v_file.'" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 105x74 "'.UP_FILES_FS_PATH.'/image_video/'.$thumb.'.jpg"' ;
exec($cmd);

}
Comment: Sir actually i want to know that how to make the ffmpeg.so file.I have just got ffmpeg.exe after compilation of ffmpeg lib.
Answer: If you want to build .DLLs and link to them (this is what .SOs are in Windows world), then you appear to not built the binaries successfully yet.
The key is to use --enable-shared configuration setting when building, so that your output includes libavcodec.dll and its cousins.
You don't have to build on your own, Zeranoe already has prebuilt binaries: "Shared" are those DLL/SOs, and "Dev" are static libraries to link into your project to make a connection between your code and FFmpeg built separately.


d3 scatterplot Labels

Question: i'm new to d3 and frontend
Could you look and tell on my axis max values aren't shown? like no year 2015 or no 39.50 on Y scale even tho d3.max sees them in array.
https://codepen.io/DeanWinchester88/pen/QWgGMja
const xScale = d3.scaleLinear()
                      .domain([ d3.min(years), d3.max(years)  ])
                      .range([paddings.paddingLeft,w - paddings.paddingRight - paddings.paddingLeft]);
      const xAxis = d3.axisBottom(xScale).tickFormat(d3.format("d"));
      svg.append("g")
                     .attr("transform", "translate(0," + (h - paddings.paddingLeft) + ")")
                      .attr("id","x-axis")
                      .call(xAxis);
  const yScale = d3.scaleLinear()
                      .domain([ parseInt(d3.min(timings)), parseInt(d3.max(timings))])
                      .range([h - paddings.paddingBottom, paddings.paddingTop]);
  const yAxis = d3.axisLeft(yScale).tickFormat( (d) =>  `(${d.toFixed(2)}`);
      svg.append("g")
       .attr("transform", "translate(" + paddings.paddingLeft + ",0)")
        .attr("id","y-axis")
       .call(yAxis)

Comment: The reason your y axis stops before 39.5 (regardless of ticks) is that you use parseInt which gives your scale a different domain than you think. The ticks in the axis are based on both number of ticks and roundness of value, if you want to override these you can use axis.tickValues, I can't find an answer to this effect right now and am out the door, but will take a second look later today.
Comment: well scale X with years doesn't have parse and still i see no year 2015
Answer: As noted in the comments there is an issue with how you parse the domain for the y axis: by using parseInt you don't capture the full domain. This only affects how far the axis line extends, not whether ticks capture the entire domain.
Default Ticks
As for the ticks, a D3 axis prioritizes clean numbers and an ideal number of ticks (by default 10 if I remember right - though the number is more of a suggestion than constraint). Also, the axis generator does not consider the rendered size of the axis.
If we have a domain from 1.999 through 9.999 we'll see that our ticks are 2,3,4,5,6,7,8,9, prioritizing both count and roundness as noted above:

var scale = d3.scaleLinear()
  .domain([1.999,9.999])
  .range([20,290])

console.log(scale.ticks());

d3.select("body")
  .append("svg")
  .attr("transform","translate(0,50)")
  .call(d3.axisBottom(scale));

The axis extends to 9.999, just that this is beyond the last tick, which does look a bit odd
While this is cleaner than ticks of 1.999, 2.999, 3.999... in both terms of number and amount of text, it doesn't show the extent of the domain.
In some cases increasing the number of ticks (axis.ticks(idealNumberOfTicks)) will result in the desired outcome, this may be true when dealing with domains that consist of something like integers representing years, as in your case: .ticks(d3.max(years)-d3.min(years));, which should create ticks for every year since the integers are considered suitable round numbers given the desired count of ticks.
Specifying Specific Ticks
We can specify values to be used as ticks with axis.tickValues([values]), which will set the ticks used in the axis. In the case of your years axis, this is fairly straightforward, we'd want a tick for every unique year, so we'd only need to create an array that contains each year:
 .tickValues(d3.range(d3.min(years),d3.max(years)));

It isn't always this straight forward. Using the example scale in the snippet above (more analogous to your y scale), we could use the ticks provided by scale.ticks() and add two new ticks but this means there is a high likelihood of overlap or irregular spacing when combining manual ticks with the automatically generated ticks:

var scale = d3.scaleLinear()
  .domain([1.999,9.999])
  .range([20,290])

var ticks = [1.999,...scale.ticks(),9.999];

var axis = d3.axisBottom(scale)
  .tickValues(ticks)
  .tickFormat(d3.format(".3f"))

var svg  = d3.select("body")
  .append("svg")
  .attr("transform","translate(0,60)")
  .call(axis);

We could make this more complicated to better set the tick values, but it'll be very data dependent, often result in non-round tick values, and is likely better resolved by using scale.nice(), described below.
One other option if discarding the automatically generated ticks, especially when dealing with times or dates, is to use d3.time to require a tick every specified interval, as noted in the d3-axis docs with the example: axis.ticks(d3.timeMinute.every(15));. However, this doesn't set ticks so that they contain the entire domain.
scale.nice()
There is a better option than manually adding or overriding the automatic ticks however, and this is using scale.nice(), which:

Extends the domain so that it starts and ends on nice round values.
This method typically modifies the scale's domain, and may only extend
the bounds to the nearest round value. An optional tick count argument
allows greater control over the step size used to extend the bounds,
guaranteeing that the returned ticks will exactly cover the domain.
Nicing is useful if the domain is computed from data, say using
extent, and may be irregular. For example, for a domain of [0.201479…,
0.996679…], a nice domain might be [0.2, 1.0]. If the domain has more than two values, nicing the domain only affects the first and last
value. (docs)

Taking our example from above we get:

var scale = d3.scaleLinear()
  .domain([1.999,9.999])
  .range([20,290])
  .nice()

console.log(scale.ticks());

d3.select("body")
  .append("svg")
  .attr("transform","translate(0,50)")
  .call(d3.axisBottom(scale));

This is the solution I'd offer for your y scale, while specifying specific ticks or using axis.ticks() to specify a number of ticks is ideal for your x axis.
Comment: wow.thank you. I undestood but then i try to apply i have even more weird values on scale. https://codepen.io/DeanWinchester88/pen/QWgGMja

d3 scatterplot Labels


Connecting from a SignalR client to a Spring websockets backend

Question: I have a client-server application written in .Net. The client connects to a SignalR hub in the backend service using the SignalR client.
In the next few months I'm going to be migrating my backend service from .Net to Java and Spring boot.
I have to maintain backwards compatibility for my clients.
My question is, is it possible to connect from a SignalR client to a non-SignalR websockets server?
Answer: Sure it's possible. But it wouldn't be easy. You would need to implement the SignalR protocol on the server yourself. It is documented at https://github.com/aspnet/AspNetCore/tree/master/src/SignalR/docs/specs.
Comment: Are you familiar with an existing open source implementation?
Comment: Yeah, the .NET implementation
https://github.com/aspnet/AspNetCore/tree/master/src/SignalR/server


A problem about sets

Question: Given set $X$, does there exist sets A and B that are subsets of $X \times X $ (Descartes product) and satisfy the following condition:
$A \cup B = X \times X$
for every a $\in X$, $(\{a\} \times X) \cap$ A is finite, for every $b \in X$, $(X \times \{b\}) \cap B$ is finite.
Consider $X$ as finite set, the problem is trivial.
Consider $X$ as countable set, the answer is "yes". we can arrange the elements in $X$ as a sequence {$x_n$},and we take $A =\{(x_i,x_j), i \leq j\}$, $B = \{(x_i,x_j), j \leq i\}$.
Does this hold for arbitrary sets?
Comment: What do you mean when you say "limited"?
Comment: Sorry, I mean "finite".
Comment: Sorry, it's a mistake.
Comment: What is your question?
Comment: For an arbitrary set X, does it exist sets A and B of this kind?  I can only solve when X is finite or countable.
Answer: The statement is not true for uncountable sets, here is a proof by contradiction.
Let $X$ be an uncountable set. Let $a_n$ be a countably infinite sequence of points in $X$. For each $a_i$, the set of points of the form ($a_i$,$x$) is finite in $A$. So for each $a_i$ there are uncountably many points of the form ($a_i$,$x$) in $B$.
Now as there are finitely many points $x_j$ in $X$ for which ($a_i$,$x_j$) belongs to $A$ for each $a_i$, and $X$ is uncountable, hence there will be some point $y \in X$ such that ($a_i$,$y$) does not belong to $A$ for any $a_i$. So ($a_i$,$y$) belongs to $B$ for all $a_i$, a contradiction.
Answer: It's not possible for $X = \omega_1$. For all $n \in \omega$ let $s_n$ be the maximum $s$ such that $(n,s) \in A$. This is a countable set, so it can't be cofinal in $\omega_1$. So there is some $s'$ bigger than all of them. So for all $n \in \omega$, $(n,s') \in B$.

A problem about sets


How can I change the cursor in vim depending if I'm in insert mode or normal mode?

Question: I'm used to working on GVim, but I want to make most of vim+tmux too. Therefore I have decided to switch to vim. But in vim the cursor style does not change depending on the mode.
I use zsh and gnome terminal.
I have tried this answer: How to make cursor change from thin line to block based on normal or insert mode in Console Vim on Gnome Terminal
<code>if has("autocmd")
  au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
  au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
  au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
endif
</code>
but it changes the cursor globally.
I have also tried this plugin, but it hasn't worked either. (How can I check if the plugin is working?)
Comment: According to [the current docs of that plugin](https://github.com/jszakmeister/vim-togglecursor/blob/master/doc/togglecursor.txt#L26), it needs VTE > 0.39, which is not available for [any version of Ubuntu](http://packages.ubuntu.com/search?keywords=libvte9).  Can you try with any of the other terminal emulators mentioned (`rxvt`, `konsole`)?
Comment: Please don't cross-post questions; you already asked it here http://stackoverflow.com/q/34251566/1439843
Comment: See [this](http://vim.wikia.com/wiki/Configuring_the_cursor) , "Comments "section, after "See also"
Comment: I'm voting to close this question as off-topic because it [has been posted](http://stackoverflow.com/q/34251566/1081936) (and answered) on another site in the SE network.
Comment: See http://stackoverflow.com/a/42118416/52817
Answer: Two different options are listed here:

https://stackoverflow.com/questions/34251566/how-can-i-change-the-cursor-style-in-vim-depending-if-im-in-insert-mode-or-norm
https://stackoverflow.com/questions/6488683/how-do-i-change-the-vim-cursor-in-insert-normal-mode

.vimrc files with good comments will help you too, e.g. https://github.com/thoughtbot/dotfiles/blob/master/vimrc
Comment: While your answer is valid, you should provide the steps here, links and their content can change and then your answer would be a dead end. You still can refer the links as sources.
Comment: @Videonauth sorry, I was not sure if it could be a duplicate if the question were asked on a site of the same network - so I choose to put the links. I'm waiting 15rep to be able to comment instead of answering.
Comment: @ponsfrilus It's  a cross-post, the first question you link is also asked by Jonas, and it (sort of) duplicates the second question you linked. So I flagged for duplicate at SO, and asked for moderator attention on this question.
Comment: yes, I am sorry for that. At the time of posting I did not know those websites are so well connected. I just thought I ask at two places to reach out to more people.
Comment: @Jonas No problem, it can happen ;)


$(r \wedge \neg s) \rightarrow \neg q$

Question: Answers provided at this link do not satify my question.
How can this English sentence be translated into a logical expression?
In Kenneth Rosan, the answer to this following sentence

"You cannot ride the roller coaster if you are under 4 feet tall unless you are older than 16 years old."

is given as,

$(r \wedge \neg s) \rightarrow \neg q$

Where,
q: "You can ride the roller coaster."
r: "You are under 4 feet tall."
s: " You are older than 16 years old."

My solution:
So, I broke down this compound sentence as follows:

"[You cannot ride the roller coaster] if [you are under 4 feet tall] unless [you are older than 16 years old.]"

Now, substituting variables in given compound sentence.

($\neg q$) if (r unless s).

Applying equivalence formula for Q if P $\Leftrightarrow$ P $\to$ Q

(r unless s) $\to$ ($\neg q$)

Now, solving for unless. So, (r unless s) $\Leftrightarrow$ ($\neg s \to r$) ref.

($\neg s \to r$) $\to$ ($\neg q$)

Again solving for $\to$ (implication), we get:

(s $\lor$ r) $\to$ ($\neg q$)

So, my derivation is obviously wrong and does not match with Kennet Rosen.

My Question: What mistake I did? and How to derive the given answer systematically?
Answer: As noted by Jay, Kenneth Rosen interprets (r unless s) according to:
$$
\begin{array}{cc|c}
r & s & (r \text{ unless } s) \Leftrightarrow (\neg s \to r) \\\hline
0 & 0 &  0 \\
0 & 1 &  1 \\
1 & 0 &  1 \\
1 & 1 &  1 \\
\end{array}
$$
The issue turns out to be the order of operations for "unless".
You started by breaking it up like this

"[You cannot ride the roller coaster] if [you are under 4 feet tall] unless [you are older than 16 years old.]"

And substituted variables to get:

($\neg q$) if ($r$ unless $s$).

If instead we use a different order of operations to group these, it works out with your definition of unless.  That is, we have:

$((\neg q) \mathbf{\text{ if }} r) \mathbf{\text{ unless }} s$

Now using $(P \mathbf{\text{ if }} Q) \Leftrightarrow (Q \to P)$

$(r \to \neg q) \mathbf{\text{ unless }} s$

Now using your $(P \mathbf{\text{ unless }} Q) \Leftrightarrow (\neg P \to Q)$

$\neg s \to (r \to \neg q)$

expanding

$\neg s \to (\neg r \lor \neg q)$

expanding

$s \lor (\neg r \lor \neg q)$

This is the same as the other result.
To see this, use associativity of logical or

$(s \lor \neg r) \lor \neg q$

Then turn it into an implication

$\neg(s \lor \neg r) \to \neg q$

Use demorgan's law

$(\neg s \land r) \to \neg q$

(EDIT: Previously I arrived at the answer with the same order of operations, but a different interpretation of unless: $(r \text{ unless } s) = (r \text{ and } \neg s)$. Because "(anything) unless True = True" seriously sounds wrong to me. My interpretation of unless worked in this case, but apparently is not the correct english interpretation. Apologies.)
Comment: For this reason, we are going to translate 'P unless Q' with just ¬Q → P unless stated
otherwise from [rpi.edu](http://www.cogsci.rpi.edu/~heuveb/teaching/Logic/CompLogic/Web/Presentations/PropLogicReview.pdf)
Comment: Also, what formula you assumed for "r unless s"?
Comment: @Ubihatt I used no formula. I filled it out how I interpret the phrase in english. So it appears this may just be a natural language ambiguity if you interpret it otherwise.
Comment: Kenneth Rosen also has formula for **unless** which exactly matches with formula embedded in my previous comment.  Please check. **Unless** is a keyword.
Comment: Interpreting "P unless Q" = "¬Q → P", would mean "You cannot ride the roller coaster if you are under 4 feet tall unless you are older than 16 years old." says you cannot ride the roller coaster if you are older than 16 years old, no matter what your height is. Is that really how you interpret that phrase?
Comment: Please refer this [uidaho.edu](https://www.webpages.uidaho.edu/~morourke/202-phil/11-Fall/Handouts/Philosophical/Unless.htm) It conveys my thought.
Comment: @Ubihatt I figured out how to get it to work with that interpretation of unless. It is an order of operations issue.
Comment: Little thing that irks me is how to decide between (($\neg q$ **if** $r$) **unless** $s$) and ($\neg q$) **if** (r **unless** s). How the order to precedence works?!?
Comment: @Ubihatt I think that is a good question, but since I initially interpreted the sentence incorrectly myself (but just happened to get the same final answer), I'm not sure. I guess I need to read some logic books myself.
Answer: The mistake is to interpret the sentence as $$(\neg q)\ \textbf{if}\ (r\ \textbf{unless}\ s)$$
The correct interpretation is $$  (\neg q\ \textbf{if}\ r)\ \textbf{unless}\ s$$
Comment: You beat me to the punch =) Nicely done.
Answer: I have a discrete math book by Kenneth Rosen, and here is an excerpt from the book listing the equivalent ways to express $p \implies q$ in English. The one you mentioned is boxed in blue.

But where did you go wrong? I believe it was at this step

Now, substituting variables in given compound sentence.
  ($\neg q$) if (r unless s).

The word unless does not attach $s$ to $r$; it attaches $s$ with the proposition $\neg q$ if $r$. The reason for this is that there was a proposition established prior to unless, which was the statement, "You cannot ride the roller coaster if you are under 4 feet tall." That sentence is established as a proposition; it is the $q$ in the table I provided.
So the correct statement using your scheme is
$$\big( \, \neg q \, \textbf{ if }  \, r \, \big) \, \textbf{ unless } \, s,$$
which is equivalent to
$$\neg s \implies (r \implies \neg q).$$
Can you take it from here?
Comment: I see where you're coming from. I don't think it's your English. I was looking at other sites and papers, and there isn't a consensus as to what "unless" means in general, for it can be construed in different ways in different contexts. This link is particularly helpful as to why in logic this particular convention was adopted: https://math.stackexchange.com/questions/1295106/how-is-p-implies-q-same-as-q-unless-not-p
Comment: You might also be interested in these other links regarding the ambiguity of "unless" outside of mathematics: Reddit: https://www.reddit.com/r/askphilosophy/comments/52585m/interpreting_the_word_unless_in_symbolic_logic/

and a linguistic paper: http://web.stanford.edu/~danlass/Nadathur-Lassiter-unless-SuB.pdf
Comment: As you saw, I initially interpreted unless differently, and just happened to get the right answer erroneously. So I learned something here too. But I'm struggling how "True unless True" evaluates to True.  "The dog is angry unless the dog is fed".  If the dog is angry and the dog is fed, I would interpret that as false.  Is my english screwed up, or what am I missing?
Comment: Maybe what you're missing is that $F \implies T$ is true (similarly, $F \implies F$ is true). "The dog is angry unless the dog is fed," which is the same as "If the dog is not fed, then the dog is angry." If the dog is indeed fed, then the statement "the dog is not fed" is false, of course. But then the statement "If the dog is not fed, then the dog is angry" is actually a true statement (a false hypothesis can be used to derive any conclusion). The only way the statement could be false is when the dog is not fed, but the dog is not angry. Does that help?
Comment: To add to what I said, "True unless True" is equivalent to "False implies True," which is a  true statement, per the definition of "implies" that we have agreed to adopt. We have agreed that $p \implies q$ is false if and only if $p$ is true and $q$ is false, and $p \implies q$ is true otherwise.
Comment: @HBrown Here is a link that could elucidate this topic, if indeed my interpretation was your correct intention: https://math.stackexchange.com/questions/1583209/false-implies-true-is-a-true-statement/1583244
Comment: I understand how implications work. I can see that "If the dog is not fed, then the dog is angry" does not give us any information if the dog _is_ fed, and so the dog could be angry or not in that case and the statement is holds true. But to me (again, maybe my english is screwed up), "The dog is angry unless the dog is fed" says more. To me I would interpret that statement as "false" if "the dog is fed" and "the dog is angry".
Comment: I've come up with other examples with "unless", and I interpret them slightly different based on context, so I guess my english is just sloppy. Wow. This is crazy I've never noticed this til today. Now I'm curious to ask a bunch of engineering friends versus math friends and see how they interpret the english phrases.
Comment: Fascinating. Thanks for all the follow up links.
Comment: You're welcome. Good luck.

$(r \wedge \neg s) \rightarrow \neg q$


Double buffering always necessary?

Question: Question from the graphics newbie:
What I know by now is that "usually" double buffering is used: You calculate the content of frame x+1 while frame x is shown on the screen, if you want to achieve the maximum update rate, calculation must not take longer than one frame time, otherwise the "drawing process" is visible.
So, having two framebuffers absolutely makes sense, and I guess that's why we have that "glfwSwapBuffers" call in some OpenGL tutorials.
But what if I program my things in a way that every primitive leads to fragments that are horizontal lines, and let the GPU process it from top to bottom line "on the fly"?
In this case I would need only one framebuffer that could be filled with a static background, and I would only have to store the other objects in some much smaller memory.
Is this possible at all?
Is there even any GPU implementation that does it that way to save memory?
Comment: Just as an aside, sometimes, if you have the memory to spare, triple buffering is used. This allows more flexibility in the rendering rate. Imagine you are targeting 60Hz but occasionally the renderer takes > 1/60th of a second. With double buffering, this would cause a dip to 30Hz. Triple buffering allows the update rate to remain more stable but at the price of more latency.
Answer: Indeed there are/were 'just in time' renderers.
For example, Dreamcast (PowerVR CLX2) had a mode where the 'frame buffer' only had to be a few rows of tiles in size. The system would be rendering into one row while the display was reading out of some subset of the others. It would then cycle through the buffers.
In order to do this, however, you do need a display-list rendering system. A standard 'immediate mode' renderer is not appropriate.
Of course, scene complexity needs to be considered carefully for this sort of scheme to work. In particular, if one tiny section of the screen contains particularly complex geometry, the renderer might not finish it in time before the display needs to read it. Allocating more memory for the partial screen buffer allows for more variability in scene complexity.
I also have a feeling/seem to recall some old (e.g 60s/70s?) flight simulators might have rendered 'on the fly' because memory (for a frame buffer) was once fiendishly expensive.
Alternatively, the PowerVR PCX1/PXC2 ports of Tomb Raider had an optional single buffered rendering mode. (This was primarily because one of the guys doing the port (cough, me, cough) only had a 2MB 2D graphics card which could only allocate a single 1024x768 framebuffer).  Again, since the system was tile-based, it didn't suffer from the nasty artefacts you'd get with single buffering on a traditional Z-buffer system.
UPDATE:
FWIW there's another related question on "Racing the Beam" here
Comment: Another interesting reference: Frameless Rendering: Double Buffering Considered Harmful, Bishop et al, SIGGRAPH '94.

Double buffering always necessary?