Music City Code 2017

I just got back from Music City Code 2017 and it was a blast.  It was my first time going there, and I had no idea to expect.  The talks were much better than I thought they would be, the venue was nice (Vanderbilt has a wonderful campus), and I got to meet some great people.

Let’s break down the days.

 

Day 1

Keynote: Change Your World with this One Simple Trick by Jeremy Clark (@jeremybytes)

This keynote was great.  The slides were all hand drawn, reminiscent of David Neal’s talks.  It was all about how meeting someone new can make you a better developer, and that’s what the conference was all about.

Among some of the good tips:

How to start a conversation

  1. Hi I’m <so and so>?
  2. What do you do?
  3. What technologies do you use?

And he explained how developers love to talk, but hate to start conversations.  You could tell everyone was trying this out throughout the conference, and I got to meet some interesting people.

 

F# Type Providers by Chris Gardner (@freestylecoder)

 

I had met Chris since he does the DevSpace conference here in town, and I was going to this conference to learn some new things, so I thought F# was a decent one to go learn about.  My experience with it was one day during Advent of Code, so I wanted to see some of the cool things that it had to offer.

F# Type providers was a awesome way to check the types of a data source at compile time.  The more errors you can push earlier, the better.  Why wait until runtime, when building the code can tell you if your datasource has missing or wrong types.  I’ll probably never use this, but it’s a cool concept

Data Visualization with NVD3.js and D3.js by Dustin Ewers (@dustinewers)

Dustin was a fun presenter.  He started off with a great example of what makes data visualization (the ability to interact and tell a story).  He had a great sense of humor, and presented in an interesting way.  We didn’t get as deep into D3.js as I wanted (we use it someplace at work, and I’d like to understand how it works under the hood), but he introduced me to nvd3.js to create really quick line graphs.

I was talking to some of the attendees of how to set up a Python webserver to host some of this sort of data.  I told them I’d get them something over lunch.  During lunch, I wrote up a quick script (you can find it here).  It was just using bottle to spin up a webserver and then figuring out how to load that up into a line graph in nvd3.  It was a lot simpler than I expected, and the other guys appreciated it a lot.

Lunchtime Functional Programming Panel

This was just a 4 person panel talking about how to get into functional programming and the benefits of it.  A lot of it was stuff I had already drank the Kool-Aid for, so nothing was too new.

 

A Lap Around Xamarin by Douglas Starnes (@poweredbyaltnet)

I don’t do a lot of .NET or mobile development, and this was probably the wrong talk for me.  I didn’t get a lot out of this talk, since the text was too small for me to read to understand what was going on.  It was alright, and there was nothing against the presenter or material, just ended up not being for me.

 

IoT with the ESP8266 and NodeMCU Firmware by Jason Follas (@jasonfollas)

This was an interesting talk about the options you have when building cheap IoT devices.  My co-works talk about the ESP8266 a lot, and I now know a lot more about it.  Most of this talk was explaining Lua, which I had already known, but seeing the workflow for the ESP8266 was pretty cool.

 

Day 2

ElasticSearch in an Hour by John Berryman @(jnbrymn)

I really liked this talk.  I knew nothing about ElasticSearch even though we use it at work on some other projects.  I thought this was a great introduction into how search engines work and in particular, ElasticSearch.  We talked about tokenization, stemming, relevance and indexing.  There were also some great examples contrasting a relational database and ElasticSearch.

 

Lightning Talks

So they had lightning talks in the same time frame as the other talks.  It’s a shame, because this meant there were 8 other talks going on at the same time.  As a result, only one person had registered to give a lightning talk in the two sessions I went too.  There was only about 12 people in the first one, and 4 in the next one.  So, we just did impromptu lightning talks.  I gave two talks, one recapping what I had done the day before with bottle/NVd3 and another that I gave at ADTRAN about Terrible,Terrible Things you can do in C++.  I got to learn a whole lot of other stuff, such as bayes statistics, F# Type Providers (again), Accessibility, and Interview techniques.

 

Lunchtime Software Quality Panel

It was refreshing to hear people in the industry talk candidly about how they expect people to be writing tests up front, and how to change culture to address software quality.  There was a lot of great discussion, and I agreed with most of it.

 

R: It’s Not Just For Pirates Anymore by Dustin Ewers (@dustinewers)

I liked Dustin’s talk the day before, so I decided to listen some about R.  I don’t have any plans to write any R, but it was good to know what the language was capable of.  It reminded me of Pandas in Python.  Dustin had the same good humor and relevant examples.  It was also cool to see how easy it was to write a clustering algorithm or decision tree.  It seems that machine learning is a first class citizen for this language.

 

