Financial Blunders and gift giving – 2017 edition!

I detailed in my post last year here about my financial blunders in 2015 and 2016 … now its time for this years blunders!!

-Sold Bitcoin too early in early May (@ $1600 instead of waiting a few weeks when it went up to $2800) – this decision cost me about $10k in lost potential funds.
-Held Ethereum too long. I should have sold ETH at $400 in June but didn’t want to make the same mistake as above ^ but held TOO long .. it went back down to $200 and now thats like $2k in lost potential funds
-Booked too many flights from Seattle to San Francisco because I stupidly expected my TN visa application to be swift – it was not. I was rejected twice for my visa application, had to wait an extra week for parents/company to ship me extra documents and missed those flights. Total cost of missed flights was about $650.
-Coming back from Seoul to San Francisco in July. For some reason Expedia did not put me in the Asiana airlines system. So after much calling and waiting, I had to cancel this ticket as well and book another one. This was a $650 ticket as well + missed work days.
-Messed up currency exchange rates while I was trying to convert CAD back to USD – this blunder cost me $1k USD because I stupidly kept trying to convert back and worth to try and make it work with paypal and eventually gave up – $1k in fees later.

Generosity
I have to admit, I’m a pretty generous guy. I often give away stuff to my family and friends for free. This year when I go back to Canada in a few months, will be no different. I’m giving my Amazon echo show ($200), Logitech Mouse, Asus gaming laptop ($500), Toshiba Portege Z30 ultrabook ($300) to my brother, Amazon Echo Show ($200) to my parents, Soundblaster Roar 2 ($200), Amazon Echo Dot ($50), and HP Elitebook 820 ($300) to my relatives for easy video conferencing to my parents. That’s a lot of stuff!

Over the past few years this is what I’ve given away for free:
2011 – gave my mom a Kindle Fire ($200) – it was the first generation and wasn’t available in Canada at that time
2012 – gave my dad my Nexus 7 tablet ($200)
2013 – gave my friend my Canon wireless microphones ($200)
2013 – gave my relatives all Kindle Fires ($100 each)
2013 – gave my mom a Kindle Fire HD 8 ($200)
2013 – gave my brother a Contour Roam action cam ($200) and Shure SE250 earphones ($200)
2014 – gave my friend my Audio Technica noise cancelling headphones ($200)
2014 – gave my dad a Lenovo smartphone ($200)
2014 – gave my brother a Soundblaster AX200 speaker ($200)
2014 – gave my mom a Lenovo Thinkpad Twist laptop ($300)
2014 – gave my mom my old iPhone 4S ($400)
2015 – gave my friend a bunch of my PS3 games ($1000+ originally)
2015 – gave ebayer my OLED TV for free ($500)
2015 – gave my dad my Polk Audio Hampden speakers ($200)
2015 – gave my mom my Audyssey Wireless speakers ($200)
2016 – gave my mom a Huawei Honor 5X ($200)
2016 – gave my friend my GoPro Hero 3 ($200)
2016 – gave ebayer my Thinkpad Yoga 14 laptop for free ($500) + Kindle Fire HD ($80)
2017 – gave my friend my Dell USBC Dock ($80)
2017 – gave my friend my Samsung Soundbar ($200)
2017 – gave my mom Amazon Echo Show ($200)
2017 – gave my relatives Amazon Echo Dot ($50) + Soundblaster Roar 2 ($200) + HP Elitebook 820 ($300)
2017 – gave my brother Amazon Echo Show ($200) + Toshiba Portege Z30 ultrabook ($300) + Logitech Mouse + Asus gaming laptop ($500)

Why is toggling a search box in a header so difficult in Angular 2?

In Angular 2 I have the following pseduocode…

<header>
<form class="searchContainer" [ngClass]="{'visible': showSearch, 'invisible': !showSearch}">
...
</form>
</header>

As you can see I have a header with a search form container that has the class ‘visible’ when the variable ‘showSearch’ is true, and ‘invisible’ otherwise. As a component by itself with this html, this works fine. When the user clicks the search icon showSearch is set to true and the form shows.

