Monday, September 12, 2016

Vim + Go + Mac

There's a lot of notes written for getting Vim + Go up and running, but a lot of the notes assume you're already in modern Vim-land.  Here's what I did to get up and going from scratch.

0.  Start off with a totally clean vim configuration.

Save off your current files/setting if they're important to you.

    cd $HOME
    rm -rf .vim .vimrc .viminfo

1.  Install a vim with lua support.

I think the easiest way to do this is to install the latest macvim from Homebrew.  If you're a developer on Mac,  Homebrew is well worth looking into.

    brew install macvim --with-cscope --with-lua --override-system-vim
    brew linkapps macvim
    brew install vim --with-lua --override-system-vim

2.  Install Vundle

There's a couple of Vim package managers.  I don't know enough about Vim package management to recommend one over another, but Vundle seems to be pretty popular.

    git clone https://github.com/VundleVim/Vundle.vim ~/.vim/bundle/Vundle.vim

Here's the minimal .vimrc needed to get bootstrapped.

    set nocompatible              
    filetype off                  

    set rtp+=~/.vim/bundle/Vundle.vim

    call vundle#begin()
    Plugin 'VundleVim/Vundle.vim'
    "Plugin 'Valloric/YouCompleteMe'    reserve for step 3 below
    "Plugin 'fatih/vim-go'              <------- font="" nbsp="">reserve for step 4 below
    call vundle#end()            

    filetype plugin indent on    

Restart vim and install the plugins with the command

    :PluginInstall

3. Install YouCompleteMe

This require you install XCode from Apple.  Start off by installing cmake.

    brew install cmake

Install YouCompleteMe and pull in submodules.

    cd ~/.vim/bundle
    git clone git@github.com:Valloric/YouCompleteMe.git
    cd ~/.vim/bundle/YouCompleteMe
    git submodule update --init --recursive

Build YouCompleteMe

    cd ~/.vim/bundle/YouCompleteMe
    ./install.py --gocode-completer

Make sure ~/.vimrc has the line

Plugin 'Valloric/YouCompleteMe'

Restart vim and install the plugin as we did above


    :PluginInstall

4. Install Vim-Go

Download the latest release from https://github.com/fatih/vim-go/releases and untar it.

    cd /tmp
    curl -s https://codeload.github.com/fatih/vim-go/tar.gz/v1.8 | tar xf -

And move all the directories into .vim.  It seems there should be and easier way to do this... ping me if you know what it is!

    (cd /tmp/vim-go-1.8; tar cf - autoload compiler doc \
       ftdetect ftplugin gosnippets indent plugin scripts syntax t templates) |
      (cd ~/.vim; tar xf -)

Then add to .vimrc

    Plugin 'fatih/vim-go'

Restart vim and run

    :PluginInstall

Tuesday, August 30, 2016

Mapping Ctrl, CapsLock Tap to Esc

Now you can vi just as Bill Joy intended!  Here's an article that makes tapping the control key send an Esc.

Setting up ssh for github

On Mac and Linux, set up an ssh key in the usual way:

    ssh-keygen
    cat $HOME/.ssh/id_rsa.pub

Copy that into the github ssh keylist.

Linux:  start the ssh agent.  This will be good for the duration of the session.

    exec ssh-agent bash
    ssh-add

Mac: add the ssh key to the keychain. This only needs to be done once.

    ssh-add

To test your connection to github.

    ssh -T git@github.com

Thursday, June 23, 2016

GitHub based dotfiles

Not much new here, this is just my take on StreakyCobra's excellent work, with these differences:

  • I made two repos, one for dotfiles, one for scripts that go into $HOME/bin.
  • I made two commands dotf and binf that correspond to StreakyCobra's config.
  • incorporated github repos dotf and binf as noted.

# create github repo "dotf"
git init --bare $HOME/.dotf
alias dotf='/usr/bin/git --git-dir=$HOME/.dotf/ --work-tree=$HOME'
dotf config status.showUntrackedFiles no
dotf add .bash_profile

dotf commit -m "first import"
dotf remote add origin git@github.com:YOURNAME/dotf.git
dotf push -u origin master

# create github repo "binf"

git init --bare $HOME/.binf
alias binf='/usr/bin/git --git-dir=$HOME/.binf --work-tree=$HOME/bin'
# binf config status.showUntrackedFiles no  ## want to track unused files

cd $HOME/bin
dotf add some-file
dotf commit -m "first import"
binf remote add origin git@github.com:YOURNAME/binf.git
binf push -u origin master


Wednesday, June 15, 2016

Do you have a restless urge to program?

I finally found a scan advertising the Famous Programmers' School which originally appeared in the April 1982 of BYTE, page 384.

"Top down programming for the masses."

Friday, May 13, 2016

Adding a git commit template

So I find myself constantly forgetting to add the jira ticket number to commits that need them.

echo JIRA >~/txt/git-commit-template.txt