Career Growth Questions You’re Afraid To Ask by Cassandra Faris (@cassandra Faris)

I was originally going to go to a JS talk, but I decided to do a soft skills talk instead.  This was an interesting take from a recruiter/HR perspective of how to for a new job.  It was nice to see what they were looking for in candidates, what were red flags, and the advice on how to sell yourself.

 

Wrap-up

I will definitely go back to Music City Code next year, as it was much better than I expected.  Talks were good, food was good, people were friendly, and I couldn’t ask for much more.  Plus it’s an hour and a half away from me, so it makes it much easier to be able to go check it out each year.

The Thing I Hate About Distributed Systems

I’ve always been fascinated with distributed systems.  It’s awesome that although we haven’t seen much in terms of increase of processing power, but instead we are moving to multi-core commodity hardware and scaling horizontally across it.  When I just started professionally programming, distributed systems just meant you had a handful of programs keeping in concert with each other of sockets, each doing different pieces of the solution.   It was a simpler time.

Now, you’re talking about a much more massive scale.  I contribute IoT and cloud services like AWS or GCP with the rise of accessibility for making distributed programs easy.  There’s also a slew of tools that are awesome and specifically designed for managing distributed systems.  Kafka for your messaging, Zookeeper for service management, Spark for Data Science, the list goes on.  Even my favorite language, Elixir, is built with distributed systems in mind.  But there’s a catch

Continue reading

Alexa-Controlled Remote Part II

So I got my new LEDs in, and lo and behold, it works!

To make sure that they were blinking, I wrote a quick Python script that toggled multiple pins (right now its hardcoded to just 1 pin, but I could have changed variables to toggle others).  This was very nice, as I could have it turn on every 15 seconds or so and watch it on my phone camera.


import RPi.GPIO as GPIO
import time

gpio_start = 18
gpio_end = 19

GPIO.setmode(GPIO.BCM)

for x in range (gpio_start, gpio_end):
   GPIO.setup(x, GPIO.OUT)

while True:
   
   for y in range (gpio_start, gpio_end):
      GPIO.output(y, True)
      print 'on ', y
   time.sleep(15)
   
   for z in range (gpio_start, gpio_end):
      GPIO.output(z, False)
      print 'off ',z
   time.sleep(15)

Toggling pins through Python was nice and easy.

Continue reading

DIY Alexa-Controlled Remote Control

So, I think I’m going to embark on my first official hardware project.  I want to make something I can voice-control that allows me to do common operations on my projector and sound system (Like power on, switch to Blu-Ray, etc.)  I don’t have much of a HW background (I’ve made it maybe halfway through Make Electronics – excellent book by the way), so I figured this would be interesting.  I got a new RaspberryPi 3 for Christmas, and have been looking for a good project for it.

So, I knew I needed an IR transmitter to simulate a remote.  I figured I’d get a IR receiver as well to record signals and learn more.  So I browsed the web and found two that I liked (IR Transmitter and IR Receiver) from the same company.  It looked no-fuss as well, where I just had to connect ground, voltage, and two GPIO pins.  Didn’t sound too bad.

So let’s get started!

Continue reading

PyTennessee 2017 Day 2

Some of our party were feeling ill for the second day of PyTN, so we made it as far as my talk, and then had to boogey out of there.

Let’s see what I went to though:

 

Keynote: A deeper look at the Operating System by Sophie Rapaport (@sfrapoport)

Sophie was a good speaker, keeping us engaged for most of the talk.  While I knew most of the stuff from before, due to operating systems and working on embedded systems,it was still nice to see Sophie explain that even just with Python, you can start learning about under the hood parts of the language without diving into C.  I think it was a nice talk for all the people who had no OS experience before.  She also was able to relate to why we should care, and I’ve always liked when a speaker finds a way to connect the why with the how.

 

Scraping a great data set to predict Oscars by Deborah Hanus (@deborahhanus)

This was a nice quick talk about the methodology Deborah used to complete one of our course projects.  Her goal was to predict box office hits and Oscars using data science.  She walked through how to scrape data from multiple sources, how to analyze and clean data, and then how to present it.   I didn’t find too much of this revolutionary, but it did offer a glimpse into how easy it may be to grab a data set and go to town on it.

Lunch Lightning Talks

This was another set of good lightning talks.  We heard about writing great tutorials, Legacy Python vs Python 2, and a few others that I can’t remember

What Time is it Anyway by Greg Back (@gtback)

