How to survive Dragon Age: Inquisition combat on Nightmare difficulty?

Question: I tried using two mages and two warriors for my party. However I have realized that my mage character is more offensive with her spells than using supportive spells for my party. I am thinking about resetting my stats again for $400 gold, so my mage is more supportive to the party? Nightmare difficultly has proven to be very punishing for tactical failure. I want to improve my party's abilities, and tactics, but I do not know where to go for help.
How does anyone survive dragon age inquisition combat on nightmare difficulty? Is it dependent on a specific character class?
Answer: Well, I made my way to Skyhold around the 20 hour mark, and that's when combat became a hell of a lot easier. Prior to that, I had to abuse the hell out of the tactical camera on some fights. Once I got specializations unlocked though, even Nightmare was a cakewalk. My setup was as follows: Sword and Board Champion Inquisitor, 2H Cassandra, Vivienne, and Archer Cole.
By making myself the tank, I was able to have much more control over the fight than I would by just leaving an A.I. to tank. The Tactical camera is broken, so I only used it to pace fights in the start of the game. Using the tactical camera past that was just redundant, since it glitches out constantly, and won't let you move your characters where you can actually move them. I noticed more often than not, if I moved a ranged character to a vantage point, and went into tac-cam, I would be kicked off of the vantage point because the game thought I shouldn't be allowed up there.
Knight-Enchanter is incredibly overpowered. More often than not, it seemed like I was just 2 manning harder fights with my K.E. and Champion. My Guard never dropped on my Warrior, I'd seldom lose barrier on Viv, Cole usually would stay alive unless it was a dragon fight, because I'd forget to move him during the wing attack. As for Cassandra, she would full-heal the party when she died, with a 60 second cool-down. That same buff also increases the parties damage and damage resistance as well, if I remember correctly. After I equipped her with a crafted piece with the masterwork to give a 15% chance to rez to 50% upon dying, I didn't have to ever rez her with Viv, because that "15%" was 100%. Seriously. She died a good 20 times over the course of one fight, and I didn't rez her a single time with my mage.
In hindsight, I think Solas would have been a better choice than an Archer, but I hate leaving doors unlocked. With Cass in my group, not only did I manage to absolutely destroy all demons/rifts, but when my party was low on health, I could switch to her, sacrifice her to get a full heal on the party, and she'd instantly rez to 50%, I'd say that's a pretty good trade-off. A few times, my tank was the only one left standing on a dragon fight. I would pop damage invulnerability, revive vivienne, get cole and cassandra both up, sacrifice Cassy once again to heal the group and get her to 50% instead of 10% from the revive, and go from there.
Seriously.. Templar and Knight Enchanter in the same party are so broken it's not even funny. By the 30 hour/level 12 mark I was going through Nightmare like it was Casual. I'd go through an entire play session without ever touching a potion. The hardest part about Nightmare difficulty, is getting to Skyhold. After Skyhold, it's a joke if you use a Knight/Enchanter PC or Vivienne, you can solo dragons. Seriously, I've done it.
EDIT: Also, remember, it's not after level 10 that you unlock specializations like some people think, it's as soon as you hit Skyhold. I just unlocked K.E. at level 9.
Comment: Also KE with few points in fire (Clean Burn) can keep Barrier up almost  all the time. I'm also exploiting KE + Templar + Champion + control / support rogue on Nightmare. It's so easy it's almost like cheating.
Answer: What works for me is two mages, archer and shield tank. For the mages, I build them the same. Barrier, flashfire to panic, winters grasp to freeze. Anything that takes an enemy out of combat even for a few seconds, and dispel to get rid of demons when closing rifts before they even spawn.
For rogue, get sleep powder and upgrade ASAP. You can take an enemy out for 20 seconds! Just don't hit him or he wakes up. Then all archer tree. For tank, all the taunts, shield wall.
Don't ever let your mages do things on their own. Disable their abilities in tactics menu. Focus fire all members on one enemy at a time and remember to barrier your tank and always be stunning, freezing or putting things to sleep. With all that CC you shouldn't have too many issues. This is tactical cam heavy so if it's not fun for you then Nightmare is gonna give you issues. Hope this helped.
Answer: I have discovered the following party build that has withstood hordes of rampaging enemies on nightmare difficulty, with no potions, and no health, that can be established at beginning levels. Yes, I said no health.
The most recent test was fighting three wisps, one pure wisp, and three bog-swamp-rhino-bore-rampaging-things, at once, on level 9. I remember Cassandra was bulldozed by those two creatures 30 feet from my party with very little health, yet we survived when I ordered my team to disengage and stand around her, provide protection while she recovered. I think that battle end inside a log cabin, with a battle time of 15 minutes?
My party is two spirit-mages and two shield-warriors with less than 100 armor rating. The shield-warriors are not two-handed warriors, but shield-and-sword warriors.
Here is my theory on why this party is so successful:
The two shield-warriors are specialized in the weapon and shield perk tree and the a little bit of perks in the guard perk tree. All of the perks in those trees help the warriors take tremendous punishment. They also randomly generate guard protection, but I am not sure where that comes from.
The two spirit-mages specialize in all of the spirit support spells, three of the biggest are barrier, dispel, and revival. Barrier protects your two warriors from all damage for a limited time. Dispel removes magical traps created by enemy mages. Revival brings your whole team back to life minus the caster.
The mutual team work occurs when the two shield-warriors taunt the enemy and draw fire from the mages. The mages provide magical defense for the two warriors, and occasionally themselves. Having two warriors doubles the defense against enemies flanking your two mages. Having two mages cuts the defensive spell cool downs in half.
I said no health required. Having two mages with barrier, one can almost spam continuous magical defense on either the two warriors or all four party members. Because the warriors also randomly generate protective guard on top of their health, this combined with the nearly continuous generation of protective barriers decreases the window of damage opportunity to once every 10 to 20 hits. Using my two warriors and two mages party, I was able to restore, dispel, and revive my party through the hairiest battles I would of thought impossible to survive when I first started playing, after I had used all of my potions and everyone's health was at their lowest.
I have also learned additional tactics with this party. The mind blast can interrupt any enemies attack. This is very useful for pausing the lesser-terror-stick-tree-like-screaming-popping-out-of-ground-creatures from stunning your team almost indefinitely. Remember, you have two spirit-mages to spam the mind blast spell. I found myself actually moving the mages closer to, but behind the warriors at all times, so they can utilize the mind blast spell. This turns into an elegant dance of the party, where the warriors attack the current highest property enemy of your choice, and the mages dance around the warriors. Any enemy that tries to target the mages, either becomes taunted by the warriors, or they are mind blasted. It helps to have at least one additional crowd control spell on the mages, such as freeze or shock, but optional. I found battle proximity for the mages is matter of preference for the player. The revival spell is the most devastating weapon in the party. Once the enemy has thrown everything at the party to near exhaustion to kill all but one of the mages, that mage will revive the whole party back, with additional protection from the upgraded revival spell. If the party dies again, you can cast revival a second time with the other mage. This party is a living nightmare for the enemy.
One issue resolved : The barrier spell is double casted automatically by both mages, which waste the opportunity to cast them in chains. I resolved this problem by making sure I was in selection of one of the two mages in the tactical view, which prevents the game from auto-casting the spell, and allowing the other mage to cast the barrier spell automatically.
Disclaimer : The full benefit of this party build requires full use of the tactical view. The smallest window between chain casting barrier with two mages was less than three seconds, but keep in mind that the barrier spell is only one out of many different defensive tools at your disposal, such as: all of the warriors crowd control attacks, the randomly generated warrior guard, the strategic positioning of your team mates to minimize damage from incoming spells and arrows (such as attacking archers first and moving the mages behind the archers), the mind blast spell, and the revival spell.
Additional Disclaimer : This party is not invincible, but it is a die hard party. Because of the 3 second window between chaining barrier spells, there is a possibility that one attack out of ten will kill one of your team mates with no health.
I challenge anyone to try my suggested party build and test if it works or not to what I have written.
Comment: You can disable auto-casting in Behaviours tab of the character - open "spell book" (default P) and switch to said tab, from here find Barrier spell and simply put it on "Disabled" (if I'm not mistaken). You can also disable AI as whole - also in one tab in "spell book", but can't recall the name of it.
Answer: I am playing on Nighmare difficulty, and besides skills, is more of armor and weapons i think. Right now im 35 hours in, just got skyhold, and im having a hard time with the swamps at lvl 10. 2 mages, Varric and my warrior as my main party. The problem is the mages are undergeared and to tell you the truth, is kinda hard on the gap between 10 and 12. Just have some patience to craft the right armors and to gather enough materials.
Dont rush the game and you will have a good time.
Regarding mages , i would sugest having both mages have at least barrier, then spect on any tree u want. Remember that after lvl 10 you get the specializations so plan accordingly, not like me :P
Answer: Nightmare difficulty is it?
I went through Nightmare with three mages and Cass, a lot of the big bad guys have elemental weaknesses that can be abused to make fighting against them easy - Dragons I'm lookin' at you. My set up is with myself as a mage, Knight-Enchanter, Viv and Solas as the mages, though I switch Solas around for Mr.SassyTevinter when fighting dragons with spirit damage weaknesses for his Necromancer tree DOTS, if all have barriers then your enemies will have a hard time doing any damage especially with perks for Viv and my own character that allow damage I do to be added to barrier strength, meaning I can sustain my barrier indefinitely if I avoid getting surrounded and beat on.
Mages are pretty much the bane of bosses, anything with a weakness can be obliterated by them, the hard part is when versing large amounts of little bastards with resistances in which you can't set up on them first (I remember running over to the dragon in the Hinterlands as a mage just to see what the dragon was made of so I could prepare for the fight by making good staffs of their weakness and the lovely energy barrage spell that takes the element of your staff - a must have for me), such as undead and despair demons to cold or Rage demons to fire which is why Spirit damage from the Knight-Enchanter's sword is useful.
So, I think Mages are the best way to go, but I've done nightmare on others.
As far as I can tell, for Rogues abusing the hell out of Crit and Stealth is the best way to go, stealth is also good for running away, as you can run far enough to get your party back up and go back and your enemies will not be replenished, this works for little enemies and groups but not for bosses really, Death Blow is great, large damage with colossal damage on a crit as well as two strikes when an enemy veers near the half health mark and it increases damage the closer they get to death, I highly recommend it for dagger rogues. Bow rogues I'm not so great at, I've not really tried them, I imagine they play a lot like a less adaptable mage.
Warriors are the very tricky part, they're great for keeping attention, but I find that to be all, Warriors against enemies with armor and physical damage resistances which make the warrior have to trade blows toe-to-toe for an extensive period of time definitely aren't all that great. If you have a few mages to support however, you can abuse Dragon Rage as a reaver behind barriers to great effect if you don't mind carrying around plenty of regen potions all the time.
Bottom line, Nightmare is definitely beatable but you have to pay attention to battles, abuse the stop-start pause function and build your characters to be able to benefit one another rather than going for abilities to make each character individually strong.
With your mage, provided friendly fire is on, I suggest you invest heavily into the spirit tree and whatever spec you go for, then fine tune the tactics page of your character profile so that your support skills are preferred, rather than enabled or disabled, this means they cast them with much more regularity when mana is available and the situation needs it.
Probably strayed off topic a lot there, but came back around to the point xD.
Answer: Im running Cass,black wall and I build all as shielders plus the skyhold specs. My inquisitor is Ke with barrier focus. My whole party is in the enemies face with guard and barrier constantly up. Ke is very strong so not having guard isn't an issue. Also make sure to max out potions and grenades just in case. Jar of bees is very funny and effective.
This is basically just a brute force through and through, but as long as you focus and stay grouped its nuts.
Answer: Either get blackwall or make your main character champion. 2 mages and a range rogue, rotate barrier to keep it up 100% keep 1 mob sleeped as rogue with the sleep arrow. Then CC mobs with flashfire and winters chill while you focus dps them down 1 and 1. I recommend Vivienne as one of your mages, cause knight enchanter is op and also her focus ability is really nice. Im 60+ hours in on nightmare and doing fine nothing is difficult after you get like level 12 with the proper setup and spec. A champion tank cant die ever, you shouldn't even use pots on your tank if he is champion.
Answer: Honestly I didn't bother reading the other walls of text, so this may be repetitive:

Get used to playing with the tactical camera. Early and mid-game it is necessary for proper positioning your party and to set up combos.
Identify your clutch abilities and remove them from the AI tactics. Things like an Archer's upgraded Full Draw (20 second single target sleep, refreshable; cooldown is less than duration) and any Mage's Barrier are abilities you do NOT want to see on cooldown when you really need them.
Consider getting the extra potion slot and maybe even upgrading the maximum number of potions you can carry. Equipping all your characters with Regeneration pots will help you recover out of combat and save your insta-heal pots for in-combat scenarios. The third slot can be used to equip a variety of tactical grenades. Slow Pitch is excellent for keep enemies grouped up for combos and  AoEs, and the Jar of Bees does more damage than it has a right to, being a damn Jar of Bees.
Most encounters have a 'key'. It may be one particular enemy that needs to either die fast, or be crowd controlled throughout the fight. The 'key' might be as simple as a bottleneck near the engagement area or a pillar to line-of-sight ranged attackers, making them come to you rather than having your party cross an open arena to engage them.
It's okay to not play as your Inquisitor; different encounters play to the strengths of different classes. Some have good terrain for archers to get above the action, and you'll benefit by positioning them and protecting them while they dish out the extra damage. Other times, you'll want to control bottlenecks or specific enemies with your tank. As the player, you'll always be better than the AI so, if the situation calls for it, take control of those lynch-pin party members to make sure things are done right.
Answer: So i made a list of compositions which i found that worked well:

Blackwall - 2 handed w/special = Unkillable
Sera- Bow + Tempest special = no cooldown barrage Heavy draw. + Time stop
Viviane - Spirit + KE = Unkillable mage w/ great buffs
Inquisitor - Dual blade + Tempest rogue = pure no cooldown dps monster

Setup with time stop. When things get tight, Ice armor damage mitigation 75% w/taunt freeze. Half of enemies are dead before they start their attack. Bosses become notably easier.
Comment: Okay.  And how is someone supposed to get to this point?  Presumably, you don't start overpowered.
Comment: You should format this better, it is unreadable like this.
Comment: @nopesalot, i improved the format of your question. Could you take the time to format your question the next time?
Answer: Cass, Blackwall, Dorian/Solas, Ranged Rouge inquiz, poison + archer. I walked through nightmare, just don't rush the story and fight things of your own level. Both of my tanks were sword and shield.
Comment: Could you clarify why?


From where Ubuntu help(yelp) reads its files?

Question: I tried to remove Ubuntu Desktop Guide from Yelp(Ubuntu help)..
sudo apt-get purge ubuntu-docs

But still shown whenever I open help?!
From where are those files? and how yelp treat them? and how to get rid totally of those ubuntu-docs?!
In fact yelp is responsible for showing two documentation one for for gnome-help which can be founded under path: /usr/share/help/C/gnome-help and other for Ubuntu,unity which can you show files under /usr/share/help/C/ubuntu-help, but when you purge ubuntu-docs this folder is removed but still documentation still available in Yelp!!!
I'm getting confused from where yelp is providing this documentation?!!!
Comment: The docs come in about 60 languages. Do you still have some of the other languages installed? (which can include versions of English other than U.S.. "C"). Look for other `ubuntu-help` directories under `/usr/share/help`, such as en_CA or en_GB or en_AU.
Comment: Oh, and it might be using a language pack specific version under `/usr/share/help-langpack`. On my system to find everywhere ubuntu-docs stuff was stored, I picked a file name at random and did `locate a11y-braille.page`
Comment: @DougSmythies you can delete those language packs and nothing happens, try it :)
Comment: Yes, there does seem to be some weirdness going on. I am in Canada, and so yelp is using the en_CA stuff on my system. However, yelp doesn't pick up any changes unless I modify the the "C" version of the file, but then it picks up the new en_CA version. Yelp must cache stuff somewhere, but I haven't been able to figure out where. I am on the ubuntu-docs team and will try to get help from some others.
Comment: @DougSmythies thanks friend...that exactly what make me confused with..   It's not affected by neither langpack nor ubuntu-docs
Answer: The translated pages (everything but en_US) belong to the language-pack-gnome-[LANG]-base packages. When both those and the ubuntu-docs package have been removed, you shouldn't be able to view the docs.
Edit:
$ echo $LANGUAGE
sv
$ sudo apt-get purge ubuntu-docs language-pack-gnome-sv-base
Läser paketlistor... Färdig
Bygger beroendeträd
Läser tillståndsinformation... Färdig
Följande paket kommer att TAS BORT:
  language-pack-gnome-sv* language-pack-gnome-sv-base* ubuntu-docs*
