Friday, December 08, 2017

Social Security Basics

I recently attended a few workshops sponsored by GM and hosted by Fidelity.  Here's what I learned:

Important Terms:
FRA - Full Retirement Age - 66 or 67, depending on your birthday.

AIME - Average Indexed Monthly Earnings - This is the average monthly amount you earned in your highest-earning 35 years.  It is indexed for inflation.  AIME is used to calculate PIA.  If you don't have 35 years of earnings, zeros will be averaged in.

PIA - Primary Insurance Amount - amount of Social Security payments you will receive at full retirement age (FRA).

Estimating your benefits - your PIA is based on the average of 35 highest earning years, so try to work 35 years if possible.  Details are  here.

If you were a homemaker and didn't work many years, you can claim 50% of your spouse's PIA if that is more than yours.  It does not affect your spouse's amount.

When to claim your SS benefits?
If you wait until FRA, you get 100%.  If you claim earlier you get less, claim later you get more, until age 70 when the amount does not go up.  There's no magic to claiming at your FRA.  You can claim earlier or later. It's not "right" to claim at FRA, it's just one option.

From for birthdate in 1958
Age% of PIA
62 70
63 80
64 87
65 93
66 100
67 108
68 116
69 124
70 127

For each year you wait you get about 8% increase in payments.
Better to wait if you have other resources, but it depends on your expected life expectancy.
The break even age is 81 or 82.  Will you be alive then?  If not, take SS early.

The average amount of SS paid is $1,300 per month, or $15,600 per year.
$2,788 is maximum you can receive per month.  So if you paid in buckets of money during your career you may reach this level at age 64, so you might as well start taking then, because it won't hurt you.

Survivor benefits can start when the survivor is 60 yrs old.

Working before FRA may reduce your PIA.  Details
here.  Some states tax SS income.

Will SS go bankrupt?  In the year 2034 trust fund will go dry, but SS can still fund 77% of obligations from taxes, we just won't have the trust fund.

One scary tidbit was that health care costs for a couple over 65, with Medicare, was $902 a month.

Friday, December 01, 2017

Git Access Error on Windows 7: unable to access ... Received HTTP code 407 from proxy after CONNECT

Occasionally I get this error connecting to Git a github:

$ git pull
fatal: unable to access '': Received HTTP code 407 from proxy after CONNECT

The proxy is complaining that the password is out of date by giving us a  407 error,  which is an authentication error.  Then I remember I just changed my system password.

The solution is easy, just tell Git your new password:

git config --global http.proxy
git config --global https.proxy

Friday, November 24, 2017

Saving Money by Moving to an OOma phone

Being the frugal person I am (having the ginger and Scottish genes), I found it hard to pay $20 a month to my cable provider for an internet land line.

(I know, I know, the 70s called and wants their phone back)

I replaced my internet provider's $20/month phone with an $80 one time purchase Ooma phone.

Transferring our old number to the new Ooma phone cost a one time fee of $40.
The Ooma phone has to charge taxes on their service of $3-$4 a month.
At a one-time charge of $120 with the monthly tax , our family should start saving money in only seven months.
We should be saving $17 a month after that.

And one more thing:  Removing your internet phone from your internet provider makes switching to lower cost internet providers easier.  No messy phone number to switch every time you go with a lower cost provider.

Wednesday, November 22, 2017

JavaScript Notes

Objects and Prototypes

Notes from Jim Cooper's excellent PluraSight course on JavaScript Objects and Prototypes and Kyle Simpson's Advanced JavaScript class, and my random scribblings.