And one of these commands

git config commit.template ~/txt/git-commit-template.txt
git config --global commit.template ~/txt/git-commit-template.txt

or put in in .git/config (per repo) or $HOME/.gitconfig (global):

    [commit]
            template = /Users/mh/txt/git-commit-template.txt


Don't forget to manage your git commit template in git!

blogodex = {"toc" : "git", "idx" : "commit template"};

Friday, April 29, 2016

Python: virtualenv quickstart

Installation

pip install virtualenv

Usage

mkdir myproject
cd myproject
virtualenv foo
source foo/bin/activate
pip install hjson       # install packages...
./foo/bin/python
import hjson

Getting pip if necessary

curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
python get-pip



Getting ssl if necessary in order to get pip on your linux box

symptom:    ImportError: cannot import name HTTPSHandler

yum install openssl openssl-devel
or
apt-get install openssl openssl-devel


References
https://pip.pypa.io/en/stable/installing/
http://docs.python-guide.org/en/latest/dev/virtualenvs/

Wednesday, April 27, 2016

Encrypting UDP Game Traffic

not only encryption protects your players from classical attacks, it also protects your games against cheaters too.
As a side bonus, with proper encryption you can be sure that network errors which corrupt your packets are not going undetected (and with unencrypted UDP those 16-bit UDP checksums can detect only one out of 60’000 in-transit corruptions, which means that with all those millions of packets you’re sending out each second, some corruptions WILL go undetected, causing all kinds of trouble).

http://ithare.com/udp-for-games-security-encryption-and-ddos-protection/


Tuesday, April 19, 2016

Classic Programmer Paintings!

http://classicprogrammerpaintings.tumblr.com

My Favorite:




Hieronymus Bosch “A visual guide to the Scala language”  oil on oak panels, 1490-1510.

The left panel shows the functional features, the main one describes the type system, and the right the object oriented parts.

Friday, March 18, 2016

brewing mysql / binlog reader

Here's what I did to set up MySQL 5.6 on my Mac in binlog row mode, prepping to talk to Aurora.
+1 for brew services!

Install and Test

brew install mysql56
brew tap homebrew/services
brew services start mysql56

mysqladmin -uroot create mh
mysql -uroot

Find my.cnf

/usr/local/bin/mysqld --verbose --help 2>/dev/null | grep -A 1 "Default options" 
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

Configuring binary logging

$ cat /usr/local/etc/my.cnf 
[mysqld]
log-bin=mysql-bin
binlog_format=row
server-id=1235

binlog status

Restart mysql and you can see the logs and current position.

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       143 |
| mysql-bin.000002 |       120 |

+------------------+-----------+
mysql> show master status;
+----------------+----------+-
| File           | Position | 
+----------------+----------+- . . . 
| mysql-bin.000002 |     1309 

+----------------+----------+-

Tailing the binlog


mysqlbinlog --read-from-remote-server --host=localhost  mysql-bin.000001 -uroot -v --stop-never

Insert some data like this

mysql> insert into t values(99);

and you'll see it come out like this

# at 1309
#160318 11:40:42 server id 1235 end_log_pos 1379 CRC32 0xaf303ba0 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1458326442/*!*/;
BEGIN
/*!*/;
# at 1379
#160318 11:40:42 server id 1235 end_log_pos 1421 CRC32 0xb302b235 Table_map: `mh`.`t` mapped to number 70
# at 1421
#160318 11:40:42 server id 1235 end_log_pos 1461 CRC32 0x4d9e5013 Write_rows: table id 70 flags: STMT_END_F

BINLOG '
qkvsVhPTBAAAKgAAAI0FAAAAAEYAAAAAAAEAAm1oAAF0AAEDAAE1sgKz
qkvsVh7TBAAAKAAAALUFAAAAAEYAAAAAAAEAAgAB//5jAAAAE1CeTQ==
'/*!*/;
### INSERT INTO `mh`.`t`
### SET
###   @1=99
# at 1461
#160318 11:40:42 server id 1235  end_log_pos 1492 CRC32 0x94dcc720 Xid = 73
COMMIT/*!*/;


blogodex = {"toc" : "MySQL binlog", "idx" : ["MySQL","binlog","configuration"]};

Thursday, March 17, 2016

brew services


You can use brew to interface with launchservices.  It's great!

Setup:

  • brew tap homebrew/services

Usage:
  • brew services list
  • brew services start etcd
  • brew services restart etcd
  • brew services stop etcd
Lots of details over at thoughtbot!

blogodex = {"toc" : "brew", "idx" : ["services", "launchd"]};

Tuesday, March 8, 2016

Animating an OpenSCAD Figure



First, let's draw a cube:

    cube(10,true);

Now, let's animate a 360 degree turntable view of the cube:

    rotate([0,0,$t*360])
        cube(10,true);