Now the issue comes when I want to hide this container again. I want to set showSearch to false and thus hide the container when the user clicks anywhere that isn’t the header (ie. the body of the page).
Now in jQuery, this would be easy. On click of the body, you would find the element with ‘.searchContainer’ and removeClass(‘visible’).addClass(‘invisible’) right? Easy.

Except this is Angular 2. We don’t have jQuery (or want to use it) here. Normally what I would do in this case, is to have something like this in the parent component that contains the header component:

<app-header [showSearch]="showSearch"></app-header>
<body>
..
</body>

That’s the HTML. I pass the showSearch variable down from the parent to the child and toggle it with the parent right? That’s how normally it works. One way binding. (If the child needs to talk to the parent it uses event emitters instead).


@HostListener('click', ['$event'])
closeSearchBox(event) {
const toElement = event.toElement;
let insideHeader = false;
let node = toElement;
while (node != null && node.classList !== undefined) {
if (node.classList.contains('header-container')) {
insideHeader = true;
}
node = node.parentNode;
}

if (!insideHeader) {
const searchBox = this.elementRef.nativeElement.querySelector('.search-container');
const searchMenu = this.elementRef.nativeElement.querySelector('.header-menu-list');
if (searchBox.classList.contains('visible')) {
this.showSearch = false;
}
}
}

So this should work right? I have an HostListener on the parent (that’s really the whole body of my app) so if the user clicks anywhere it will check to see if the element is outside the header (because we dont want to close it if its inside the header), and close the search container if it is.

Problem is… it didn’t work. I don’t know why. I searched StackOverflow, Angular Docs, scoured Google etc nothing. I even tried using EventEmitter but thats usually only from child to parent and not parent to child. Two-way bindings? nope doesn’t work either. It *should* just work inherently as part of Angular’s single way binding. Maybe the HostListener is outside the Angular Zone and I can use ChangeDetectorRef to detectChanges? Nope. That didn’t work either.
I *could* use a service and just subscribe to that service from the child component … but thats kind of overkill for ONE variable change to toggle a search box.

So finally. I had to make a solution that is not so elegant, and doesn’t use any variables or bindings. But it works.

<header>
<form class="searchContainer invisible">
...
</form>
</header>

So I took a jQuery-like approach of just toggling the class manually with ‘elementRef.nativeElement.classList’ instead. Its not as pretty as using bindings, but at least this way it works.


toggleSearchHeader(showHeader) {

if (showHeader) {
this.searchHeaderMenu.nativeElement.classList.remove('visible');
this.searchHeaderMenu.nativeElement.classList.add('invisible');
this.searchHeaderBox.nativeElement.classList.remove('invisible');
this.searchHeaderBox.nativeElement.classList.add('visible');
} else {
this.searchHeaderMenu.nativeElement.classList.remove('invisible');
this.searchHeaderMenu.nativeElement.classList.add('visible');
this.searchHeaderBox.nativeElement.classList.remove('visible');
this.searchHeaderBox.nativeElement.classList.add('invisible');
}

}

I have to substitute changing one variable showSearch with a whole method that does janky DOM crap and..


@HostListener('click', ['$event'])
closeSearchBox(event) {
const toElement = event.toElement;
let insideHeader = false;
let node = toElement;
while (node != null && node.classList !== undefined) {
if (node.classList.contains('header-container')) {
insideHeader = true;
}
node = node.parentNode;
}

if (!insideHeader) {
const searchBox = this.elementRef.nativeElement.querySelector('.search-container');
const searchMenu = this.elementRef.nativeElement.querySelector('.header-menu-list');
if (searchBox.classList.contains('visible')) {
searchBox.classList.remove('visible');
searchBox.classList.add('invisible');
searchMenu.classList.remove('invisible');
searchMenu.classList.add('visible');
}
}
}

So yeah as you can see those are the changes I needed to get it to work. For some reason, using a variable inside `HostListener` and passing that down to the child component doesn’t reflect the bindings. So I have to use a more archaic way instead. Not only that but its much more difficult to test with unit tests now that it relies on the DOM instead of an Angular variable. Bleh. If anyone knows why this is, let me know please! comment on this post..

Response to recent Google employee’s memo..