0 att uppgradera, 0 att nyinstallera, 3 att ta bort och 0 att inte uppgradera.
Efter denna åtgärd kommer 63,9 MB att frigöras på disken.
Vill du fortsätta? [J/n] j
(Läser databasen ... 636783 filer och kataloger installerade.)
Tar bort ubuntu-docs (15.04.3) ...
Tar bort language-pack-gnome-sv-base (1:15.04+20150615) ...
Raderar konfigurationsfiler för language-pack-gnome-sv-base (1:15.04+20150615) ...
Tar bort language-pack-gnome-sv (1:15.04+20150615) ...
Hanterar utlösare för software-center (13.10-0ubuntu6.1) ...
INFO:softwarecenter.db.update:translation information in database is up-to-date
Hanterar utlösare för bamfdaemon (0.5.1+15.04.20150202-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
$

Then, when calling yelp, I get a "Document Not Found" message.
Comment: I don't think so, you can test it your self make some edit in those lang packs, though you'll not see your changes in yelp. Moreover I did already remove ubuntu-docs and language-pack-gnome-[LANG]-base and still having the documentation valid :)
Comment: @Maythux: I just edited my answer. Probably there is some misconception involved here.
Comment: I did the procedure as per Gunnar's instructions. In my case Language was "en_CA:en". It worked for me. Now, I will re-install.


Linq Select All Items Matching Array

Question: I have a data collection of type IEnumerable<Objects.LabourHours> containing labour records for various employees. I wish to filter the list and return only records for selected employees, which is specified by a list of int[] employees containing the EmployeeIDs.
class LabourHours
{
    public int ID {get;set;}
    public int EmployeeID {get;set;}
    public int HoursWorked {get;set;}
}

How would I go about this? I am sure this has been asked before but I can't find anything similar on here. The closest I have found involves grouping the records by UserID, which is not what I need - I need the actual records.
Answer: You can filter your list with LINQ Where using Contains method:
var result = list.Where(x => employees.Contains(x.EmployeeID));

Comment: hmm so simple! All the solutions I found online were a combination of .All() and .Any() which resulted in a grouped return value rather than individual items. Is it just me though or is this the wrong way round compared to all other Linq operations?
Answer: If you want the result to preserve the order of the employees array, you can use Select on the array. From the doc, it "Projects each element of a sequence into a new form", which is basically what you'd want to do in this case.
var result = employees.Select(e => labourHours.First(l => l.EmployeeID == e));

Use FirstOrDefault if all employees don't necessarily have an associated labourHours entry.

Linq Select All Items Matching Array


Pendant Light is Hanging Crooked- How to align it with three screw mount?

Question: I have a pendant light that was installed before I moved into this home. The pendant cover is held in place by three screws, in a triangle. I recently replaced the lights, but cannot figure out how to get the cover to sit nicely and perpendicular to the floor, particularly given that I have to hold the cover while screwing in the screws.
A picture is attached showing two of the three shoes and the crookedness.
Apologies if this is easy, but I can't figure out the right search terms for it.
Comment: I think it would be easy as just moving the chain to the notch on the ring to the left.
Answer: Slightly loosen the screws that are too high then tighten the ones that are too low.
This will move the weight of the bowl to the high side, rebalancing it.
Repeat until satisfied.
Comment: If the globe is somewhat off kilter due to manufacturing method, loosening the screws and rotating it may also make a difference in how it hangs. If it's perfectly uniform that should not change anything.


How do I determine my highest obtained rank for the current season in Heroes of the Storm?

Question: Heroes of the Storm has two ranked play modes: Hero League and Team League. Depending on how well you do in a season you earn rewards. Presently, players are competing for 2017 Ranked Season 1 Rewards. Your peak rank determines what rewards you receive.
While I have finished my placements for both modes in Team League I believe I have fluctuated between two different tiers, but want to be sure. Is there a way to determine my peak rank prior to the season changing over?
Answer: You can find this information in the Statistics-Tab in your profile. Just select a season and then you can find your highest ranks in the bottom right corner.


Why am I still getting the error: "CryptoUnavailableError: No crypto library available" in Python?

Question: I am trying to make an API call through Python to Google's DFA and am using their suggested code. However, it is still not saying the credentials object is defined and throws the error:
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\Python27\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Python27\lib\site-packages\oauth2client\client.py", line 1502, in __init__
    _RequireCryptoOrDie()
  File "C:\Python27\lib\site-packages\oauth2client\client.py", line 1456, in _RequireCryptoOrDie
    raise CryptoUnavailableError('No crypto library available')
CryptoUnavailableError: No crypto library available