This was another quick talk discussing the options that you have in Python of how to get timing right.  We explored what the standard library gave us (which is great if you need to be timezone naive), and what some other libraries offered (including up to date timezone information.

BDD To The Bone by Pat Viafore (@PatViaforever)

So this was my talk!  It went quite well in my opinion, but I’m biased.  I didn’t get the audience I was hoping for (~25 people) but I saw a lot of vigorous nodding so I got some things right.  I had some immediate feedback and questions, which means people were interested.  I talked to some QA engineers from Emma, and some local Huntsville people and had some good discussions on how BDD can help people.

I had some nerves in the beginning, but I think the talk went smoothly.  See for yourself at https://youtu.be/H2FuJYlbzDg

 

We were so tired after all this though, we skipped the last two talks and headed home.  It was another great conference.  I wish I took some more time to meet more people, but I’ll have another chance when we go next year.

PyTennessee 2017 Day 1

Well, I’ve made it to another conference (they are even letting me present at this one).  I was in Nashville for PyTenessee.  I love Python, and this is a great conference and community to be a part of .

 

Keynote: The Importance of Community and Networking, by Sarah Guido (@sarah_guido)

I watched Sarah the first time I went to PyTennessee two years ago, and she had one of my favorite talks about data science.  This time, she was talking a bit about her personal journey, from classically trained trumpet player in college, to a senior data scientist at Mashable.   She gave some great tips of how to give back to the community (starting meetups, going to meetups, slack channels, open source contributions) and gave some great tips to avoiding burnout.

 

What’s in your pip toolbox? by Jon Banafato (@jonafato)

So I was trying to figure out a lightning talk, so I didn’t pay too close attention to this one, but what I did get out of it was something I’m going to go use at work.  I knew most of the pip requirements.txt information, but I learned about pip-compile and pipdeptree.  Pip-compile was nice as it helped you with a requirements.txt file based on the libraries you import, not giving you anything extraneous.   pipdeptree was a great tool to show  where your dependencies in pip are coming from.

 

Lunch Lightning Talks

There were a series of 5 minute lightning talks.  I decided thirty minutes before them that I’d write a unit test talk.  However, I fought with Linux windowing twice and never got it going :(.

Other talks were things like pipenv, xpath, and Rust community.

 

A brief introduction to concurrence and coroutines by Eric Appelt (@appeltel)

This was probably my favorite talk.  Eric did a good job with easy to understand examples, and walked through iteration, generators, and then to the new async/await syntax in Python 3.5.  I learned a lot through this, but I don’t know if I’ll get to asyncio stuff at ADTRAN.  It is in 3.5 only (we’re using legacy Python only), and it has a bit of a viral effect.

 

Let’s Build A Hash Table, In C by Jacques Woodcock (@jacqueswoodcock)

This one was alright.  I knew C pretty well, and I’ve written hash tables before, so I didn’t learn a whole lot new.  The slides were pretty good, though.

 

Big data Analysis In Python with Apache Spark, Pandas, and Matplotlib by Jared M. Smith (@jaredthecoder)

This was another great talk.  I heard Jared on Software Engineering Daily a few weeks ago, and liked that episode.  I saw his picture in the PyTN bios and recognized it and decided to go to his talk.  It was a bonus that it was about data science.  I’ve been to a few meetups where Spark was talked about, but Jared gave a good example of how to actually use it.  The Pandas and Matplotlib part felt a little tacked on, but it was good to mention it (I probably feel this way because I knew what he talked about.)  I wish we could have saw some more examples.

 

Keynote: Humaning is Hard by Courey Eliot (@dev_branch)

This was a short, but very honest talk about privilege, disabilities, mentoring, community and helping people in need.  She held everyone’s attention, and it was refreshing to see such a candid talk on such a tough subject.

 

Advent Of Code 2016 Day 21 (PHP)

Advent of Code 2016 Day 20 (F#)
Advent of Code 2016 – Day 19 (Swift)

Advent of Code 2016 Day 18 (Bash)

Advent of Code 2016 Day 17 (Ruby)

Advent of Code 2016 Day 16 (Scala)

Advent of Code 2016 Day 15 (Typescript)

Advent of Code 2016 Day 14 (Go)

Advent of Code 2016 Day 13 (Lua)
Advent of Code 2016 Day 12 (C#)
Advent of Code 2016 Day 11 (Groovy)

Advent of Code 2016 Day 10 (OcaML)

Advent of Code 2016 Day 9 (Factor)

Advent of Code 2016 Day 8 (c++)
Advent of Code 2016 Day 7 (Javascript)
Advent of Code 2016 – Day 6 (Julia)
Advent of Code 2016 – Day 5( Java 8)

Advent of Code 2016 – Day 4 (Perl 6)

Advent of Code 2016 – Day 3 (Clojure)
Advent of Code – Day 2 (Python 3)
Advent Of Code 2016 – Day 1(Haskell)

Day 20

Start: 1/6/2016

Finish 1/7/2017

Language: PHP

SPOILER ALERT: If you have any inkling, any whatsoever, to work on the Advent of Code…. DO NOT READ THIS BLOG POST.  DO NOT LOOK AT MY GITHUB PROJECT.  It is no fun if you’re not solving it yourself, and you’ll feel so much better about yourself if you can figure it out without looking up an answer.  This blog post is not to give away the answer, but instead, is there for people to learn from.

As always, the following code is in my GitHub: https://github.com/pviafore/AdventOfCode2016

The Challenge

This challenge was to take a string, and apply a series of transformations on it (Swapping letters, rotating, reversing, etc.)

My idea was to keep an array where the head pointer moves around based on rotations, and operating based on that (similar to the idea of a circular array)

 

Part 1

Code Code Code ……


<?php

$head = 0;
$arr = array("a", "b", "c", "d", "e", "f", "g", "h");

function convertIndex($index){
    global $arr, $head;
    $newIndex = $index+$head;
    while($newIndex < 0){
        $newIndex += sizeof($arr);
    }
    return  $newIndex%sizeof($arr);
}
function getCharAt($index)
{
    global $arr, $head;
    $newIndex =convertIndex($index);
    return $arr[$newIndex];
}

function setCharAt($index, $value)
{
    global $arr, $head;
    $arr[convertIndex($index)] = $value;
}

function swapPos($pos1, $pos2) {
    $tmp1 = getCharAt($pos1);
    $tmp2 = getCharAt($pos2);
    setCharAt($pos1, $tmp2);
    setCharAt($pos2, $tmp1);
}

function swapLetters($letter1, $letter2) {
    global $arr;
    $index1 = array_search($letter1, $arr);
    $index2 = array_search($letter2, $arr);
    $arr[$index2] = $letter1;
    $arr[$index1] = $letter2;
}

function reverse($pos1, $pos2) {
    for ($i = $pos1, $j=$pos2; $i < $j; $i++, $j--){
        swapPos($i, $j);
    }
}

function printArray() {
    global $arr;
    for ($i = 0; $i < sizeof($arr); $i++){
        echo getCharAt($i);
    }
    echo "\n";
}

function rotateLeft($steps)
{
    global $head;
    $head += $steps;
}

function rotateRight($steps)
{
    global $head;
    $head -= $steps;
}

function move($from, $to) {
    global $arr;
    
    if ($to =$to; $i--){ 
            $newChar = getCharAt($i);
            setCharAt($i, $char);
            setCharAt($i+1, $newChar);
        }
    }
    else {
        $char = getCharAt($from);
        for ($i = $from+1; $i<=$to; $i++){ 
            $newChar = getCharAt($i);
            setCharAt($i, $char);
            setCharAt($i-1, $newChar);
        }
    }
}

function rotatePos($letter) {
    global $arr, $head;
    $index = 0;
    for ($i = 0; $i = 4) {
        $index += 1;
    }
    rotateRight($index+1);
}

function getLines() {
    $f = fopen("../day21.txt", "r");
    $lines = array();
    while (($buffer = fgets($f)) !== false) {
        $lines[] = trim($buffer);
    }
    fclose($f);
    return $lines;
}

function processLine($line) {
    $words = explode(" ", $line);
    if($words[0] == "swap" && $words[1] =="position"){
        swapPos($words[2], $words[5]);
    }
    if($words[0] == "swap" && $words[1] =="letter"){
        swapLetters($words[2], $words[5]);
    }
    if($words[0] == "rotate" && $words[1] =="left"){
        rotateLeft($words[2]);
    }
    if($words[0] == "rotate" && $words[1] =="right"){
        rotateRight($words[2]);
    }
    if($words[0] == "rotate" && $words[1] =="based"){
        rotatePos($words[6]);
    }
    if($words[0] == "reverse"){
        reverse($words[2], $words[4]);
    }
    if($words[0] == "move"){
        move($words[2], $words[5]);
    }
}


$lines = getLines();
foreach($lines as $line){   
    processLine($line);
}
printArray();
?>

This was my first foray in PHP in quite some time.  It was a bit more verbose than I remembered, but I still got this one relatively easy.

The main loop was easy, as it mostly took things line by line by line, and then chose a transformation based on the text.

Most transformations are straight forward.  I keep a global array and head pointer, along with a way to convert indices, get characters and set characters in the array.


$head = 0;
$arr = array("a", "b", "c", "d", "e", "f", "g", "h");

function convertIndex($index){
    global $arr, $head;
    $newIndex = $index+$head;
    while($newIndex < 0){
        $newIndex += sizeof($arr);
    }
    return  $newIndex%sizeof($arr);
}
function getCharAt($index)
{
    global $arr, $head;
    $newIndex =convertIndex($index);
    return $arr[$newIndex];
}

function setCharAt($index, $value)
{
    global $arr, $head;
    $arr[convertIndex($index)] = $value;
}

Swapping based on positions and swapping based on letters are pretty straight forward



function swapPos($pos1, $pos2) {
    $tmp1 = getCharAt($pos1);
    $tmp2 = getCharAt($pos2);
    setCharAt($pos1, $tmp2);
    setCharAt($pos2, $tmp1);
}

function swapLetters($letter1, $letter2) {
    global $arr;
    $index1 = array_search($letter1, $arr);
    $index2 = array_search($letter2, $arr);
    $arr[$index2] = $letter1;
    $arr[$index1] = $letter2;
}

Reversing and Rotating were also pretty easy.


function reverse($pos1, $pos2) {
    for ($i = $pos1, $j=$pos2; $i < $j; $i++, $j--){
        swapPos($i, $j);
    }
}

function rotateLeft($steps)
{
    global $head;
    $head += $steps;
}

function rotateRight($steps)
{
    global $head;
    $head -= $steps;
}

Once we get into moving (removing from one index and inserting in the other index), it took me a little while longer to get this.  I treat moving differently based on which direction I’m going to, and then I effectively “bubble” the values to the appropriate position.  I originally tried to do array slicing and recombining, but my wonky index recalculations made it tricky.


function move($from, $to) {
    global $arr;
    
    if ($to =$to; $i--){ 
            $newChar = getCharAt($i);
            setCharAt($i, $char);
            setCharAt($i+1, $newChar);
        }
    }
    else {
        $char = getCharAt($from);
        for ($i = $from+1; $i<=$to; $i++){ 
            $newChar = getCharAt($i);
            setCharAt($i, $char);
            setCharAt($i-1, $newChar);
        }
    }
}

Lastly, I worked on the rotate based on the position of a letter.  I pretty much searched for the letter in my array, then figured out how many rotations needed to happen.


function rotatePos($letter) {
    global $arr, $head;
    $index = 0;
    for ($i = 0; $i = 4) {
        $index += 1;
    }
    rotateRight($index+1);
}

 

Part 2

This part was to unscramble a password rather than scramble a password.  I reversed the lines of code, and reversed the relevant sections (such as rotating left when the command is rotate right)


function processLine($line) {
    $words = explode(" ", $line);
    if($words[0] == "swap" && $words[1] =="position"){
        swapPos($words[2], $words[5]);
    }
    if($words[0] == "swap" && $words[1] =="letter"){
        swapLetters($words[2], $words[5]);
    }
    if($words[0] == "rotate" && $words[1] =="left"){
        rotateRight($words[2]);
    }
    if($words[0] == "rotate" && $words[1] =="right"){
        rotateLeft($words[2]);
    }
    if($words[0] == "rotate" && $words[1] =="based"){
        rotatePos($words[6]);
    }
    if($words[0] == "reverse"){
        reverse($words[2], $words[4]);
    }
    if($words[0] == "move"){
        move($words[5], $words[2]);
    }
}

The tricky part of this one was figuring out how the rotate based on the position of a letter was handled.  Based on some pen and paper calculations, I found a way to derive how many rotations were needed to get to the next password


function rotatePos($letter) {
    global $arr, $head;
    $index = 0;
    for ($i = 0; $i < sizeof($arr); $i++){
        if (getCharAt($i) == $letter) {
            $index = $i;
            break;
        }
    }
    $numRotations=0;
    for ($j = 0; $j < sizeof($arr); $j++) {
        if ($j = 4 && ($j + $j + 2) % sizeof($arr) == $index) {
            $numRotations = $j+2;
            break;
        }
    }
    rotateLeft($numRotations);
}

 

Wrap-up

I had a lot of stupid mistakes in my part 2.  I kept not thinking through the problem.  Also PHP’s verbosity was weighing me down.  I felt like the array functions were clunky, and my code endd up all over the place.

I give myself a B- on this one.  I could have done better, and thought through the problems better.  My PHP code isn’t great either, so I wasn’t satisfied with this, but it’s better than some other ones.

Next up, is Day 22 with Elm.