Charisma

Looking back through the past elections going back to the 1980 election of Reagan, I noticed something about the winners. All but one had charisma. Despite some candidates being more capable and experienced. The charismatic candidates were better able to rile up their voters to get them to come out and vote, coupled with particular pains felt by those particular voters.

Let’s take a look at the elections:

1980: Reagan vs Carter (incumbent)

We had an oil shortage, inflation was high, coupled with high unemployment. Trouble abroad with Iran (hostages), and some other factors. Reagan was a masterful orator and could communicate with the masses. He gains the nickname, “Great Communicator“. He is able to get everyone on his side, wins in a landslide 489-49 electoral votes. Charisma wins.

1984: Reagan (incumbent) vs Mondale 

The economy is doing better for some, I still heard rumblings of tough times from the lower middle class. AIDS epidemic is front and center in the news. The First Lady, Nancy, is out and about with say no to drugs campaign. Mondale is not a very exciting candidate and things weren’t “feeling” so bad for the incumbent president. But it is hard for Mondale to compete with the charisma of Ronald Reagan, being obliterated in the general election 525-13.  Charisma crushes it.

1988: Bush (HW) vs Dukakis

Ok this is the one election that I felt wasn’t really affected by charisma of the candidates. I mean Dukakis was short and didn’t have the “look” people wanted in a president. Bush is actually quite boring but he gets to ride on the coat tails of a hugely successful and charismatic Reagan. I used to say the Republicans screwed themselves when they passed the two-term limit amendment to prevent another FDR. I think Reagan would’ve easily won a third term. I guess they were protecting themselves from a possible third Clinton or Obama term in the future🙂 I digress, Bush goes on to win 426-111. We have two pretty boring candidates, for this argument I will give Bush the charisma points. Charisma wins again.

1992: Clinton vs Bush (HW) (incumbent)

Ah my first election, I missed being able to vote in 1988 by a measly one year. So I was excited to begin the process of being able to vote. We’ve entered a new decade. Just coming off the Gulf War, some folks are upset that we went to war. Oil prices spiked in 1990 still fresh in minds. People are still talking about trickle down and supply side economics from the 80s not working for them. A charismatic southern democrat, Bill Clinton. He found a way to engage the young voters. He’s able to charm folks to a win over the incumbent President Bush. Clinton wins 370-168 even with a third party candidate in the mix. Charisma for the win.

1996: Clinton (incumbent) vs Dole

The economy is booming, the internet is opening to public, and gas prices were low, good ole $1 for a gallon. The Dow Jones was hovering in the 5000, by election time it had risen above 6000. Personally, just graduated college in 1995, got a good paying job as a software engineer. The administration wasn’t doing as well publicly though. Despite the scandals happening at the time, like the Lewinsky scandal, Clinton marches to a decisive 379-159 win over the experienced but less charismatic, Dole. Charisma 5 for 5 so far.

2000: Bush (Dubya) vs Gore

The new millennium. We survived the doom and gloom of the Y2K bug where the entire internet was going to just shutdown because of storing years as 2 digits instead of four, nothing happened🙂 The Dow Jones is well into 10000.  Tech is moving a faster pace: Google, founded in 1998 and  Amazon, founded in 1994, are both thriving. This is the year I got married, relocated to North Carolina, got a new job, and bought our first house all in the span of 4 months. So the Clinton/Gore administration policies were serving me just fine. The rest of the country didn’t seem to agree with me, well they kind of did.  This would’ve been another case where the 22nd amendment hindered a possible third term, Clinton was still quite popular, with an approval rating of low to mid 60s. Despite his approval ratings, Gore was very boring. He was intelligent and a statesman but just bleh. In comes a cowboy, a president you could have a beer with, but has the rough and tough charisma people think we need. This was a devastating election because it was so hotly contested when CNN announces it for Gore only to retract it because of discrepancies in Florida. Ultimately, Bush wins the election 271-266. Cowboy charisma wins over boring statesman.

2004: Bush (incumbent) vs Kerry

Just 3 years after the worst attack on American soil, we are at war in Afghanistan and Iraq. The economy isn’t fairing very well, after the dot com bust. Gas prices are rising, finally hitting $2. Bush has a pretty high approval rating, in the 60s, coming off his first term and his handling of September 11th. Remember, Bush was the cowboy. We put up John Kerry to be the opposing candidate. Kerry was a skilled politician, but not charismatic at all. He added John Edwards to his ticket which helped a little, but not enough to overcome the cowboy charisma of Bush. Bush wins 286-251. Charisma 7, boring 0.