$t is filled in when the animation is in process.  You can see it in action like this:

    rotate([0,0,$t*360]) {
        echo($t);
        cube(10,true);
    }

To enable the animation:

  • View/Animate to fill in the animation parameters
  • fill in FPS and Steps.  Good values are 24 and 240
  • don't fill in Time.  It is derived from the other parameters.  This is the value of $t in the code.
  • To grab the frames, click the Dump Pictures box.  This will create files frameXXXXX.png in the same directory as your SCAD file.  Note that this implies you've saved your file.

Once you've got the files, you can string them together into an animation.  There's a ton of ways of doing that; I use QuickTime Player 7 on my Mac:


  • File / New Player
  • File / Open Image Sequence - navigate to your folder, and select the first generated file (frame00000.png).  QuickTime will figure out the list of frames from there.
  • Frame Rate: 24
  • You should have a quicktime movie of your animation.  Save it out and you're good to go!


blogodex = {"toc" : "OpenSCAD", "idx" : ["animation", "turntable"]};


Monday, February 29, 2016

Some Raft References


https://ramcloud.stanford.edu/~ongaro/userstudy/
Raft is a consensus algorithm designed to be easier to understand than Paxos. To measure Raft's understandability, we conducted an experimental study using CS students at two universities. We recorded a video lecture of Raft and another of Paxos, and created corresponding quizzes. This page makes our materials available for anyone interested. We think these are valuable resources for anyone learning consensus (whether Raft or Paxos or both).
Raft is a consensus algorithm for managing a replicated log. It produces a result equivalent to (multi-)Paxos, and it is as efficient as Paxos, but its structure is different from Paxos; this makes Raft more understandable than Paxos and also provides a better foundation for build- ing practical systems. In order to enhance understandabil- ity, Raft separates the key elements of consensus, such as leader election, log replication, and safety, and it enforces a stronger degree of coherency to reduce the number of states that must be considered. Results from a user study demonstrate that Raft is easier for students to learn than Paxos. Raft also includes a new mechanism for changing the cluster membership, which uses overlapping majori- ties to guarantee safety.
Lectures
Raft lecture (Raft user study) - YouTube
Tech Talk - Raft, In Search of an Understandable Consensus Algorithm

Raft Consensus Algorithm
    Consul is a new product by HashiCorp which aims to solve the core issues of service discovery and configuration. As part of that it needs to maintain a strongly consistent catalog shared between multiple servers for availability. Raft was used as the consensus protocol for Consul because it was the most readily understandable and simple algorithm available.
    The simplicity of Raft reduced our time to market, and now Consul powers HashiCorp, a number of customers using our on-premise product, and hopefully soon many thousands of other clients through our open source efforts.
    We've open sourced our Raft library as well, allowing others to use it independently of Consul. The library fully implements the protocol as described, following the paper as closely as possible.
Raft - secret lives of data




blogodex = {"toc" : "Raft"};

Saturday, February 6, 2016

jq -- lightweight flexible JSON processor

"jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text."
https://stedolan.github.io/jq

brew install jq

blogodex: jq / json

Friday, February 5, 2016

Installing Consolas font on Mac

Courtesy of ikato blog:

brew install cabextract
cd ~/Downloads
mkdir consolas
cd consolas
curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
cabextract PowerPointViewer.exe
cabextract ppviewer.cab
open CONSOLA*.TTF


blogodex: / fonts, consolas, mac

Friday, January 22, 2016

Three options for a new blogodex

The current blogodex is fine, except it's a bit tedious to type.  I'm OK with it, but it may bother other people.  In addition, it depends on a certain amount of care to not introduce syntax errors.

Thinking about it, three alternatives going forward:

  • stick with current blogodex.  pros and cons as per above.
  • switch blogodex to YAML.  I really liked this idea, until I saw that blogger would put extra formatting cruft in a multi-line block.  Additionally, blogger labels aren't multi-line friendly.
  • Make a new blogodex format, a bit more forgiving typing-wise.
Ideas for new blogodex to try:
  • maintain backwards compatibility.  lines that begin with "blogodex =" are 1.0, lines that begin with "blogodex:" are 2.0
  • format something like this:  blogodex:  optional-TOC / optional-Index Entries
  • B: my toc topic
  • B: toc topic / index topic 1, index topic 2
  • B: toc topic (no index)
  • B: / index topic (no toc)
  • what delimiters are best?
blogodex: blogodex / blogodex 2.0

TechCrunch: The Stack Fallacy

A coworker pointed me to this article which meshes well with my experience:

http://techcrunch.com/2016/01/18/why-big-companies-keep-failing-the-stack-fallacy

my takeaways:

  • It's easier to build pieces below your level in the stack than above, because you are your own customer and know what you want.
  • "Product management is the art of knowing what to build."
  • "the what is 100 times more important than the how."
related:


blogodex = {"idx" : ["Stack Fallacy", "building software"];