I have installed the pyOpenSSL library, and pycrypto library with the VCForPython compiler. I have also managed to edit all 3 app.yaml files in the LiClipse client to append:
libraries:
- name: pycrypto
  version: "latest"

onto it.
This is what my code looks like so far with arbitrary credentials:
import json
import sys
import apiclient
from oauth2client import crypt
import ssl
import urllib2
from OpenSSL import crypto

HAS_OPENSSL = False
HAS_CRYPTO = False
try:
  from oauth2client import crypt
  HAS_CRYPTO = True
  if crypt.OpenSSLVerifier is not None:
    HAS_OPENSSL = True
except ImportError:
  pass

from oauth2client.client import SignedJwtAssertionCredentials

client_email = 'example.apps.googleusercontent.com'

with open("C:\My Project-1234.p12") as f:
        private_key = f.read()

credentials = SignedJwtAssertionCredentials(client_email, private_key,
    'https://www.googleapis.com/auth/dfareporting')

from httplib2 import Http

I realize there is probably some excess in the beginning. I have not been able to get past this step.
I feel like I have tried everything and am still getting thrown the 'no crypto library' error.
Can anyone help? THANK YOU!
PS - I am using Windows 7 and Python 2.7 and LiClipse.
Comment: Have you confirmed you can actually import pyopenssl or pycrypto from your script? Try importing those before *oauth2client* to verify.
Comment: pyopenssl seems to import. i have not been able to get pycrypto installed despite downloading the compiler and windows sdk. I now have the code running until the last line here: "service = build('dfareporting', 'v2.1', http=http_auth)" where i am actually attempting a call. I am now getting the error: OpenSSL.crypto.Error: []. So, still related to the cryptos it seems.
Comment: I also have this problem in Windows 10 (upgraded from Win 7), Python Tools for Visual Studio, Visual Studio 2013 and Python 3.4 virtual env. Strangest thing: it works with a venv in an Eclipse project. I manually compared site-packages in both venv's but can't see any difference. My Python skills not good enough to figure out why it works in one venv and not the other
Answer: The above method was to make an API call as a 'service' Google account. I retried as an 'installed application' account with new credentials and a different way to make the API call which did not require any crypto type libraries.


css menu hover displaying submenu out of alignment

Question: I have an issue where the leftside navigation menu has submenus on hover and is out of alignment.
DIV#nav-cat UL UL.level2 {
z-index: 8007;
position: absolute;
border-bottom-color: #b0ccdc;
border-right-width:1px;
background-color: #e8f1f6;
border-top-color: #b0ccdc;
width:132px;
display: none;
border-top-width:1px;
border-bottom-width:1px;
border-right-color: #b0ccdc;
border-left-color: #b0ccdc;
border-left-width:1px;
top: -2px;
left: 178px;
}

The first menu "Electronics" displays the submenu correctly by the side. Another menu "Apple accessories" is for example displaying submenu (Mobile case) out of alignment. It is displaying at the top rather than by the side of the menu.
The css classes are

 and
.

I am unable to locate the issue. Kindly guide me to correct the css.
Answer: DEMO
HTML

CSS
.submenu{
    position:relative;
    height:15px
}
.submenu:hover > .level2{  /*target this li level2*/
    position:absolute;
    left:183px; /*width of submenu*/
    top:0;
}

Answer: You have set that element to position: absolute with  top: -2p; This is why it is located where it is. So to answer you question 'Kindly guide me to correct the css.' The offending CSS is below
DIV#nav-cat UL UL.level2 {
z-index: 8007;
position: absolute;
border-bottom-color: #b0ccdc;
border-right-width: 2px;
background-color: #e8f1f6;
border-top-color: #b0ccdc;
width: 175px;
display: none;
border-top-width: 1px;
border-bottom-width: 3px;
border-right-color: #b0ccdc;
border-left-color: #b0ccdc;
border-left-width: 1px;
top: -2px;
left: 178px;
}

To fix the issue you need to set the parent to position: relative
DIV#nav-cat LI.submenu {
position: static; <-- remove this
position: relative; <-- add this
display: block;
background: url(../../../../../includes/templates/tpl_default/images/categoriescss_bg.gif) bottom no-repeat;
}

I have tested the above code in a Firefox console and it works perfectly.
Comment: So how can i get it aligned with the main menu.
Comment: if you change your CSS `DIV#nav-cat LI.submenu` from `position: static;` to `position: relative;` all your issues will be resolved.
Comment: Thank you. That did the trick. But the Apple accessories submenu is displaying with height reduced, since there is only a single item. How can i correct that ?
Comment: You can set a `min-height` to an element.
Comment: Thank you. Changed line-height:27px; and min-height: 27px;


isEqualToString doesn't work