2008: Obama vs McCain

In 2008, we are all annoyed at the high gas prices rising well past $3/gallon. Ravaged New Orleans by Hurricane Katrina which was hugely mismanaged, and Bush was blamed for it. The economy is doing poorly still reeling from the dot com bust and in the midst of what folks termed, The Great Recession. A young charismatic African-American, Barack Obama, rises from the Democratic party to round up millennials and minority groups with an easy to remember slogan: Yes We Can. Contrast this to McCain which many liberals seemed to like except when he was running for president, he became a different person to appeal to his base. He wasn’t very charismatic, which he tried to offset with his running mate, Palin. These two could not be more opposite. Obama wins 365-173 to become the first African-American president.

2012: Obama (incumbent) vs Romney

Two years after the Patient Protection and Affordable Care Act passes, people are upset at being forced to get health care. The administration bailed out the auto industry, bailed out Wall Street, gas prices are still in the upper $3. But the economy has survived, the Dow Jones hit a low of 6627 in 2009. By 2012, it had rebounded back to 13000. Romney was a capable candidate, especially compared to Bush from 2000. He was a successful governor, he would’ve been a capable president. Romney was missing one thing, charisma. He was no match for Obama’s charismatic speeches. Obama wins the 2012 election, 332-206.

2016: Trump vs Clinton (Hillary)

We finally hit the present. Gas prices are back into the low $2 range. The Dow Jones has climbed above 18000. This was an election purely based on charisma. Donald Trump is able to rile up his base to get people voting. He did it in a different manner, a pretty nasty bully but behind all the nasty things he said, he did have a message that many folks heard. But the Democrats thought that an experienced candidate that could maneuver the intricacies of the presidencies would be enough to win. We missed one aspect, Hillary Clinton was a dud from a personality point of view. She always seemed fake, tried to hard to empathize and I believe that was truly her undoing. Trump wins 306-232. Charisma wins yet again.

I’m extremely disappointed in the outcome of this years election. I still believe that Hillary Clinton was a more qualified candidate. I think she would’ve been tougher than any man could ever hope to be. She would’ve been a hawk in the Oval Office. She just couldn’t convince the people of that, which is equally important.

I firmly believe it doesn’t matter how much you know and how capable a leader you could be, if you lack personality you will NOT win the presidency. You need to have the charisma to be able to rile up your voters in order to increase your turn out. That’s really all it takes now, in this age of social media.

Looking forward to 2018 mid-terms and 2020! I just pray to God that Trump doesn’t destroy everything before then.

Network performance

Recently I had some network issues at work with lower than normal speeds, narrowed it down to the D-Link switch. I rebooted it and things seemed to be back to normal. Then at home I was hitting some similar performance issues both wired and wireless.

First thing was to verify that the wall port was giving me the correct speeds, then through the switch. Bingo, speeds were dropping. Ensured I was using Cat6 cables, found one cable that just didn’t want to connect, threw it out. Then I used the IT Crowd mantra and tried turning it off and on again. Speeds were back to normal.

Rebooted the downstairs switch as well, used iperf to measure the wired performance, 935 Mbits/sec.

$ iperf -p 2222 -c 172.31.6.3
------------------------------------------------------------
Client connecting to 172.31.6.3, TCP port 2222
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 172.31.6.221 port 35464 connected with 172.31.6.3 port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.09 GBytes   935 Mbits/sec
$ iperf -p 2222 -c 172.31.6.3
------------------------------------------------------------
Client connecting to 172.31.6.3, TCP port 2222
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 172.31.6.221 port 35470 connected with 172.31.6.3 port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.09 GBytes   935 Mbits/sec

So wired performance fixed. Next up was the wireless. I was getting 8.3MBps/66.4 Mbps, second run 7.0MBps/56Mbps. Reading the dd-wrt docs it reads:

You must use HT40 channel width & WPA2 AES when encrypting your wireless connection, otherwise the router will fallback to 802.11a/g speeds since WPA2 AES is a mandatory requirement of 802.11n specification as WPA2 AES is the only approved encryption method in the 802.11n standard.

