SPI using pyBusPirateLite

Settings of SPI. This Python library using Bitbang Mode. Reference to original SPI Documentation.

from pyBusPirateLite.SPI import *

spi = SPI("COM17", 115200, 1)

spi.speed = '1MHz'

data = spi.transfer( [ControlRegAddr.M_S_CTRL | (1<<7), 0x18], autoCS = True)

Bus Pirate: Entering binary mode

Bus Pirate LCD adapter v2

Raw-wire (binary))

Bus Pirate 101 tutorial


SPI (binary))

Controlling WS2812B LEDs with a Bus Pirate

BusPirate using pyBusPirateLite

This is small guide how to use BusPirate with Python.

First you need Python 3 (tested on windows Python 3.5.3 64bit)
Don’t forget add Python to enviroment variables to easy install packages with pip.

Install required packages

pip install pyserial

Download library pyBusPirateLite and install or copy to your project root.

Your project could look like this in Eclipse with PyDev.

Notes On Creating A Hexo Theme

Notes On Creating A Hexo Theme


To Update NPM: npm install npm@latest -g.

In 2015 it makes sense to use NVM. NVM Installation

Update NPM: npm install npm@latest -g

Hexo: why can’t you use helper functions in source code?
This should be in docs.

Creating a Custom Index File in Hexo

Trying to generate a custom index file in source, hexo would ignore
source/index.md no matter what I did. What I had to do was uninstall
hexo-generator-index. See
. Then it works. So, that
will be part of the setup for my theme. But, it’s worth it in order to properly
seperate the theme from the content, I think. Having everyone edit the theme
index.ejs template is no good.

Hexo Rendering Raw EJS File Problem I Encountered

Sometimes the server would keep rendering an old version of my code, but as
text. So I’d see stuff like