As many people on the internet know, a few days ago a Google employee’s internal memo was leaked out.. and there has been a big fuss about it.
Not only was there so much hate on that guy, claiming that he was ‘misogynist’ and ‘male chauvinist’ but his name and picture were actually leaked by the press as well! If this wasn’t character assassination and defamation I don’t know what is.

So, I’ve actually read the memo, and while I disagree with portions of it, for the most part I agree with him. My opinion is not a popular one in the liberal majority Silicon Valley. But I can assure you there is nothing that sexist / misogynist about what he wrote. First off, people should stop using that term so frequently because it literally means someone who hates women. This memo does not come off to me as someone who hates women. The main point he was getting across is that 1. conservatives are discriminated against in the tech industry and 2. Women’s biological differences with men are the reason why there aren’t as many women in the tech industry

His first point is actually true, since Google promptly fired him after that memo leaked. As a private company they have all the right to do that, but it goes to show what happens when you have an unpopular conservative opinion in a sea of liberal opinions. Yes he had freedom of speech, but in the end if he violated Google’s code of conduct they had every right to fire him. I just don’t think it was fair since his opinion was actually quite valid.

Secondly, as an Engineer I am usually very skeptical of claims unless they are backed by science. I don’t believe in conspiracy theories like area 51 / aliens or chemtrails or 9/11 theories or moon landing hoax theories or stuff like that. I don’t believe in superstitions like Feng Shui or chinese medicine (pseudoscience) or go to tarot readers or astrologists since I don’t believe in the supernatural. I don’t believe in ghosts or monsters. I DO believe in global warming, because that’s backed up by science.
Now, while this is very hard to prove by science, it is actually common sense to everyone that men and women are not the same. Our bodies are built very differently. Our brains are wired very differently. There is a gender difference in humans just like there is in every other animal. That is quite easy to accept. So I don’t understand what is so misogynist or hard to understand that differences in the way each gender thinks is the reason why certain genders perform certain roles?? Being different is good. There’s nothing wrong with being different. If people really want a society where men and women are treated exactly the same, I would recommend those people to move to a communist society. Perfect gender equality there.

Men usually perform roles with physical labor like construction or mining, or roles that involve analytical thinking like mathematics, science or engineering. That is not to say women can’t do those roles, but definitely men have a dominant advantage in those roles. Women on the other hand, are much better at serving and caring for people. That’s why women tend to be clerks, cashiers, customer service reps, broadcasters, receptionists, nurses, etc. They are better suited for those positions than men. There is nothing misogynist or women-hating about this train of thought, this is the way that I feel after looking at other animal species and interacting with humans. Male lions don’t ask female lions to do the same task, they each have their own responsibilities. So why is it so unacceptable for humans to be the same? Even in engineer crazy India and China, there are more males than females in engineering. They have no reason to discriminate against women there (Asians are notorious for pushing that field onto all their children), yet there are still more males. Why? because men and women’s brains are different, that’s why. Its not hard to understand why. Anyone who’s been in a relationship before can tell you that women’s minds are way more emotionally complex than a man’s mind.

Because people like to be social justice warriors. They like to think that taking the stance that women are the victims of social constructs, that women can do anything men can do, and somehow that will make others think of them as better people and supporting gender equality more. Its total nonsense, just like third-wave feminism. I support equal pay for equal work and gender equality, but I do so while acknowledging that men and women have different roles in society. People are just fooling themselves, they are denying science and biology because ironically, they are the victims of the liberal social construct, the very social constructs that they fight against. Do they also believe that social constructs are the reason why men can run faster and jump higher than women can? The liberal echo chamber of the Bay Area puts pressure on people to care or think about minorities, disabled, women, etc to help anyone who’s “oppressed” historically, even if it goes against science or what they actually believe. This is unfortunate, and the firing of this man for his memo (which is personal btw it wasn’t meant to be leaked), just goes to show that if you do not reflect this liberal echo chamber, then you will be punished for it in America. Those are just my 2 cents on this issue.

tldr; I’m not a misogynist, I’m for gender equality, but I also believe men and women are biologically different and that makes them better at certain positions for each gender. This is backed by science and I support it.