Security was already WPA2 AES, but the Channel Width was set to the dd-wrt default of Full (20MHz). I changed it to Wide HT40 (40 MHz). Rebooted the router, and gave the tests another go.

First I used dd and nc then iperf. The dd reported 13.7MBps/109.6Mbps.

$ dd if=/dev/zero bs=1024K count=512 | nc -v 172.31.6.3 2222
Ncat: Version 7.12 ( https://nmap.org/ncat )
Ncat: Connected to 172.31.6.3:2222.
512+0 records in
512+0 records out
536870912 bytes (537 MB, 512 MiB) copied, 39.1152 s, 13.7 MB/s
Ncat: 536870912 bytes sent, 0 bytes received in 39.32 seconds.

iperf results in similar results if only slightly slower.

$ iperf -p 2222 -c 172.31.6.3
------------------------------------------------------------
Client connecting to 172.31.6.3, TCP port 2222
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 172.31.6.211 port 52358 connected with 172.31.6.3 port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   110 MBytes  92.2 Mbits/sec
$ iperf -p 2222 -c 172.31.6.3
------------------------------------------------------------
Client connecting to 172.31.6.3, TCP port 2222
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 172.31.6.211 port 52360 connected with 172.31.6.3 port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   102 MBytes  85.0 Mbits/sec

Two runs resulted in 92.2Mbps and 85.0Mbps. The three runs average out to 95.6Mbps wireless.

While not bad wireless performance, I was hoping to get closer to the 300Mbps product rating.

Network Hardware:

Computers:

  • Lenovo T460S
  • homebuilt server, MSI 785GTM-E45 motherboard with gigabit port

More Go links

Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.

https://github.com/spf13/cobra

Viper is a complete configuration solution for go applications including 12 factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats.

https://github.com/spf13/viper

pflag is a drop-in replacement for Go’s flag package, implementing POSIX/GNU-style –flags.

https://github.com/spf13/pflag

7 common mistakes in Go and when to avoid them
https://www.youtube.com/watch?v=29LLRKIL_TI

Go! Speed Racer Go!

I finally reached a point where I could start running the go version of sm-photo-tool. I finished the option validation for the list command. While I was testing it I noticed how much faster the Go version felt. Here are the python vs Go versions of the commands.

The python version took 80 milliseconds to run the validation of parameters and print out the error message. This is expected, you have to start the python VM (and if not precompiled, the code would need to be compiled). In this test, the code was precompiled.

$ time sm-photo-tool list invalid blah
ERROR: valid options are ['album', 'galleries']

real	0m0.080s
user	0m0.059s
sys	0m0.021s

Ok so how fast is the Go version? My guess was half the time, 40ms. I was way off. Try 6ms. SIX! That’s amazing to do the exact same amount of work.

$ time ./sm-photo-tool list invalid blah
ERROR: valid options are [album galleries]

real	0m0.006s
user	0m0.001s
sys	0m0.005s

Control your caps

On all of my computers I use gnome-tweak-tool to remap CAPSLOCK to CTRL. But there are times when I’m working in a virtual machine that doesn’t have that setup so I need to go back to old school methods.

If you’re on a box just run this from any terminal:

setxkbmap -option ctrl:nocaps

That avoids trying to kill a program with C which usually doesn’t work🙂

Go resources

Mostly a note to myself, but others might find them useful.

Use of Go articles

Here are some articles of companies using Go

Go After 2 years in production
Building Web Apps with Go
Companies using Go
Go at Heroku
Handling five billion sessions a day – in real time
Open Sourcing Our Go Libraries
The March towards Go
How we went from 30 Servers to 2: Go
OpenShift 3 and Go: Teaching Old Dogs New Tricks

Node.js to Go

I found quite a few articles where folks were using Node.js and moved to Go.

A closer look at Go and Node.JS
Making the Switch
from Node.js to Golang

Farewell Node.js
From Node.js to Go, Why One Startup Made The Switch
Node.js vs Golang: Battle of the Next-Gen Languags

Go web frameworks

Since web apps are the thing these days, it’s a good idea to look at web frameworks for Go.

Gorilla web toolkit
Beego Quickstart
Go kit – distributed programming toolkit
Revel web framework
IRIS Web Framework
A Survey of 5 Go Web Frameworks
Making a RESTful JSON API in Go
Key/value logs in Go
How We Moved Our API From Ruby to Go and Saved Our Sanity

If you have a framework, article, or comparison you’d like to share, leave me a comment.

Private Golang, reporting for duty

Many modern programming languages have a mechanism for controlling the visibility of members and methods. Most of the languages use keywords like private and public.

Java and C++ use public, private, and protected. Ruby also uses keywords: private, and protected.

Python on the other hand uses convention to control visibility, prefixing your methods with _ or __. Even then it’s more of a suggestion in Python as you can call it anyway. There is nothing to prevent it from actually being called from other code. It’s an understanding among Python developers that if there is an underscore you shouldn’t call it.

Go also has no keyword to control visibility. What no keyword? There has to be something? Maybe it uses _ like python? Nope that won’t do anything. Then what would Go use to control visibility? Go uses a very simple syntax, capitalization.

CAPITALIZATION? What? Yes, that’s correct. A simple capital letter makes the member or method public. Lowercase member, methods are private.

// GetName is a public method of User struct
func (u *User) GetName() string {
  return u.name
}

// nickName is a private method of User struct
func (u *User) nickName() {
  // do something
}

The same logic applies to members. Given the following example struct, Foo is public and bar is private:

type Example struct {
  Foo string
  bar string
}

So if you want to make your Go methods or members private, just start them with a lowercase letter. Want others to use it, capitalize it.

Constructors? Not in Go

If you’ve used any object-oriented language in the past decade, C++, Java, Python, Ruby, C#, you are used to defining a class and each having its own constructor. Here’s a sample in Java and Python, respectively.

public class User {
    private String username;

    public User(String name) {
        username = name
    }
    // ...
}
class User(object):
    def __init__(self, name):
        self.username = name

Previously, I wrote about Go having no class. Go uses structs. I covered how to write a struct and add methods to it. But now how do you create one? Let’s continue with the user example from above. In Go, we’d create a user struct:

type User struct {
    username string
}

Ok that was easy. But what about the constructor? Go doesn’t use constructors as you are accustomed. Go will basically initialize everything to their ZERO value, i.e. ints are 0, strings are empty. structs will have their members set to their respective zero values. Let’s look at the User example above.

u := User{}

This creates the User u instance with the username set to the zero value for strings, “”.

Sometimes the zero value isn’t enough. Sometimes you want to pass in values you know you need for that particular instance. That’s pretty simple too, again let’s look at the User struct:

u : User{"joeuser"}

This will set the username to joeuser. What if the struct had more attributes? You can either specify all the values in order or by name and value. Let’s add the age attribute to the User struct.

type User struct {
    username string
    age int
}

Initialize both by passing all the values:

u := User{"joeuser", 30}

Alternatively, we can initialize the username and leave the age to be it’s default zero value.

u := User{username: "joeuser"}

But what about something more complex than a two field User object? Since Go doesn’t have constructors, you have to create what I like call a “pseudo constructor”, basically a method that returns the initialized struct.

func NewUser(name string, age int) *User {
    // do whatever work you need to do
    // calculate fields, set defaults, etc.
    if age < 18 {
        fmt.Println("user is a minor")
    }
    return &User{name, age}
}

The name can be anything, I like to use NewStructName as a convention to make it easier to see what they are for.

While Go doesn’t have constructors, there are still three ways you can “construct” objects:

  • using the zero values
  • using the {} to pass in the values to the struct
  • creating a construction function to build the struct

Now “Go” and construct some objects.

Golang: search an array

Go is a pretty awesome language, typed, C-like, fast. I’m porting one of my python applications to Go. Searching an array isn’t as simple as it is in python though.

In Python you can use in or not in:

if self.args[1] not in self.valid_options:
    print("ERROR: valid options are %s" % self.valid_options)
    sys.exit(1)

Go doesn’t have membership operators, so you have to search the string for what you want. Then you get the index and see if it actually exists:

i := sort.SearchStrings(lc.valid_options, args[1])
if i >= len(lc.valid_options) ||
  i < len(lc.valid_options) && lc.valid_options[i] != args[1] {

  fmt.Printf("ERROR: valid options are %v\n", lc.valid_options)
  os.Exit(1)
}