<% if (site.tags.length){ %>

The raw ejs, essentially. Restarting the server or running hexo clean didn’t
do anything.

After some time, I realized it was due to the gedit swap files being read by
hexo as the actual layout files: for example, tag.ejs~. My partial helpers
looked like: <%- partial('_partials/tag') %>, and apparently hexo was reading
in tag.ejs~ instead of tag.ejs. And therefore, the ejs wasn’t rendering.

To fix this, I simply changed my partial helper to <%- partial('_partials/tag.ejs') %>. Problem solved.

Hexo Excerpt Variable

I was confused by the behavior of the hexo excerpt variable. If you define
excerpt: something in the front matter, hexo ignores that. Instead, to get it
to work, one needs to add a <!-- more --> comment in the source of the post.
Or, you can install a plugin that allows you to define custom excerpt in the
front matter.

Scripts Directory

One of the things I really discovered too late is the “Scripts” directory in the
theme folder. In Hexo, the various plugins drive the structure of the site, as
opposed to the placement of different files and directories, as in Jekyll. The
plugins programatically create folder structure, etc, where in Jekyll I mostly
used the liquid markup to structure the site.

The problem is, then, that the user wants to extend hexo to do some sort of
custom thing. If one had to publish a new plugin, that’d be too much work. But
the theme level scripts folder allows one to extend the base hexo functionality
in ‘user space’ effectively.

How To Impress Employers at Infosessions

How To Impress Employers at Infosessions

Top tech talent knows that industry recruiters often bring a stack of
pre-negotiated offers to university infosessions, so that they can snag
programmers and UX designers who really stand out. Instead of spending valuable
time validating a particularly promising candidate’s skillset through a
protracted series of interviews, it’s often more efficient to simply give the
individual an offer right then and there
. Internal studies at Google have shown
that experienced recruiters can usually tell if a programmer has ‘what it takes’
just from how they act at infosessions: the insightful questions they ask, the
stickers on their laptop, and how they comport themselves in general.

Read More
NAV Web Service Programming Resources

NAV Web Service Programming Resources

Here are some of the resources I found helpful for learning to develop Dynamics NAV web service based applications.

C/AL Programming:

Introduction to CAL Programming
This provides a good overview of the basics of CAL programming, which can become necessary in building a web service applications when a custom codeunit or page extension is required.

Setting up Web Services:

Vjecko Web Service Recorded Session
Vjecko.com has a lot of detailed articles about web service programming, but this older post has a pdf and recorded session that shows how to expose and connect to web services from a .NET application. Unfortunately, he shows how to create Web Service references in .NET using the now-deprecated Web Refrence method (from .NET 2) instead of the more current Service Reference method.

Using Service Reference to Connect to Web Services
This explains how to use Service Reference, using code instead of XML web.config configuration, which I found difficult to configure. (Each time I updated the service reference, I would have to reconfigure the XML).

Migration to SQL Server from C/SIDE Database
In order to use web services, you don’t need to be using the Role Tailored Client, but you must be using the a SQL server based NAV database. Web Services can be configured and exposed using the Classic Client for SQL Server Databases.

Debugging Code Called by Web Services
C/AL code won’t necessarily execute the same as it did in the Classic Client when called as a Web Service. C/AL code called as web service execute in the NAV Server tier, instead of the client. Certain functions aren’t available for code running in the NAV Server, and some design changes need to be made (for example, CONFIRM dialogue boxes don’t make sense in the context of a web service). To debug the codeunits called through web services (or the Role Tailored Client), you will need to use Visual Studio.
More information.

Deploying a .NET Application:

Deploying to IIS After you’ve built a .NET application that consumes .NET web services, you’ll have to find a way to deploy it on your servers, or Azure. Connection strings can be used to specify different NAV servers for different environments (like development, QA, and prod).

Adding Lookup Field to a Page in Dynamics NAV

Adding Lookup Field to a Page in Dynamics NAV

One of the problems I faced in building a non-trivial application that consumed
NAV Web Services was figuring out how to “join” fields from different tables.
For example, when exposing a list of jobs from a job table which includes a
resource needed for the job, you might need more than just the resource id
that’s a field in the table: you might also need the resource name and
description. While this is easy to get for one record, what about when you
need a few hundred records in a table that has been dynamically filtered? When
exposing a Page as a web service, it’s easy to include the fields of the table
that the page is based on, but it’s less clear how to include fields from
another table.

Forum posts like this led me to believe that I couldn’t expose flow fields in a Page web service, and I would get exceptions when I tried to expose all the fields of a table. In fact, it’s perfectly possible to expose a flow field: it’s flow filters that don’t work with web services. But, I also didn’t want to modify the underlying [job] table to add a flow field, and didn’t see an easy way of adding a flow field to a Page. I tried “joining” the data in the C# application, but found network overhead made the application unusuably slow.

The solution to this problem was to use C/AL code to the Page to effectively create a lookup / flow field. This way, the data is “pre-joined” before leaving the NAV Server, which is fast and clean, but you didn’t modify any tables. Here’s how it’s done:

Step 1. Add a Field with SourceExpression Set to a Function Name

To start, we create a Page using the wizard that includes all of the fields of an underlying table. Then, we create manually add fields that will contain the lookup data from other tables. The text in the SourceExpression column will be the name of the function that populates this field.
Add a Field with SourceExpression Set to a Function Name

Step 2. Create Function in the Page’s C/AL Code

With the Page field designer open, go to the functions tab of C/AL Globals form, and add a function with the name of the text in the SourceExpression column. Set the return type of the function with the “Locals” button, and a function trigger will appear in the C/AL code editor for your page. Add code to the body of the function trigger that will be called for each record to provide a value for the field.
Create Function in the Page's C/AL Code

Static NGINX Locations

Static NGINX Locations

I try to get a lot of mileage out of the single AWS t2.micro instance I keep running,
which means I have many different projects running on different paths on a single server. Everytime I finish a project, I have to relearn how to add new “locations” (paths) to the NGINX virtual host.

I was really frustrated when I couldn’t figure out how to add a static location for the Jekyll
website I created for the game I’m developing. I kept trying to do something like this:

location / {
  root /home/ubuntu/personal-website;
location /array {
  root /home/ubuntu/array-website/_site;

But everytime I tried to visit [http://ptsteadman.com/array], I would get a 404 error.
I tried a bunch of things: I changed the “root” of the the / location to my game website, and it worked. But no matter what I did, after using sudo service nginx restart,
trying to visit the /array location still resulted in a 404. I couldn’t add the new route/location.

Eventually, I realized that the text after the slash in the location is the directory that
NGINX will try to find in the “root” location. So, location /array will look for the directory (or file)
array in whatever directory “root” is set to. So, I created a symlink to the root of my
static jekyll site with the command ln -s /home/ubuntu/array-website/_site /home/ubuntu/array, and
then I could set up my nginx config file in sites-enabled as below:

location / {
  root /home/ubuntu/personal-website;
location /array {
  root /home/ubuntu;

I think this stuff is all pretty obvious to someone who really understands NGINX and file serving,
but I only touch NGINX when I’ve finished a project and feel impatient to deploy. I think it’s very confusing
that NGINX seems to handle paths differently between / locations and and /foo locations,
but a real understanding of NGINX might clear things up.

Spaces for Newline Indents in VS

Spaces for Newline Indents in VS

It’s really annoying when Visual Studio shows you this:

But github or vim shows you the same file like this:

If you use the “show whitespace” Visual Studio chord (CTRL-R, CTRL-W),
you’ll see that visual studio inserts tabs instead of spaces by
default for newline indent:

Visual Studio displays tabs as having the same
width as four spaces. But if you’re collaborating with someone working
in another text editor like vim, your automatically-inserted tabs will
appear larger than four spaces.

Here’s how to make visual studio insert spaces instead of tabs on newline indents:
go to Tools->Options->Text Editor->All Languages->Tabs:

That’s better:

Welcome To Hexo