Use to play with JavaScript.

  1. Six Ways to Create Objects:
    1. Creating objects with Object Literals
      'use strict';
      var cat = {name: 'Fluffy', color: 'White'}
      console.log(; //Fluffy
      cat.age = 3; //we can create properties on the fly
      cat.speak = function() {console.log("Meeooow") }//add functions directly
    2. Creating objects with constructors:

      Calling "new" makes the function a constructor and does four magic things:

      1. Creates new object
      2. Sets the 'this' to its context
      3. Calls the function
      4. Returns a pointer to the new object

      Here's Jim's example:

      function Cat(name, color) { = name
        this.color = color
      var cat = new Cat('Fluffy','White');
      This writes:
      [object Object] {
        color: "White",
        name: "Fluffy"
    3. Creating objects with Object.create syntax Object.create()

      The "create()" method exists at the top level object cleverly named, "Object".

      Object.create(proto[, propertiesObject])

      "Object.create()" creates a new object and sets its prototype link to be the first parameter passed in. It also copies the properties from propertiesObject to the new object.

      The "new" keyword is just syntactic sugar, we could do the previous example like this:

      var cat = Object.create(Object.prototype,
      name: {
      value: 'Fluffy',
      color: {
      value: 'White',
      o = {};
      //is shorthand for 
      o = Object.create(Object.prototype);
    4. A Fallback Polyfill for Older Browsers

      Older browsers may not have the "create()" method, so you can use a polyfill from

      if (typeof Object.create !== "function") {
          Object.create = function (proto, propertiesObject) {
              if (!(proto === null || typeof proto === "object" || typeof proto === "function")) {
                  throw TypeError('Argument must be an object, or null');
              var temp = new Object();
              temp.__proto__ = proto;
              Object.defineProperties(temp, propertiesObject);
              return temp;
    5. Creating objects with the new ECMAScript 6

      ES6 has new built in support for creating classes:

      'use strict';
      class Cat {
         constructor(name, color) {
            this.color = color
         speak() {
  2. Properties
    1. Bracket Notation

      Besides the dot notation, 'this.color = "blue"' you can use the bracket notation. An advantage of the bracket notation is that you can use property names with embedded spaces:

      cat['color'] = "blue";
      cat['Eye Color'] = "green";
    2. Descriptors

      JavaScript properties have 4 descriptors: value, writable, enumerable, and configurable.

      1. Value

        This is simply the actual "value" of the property.

      2. writable

        "writable" is a boolean that determines if the value can be written over.

        var cat = {name: 'Fluffy', color: 'White'}
        console.log(Object.getOwnPropertyDescriptor(cat, 'name')
        Object {
          value: Fluffy
          writable: true
          enumerable: true
          configurable: true

        To set a property of field use defineProperty

        Object.defineProperty(cat, 'name', {writable: false})
        var cat = {
           name: {first: 'Fluffy', last: 'LaBeouf'}, color: 'White'

        To prevent writing of an object:

      3. enumerable

        If "enumerable" set to false, the property will not show up in any list

        Object.defineProperty(cat, 'name', {enumerable: false})
        console.log(JSON.stringify(cat))//will not show enumerable-false items

        How to Loop Over Enumerables:

        for(var propertyName in cat) {
          console.log(propertyName+':'+ cat[propertyName])
      4. configurable

        If configurable is set to true you cannot change enumerable attr or configurable attr, or delete it, but can change writable attr.

        Object.defineProperty(cat, 'name', {configurable: false}
    3. Getters and Setters

      Let's create a new property and add a get() and set() methods.

      var cat = {
         name: {first: 'Fluffy', last: 'LaBeouf'}, color: 'White'
      Object.defineProperty(cat, 'fullName',
      get: function() {
        return + ' ' +
      set: function(value) {
        var nameParts = value.split(' ') = nameParts[0] = nameParts[1]
      console.log(cat.fullName); //"Fluffy LaBeouf"
      cat.fullName = 'Top Cat'; //"Top Cat"
  3. Prototypes and Inheritance
    1. We can add methods to individual objects. Here we create a 'last' method to an object, arr.

      'use strict';
      var arr = ['red','blue','green']
      Object.defineProperty(arr, 'last', {get: function() {
         return this[this.length-1];}});

      But wouldn't it be nice to add a method to all arrays. We can by adding a method to 'Array's prototype which is shared by all the Array objects. If an individual object doesn't contain a function, it looks to its "prototype" to see if it has that function.

      'use strict';
      var arr = ['red','blue','green']
      Object.defineProperty(Array.prototype, 'last', {get: function() {
         return this[this.length-1];}});
      console.log(arr.last); //"green"
      console.log(['sour','sweet','bitter'].last); //"bitter"

      All functions have a built-in property that points to another object called "prototype".

      var myFunc = function() { }
      console.log(myFunc.prototype); //[object Object] { ... }

      Objects do not have a prototype property but they have a __proto__

    2. function Cat(name, color) { = name;
        this.color = color;
      var fluffy = new Cat('Fluffy','White');
      console.log(Cat.prototype);//[object Object] { ... }
      console.log(fluffy.__proto__);//[object Object] { ... }
      console.log(Cat.prototype === fluffy.__proto__);//true
      Cat.prototype.age = 4;

      Important: A function's prototype is the object instance that will become the default prototype for all objects created using this function.

      Jim has a great example of linking two classes, "Animal" and "Cat" into an inheritance chain. It's kinda tedious and error prone. Be very careful. This is why Kyle Simpson prefers OLOO. (more on that later).

      'use strict';
      function Animal(voice) {
        this.voice = voice || 'grunt';
      Animal.prototype.speak = function() {
      function Cat(name, color) {, 'Meow'); = name;
        this.color = color;
      Cat.prototype = Object.create(Animal.prototype);
      Cat.prototype.constructor = Cat;
      var fluffy = new Cat('Fluffy','White');

      This prints:

      [object Object] {
        speak: function () {

      The above code is a little cleaner with the new ES6 "class" structure:

      'use strict'
      class Animal {
        constructor(voice) {
        this.voice = voice || 'grunt'
        speak() {
      class Cat extends Animal {
      constructor(name, color) {
        super('Meow'); = name;
        this.color = color;
      var fluffy = new Cat('Fluffy', 'White');

JavaScript Scope

My notes from Plurasight's Advanced JavaScript by Kyle Simpson. His series of online books is available on github at

A good reference site for JavaScript is the Mozilla Developer Network MDM at

A good place to learn styles of programming JS is

The actual definitive spec is at

  1. Details of Scope

    Scope: where to look for things

    JavaScript is not interpreted. Bash is interpreted. The JS compiler goes through all the code before starting execution. It finds declaration of variables and puts them into appropriate scope slots. Finds "var" and "function"s.

    JS has function scope only (kinda).

    lhs - left hand side (target)

    rhs - right hand side (source)

    "undefined" really means uninitialized

    Kyle has a good way of explaining scope: When executing a function "foo" and encountering a variable "foo", JavaScript asks the question: "Hey, scope of 'foo' do you have a lhs reference to variable x?"

    For a function declaration, the first thing in the statement is "function name()".

    function bar() { ... }

    function expressions should have names

    var foo = function bar() { ... }

    Why use named functions and not anonymous?

    1. Can refer to itself for recurse
    2. Can find it in minified stack trace
    3. Is self-documenting
  2. eval

    "eval" cheats lexical scope. putting an "eval" in your code, forces the engine to run slower in strict mode, code is more optimizable. Don't use eval unless absolutely necessary.

    For example, using setTimeout with a string of code is bad practive since it invokes "eval()"; better to use with a function:

    setTimeout("console.log('hi')", 1000); 
    setTimeout(function () {console.log('bye');}, 2000); //ok with func pointer
  3. "with" is "more evil than eval"
    var obj = { a: 2, b: 3, c: 4 };
    with(obj) {//implies an obj.
    a = b + c;

    "with" effects the scope and in strick mode, you can't use "with".

Immediately-invoked-function-expression (IIFE) pattern

This is a widespread pattern in JavaScript with a history here: It forces a function to run immediately - hense the catchy name.

var foo = "outside";
(function() {
  var foo = "inside";
  console.log("foo:"+foo)//prints "inside"

"let" (ES6) and block scope

"let" will set the scope of the variable to the "for" loop (or outer braces), not the function scope as "var" would have done. creates an implicit block on the "for".

function foo() {
  for(let i=0; i<var.length; i++) {

warnings: "let" is not hoisted. If in the middle of an if statement block, the variable is only available after the "let". The area above the "let" declaration where the variable is not defined is called the "Temporal Dead Zone".

How to get a new scope? create a function, catch, or a brace with the "let" in ES6

"undefined" is a value, meaning a variable doesn't currently have a value.

"undeclared" never been declared. reference error.


during compile phase, functions and then declarations are "hoisted" to the top.

var a=6;
function foo() { ... }

The compiler rearrages and hoists declarations to top

function foo() { ... }
var a;

Why hoisting? mutual recursion would be impossible. like c header files.

The "this" pointer

Four Rules for how the 'this' keyword get bound.

Every function, while executing, has a reference to its current execution context called "this".

The value of the "this" pointer depends on the call site i.e., where the method gets invoked.

BTW, "this" is not like "this" in any other language.

  1. new

    "new" turns a function into a constructor call and sets the this pointer

    The "new" constructor does four things:

    1. A brand new empty object will be created
    2. The new object gets linked to another object
    3. The new object gets bound as the "this" keyword for the function call
    4. If the function doesn't return something, it will return "this"
  2. Explicit binding Rule

    .call() or .apply() take as their first arg "this"

    example of hardcoding

    function foo() { console.log(; }
    var obj = { bar: "bar" };
    var orig = foo;
    foo = function() {; } //forces this context on foo

    utility to do hardbinding:

    function bind(fn,o) {return function() {; };}
    function foo() { console.log(; }
    var obj = { bar: "bar" };
    foo = bind(foo,obj);

    put bind on Function prototype

    if(!Function.prototype.bind2) {
      Function.prototype.bind2 =
        function(o) {
          var fn = this; //the original function
          return function() {
            return fn.apply(o,arguments);
    var obj = { bar: "bar" };
    foo = foo.bind2(obj);

    ES5 has a builtin "bind"

    hardbind makes "this" be predictable
  3. Implicit binding Rule

    - object calling function becomes the "this"

  4. Default Binding Rule

    in strict mode, default "this" is set to the undefined value

    not in strict, "this" defaults to global, which in browser is window

Summary: Four Questions to determine what is the "this" object
  1. Was the function called with the "new" keyword? use that object.
  2. Was it called with .call() or .apply(). Use explicit object
  3. Was the function called with an owning object? use that.
  4. Default: global object (except in strict mode)

Details in his second book "You Don't Know" - chapter 2


Closure comes from Lambda calculus. Closure is when a function "remembers" its lexical scope even when the function is executed outside that lexical scope.

function foo() {
  var bar = "bar";
  function baz() {

function bam(baz) { baz(); }

//calling a method that returns a method that retains lexical scope (Closure)
function foo() {
  var bar = "bar";
  return function() { 

function bam() {
    foo()();  //call the returned method


The Classic Closure Example

for(var i=1; i<=5; i++) {
  setTimeout(function() {
    console.log("i: "+i);//writes 6 since i references outer scope

for(var i=1; i<=5; i++) {
  (function(i) {//use an IIFE
  setTimeout(function() {
    console.log("i: "+i);//writes 1,2,3,4,5

Classic Module Pattern

Two Characterics of Classic Module Pattern

1. Must have outer function wrapper

2. One or more functions that are returned that have closure over inner scope to access variables

example of module pattern

var foo = (function() {
  var o = {bar: "bar" };
  return {
    bar: function() {
//example of modified module pattern
var foo = (function() {
  var publicAPI = {
    bar: function() {
    baz: function() {
return publicAPI;

Object Orienting

OO Design Patterns

  1. Prototype

    Every single "object" is built by a constructor function.

    Each time a constructor is called, a new object is created.

    A constructor makes an object linked to its own prototype. (In class-based system, new objects are instantiations of the class)

    An object has a link called ".prototype" pointing to its prototype object. The prototype object has a link back to the object called ".constructor"

    A object has a private link called "[[Prototype]]" which points to its prototype object.

    Three ways to get a "new"'d object's prototype.

    1. A object in all browsers except IE has a public link called "__prototype__" (called DunderProto) which points to its prototype object.(in ES6, adopted in IE11)

    2. The standard way to get an object's prototype is "Object.getPrototypeOf(o)" (in IE9, ES5)

    3. For IE8 (ES3): o.constructor.prototype (but .constructor and .prototype are writtable)

    A function has a [[Prototype]] link (__proto__ in ES6 and all browsers except IE below 10) to the object "Function"'s prototype which contains "call()", "apply()", and "bind()".

  2. Inheritance

    Classical inheritance copys the class to make object. Instead use "Behavior Delegation".

    OLOO - Objects Linked to Other Objects

    function Foo(who) { = who;
    Foo.prototype.identify = function() {
      return "I am " +;
    function Bar(who) {,who);
    Bar.prototype = Object.create(Foo.prototype);
    Bar.prototype.speak = function() {
        alert("Hello, " + this.identify() + ".");
    var b1 = new Bar("b1");
    b1.speak(); //alerts: "Hello, I am b1."
    //a slight improvement
    var b1 = Object.create(Bar.prototype);,"b1");
    //moving forward
    bar b1 = Object.create(Bar);

Monday, November 13, 2017

Building Beautiful RESTful APIs in .Net Core - Adnug November Meeting

Nate Barbettini talked to 26 developers at the Austin .Net Users Group.

Here's my notes from his talk:
RPC (Remote Procedure Call) vs. REST (REpresentational State Transfer)
RPC endpoints are verbs (, in REST endpoints are resources (/User)

HATEOAS - hypermmedia as the engine of application state
Data exchange should be treated as if the client were a web browser
No documentation or out-of-band info needed

Use RPC when dealing with a simple object, like the Slack API
Use REST when dealing with lots of different objects with CRUD operations possible on all of them
GraphQL is useful when trying to traverse a graph of REST calls

REST + JSON is popular but hard because no schema is available for the data.
HAL and JSONSchema try to solve that.  Also Ion trys to give structure to JSON data.
The Ion content type is application/ion+json
Ion data is embedded in JSON with fields, like "href","rel", and "value".

ASP.NET Core is a full rewrite of .Net to be portable, faster and cleaner.
Dependency Injection is now in the framework, don't have to download StructureMap

Nate has a free eBook about starting with .Net Core at
Demo to create new .Net Core API with Web API template.  No diff between MVC or API controllers.

Nate used package Entityframework inmemory to do development of demo.  inmemory just gives an inmemory

ASP.NET Core is friendly to async/await pattern.  async first philosophy.


Nate has a course on this. is the result of his 4 hour Lynda course.

Nate has done a great job of learning .NET Core and sharing his knowledge with the community free of charge.

Wednesday, November 01, 2017

Just Switched Electrical Providers to Our Energy LLC Using

In Texas we can choose our electrical provider. is a website to help consumers pick a provider, but it's very difficult to find which provider is the cheapest for me, since providers have a complex rate structure.  I did a previous blog post on choosing an electric provider.

I've found a great website,, which cuts through all the weird pricing structures and shows the best rate for your usage.  The service costs $10, but it saved me $150 for the next year. said my cheapest option was Our Energy LLC, so I switched.   I had not heard of them before,  but will let you know how they work out.

Be careful not to just continue with your "current" provider when your time is up.  I think they are tempted to offer you a decent plan, but not the best, since it's such a hassle to change.  When I called my provider, and said that I had found a better rate, they offered me a better rate plan than what was mailed to me to renew. 

Here's my results from


Saturday, October 28, 2017

Saving for Retirement

The Basics of Saving for Retirement

I know, I know, I've waited to long to have "the talk" with my daughter who is a Junior in college. But something else always came up. The time never seemed right and I felt awkward, but I finally sat down with her and told her what I wish I'd known at her age about finances. I would be much further along in retirement savings if I'd just known these facts.

You can work hard all your life, put lots of money into your savings, but can still end up with a poor retirement if you don't save well.  Save wisely and you can enjoy a wonderful retirement.

How much money do you need to retire? 
The Four Percent Rule. The typical rule of thumb is that you can take out 4% of your money every year for your retirement.  So if you need $40,000 dollars a year from your savings, you will have to save one million dollars by retirement age.  That's a lot of money and it doesn't just happen.

General Tips
1. Don't buy toys on credit.   Credit cards carry a huge interest rate and you will be losing money every time you have a balance at the end of the month.  Pay your credit cards off at the end of the month.  Buy clothes at Goodwill, eat frugally, take local vacations, drive an old car, use a Windows computer - do what you must, but never carry a balance on your credit cards.

Your home and cars are the only things you should buy on credit.  Save up your money so you don't have to buy cars on credit.

2. Use a Credit Union.  Banks are made to provide profits for their owners, the stock holders.  Banks try to wring every last cent from you.  Credit Unions belong to the depositors and hence try to serve you, the depositor.  That being said, sometimes banks can provide services like ATMs everywhere that make them worth a second look, but remember banks live to make other people money.

Bankers circling to figure out ways to charge more fees
Basics of Investing
1.  You get paid for risk.  Since inflation runs about 2% a year, if you put your money in the bank in a risk-free FDIC insured account at 0.05% interest, you are losing money every year.  You need to take more risk to earn more money.

2. What is the stock market?  When you own a stock, you own a little piece of the company.  When the company makes a profit for the year they will pay you a tiny part of that profit which is called a dividend.  If a company has a million stock shares, and you own one stock, you will get one-millionth of their profits for the year.  Although some companies don't pay dividends, but let their stock price rise instead.  Either way you can make money.

3. Stocks are risky. If the company goes bankrupt you can lose all the value of your stock.  But with greater risk comes greater reward.  The stock market averages about 8% returns a year.

4. What are stock funds?  Stock funds are composed of a group of other stocks.  It's like a basket of baskets; when you buy a stock fund (big basket), you buy a small piece of multiple stocks (little baskets).  Two types of funds exist, managed and indexed.  Managed funds buy stocks based on the opinion of a highly paid stock picker.  Index funds buy stocks based on an list, like the 500 biggest companies in the stock market (the S&P 500 list) or the 1000 biggest companies (the Schwab 1000).

Index funds will almost always beat managed funds because managed funds have a higher expense, like 1-2% of all your money, while index funds may only charge you .03% of your money invested in them.  Over the decades this tiny difference can amount to over a hundred thousand dollars.

Don't invest in individual stocks, buy index stock funds. Individual stocks are fun to play with, but they're not stable enough to warrant high-stake investments.

You can buy stocks and bonds at a company like Vanguard or Schwab.  You create an account and send them money and they will buy and hold the stocks and bonds for you.

4. What are bonds?  Companies borrow money from investors by selling bonds. They are like government savings bonds - you buy them now and can redeem them later with interest. While bonds earn interest and are safer than stocks, they don't earn as much potential profit.  When a company goes bankrupt the bond holders get their money before stock owners, less risk so less reward.  Government bonds are the safest investment, but only pay about 1.5 - 2% returns.

6. Diversify.  You should own a mix of stock index funds and bonds in case the stock market goes way down.

What percentage in stocks?  One rule of thumb is to have the percentage of stocks the same as (120-your age), so at age 50 you should have 70% of your savings in stocks, both domestic and foreign.  When you are 20 you should be 100% in stocks, since you have a lot of time to ride out the ups and downs in the market.
You should also diversify over countries.  Have some stock and bonds from other countries.
 John Bogle, founder of the Vanguard Group which champions low cost index funds recommends this set of funds:
40% in the Vanguard Total U.S. Stock Market Index Fund
20% in the Vanguard Total International Stock Market Index Fund
40% in the Vanguard Total Bond Market Index Fund

7. Dollar cost averaging and beating the market.  Trying to invest money in the stock market when you think it is low, and selling when you think it is high almost never works.  Instead, invest every month when its going up and down and just ride out the storms.

The S&P 500 in 2008 was around 1500 and dropped to 700.   Many of my friends sold their stocks and lost half their investments.  If they would have been patient, they would have made all that money back and then some since the market has recovered to 2500.

8.  Real Estate.  You can invest in real estate, but it takes time to manage.  Your own home is typically, but not always, a good investment.  Another way to invent in real estate is a Real Estate Investment Trust (REIT), which is like a stock, but it invests in real estate like apartments, shopping malls, office buildings, and homes.  This is the simplest way to own real estate.

9.  Invest in ways that minimize your taxes.  Your work will typically have a Retirement 401(K) plan that will allow you to invest money without it first being taxed.  They will typically match a part of your investment, like the first 4% of your salary.  You get to deduct the amount you invest from your income so you don't have to pay taxes on it, yet.  When you retire you will pay taxes when you pull money out, but the money has grown for 30 years without paying taxes.

If your company doesn't offer a 401K, you can invest in an IRA, or a ROTH account. If you invest in an IRA, it is untaxed going in, allowing for compounding interest on the full amount you put in, but taxed when you withdraw money from the account. If you invest in a ROTH account, money is taxed going in, but considered non-taxable income when withdrawn.

10.  How much to save?

As a general rule you should try to 15% of your salary for retirement. The following table shows how far along you should be at a particular age to be on track.

Age Save this multiple of your salary
30 1x
40 3x
50 6x
60 8x
67 10x

In Summary
Save 15% of your salary for retirement every month in a mix of domestic and international stock index funds and bond funds into your company 401K or a ROTH account.

Planning and saving for your future is hard work, but your 65 year old self will thank you.