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"];

Friday, December 25, 2015

Spotify Apollo: new Microservice libary

public final class App {

    public static void main(String[] args) throws LoadingException {
        HttpService.boot(App::init, "my-app", args);
    }

    static void init(Environment environment) {
        environment.routingEngine()
            .registerAutoRoute(Route.sync("GET", "/", rc -> "hello world"));
    }
 }

blogodex = {"toc" : "Apollo", "idx" : ["microservice", "java"]};

Saturday, December 19, 2015

Getting a classpath out of Maven

Got the classpath blues? Here's some maven incantations:

$ mvn dependency:build-classpath
/Users/mharrison/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar:/Users/mh/.m2/repository/org/apache/commons/commons-csv/1.2/commons-csv-1.2.jar

$ mvn dependency:build-classpath -Dmdep.outputFile=classpath.txt
[INFO] Wrote classpath file '/Users/mh/g/javalogic/ggprocessor/classpath.txt'.

And some more maven magic here, including copying jar files and building an executable directly.

blogodex = {"toc" : "Maven", "idx" : "classpath"]};

Tuesday, December 15, 2015

Centos requires these packages to build Python2.7

yum groupinstall -y "Development tools"
yum install -y zlib-devel
yum install -y bzip2-devel
yum install -y openssl-devel
yum install -y ncurses-devel
yum install -y sqlite-devel
yum install -y readline-devel.x86_64

leaving a few leftovers:

Python build finished, but the necessary bits to build 
these modules were not found:

_bsddb             _tkinter           bsddb185        
dbm                dl                 gdbm            
imageop            sunaudiodev                        

Tuesday, December 1, 2015

Awesome Forth Tutorial

I've always loved Forth, so I was really happy to discover Nick Morgan's online tutorial "Easy Forth."  Not only does he do a great job introducing the concepts, he's wrote an embeddable Forth interpreter in Javascript so that all the examples can be typed into a live interpreter.  He wraps it up by writing the Snake game in Forth running in an interpreter window.

And if this whet's your retro-enthusiasm, he's got got an Easy 6502 book as well!

http://skilldrick.github.io/easyforth

blogodex = {"toc" : "Forth", "idx" : ["online emulators"]};