Question: For some reason when I do a [string isEqualToString:string] I get a "NO".
In the picture "item" was declared as a @property NSString *item;  I originally declared it as a plain NSString *item but it still didnt work.
Any ideas what I am doing wrong?
Here is the code,  I tried to do a screen shot to show the debugger output, but not enough reputation.
- (IBAction)playCourseSelection:(id)sender
{
    // Get File Directory
    NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDirectory = [arrayPaths objectAtIndex:0];
    NSString *filePath = [docDirectory stringByAppendingString:@"/playCourse.txt"];

    // Write String for course
    NSString *writeString = item;

    BOOL test;

    test = [item isEqualToString:@"Add Course..."];

    if (test)
    {
        writeString = @"";
    };

    [writeString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

    // Close the file
}

self            EditCourseViewController *  0x0848c770
test            BOOL    '\0'
writeString NSString *  0x07676b80
item            NSString *  0x07676b80

Comment: Suggestion: Set a breakpoint at "if (test)". Check there the value of "item". If it is what you expect @"Add Course...", check that your string literal @"Add Course..." with that it is compared does not contain any invisible characters, and check that "..." is in both cases either three dots or the single special character "...".
Comment: Where do you initialize item? What's the output of: NSLog(@"Item: %@\n", item); ?
Comment: Welcome to Stack Overflow! Please format your code.
Comment: [item isEqualToString:[NSString stringWithFormat:@"%@",str1]];
Comment: @FaJitendraDeore, what is that trying to achieve?
Comment: 2013-08-03 17:14:13.826 GolfScorecard[28156:c07] Item: Add Course…
2013-08-03 17:14:13.828 GolfScorecard[28156:c07] writeString: Add Course…
2013-08-03 17:14:13.828 GolfScorecard[28156:c07] Test: 0
Comment: I am trying to compare two strings. If they are equal I want to write a null value to a file.  If they are different, I want to write the string to a file.
Comment: @Mike Try to write a complete example in [CodeRunner](http://krillapps.com/coderunner/) or http://ideone.com/
Answer: `@"Add Course..." is not equal to item.
if u see NSLog(@"item is %@",item);   console print " item is (null)"
So [item isEqualToString:@"Add Course..."] is NO
Answer: I figured out the answer.  Who knew it would take forever (like all day).  So I guess XCode recognizes the points of ellipsis (...) and assigns them a value different than three periods.  I removed the three periods and it works:
Comment: This is not correct. Xcode doesn't replace the characters "..." or the single character '…'. Example: `NSLog(@"%d", [@"Add Course..." isEqualToString:@"Add Course..."]);` prints 1.
Comment: Jano, you might be right, but XCode did not treat "Add Course..." correctly.  My only suspect is that the "..." were not treated as a true string.  When I removed "..." from the end of the string, everything worked correctly.
Comment: Something else is going on. You could try posting the complete code here, or even the whole project in github, or test a sample on CodeRunner or ideone.com.

isEqualToString doesn't work


Vector spaces and subsets of Matrices

Question:
Hi, I was wondering if anyone could help me with this linear algebra problem.
I have solved a) by using matrix multiplying by scalars and matrix addition/subtraction. And hence concluded that I should get the return of
Row 1: (3 3) Row 2: (-2 -5)
I have also solved b) by creating a matrix from the 2x2 matrices and used row reducing operations. From this I found each line to have a pivot variable and hence having a unique solution. Which thus means that they are linearly independent.
However I'm now stuck on parts c) and d). I know to prove that a subset is a subspace it must meet the three conditions:

It is closed under addition

It is closed under scalar multiplication

The 0 vector is in the subset.

But I'm unsure how to prove that these do/do not hold true.
Any help is appreciated.
Comment: for part (c) and (d)... could you have answered the question if we were instead talking about the subset of $\Bbb R^4$ given by $\left\{\begin{bmatrix}a\\b\\c\\d\end{bmatrix}~:~a+b+d=0\right\}$.  There is no difference between your problem and this one except for flavor.
Comment: Suppose that $V=\begin{bmatrix}a&b\\c&d\end{bmatrix}$ satisfies $a+b+d=0$ and suppose also that $V'=\begin{bmatrix}a'&b'\\c'&d'\end{bmatrix}$ satisfies $a'+b'+d'=0$.  Their sum is $V+V' = \begin{bmatrix}(a+a')&(b+b')\\(c+c')&(d+d')\end{bmatrix}$.  Does this result also satisfy that the sum of the entries (*apart from the bottom left entry*) equals zero?  In other words, does $(a+a')+(b+b')+(d+d')=0$ given that both $a+b+d=0$ and $a'+b'+d'=0$?
Comment: I'm sorry, I'm still a bit lost on this. Why do we choose to use the determinant of the equation? Is this just to compare something to give desired result? I'm not sure I could have answered it even if it was in terms of R4
Comment: "*Why do we choose to use the determinant*"  Where do you see anyone talking about determinants?  You do realize that matrices can be written with square brackets rather than parentheses and they mean the same thing, right?
Comment: Okay I'm sorry I mistook what you said but there's no need to be a bit mean. I thought when you used a' b' c' and d' that these meant the determinants. I'm sorry I'm not 100% sure of this topic, I'm just trying my best to learn.
Comment: I merely used the apostrophes to indicate that they are another variable with a similar role to the unadorned variable.  I could just as easily have called them $e,f,g,h$ instead of $a',b',c',d'$.  I chose to keep them with the same letter in order to make it clearer that both $a,b,c,d$ and $a',b',c',d'$ satisfy very similar properties, namely that $a+b+d=0$ and $a'+b'+d'=0$.  I viewed it as far more convenient to see the relationship like this rather than saying $e,f,g,h$ who satisfy $e+f+h=0$.
Comment: Okay thank you for clarifying that
Answer: Recall our basic definitions of matrices and arithmetic surrounding matrices...
Very loosely defined, a matrix is a rectangular array of elements with some number of rows and some number of columns (even possibly zero).  They can be pictured either with square brackets or with parentheses, both are common and mean the same thing.
We can add two matrices so long as they have the same number of rows and have the same number of columns.  To do so, we just perform the elementwise addition of each element.  For example, we have:
$$\begin{bmatrix}1&2\\3&4\end{bmatrix}+\begin{bmatrix}50&60\\70&80\end{bmatrix}=\begin{bmatrix}51&62\\73&84\end{bmatrix}$$
We can multiply a matrix by a scalar.  To do so, we just multiply each element of the matrix individually by the scalar.  For example, we have:
$$5\cdot \begin{bmatrix}1&2\\3&4\end{bmatrix}=\begin{bmatrix}5&10\\15&20\end{bmatrix}$$
This understanding of how to add matrices and multiply matrices by scalars is a critical first step in adequately understanding and defining the vector space in your question.  Make sure you are comfortable with matrices as objects.

Now, in your question you are interested very specifically at the set of $2\times 2$ matrices (matrices with two rows and two columns) with real entries whose top left, top right, and bottom right entries add up to be equal to zero.  That is to say, the set:
$$\left\{\begin{bmatrix}a&b\\c&d\end{bmatrix}~:~a+b+d=0\right\}$$
This includes for instance the matrices $\begin{bmatrix}1&2\\3&-3\end{bmatrix}$ since $1+2+(-3)=0$ as well as $\begin{bmatrix}1&0\\0&-1\end{bmatrix}$ since $1+0+(-1)=0$ and so on...
We ask whether or not this set (coupled with the scalar field of $\Bbb R$ and arithmetic operations as described earlier) satisfies the properties necessary to be called a vector space.
We should already know that the space of all $2\times 2$ real matrices is in fact a vector space over $\Bbb R$ and so we do not need to check here all of the mundane properties such as associativity of addition of vectors, distributivity of scalars over vectors, that the scalar field is actually a field and what not... we can instead focus all of our attention on proving that our set is closed under addition, is closed under scalar multiplication, and contains the "zero" vector (the additive identity of our set, in this case the $2\times 2$ matrix who contains only zeroes).
To check that the set is closed under addition, we need to check that any two matrices we take from our set such as $\begin{bmatrix}1&2\\3&-3\end{bmatrix}$ and $\begin{bmatrix}1&0\\0&-1\end{bmatrix}$, their sum will also wind up in the set.  Indeed, here we have $\begin{bmatrix}1&2\\3&-3\end{bmatrix}+\begin{bmatrix}1&0\\0&-1\end{bmatrix} = \begin{bmatrix}2&2\\3&-4\end{bmatrix}$ is also an element of the set since $2+2+(-4)=0$, the defining trait of what it means to be in our set.
Of course, there are infinitely many vectors in our set, we can't check every addition possible individually... so instead we choose to be general.
Suppose that $\begin{bmatrix}a&b\\c&d\end{bmatrix}$ and $\begin{bmatrix}a'&b'\\c'&d'\end{bmatrix}$ are two elements in our set of matrices.

 (the apostrophes here have no mathematical meaning and are just used in order to give the second set of variables similar but different names to tell them apart.  They could just as easily have been called $e,f,g,h$ or $\heartsuit,\clubsuit,\diamondsuit,\spadesuit$ or any other four symbols)

By the fact that they are elements of our set, that means by definition of our set that they satisfy $a+b+d=0$ and $a'+b'+d'=0$ respectively.
We ask whether their sum also belongs to the set, that is whether $\begin{bmatrix}(a+a')&(b+b')\\(c+c')&(d+d')\end{bmatrix}$ satisfies the property that the top left, top right, and bottom right entries add up to equal zero... that is whether or not $(a+a')+(b+b')+(d+d')=0$
Indeed, by a bit of algebraic rearranging, we have $$(a+a')+(b+b')+(d+d')=(a+b+d)+(a'+b'+d')=0+0=0$$
Here, we used what we knew about the original pair of matrices, that they were in the set as well and so individually had their entries satisfying the property.  This shows that regardless what two matrices we picked, so long as they were from our set their sum will also be in our set.
As for scalar multiplication, this follows similarly.  We let $k$ be any element from our scalar field and $\begin{bmatrix}a&b\\c&d\end{bmatrix}$ be an element from our set of matrices.  We ask if $k\cdot \begin{bmatrix}a&b\\c&d\end{bmatrix}$ is also a matrix in our set.
Indeed, $k\cdot \begin{bmatrix}a&b\\c&d\end{bmatrix}=\begin{bmatrix}ka&kb\\kc&kd\end{bmatrix}$ and we have the sum of the top left, top right, and bottom right entries happens to be:
$$ka+kb+kd = k(a+b+d)=k(0)=0$$
Thus, our set is indeed closed under scalar multiplication.
We move on to asking about "if zero is an element of our set."  It is important here to understand what we mean by "zero."  There are many different mathematical objects, all of whom might be given the name "zero."  In this context, we mean very specifically that element from our proposed vector space who acts as an additive identity, an element who when added to any other will not change the result.  In our specific problem, that "zero" is very specifically the $2\times 2$ matrix whose entries are all zero, $\begin{bmatrix}0&0\\0&0\end{bmatrix}$.
So... we ask... is $\begin{bmatrix}0&0\\0&0\end{bmatrix}$ a matrix in our set?  Well, the sum of the top left, top right, and bottom right entries are $0+0+0=0$ so yes, it is an element of our set.

 It is worth pointing out that this condition can be replaced with the condition "Our set is non-empty" and the set of definitions would have been equivalent.  After all, a set containing "zero" is nonempty since it contains at least zero, and a set who is nonempty and closed under scalar multiplication would include some $V$ and also contain $0\cdot V$, the result of the scalar zero multiplied by the vector $V$ which results in the vector "zero."

By showing these three properties to hold true, we have accomplished what we wanted in showing the set to indeed be a vector subspace of $\mathcal M_{2\times 2}(\Bbb R)$ (what is written in your screenshot simply as $M$)

Now, on to the question of finding a basis and a dimension for this, the common technique is to try to think in terms of "free-variables."  If we can change a variable to a "free-variable" and allow it to freely change without affecting its ability to stay in our set, we do so, but keeping in mind that some variables are dependent on one another so not all can be simultaneously turned into free-variables.  Think of it like the process of parametrizing a curve.
In your case, $c$ is a completely free variable, not relying on anything else.  We could set $c$ as anything and it would never have any impact on whether or not it is an element of our set.  Let us replace $c$ by a free variable, what I will label as $t$.
Next, we can set some (but not all) of the others to free variables.  Letting $a$ be replaced by the free variable $r$ and letting $b$ be replaced by the free variable $s$ we see that $d$ is then forced to be equal to $-r-s$ in order to satisfy the defining property of our set that $a+b+d=0$.
That is to say, every element in our space can be written in the form:
$$\left\{\begin{bmatrix}r&s\\t&-r-s\end{bmatrix}~:~r,s,t\in\Bbb R\right\}$$
We can split this up and factor this as well, factoring the free variables outside, giving us:
$$\left\{r\cdot \begin{bmatrix}1&0\\0&-1\end{bmatrix} + s\cdot \begin{bmatrix}0&1\\0&-1\end{bmatrix}+t\cdot\begin{bmatrix}0&0\\1&0\end{bmatrix}~:~r,s,t\in\Bbb R\right\}$$
Well... this is precisely what is meant when we talk about the span of the vectors $\begin{bmatrix}1&0\\0&-1\end{bmatrix},\begin{bmatrix}0&1\\0&-1\end{bmatrix},\begin{bmatrix}0&0\\1&0\end{bmatrix}$.
These vectors, which can be trivially shown to be linearly independent and span our space, then satisfy the definition of what it means to be a basis of our space.
Finally, we note that there are three vectors in our basis for our space and so the dimension of the space is simply the number of vectors in the basis and is then equal to $3$.
It should be emphasized that this is just one among many possible choices of basis.  It is a well known theorem however that a vector space will always have the same number of basis elements regardless which basis is used to describe it and so the dimension is unambiguous and does not rely on any specific basis.  For us, we could have had as a basis $\begin{bmatrix}1&2\\3&-3\end{bmatrix},\begin{bmatrix}2&3\\4&-5\end{bmatrix},\begin{bmatrix}0&0\\42\pi&0\end{bmatrix}$ for instance and been just as correct.  It would not have necessarily been what was written in a solutions manual or what the majority of people would have come up with (like the earlier choice I gave would be) but would still have been just as mathematically correct.

Vector spaces and subsets of Matrices


Prove that if $a,b\in\mathbb{Z}$, then $a^{2}-4b-3\neq 0$ by contradiction.

Question: I am going through the Book of Proof by Richard Hammack, and in the Chapter on Proof by contradiction, I came across the following exercise:
Prove that if $a,b\in\mathbb{Z}$, then $a^{2}-4b-3\neq 0$ by contradiction.
My solution went on a different aproach as the solution provided in the end of the book, so I would like some help to evaluate if it is correct, and tips for improvement.
My proof was as following:
For the sake of contradiction, suppose $a,b\in\mathbb{Z}$ and $a^{2}-4b-3= 0$. Hence, $a^{2}-3=4b$, which means $a^{2}\equiv 3(\textrm{mod }4)$.
Note that $a$ is either even or odd.
Suppose $a$ is even. Thus, there is an integer $k_1$ such that $a=2k_1$. So, $a^{2}=4k_1^{2}$, which means $a^{2}\equiv 0(\textrm{mod }4)$, a contradiction. Hence, $a$ is not even. Therefore, $a$ is odd.
Since $a$ is odd, there is an integer $k_2$ such that $a=2k_2+1$. Hence, $a^{2}=(2k_2+1)^{2}=4k_2^2+4k_2+1=4(k-2^{2}+k_2)+1$. Thus $a^{2}\equiv 1(\textrm{mod }4)$, a contradiction. Thus, $a^{2}-4b-3\neq 0$. $\blacksquare$
Is this correct? Any tips on improving?
Comment: This is correct. By curiosity, what is the approach in the book ? Yours seems the most natural to me.
Comment: Begin with showing that the choices for a square are $x^2 \equiv 0,1 \pmod 4$  Call it a lemma  if you like
Comment: A "fancier" way of saying the intermediate facts you noted is "the quadratic residues modulo $4$ are $0$ and $1$".
Comment: This is correct.  We can shave just a few words off by noting for that as $a^2\equiv 3 \pmod 4$ that means $a^2$ is odd so $a$ is odd and we don't need to consider $a$ even.  But your contradiction is just as good (actually better as my way requires showing that any $3+4b$ is odd; and showing that $a$ even $\implies a^2$ is even.  Both are frivilous and can be "done in ones head" and *I* would grant they go without saying but others might not.)
Comment: I'd also like to see how your book did it.  I imagine although it may on the surface look different is probably in essence and spirit the same as yours.
Answer: Alternative way:
Let $a^2-4b-3=0$, then
$a^2-1=4b+2$
$(a-1)(a+1)=2(2b+1)$
Both $a-1$ and $a+1$ have the same parity, both are odd or even.
Case 1: Both are odd, but RHS is even
Case 2: Both are even, but RHS is not a multiple of $4$.
Since in both cases, there is a contradiction, $a^2-4b-3\neq0$, $a,b \in Z$
Comment: Please strive not to post more (dupe) answers to dupes of FAQs, cf. recent site policy announcement [here](https://math.meta.stackexchange.com/q/33508/242).
Answer: Let's assume a² - 4b - 3 = 0 when a and b are integers.
a² - 3 = 4b
if a is even left side of this equation is odd but right side is even .
if a is odd let a = 2n +1 where n is an integer.
(2n+1)² - 3 = 4b ⇒ n(n+1) - 1/2 = b , this result is not valid because left side is not an  integer , therefore by the method of contradiction  a² - 4b - 3 ≠ 0 when a , b are integers.
Comment: Please strive not to post more (dupe) answers to dupes of FAQs, cf. recent site policy announcement [here](https://math.meta.stackexchange.com/q/33508/242).


Where did these NPCs go?

Question: A couple of NPCs in Riften seem to be permanently missing: The stable owner, and the priest at the Temple of Mara who carries out marriages. Now I can't buy a horse from that particular stable, and can't become married.
Is this a bug, or have they died? I remember a dragon attack outside of the city and possibly going on a rampage as a werewolf. If they are dead, is there any way at all to revive them?
Comment: I'm having this problem with the person that owes money to Saphire. I worked out his debt but I cannot find him to tell him.
Comment: @JuanManuel And the quest marker doesn't show up?
Comment: @agf, it does not show up. I think he's also dead
Answer: It is most likely a dragon attack. Check the area surrounding the city for their corpses. If you find them dead, and play on the PC, then you can use the console to resurrect them.
To resurrect an npc (enemy or friendly), walk up to them, open the console, click on their corpse (you'll see an npc code pop up in the center of the screen), then type resurrect and hit enter. They'll pop right up like nothing happened. If they're hostile, they will attack you.
If they don't pop right up after that, you probably misclicked their corpse, and got an item code for something near them. In this case, try clicking around till you get a different code, then try to resurrect them again.
Edit: Be careful when using placeatme as @agf suggested, it has created duplicate npc's in the past. You can get rid of these by selecting the unwanted npc while in the console window and then typing disable -> enter.
Comment: My guess is that console players are out of luck in this scenario?
Answer: Maramal's RefID is 00019DD5.
So I would try:
resurrect 00019DD5
player.placeatme 00019DD5
enable 00019DD5

Hofgrir Horse-Crusher's RefID is 00019DFE; the same should work for him.
Comment: Does resurrecting players count as cheating?
Comment: @JuanManuel [Console commands don't affect Achievements](http://gaming.stackexchange.com/questions/37694/do-console-commands-affect-steam-achievements) if that's what you mean by "cheating"?

Where did these NPCs go?


How can I take apart this leaking outdoor faucet?

Question: I have looked up how to take apart a leaky outdoor faucet. Unfortunately it looks like my faucet does not match the videos/pics I have seen.
Most videos show removing the knob, removing the nut which is around the stem, then removing the assembly which screws into the faucet housing to get at the washer.

Does where the arrow point actually come apart, because I have not felt any give on this at all and I am worried about damaging the line leading to the faucet.
Is there another faucet type I am dealing with here?
Here's the topview just to help with the identify.
Comment: Try using 2 [pipe wrenches](http://en.wikipedia.org/wiki/Pipe_wrench). Put one on the tap itself, so you can prevent the tap from moving. Use the second to turn the nut.  The basic idea here is to absorb the force being applied to the nut, so that it's not transferred to the plumbing (causing damage).  You want to get it set so that each wrench is moving in opposite directions, so all the torque is focused on the nut. Think of it like opening a mayonnaise jar, one hand on the lid, one on the jar, both twisting in opposite directions.
Comment: How is this faucet (hose bib) leaking?  Is it leaking from the part where the hose connects, or is it leaking around the valve stem at the top?
Answer: That nut should turn, but hit it with some penetrating oil (WD-40) first and let that soak in. Try to use a wrench or socket if you have one that fits snug, rather than pliers, since pliers can damage that nut. Finally, be careful when rethreading the nut back on since it's easy to cross thread or strip the threads.
If the plumber that installed this was nice, you may find the entire faucet is attached via a threaded pipe and can be spun off. My plumber was less kind and soldered the threads, so I'd have to open the wall and replace the pipe to change out the faucet. Keep in mind that when a faucet like this gets old, it may not be good enough to change the washers and repack the stem, so keep your option to replace the entire thing open.
Answer: It appears that the "nut" the white arrow points at is part of the faucet body, molded into the body to give something to turn the packing nut down onto. Verify this as fact, and if so, be careful. Applying too much force to try and twist it off will just destroy the faucet or the pipe that serves it. Then you will need to do some more serious repair work.
If so, then you have already removed the packing nut. The valve stem will now come out (in theory) but there is the packing that remains, to impede that action. The packing can get tightly lodged in there. If my contention is true, then I'd take a dental pick to slowly dislodge the packing, teasing it out one piece at a time. This does not matter, since you will want to replace the packing anyway when you put it all together.
Turn the valve stem to back it out by putting the handle back on it, temporarily, without the packing nut in place.
Also, be careful about applying too much heat to the body, as that could cause problems too.
Answer: I can confirm that the nut does in-fact come off.  I have that same exact faucet on my house and searching for the same info and found this thread.
FYI that I used some penetrating oil; that helped a lot.  For wrenches, I put a crescent wrench on the nut and some vise grips on the portion that goes into the house so I could hold onto the faucet without potentially bending/twisting the pipes in the house.  You'll notice that there's a flat section on each side of that portion that's made to hold on to.
I'd like to also mention that I had a difficult time locating the rubber washer that I was replacing on the inside.  Below is a photo of what I finally found and it works perfect.  It's a Danco 35069B.
Answer: Heat it up with a torch before trying to turn it.
Comment: A torch could melt the washers and packing, making a mess that has to be cleaned before reassembling. It could also melt any soldered fittings upstream of the fixture, causing a leak when water is turned back on.


Whole line highlight in teal colour in visual studio code? Teal colour

Question: enter image description hereThe teal colour highlighted in visual studio code on whole line in the background of code, which is annoying me and my eyes. How to remove the colour on entire line.
I tried in YouTube and googling it but couldn't find answer. Please help me out
Comment: It would be better if you take a screenshot on the pc/mac instead of taking a photo on your phone and using that. Also, it would be much better if you put the photo directly into the question instead of making the viewers go to another link.
Comment: that color is different for each Theme
Answer: It looks like you have installed the 'error lens' extension in vs code, please uninstall it
Answer: this is a dart analysis warning. either you clear the error by:

using const constructor on the widget, on this case is the MaterialApp, since you don't have any changed parameters on the widget:

...
  const MaterialApp(
    ...
  ),
...

or,

using VSCode's Quick Fixes and ignoring the errors, like so:


Java Swing JTree Expansion

Question: This method works as expected - it creates a JTree with a root node and two child container nodes (each with a respective leaf node):
private JComponent createSideBar()
{
    final DefaultMutableTreeNode top = new DefaultMutableTreeNode("Projects");
    final JTree tree = new JTree(top);

    DefaultMutableTreeNode project = new DefaultMutableTreeNode("project 1");
    DefaultMutableTreeNode version = new DefaultMutableTreeNode("version 1");
    project.add(version);
    top.add(project);
    TreePath treePath = new TreePath(project.getPath());
    // tree.expandPath(treePath);

    project = new DefaultMutableTreeNode("project 2");
    version = new DefaultMutableTreeNode("version 2");
    project.add(version);
    top.add(project);

    return tree;
}

In this case, the tree starts out closed. I'd like the application to start with all nodes fully expanded so I started by adding the following:
    tree.expandPath(treePath);

but when I un-comment it from the code above, the second set of child nodes don't show up, ie: Project 2 and Version 2 do not show up. In fact, all subsequently added nodes never show up.
For what its worth, I'm using JDK 1.5. From the docs, I can't seem to see any restrictions or why this method would have such ill-effects ... I'm going to try to look at the source but was hoping someone might have a good idea what and why this is expected behavior. I'm wondering if each subsequent node 'add' is somehow disallowed somehow - but I can't imagine would work for most run-time use cases.
Thanks,
-Luther
Answer: Unfortunately, Swing is often "helpful". In this case, it is creating a model for you from the data supplied, much the same as a JList would create a model if you supplied a Vector.
JTree and accomplices (primarily the Pluggable Look & Feel) will add listeners to the model to keep informed of updates. If you just change the data behind the (implicit) model's back, nothing will get updated other than by chance.
So, what you should do is explicitly create a model. When the model data changes (always on the EDT, of course), cause the relevant event to be fired.
Answer: If nodes are added to a node which has already been expanded, you need to reload the model.
((DefaultTreeModel)tree.getModel()).reload();

or
((DefaultTreeModel)tree.getModel()).reload(top);

This second version is more useful if you want to reload only a small part of a large tree.
Answer: Ah ... the model.
Your answers are elaborated on a bit here and here .... and even here.
I ended up doing something like:
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.insertNodeInto(newNode, parent, index);

which keeps the model directly informed. In my case, that scales just fine.
Now, how to mark one of these as the answer!?!

Java Swing JTree Expansion


Kubernetes nginx ingress accesses outside of cluster without using service

Question: Apologies if this has been answered before, but I am a little confused on Ingress Nginx is working together with services.
I am trying to implement an nginx ingress in my Kubernetes environment.
So far I have an ingress-nginx-controller-deployment setup, as well as a deployment and service for the default backend. I still need to create my actual Ingress resources, the ingress-nginx-controller-service and also my backend.
curl <NodeIP>
returns "default backend 404" on port 80 for the Node which the ingress-nginx-controller-deployment is deployed on.
However, my understanding is that exposing anything out of the cluster requires a service (Nodeport/Loadbalancer), which is the duty of the ingress-nginx-controller-service.
My question is how is this possible, that I can access port 80 for my Node on my browser, which is outside the cluster?
Could I then deploy my backend app on port 80 the same way the above is done?
I feel like I am misunderstanding a key concept here.
default backend image: gcr.io/google_containers/defaultbackend:1.0
nginx-controller image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.3
Comment: You could check this article: https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0

Also if you could you provide your ingress and service YAML it would be easier to answer your question. A few factors also depends from where you have your cluster, on-prem or locally?
Answer: I think you missed a really good article about how nginx-ingress expose to the world!
I short:
If you're using hostNetwork: true then you bypass the kubernetes network (kube-proxy). in a simple word, you bypass the container and orchestration network and just using the host network then the node with nginx-ingress container will expose port 80 to the world.
There are other ways that you can use to expose nginx port to outside of the cluster (node-port, network load balancer like MetalLB).
Comment: Are there any downsides to using a self-provisioned edge? If I understand correctly, it's using the NodePort method, but setting up another network with reverse proxying  in front to avoid the high port ranges. Would there be any downsides to this?
Comment: Thanks, that makes a lot more sense. I see that it'd be best to create the nginx ingress controller as a Daemonset then, so one pod per node (this does not seem to be too big of a problem). The downside I saw was the option `exposes every system daemon to the NGINX Ingress controller`, how big of a concern is this? Sorry am a bit new to a lot of concepts here.


Why does Python treat tuples, lists, sets and dictionaries as fundamentally different things?

Question: One of the reasons I love Python is the expressive power / reduced programming effort provided by tuples, lists, sets and dictionaries.  Once you understand list comprehensions and a few of the basic patterns using in and for, life gets so much better!  Python rocks.
However I do wonder why these constructs are treated as differently as they are, and how this is changing (getting stranger) over time.  Back in Python 2.x, I could've made an argument they were all just variations of a basic collection type, and that it was kind of irritating that some non-exotic use cases require you to convert a dictionary to a list and back again.  (Isn't a dictionary just a list of tuples with a particular uniqueness constraint?  Isn't a list just a set with a different kind of uniqueness constraint?).
Now in the 3.x world, it's gotten more complicated.  There are now named tuples -- starting to feel more like a special-case dictionary.  There are now ordered dictionaries -- starting to feel more like a list.  And I just saw a recipe for ordered sets.  I can picture this going on and on ... what about unique lists, etc.
The Zen of Python says "There should be one-- and preferably only one --obvious way to do it".  It seems to me this profusion of specialized collections types is in conflict with this Python precept.
What do the hardcore Pythonistas think?
Comment: You answered your own question by quoting the Zen. If you need a dict that retains the order of its components, you now use the one obvious way, ordered dict, rather than implementing one of many potential hacks to the existing list/dict data structures.
Answer: tl;dr (duck-typing)
You're correct to see some similarities in all these data structures. Remember that python uses duck-typing (if it looks like a duck and quacks like a duck then it is a duck). If you can use two objects in the same situation then, for your current intents and purposes, they might as well be the same data type. But you always have to keep in mind that if you try to use them in other situations, they may no longer behave the same way.
With this in mind we should take a look at what's actually different and the same about the four data types you mentioned, to get a general idea of the situations where they are interchangeable.
Mutability (can you change it?)
You can make changes to dictionaries, lists, and sets. Tuples cannot be "changed" without making a copy.

Mutable: dict, list, set
Immutable: tuple

Python string is also an immutable type. Why do we want some immutable objects? I would paraphrase from this answer:

Immutable objects can be optimized a lot

In Python, only immutables are hashable (and only hashable objects can be members of sets, or keys in dictionaries).

Comparing across this property, lists and tuples seem like the "closest" two data types. At a high-level a tuple is an immutable "freeze-frame" version of a list. This makes lists useful for data sets that will be changing over time (since you don't have to copy a list to modify it) but tuples useful for things like dictionary keys (which must be immutable types).
Ordering (and a note on abstract data types)
A dictionary, like a set, has no inherent conceptual order to it. This is in contrast to lists and tuples, which do have an order. The order for the items in a dict or a set is abstracted away from the programmer, meaning that if element A comes before B in a for k in mydata loop, you shouldn't (and can't generally) rely on A being before B once you start making changes to mydata.

Order-preserving: list, tuple
Non-order-preserving: dict, set

Technically if you iterate over mydata twice in a row it'll be in the same order, but this is more a convenient feature of the mechanics of python, and not really a part of the set abstract data type (the mathematical definition of the data type). Lists and tuples do guarantee order though, especially tuples which are immutable.
What you see when you iterate (if it walks like a duck...)

One "item" per "element": set, list, tuple
Two "items" per "element": dict

I suppose here you could see a named tuple, which has both a name and a value for each element, as an immutable analogue of a dictionary. But this is a tenuous comparison- keep in mind that duck-typing will cause problems if you're trying to use a dictionary-only method on a named tuple, or vice-versa.
Direct responses to your questions

Isn't a dictionary just a list of tuples with a particular uniqueness
constraint?

No, there are several differences. Dictionaries have no inherent order, which is different from a list, which does.
Also, a dictionary has a key and a value for each "element". A tuple, on the other hand, can have an arbitrary number of elements, but each with only a value.
Because of the mechanics of a dictionary, where keys act like a set, you can look up values in constant time if you have the key. In a list of tuples (pairs here), you would need to iterate through the list until you found the key, meaning search would be linear in the number of elements in your list.
Most importantly, though, dictionary items can be changed, while tuples cannot.

Isn't a list just a set with a different kind of uniqueness
constraint?

Again, I'd stress that sets have no inherent ordering, while lists do. This makes lists much more useful for representing things like stacks and queues, where you want to be able to remember the order in which you appended items. Sets offer no such guarantee. However they do offer the advantage of being able to do membership lookups in constant time, while again lists take linear time.

There are now named tuples -- starting to feel more like a special-case dictionary. There are now ordered dictionaries -- starting to feel more like a list. And I just saw a recipe for ordered sets. I can picture this going on and on ... what about unique lists, etc.

To some degree I agree with you. However data structure libraries can be useful to support common use-cases for already well-established data structures. This keep the programmer from wasting time trying to come up with custom extensions to the standard structures. As long as it doesn't get out of hand, and we can still see the unique usefulness in each solution, it's good to have a wheel on the shelf so we don't need to reinvent it.
A great example is the Counter() class. This specialized dictionary has been of use to me more times than I can count (badoom-tshhhhh!) and it has saved me the effort of coding up a custom solution. I'd much rather have a solution that the community is helping me to develop and keep with proper python best-practices than something that sits around in my custom data structures folder and only gets used once or twice a year.
Comment: @Chris - a Number class can expand/change based on the operations and size of the represented number.  A data structure like a set or list has no idea what's going in it and how/when/in what way it will be pulled out.  You could make make a data structure that has the operations of all of them, but you would likely end up with a data structure that had the advantages of none of them.
Comment: Chris: http://en.wikipedia.org/wiki/Duck_typing. Many times you can just pretend a `dict` is a `list` (think `for key in myDict`) or pretend that a `list` is a `set` (think `if something in myList`). When you need something more specialized, you can have it though.
Comment: "If you iterate twice over a dictionary or set using `for k in mydata` there is no guarantee that you will get the keys in the same order the second time as the first." Actually this is guaranteed, see the [docs](http://docs.python.org/release/2.6.4/library/stdtypes.html#dict.items). It's not guaranteed that the objects will stay in the same order if you start removing or adding keys.
Comment: My question was more along the lines of, would the expressive power of Python be increased if lists, dictionaries etc. were just instances of a more basic construct -- so I could (e.g.) make a list into a set just by changing a property, not copying / converting etc.  A simpler example / analogy -- I once used a language that had a Number data type.  It served as an int, long, float etc.  Saved brain damage and prevented errors.  In the same spirit -- wouldn't life be grand if Python had a generic Collection type that was a set, dict etc. as needed.  The 3.3 adds seem like unneeded complexity.
Answer: These data types all serve different purposes, and in an ideal world you might be able to unify them more. However, in the real world we need to have efficient implementations of the basic collections, and e.g. ordering adds a runtime penalty.
The named tuples mainly serve to make the interface of stat() and the like more usable, and also can be nice when dealing with SQL row sets.
The big unification you're looking for is actually there, in the form of the different access protocols (getitem, getattr, iter, ...), which these types mix and match for their intended purposes.
Comment: Thanks everyone for the thoughtful responses.  This response best summarizes what I see as the key conclusions.  (1) Realistically there is no way to do what I asked because of efficiency issues -- each data type is tailored for a specific pattern of use; and (2) more importantly, there is also not much **need** for what I asked because of the type-neutral capabilities Python provides.
Answer: First of all, Ordered Dictionaries and Named Tuples were introduced in Python 2, but that's beside the point.
I won't point you at the docs since if you were really interested you would have read them already.
The first difference between collection types is mutability. tuple and frozenset are immutable types. This means they can be more efficient than list or set.
If you want something you can access randomly or in order, but will mainly change at the end, you want a list. If you want something you can also change at the beginning, you want a deque.
You simply can't have your cake and eat it too -- every feature you add causes you to lose some speed.
dict and set are fundamentally different from lists and tuples`. They store the hash of their keys, allowing you to see if an item is in them very quickly, but requires the key be hashable. You don't get the same membership testing speed with linked lists or arrays.
When you get to OrderedDict and NamedTuple, you're talking about subclasses of the builtin types implemented in Python, rather than in C. They are for special cases, just like any other code in the standard library you have to import. They don't clutter up the namespace but are nice to have when you need them.
One of these days, you'll be coding, and you'll say, "Man, now I know exactly what they meant by 'There should be one-- and preferably only one --obvious way to do it', a set is just what I needed for this, I'm so glad it's part of the Python language! If I had to use a list, it would take forever." That's when you'll understand why these different types exist.
Answer: A dictionary is indexed by key (in fact, it's a hash map); a generic list of tuples won't be. You might argue that both should be implemented as relations, with the ability to add indices at will, but in practice having optimized types for the common use cases is both more convenient and more efficient.
New specialized collections get added because they are common enough that lots of people would end up implementing them using more basic data types, and then you'd have the usual problems with wheel reinvention (wasted effort, lack of interoperability...). And if Python just offered an entirely generic construct, then we'd get lots of people asking "how do I implement a set using a relation", etc.
(btw, I'm using relation in the mathematical or DB sense)
Answer: All of these specialized collection types provide specific functionalities that are not adequately or efficiently provided by the "standard" data types of list, tuple, dict, and set.
For example, sometimes you need a collection of unique items, and you also need to retain the order in which you encountered them. You can do this using a set to keep track of membership and a list to keep track of order, but your solution will probably be slower and more memory-hungry than a specialized data structure designed for exactly this purpose, such as an ordered set.
These additional data types, which you see as combinations or variations on the basic ones, actually fill gaps in functionality left by the basic data types. From a practical perspective, if Python's core or standard library did not provide these data types, then anyone who needed them would invent their own inefficient versions. They are used less often than the basic types, but often enough to make it worth while to provide standard implementations.
Answer: One of the things I like in Python the most is agility.  And a lot of functional, effective and usable collections types gives it to me.
And there is still one way to do this - each type does its own job.
Answer: The world of data structures (language agnostic) can generally be boiled down to a few small basic structures - lists, trees, hash-tables and graphs, etc. and variants and combinations thereof.  Each has its own specific purpose in terms of use and implementation.
I don't think that you can do things like reduce a dictionary to a list of tuples with a particular uniqueness constraint without actually specifying a dictionary.  A dictionary has a specific purpose - key/value look-ups - and the implementation of the data structure is generally tailored to those needs.  Sets are like dictionaries in many ways, but certain operations on sets don't make sense on a dictionary (union, disjunction, etc).
I don't see this violating the 'Zen of Python' of doing things one way.  While you can use a sorted dictionary to do what a dictionary does without using the sorted part, you're more violating Occam's razor and likely causing a performance penalty. I see this as different than being able to syntactically do thing different ways a la Perl.
Answer:
The Zen of Python says "There should be one-- and preferably only one --obvious way to do it". It seems to me this profusion of specialized collections types is in conflict with this Python precept.

Not remotely. There are several different things being done here. We choose the right tool for the job. All of these containers are modeled on decades-old tried, tested and true CS concepts.
Dictionaries are not like tuples: they are optimized for key-value lookup. The tuple is also immutable, which distinguishes it from a list (you could think of it as sort of like a frozenlist). If you find yourself converting dictionaries to lists and back, you are almost certainly doing something wrong; an example would help.
Named tuples exist for convenience and are intended to replace simple classes rather than dictionaries, really. Ordered dictionaries are just a bit of wrapping to remember the order in which things were added to the dictionary. And neither is new in 3.x (although there may be better language support for them; I haven't looked).


How do we show that $\int_{0}^{1}{\arctan(x\sqrt{x^2+2})\over \sqrt{x^2+2}}\cdot{dx\over x^2+1}=\left({\pi\over 6}\right)^2$

Question: I was going through the the top votes questions and I saw this quite of interesting post posted by @Sangchul Lee. I was just messing around with it and found a slightest Variation of Ahmed's integral.
$$\int_{0}^{1}{\arctan(x\sqrt{x^2+2})\over \sqrt{x^2+2}}\cdot{dx\over x^2+1}=\left({\pi\over 6}\right)^2\tag1$$
May be substitution might work
$u=x(x^2+2)^{1/2}$ the $du=x(x^2+2)^{-1/2}+(x^2+2)^{1/2}dx$
$$\int_{\sqrt{2}}^{4\sqrt{3}\over3}{x^2\arctan{u}\over x^3+u^2}\cdot{x^2\over u^2-x^2}du$$
More difficult then before. I can't remove the x variable from the integral.
Any suggestion on how to prove $(1)$?
Answer: Substitute : $u=\arctan\left(x\sqrt{x^2+2}\right)$
You will get : $$\dfrac{\mathrm{d}u}{\mathrm{d}x}=\dfrac{\sqrt{x^2+2}+\frac{x^2}{\sqrt{x^2+2}}}{x^2\left(x^2+2\right)+1}$$
Thus :
$$\int_{0}^{1}{\arctan(x\sqrt{x^2+2})\over \sqrt{x^2+2}}\cdot{dx\over x^2+1}=\int_{0}^{\arctan(\sqrt{3})}{u\over 2}\cdot{du}=\left[\frac{u^2}{4}\right]^{\frac{\pi}{3}}_0=\left({\pi\over 6}\right)^2$$
Comment: Very nice answer. +1
Answer: Using your approach $$u=x(x^2+2)^{1/2}\implies x=\sqrt{\sqrt{u^2+1}-1}\implies dx=\frac{u}{2 \sqrt{u^2+1} \sqrt{\sqrt{u^2+1}-1}}\,du$$ and, after simplifications $$\int{\arctan(x\sqrt{x^2+2})\over \sqrt{x^2+2}}\cdot{dx\over x^2+1}=\int\frac{\tan ^{-1}(u)}{2 u^2+2}\,du=\frac{1}{4} \tan ^{-1}(u)^2$$
Comment: Very nice, Claude. The OP made a mistake while calculating $\;\frac{dx}{du}\;$ ...+1
Comment: How did you make x the subject in term of u @Claude? I don't really get it!
Comment: $u^2=x^2(x^2+2)\implies x^4+2x^2-u^2=0$ which is a quadratic in $x^2$.


Apache/2.4.29 (Ubuntu) Server at Port 443 for wordpress

Question: I'm facing an error in Wordpress after installing Let's encrypt certificate in AWS on Ubuntu 18.04.
How to fix this issue?
.htaccess sample file for the blog only I'm using Wordpress, Wordpress index page is loading but post pages are showing 404 Error
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Comment: Does default apache page work on https ?
Comment: yes it's working
Comment: Can you please reset your permalink and check it again.
Comment: changed permalink also doesn't work, I found the solution I already posted.
Answer: Get solution for the issue, need to change in apache2.conf file after that it will works,
old code in /etc/apache2/apache2.conf
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

changed in to
 <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>

after that,
In order for Apache to understand rewrite rules, we first need to activate mod_rewrite. It's already installed, but it's disabled on a default Apache installation. Use the a2enmod command to enable the module:
$ sudo a2enmod rewrite

This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache.
$ sudo systemctl restart apache2

it works for me finally.


How to get a dragon soul for Bend Will?

Question: I had Bend Will, so I tried to unlock it because I have 22 dragon souls but it wouldn't let me unlock it.  I just went and killed a dragon but Miraak stole the soul from me. What do I do now?
Comment: Welcome to Gaming SE. Please edit your question to make it abit clear what you're asking. Are you having a problem unlocking a shout with dragon souls you allready have (in which case Miraak stealing your 23rd one doesn't have anything to do with it) or is your question about him stealing souls?
Answer: You need to go through the main quest line of the dragonborn dlc to be able to unlock it. Once unlocked you can spend a dragon soul on it by clicking 'unlock' or pressing the according key. This page on the site covers that extensively and refers to other helpful pages.
Answer: You need to get out of Raven Rock go back to skyrim. Fight dragons within that he useally doesn't take it unless your on his land.
Comment: This is not true. Miraak will still show up in Skyrim when killing dragons. Source: He stole my dragon soul south of Riften. Besides that, this doesn't answer the question.

How to get a dragon soul for Bend Will?


Removing duplicates from an array using std::map

Question: I'm directly posting my code which I've written on collabedit under 5 minutes (including figuring out the algorithm) thus even though with the risk of completely made of fun in terms of efficiency I wanted to ask my fellow experienced stack overflow algorithm enthusiasts about the problem;
Basically removing duplicate elements from an array. My Approach: Basically using the std::map as my hash table and for each element in duplicated array if the value has not been assigned add it to our new array. If assigned just skip. At the end return the unique array. Here is my code and the only thing I'm asking in terms of an interview question can my solution be more efficient?
#include <iostream>
#include <vector>
#include <map>

using namespace std;

vector<int>uniqueArr(int arr[],int size){
    std::map<int,int>storedValues;
    vector<int>uniqueArr;
    for(int i=0;i<size;i++){
        if(storedValues[arr[i]]==0){
            uniqueArr.push_back(arr[i]);
            storedValues[arr[i]]=1;
        }
    }
    return uniqueArr;
}

int main()
{
    const int size=10;
    int arr[size]={1,2,2,4,2,5,6,5,7,1};
    vector<int>uniArr=uniqueArr(arr,size);
    cout<<"Result: ";
    for(int i=0;i<uniArr.size();i++) cout<<uniArr[i]<<" ";
    cout<<endl;
    return 0;
}

Comment: Does the question specifically ask you to do it in C++, or did you just choose it yourself?
Comment: @James It's the language that I feel most comfortable with.
Answer: First of all, there is no need for a map, a set is conceptually more correct, since you don't want to store any values, but only the keys.
Performance-wise, it might be a better idea to use a std::unordered_set instead of a std::set, as the former is hashed and can give you O(1) insert and lookup in best case, whereas the latter is a binary search tree, giving you only O(log n) access.
vector<int> uniqueArr(int arr[], int size)
{
    std::unordered_set<int> storedValues;
    vector<int> uniqueArr;
    for(int i=0; i<size; ++i){
        if(storedValues.insert(arr[i]).second)
            uniqueArr.push_back(arr[i]);
    return uniqueArr;
}

But if you are allowed to use the C++ standard library more extensively, you may also consider the other answers using std::sort and std::unique, although they are O(n log n) (instead of the above ~O(n) solution) and destroy the order of the elements.

If you want to use a more flexible and std-driven approach but with ~O(n) complexity and without destroying the order of the elements, you can transform the above routine into the following std-like algorithm, even if being a bit too far-fetched for a simple interview question:
template<typename ForwardIterator>
ForwardIterator unordered_unique(ForwardIterator first, ForwardIterator last)
{
    typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
    std::unordered_set<value_type> unique;
    return std::remove_if(first, last,
                          [&unique](const value_type &arg) mutable -> bool
                              { return !unique.insert(arg).second; });
}

Which you can then apply like std::unique in the usual erase-remove way:
std::vector<int> values(...);
values.erase(unordered_unique(values.begin(), values.end()), values.end());

To remove the unique values without copying the vector and without needing to sort it beforehand.
Comment: Great explanation. I still do not wish to use **too much** std's. I've focused more than solving the problem in a short period of time, focusing on the algorithm.
Comment: @rolandbishop Well, a hash is really a pretty standard data structure, that is there in nearly every language (even if the C++ standards committee needed some time to realize this). If you are confident to use a `std::map`, there is no objection against a `std::unordered_set`.
Comment: I know silly but what is the difference here between using the **unordered_set** and **vector** . Forgive me if it is too silly to ask but in terms of storing only integers and providing O(1) aren't both of them do the same? Does **set** have any upper-hand?
Comment: @rolandbishop The problem with a vector is, it has O(1) insert, but only O(n) lookup (when you want to search if a certain value is in there). On the other hand a `std::set` being a binary tree gives you O(log n) insert and lookup. But a `std::unordered_set` being a hashed container can give you O(1) insert and lookup in best case (depending on the quality of the hash function, of course).
Comment: @rolandbishop Or you might also use a `std::vector` indexed by the value from the input array. This would indeed give you O(1) insert and lookup, too. But the problem is that you need to know the range of values in your input array and this range shouldn't be too large, whereas a hash set doesn't depend on the range of keys that heavily.
Comment: This was exactly why I was asking the question of vector vs set. Thank for the deep explanation!
Answer: Since you are asking in terms of an interview question, I will say that you don't get the job.
const int size=10;
int arr[size]={1,2,2,4,2,5,6,5,7,1};

std::sort( &arr[0], &arr[size] );
int* new_end = std::unique( &arr[0], &arr[size] );

std::copy(
    &arr[0], new_end,
  , std::ostream_iterator< int >( std::cout, " " )
);

No temporary maps, no temporary vectors, no dynamic memory allocations, a lot less code written so its easier both to write and to mantain.
Comment: I think this answer demonstrates familiarity with C++ rather than algorithm writing skills.
Comment: @K-ballo but this would be O(nlogn). Using a good hash table we can do this in O(n), can't we? BTW rolandbishop, map does not support O(1) search. It's implemented as a Red Black Tree.
Comment: @rolandbishop: If I was given your code I'd then ask you to write the algorithm for std::unique
Comment: Thanks for the answer. But how come? Is it that inefficient? I believe my solution is **O(n)** so can you explain why I would not get the job :). Thanks again!
Comment: @rolandbishop: `std::sort` is usually _(if not always)_ implemented as _quicksort_. I believe `std::stable_sort` is usually implemented with some variant of _mergesort_, with a less critical worse case time. Note that the standard establishes complexity requirements for its algorithms, so rolling your own version would only make sense if you can beat those minimum requeriments.
Comment: @sukunrt Thanks a lot! I really did not know that. But in terms of an interview I guess I could get a pre-built hash table provided?
Comment: @rolandbishop What they're probably looking for is the histogram approach, but this is only really feasible if the range of the values is manageable. You'd populate the histogram with the values and then scan through it outputting the non-zero indexes.
Answer: #include <algorithm>
#include <vector>

int main()
{
    std::vector<int> vec({1,2,3,2,4,4,5,7,6,6});
    std::sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    // vec = {1,2,3,4,5,6,7}
    return 0;
}
//works with C++11
// O(n log n)

Answer: In-place removal's nice for speed - something like this (returning the new size):
template <typename T, size_t N>
size_t keep_unique(T (&array)[N])
{
    std::unordered_set<T> found;
    for (size_t i = 0, j = 0; i < N; ++i)
        if (found.insert(array[i]).second))
            if (j != i) // (optional) avoid copy to self, as may be slower or unsupported by T
                array[j++] = array[i];
            else
                ++j;
    return j;
}

(For larger objects, or those that can't be safely copied, may be necessary and/or faster and more space efficient to store T*s in the unordered_set - must also provide a dereferencing comparison operator and hash function.)
To visualise how this works, consider processing the following input:
1  3  6  3  5  6  0  2  1
         <--+<----+  |
               <-----+

The arrows above represent the minimal in-place compaction necessary to produce the answer:
1  3  6  5  0  2

That's precisely what the algorithm above does, looking at all the elements at [i], and keeping track of where they need to be copied to (and how many non-duplicates there are) in [j].


How long does it take for a item to despawn?

Question: I want to know this because I died really far away and I am stressing that the items will despawn. My world tick speed is 1.
Comment: Um, this information is easily found online. Have you tried looking for answers yourself?
Comment: Tick-speed 1 is Bedrock Edition's default
Comment: No, I don't know why I didn't think of that.
Comment: 1? are you sure its 1?
Comment: Welp my items despawned :( full neatherite  with mending elytra with mending unbreaking 3 neatherite pick and sword
Answer: https://minecraft.wiki/w/Item_(entity)#Despawning
From the wiki:

Items despawn after 6000 game ticks (5 minutes) of being in a loaded chunk. If two item stacks merge, the timer is set to the item that has more time remaining. The 5-minute timer is paused when the chunk is unloaded.


SSL Client Authentication with Google Cloud Run

Question: I'm trying to move an existing backend over to Google Cloud Run. Some of the endpoints (under a specific subdomain) require SSL Client Authentication. The way this is handled at the moment is on Nginx configuration level:
<code>server {
    listen 443 ssl http2;
    server_name secure.subdomain.example.com;
    [...]

    # SSL Client Certificate:
    ssl_client_certificate xxx.pem;
    ssl_verify_client on;

    [...]

    location / {
        if ($ssl_client_verify != "SUCCESS") { return 403 $ssl_client_verify; }
        [...]
    }
}
</code>
What would be the best approach to handle SSL client certificate authentication with Google Cloud Run? I assume this would need some sort of load balancer on the correct network layer and with support for cloud run?
Of course there is always the option to authenticate in the ExpressJS app, but if possible I would prefer it to happen before even reaching Cloud Run.
Answer: You can't achieve that with Cloud Run. The SSL connection is terminated at the load balancer side (On an HTTPS load balancer, or on the Cloud Run built-in load balancer). You only receive HTTP traffic to your service.
Indeed, you can add additional security information, in the request header, but you lost the SSL flavor.
Comment: It's the design!! Use @JohnHanley answer if you want to have SSL mutual auth.
Comment: How could Google leave out something so essential?
Answer: [UPDATE 05-12-2023]
My answer is no longer current. Review these Google documents:

Set up mutual TLS with user-provided certificates
Set up mutual TLS for a global external HTTP(S) load balancer

[END UPDATE]

What would be the best approach to handle SSL client certificate
authentication with Google Cloud Run?

Cloud Run does not support SSL Client Certificate Authentication. The GFE (Google Front End) proxies requests for Cloud Run applications and does not pass-through requests. The only Google Cloud load balancers that support SSL client certificates are based on Google Maglev.
None of the Google Cloud managed compute services support SSL client certificate authentication (mutual TLS authentication).
Consider using Compute Engine instead of Cloud Run.Then configure Nginx to handle client authentication. For load balancing, use a pass-through load balancer such as External TCP/UDP Network Load Balancer
Comment: @ManfredLinzner - If you need load balancing, a pass-through load balancer would allow your backend to support mTLS. A pass-through load balancer does not proxy (SSL terminate), your backend (Compute Engine + Nginx) would then support mTLS. The point that I was making was that there are two types of Google load balancers - proxy and pass-through. Select a pass-through load balancer if you also need that feature.
Comment: Thank you! The pass-through load balancer would not allow me to implement mTLS, it would only be in interplay with Compute Engine and the correct Nginx configuration, correct?
Comment: This is an utterly confounding level of negligence on Google's part.  HTTPS is used on all levels nowadays.
Comment: @NathanMcKaskle - What negligence are you referring to? Google supports HTTPS everywhere. Offloading SSL is very common. mTLS is still rare today except in large enterprises. Please clarify your comment.
Comment: @JohnHanley The negligence I'm speaking of comes with having to add an otherwise redundant and uselss endpoint on top of what is advertised as infrastructure as a service fully managed by Google. Even in this documentation it claims SSL is part of this. https://cloud.google.com/run/docs/overview/what-is-cloud-run
Comment: @NathanMcKaskle - Please be specific. What redundant and useless endpoint are you referring to?


Meaning of Signed Long Integer

Question: I have the following requirement:
Create the Linear List functions: CreateList, AddNode, DeleteNode, SearchNode and DeleteList, for a list holding signed long integers.
I am confused about 2 terminologies here
does the meaning of signed long integers here means:
"any long integer which is positive or negative including 0" ?
am I missing something?
and 2nd
by "linear list" does it mean a singly or double linked list?
thank you
Comment: Tell your teacher if he / she asks stupid questions, then they get stupid prizes.
Answer:
I have the following requirement:
Create the Linear List functions:

This wording is already strange for C++. In C++, several functions that work on the same data are usually grouped into a class.

CreateList, AddNode, DeleteNode, SearchNode and DeleteList,

A class has a name, in this case List or LinkedList.
Since the functions are defined inside the class, their names don't need to contain the word List as that would be redundant.
The function names should also not contain the word Node since that is an implementation detail about which the caller of these functions should not worry.
The CreateList function should be the constructor of the class. Constructors don't have a name.
The DeleteList function should be the destructor of the class. Destructors don't have a name.

for a list holding signed long integers.

When designing a data type, it's easier at the beginning to work with a single concrete data type. Later that data type is usually replaced with a placeholder so that this list can be used with any type, making it a template class. For the purpose of this exercise, your teacher most probably means the single type long int (which is implicitly signed). If you want, you can also write signed long int, that's equivalent.

by "linear list" does it mean a singly or double linked list?

We cannot tell you. That's something you have to ask your teacher.
In idiomatic C++, the basic structure of the type definition would look like this, I left out the implementation details:
class LongIntList {
public:
    LongIntList();   // This is the constructor
    ~LongIntList();   // The ~ marks this as the destructor
    void Add(long int element);
    void Delete(long int element);
    bool Search(long int element);
}

In the C++ standard library, the Search function looks a bit different (it returns an iterator instead of only a boolean value), but for a beginner, the boolean is good enough. Iterators will be taught later.
In summary, your current instructions will make you write code with a simple structure, which is good for learning. But be aware that the resulting code is not considered good C++ code. After introducing the necessary concepts, your teacher will hopefully let you transform the current code into good C++ later. If that doesn't happen in the next months, you can post your current code (which must work as intended) to https://codereview.stackexchange.com/ to let experienced C++ programmers tell you what it should really look like, and why.
Answer: This is teaching terminology, here is the translation:

Linear List - a list which is not circular (last node is not linked to the first node). Can be singly or double linked. If not specified, the teacher usually wants singly, but you should ask.
signed long integers - the long type. Signed integers include negative numbers (int, long, etc.). Unsigned integers have only positive numbers (unsigned int, unsigned long, etc.).
Answer: A 'signed' integer is an integer with a 'sign' bit indicating if it is a negative or positive value.
A 'long' integer that may be longer then an int depending on the architecture. On 32-bit a long is at-least 32-bit and the same size as an int, on a 64-bit system a long is 64-bit.
You do not need to specify 'signed' as it is the default, simply declaring a variable as a long will make it a signed long variable. On the other hand if you only wanted a positive going value, you would need to specify it as unsigned long.
For a signed integer, the maximum is 1/2 the maximum of an unsigned because it's split down the middle. For example, a 16-bit unsigned integer's range is 0 to 65535, but a signed 16-bit integer's range is -32768 to 32767.
A linear list is exactly that, a list that is in a linear order, it doesn't specify how you're to create it, however as the functions use the terminology "Node" I would assume that a Linked List would suit the paradigm more correctly. See std::list as this would likely suit what you're doing.
Comment: *A 'long' integer that may be longer then an int depending on the architecture. On 32-bit a long is 64-bit, on a 64-bit system a long is 64-bit.* no guarantees of any of this being correct. `long` is at least 32 bit and at least the same size size of `int`. Everything else is up to the implementation, and nothing prevents the implementor from making all integral data types 64 bit. Don't laugh. Cray used to do almost exactly this.
Comment: Thanks for the correction, this is exactly why I use `stdint.h` defines.
Comment: "nor can you" — I can.

Meaning of Signed Long Integer