Posts

2021-01-30 | Meditation Notes and Resources

Over the past year or so I got a few people asking me about meditation and mindfulness practice and how I would recommend getting started. I am not an expert, monk, or any sort of authority on the subject. I am a beginner, and sometimes a little too proud of my progress. Right now I feel the need to reflect on this information I have gathered, and consolidate some of the texts, advice, and thoughts that I have expressed personally.

Read more...

2020-12-30 | Jump Rope with Abstractions

One skill I attempt to practice consistently is the ability to jump through levels of abstraction. This requires having a growing toolkit of abstractions, such as some of those in Shane Parish from Farnam Street’s series on The Great Mental Models. It also requires being able to have emotional awareness and detachment to abandon ways of thinking and move on to more suitable ones. This is a meta-skill that can make life better.

Read more...

2020-11-27 | What Is The Output Of Your Work?

A few years ago, while in the middle of a big product release, I turned to a co-worker and asked them: What is the output of your work?

This sounds like a silly question, but I found it to be enlightening to reflect on. Here we were, stressed out about making something. However, what we were really doing was producing the documentation, the knowledge, and the confidence in the product we were making. It is easy to get lost in the idea that what you produce is the gizmo, gadget, or the most tactile result of your actions. In some ways it is tempting to think that if you paint you produce a painting; if you write music you produce a song; if you write code it is the website or demo that is the output of your work. On reflection I found that while the direct goal is often one output of your work, in many ways is more a side-effect. In this view the main output is the information, experience, and documentation that is created by the process of doing the work.

Read more...

2018-02-24 | Reflection in C++ to Generate Serializable Structs Using libclang and Python

I have recently found myself writing a bunch of serialization (and deserialization) functions in C++ for some very basic structs, and classes. Each of these serialization functions has the same basic form which is basically a series of function calls to convert some data of some type into it’s msgpack representation. As the number of structs grows this becomes tedious and hard to upgrade. Also, there are a few points where programmer error can result in major hard to detect problems, if the ordering is wrong, or the number of fields is wrong, then all bets are off. I will be the first to admit that Google Protobufs basically solves this problem entirely by describing the transfer messages, and datatypes in its own language and then compiling the target representation.

Inspired by my recent usage of rust I decided to see if I could create the equivalent of rust’s #[derive()] syntax for applying procedural macros to a struct. You can see my experiment on github.

Read more...

2017-10-16 | How I Manage My Reading List With Trello

In college I frequently would go on book reading binges during breaks, but I could not keep myself to a consistent schedule to read for pleasure during classes. This “not enough time” syndrome carried over to after I left college, even though I was not actually particularly busy outside of work. Missing reading I started to gather books I wanted to read, but was having trouble keeping track of all of them, and sorting through what to read next. So I gave some reason to the madness by using Trello. You can view my Trello Reading List and see what I have on there.

Fundamentally by maintaining a list which is so flexible and easy to manipulate I have added some tangibility to the abstract concept of “books I want to read”. I can also track and set goals related to reading rate and diversity of books since I maintain all of that data. Another plus is that it makes it easy to track what I need to write blurbs for my website. Some of my friends use other systems, including goodreads and just maintaining a literal (and literary) stack of books. I like the Trello system because it felt easier to abandon my reading past, than it did on goodreads, which made it feel like I should log every book I have read since birth. That said the friends I have who use goodreads seem to like it.

Read on for more information on how I organize my Trello reading list.

Read more...

2016-12-23 | Making GIFs From Videos in Linux

I started making some .gifs to embed in documentation and my notes as I develop Rusty Nail. I always have to lookup how to convert the images to gifs. Every time I am also concerned with how big the .gifs are so after doing some looking around I made a little script which uses ffmpeg, convert, and gifsicle (with giflossy) to take an input mp4, webm, or any video that ffmpeg can decode.

The process is this:

  1. ffmpeg splits the video into a directory of gifs
  2. convert those images and stitches them together into one gif.
  3. gifsicle optimizes the gif and allow a stage to resize it and also change the color. The giflossy plug-in also can apply lossy compression to the gif video during the optimization step.

Read on for the script.

Read more...

2016-12-19 | My New Bash Prompt: Exit Codes, Unicode and Git Branches

I decided to customize my bash prompt. I initially started off with the following requirements:

  1. It should be two lines! I have found that having the input and my prompt on one line is not enough space most of the time.
  2. I want to see my current git branch, and also if there are any uncommitted changes in the current branch.
  3. I want to see my username, host name and current directory.
  4. The current directory should be truncated so that it shows the 4 closest directories in the path.
  5. The status if the previous command should be show in some way.

After some work I came up with the prompt shown above. I am excited to keep using it and customizing it, I am also happy that I decided to use unicode in the prompt. I have been avoiding unicode in general, but Rust has convinced me that I should try to accept unicode into my life more readily!

After going through the process, here are sometake aways:

  1. printf supports unicode more reliably than echo. I had some trouble getting echo to do what I want to do
  2. I always forget this one. Bash functions are never what I think they are. They are scripts you can define inside of a script. I always seem to find this causing problems for me.

I hope you enjoy! Below is the code for my prompt! Put it into you .profile, .bash_profile or .bashrc file depending on your preference. If you want to use it.

Read more...

2016-12-18 | Thoughts On the Coursera Machine Learning Course

I completed my first Coursera course, which was “Machine Learning” with Andrew Ng from Stanford University. The course was well taught and concentrates on building a solid base for applying Machine Learning to a variety of problems. Andrew Ng uses examples motivated by real-world problems to show how you might apply the algorithms taught. I highly recommend the course if you are looking to take a MOOC and have an interest in machine learning. I learnt a lot, but still need to apply the knowledge in some personal projects of mine.

Read on for more thoughts on the course and tips on how to succeed.

Read more...

2016-11-19 | Installing libsvm For Use With GNU Octave In Ubuntu 14.04

For week 7 of the Coursera Machine Learning course we learned about Support Vector Machines (SVM). SVMs are a useful and powerful tools for solving classification problems. They can be tailored to solve complicated classification boundaries, and don’t suffer from some of the down sides of optimizing neural networks. One of the example problems uses an SVM to classify spam emails. A SVM implementation written in MATLAB/Octave is used, but for further work libsvm (or another SVM library) is recommended. To get libsvm working with Octave in Ubuntu 14.04 there are a few steps that are not obvious. I did not find very many instructions so I compiled the steps I followed to get a stable Octave environment with libsvm. Read on for details.

Read more...

2016-11-06 | Using Z3 to Find Clock Configurations Values for ARM Cortex Microcontrollers

A few weeks ago I was setting up multiple embedded systems using the NXP Kinetis K64F12 family of microcontrollers. Do to an oversight a few of the different systems had different input clock frequencies, but all were intended to work at the same output clock frequency. This is not a major issue and the ARM Cortex-M4 processors are designed to solve this issue using a phase-locked loop (PLL). A PLL can take a clock, of one frequency and output a rather clean clock of another frequency; however, it must be properly configured. My problem now was a configuration, and mathematics problem. The parameters are calculated using the following equation:

$f_{out} = VDIV * \frac{f_{in}}{PRDIV}$, where $VDIV$ and $PRDIV$ are the parameters needed for the configuration. and $f_{in}$ and $f_{out}$ are your input and output frequency which you know ahead of time.

A solution to this equation is straightforward but requires a little bit of guessing, and also checking your answers against a series of constraints specified in the datasheet. The details of this equation and its related constraints will be approached later. I wanted to automate this task so in the future I could just adjust these values without having to dig out the datasheet and do the math again. Also to possibly automate making the clock configuration code to prevent me from being the only person who understood how to configure the clocks.

What is someone who loves automation to do? Well, you could solve the equation directly. However, Michael Abed introduced me to a program and library called Z3 which is a constraints solver from Microsoft Research which I found interesting and wanted to do a simple project with since I thought it might be useful in the future. Also, this problem is well-suited as it can take a series of equations and constraints and search the solution space rather trivially easily. Also, it has a way of deciding if no solution is possible. So I decided to use the Z3 python bindings to create a python library, with a command line tool and a web API for solving this problem. This is most certainly overkill, but considering how easily it all went together I would do it again to solve similar problems.

You can see the code on GitHub and also play with see the resulting website and API demo. But read on for more details!

Read more...

2016-10-10 | Error Handling: Implementing an Option<T> Type For Embedded C++

I have been learning Rust lately, which has been an awesome and rewarding experience thus far. However, at work, and on many of my embedded side projects I use C/C++ quite extensively. But error handling ends up being a major pain point and can make an otherwise rather simple API into a disaster. This can be especially true if you are committed to avoiding throwing exceptions for various performance and real-time reliability reasons. This is where Rust’s model comes in as a possibly solution (or at the very least an interesting one): the use of the Result<T, E> types and the Option<T> type. For the time being I am going to concentrate on the Option<T> type and write about the Result<T, E> type in a future post.

The code for this blog post can be found on github as cpp-option!

Read more...

2013-07-07 | Attaching a Rack To Your Bike with P-Clamps

A nice and simple hack for attaching things onto bikes without dropping a ton of money. Before you buy your P-Clamps, or Rubber Coated Metal Clamps, make sure to measure the diameter of the tube on your bike you want to attach the clamp to. You can get them from Grainger and McMaster-Carr, but they are also easily found in your local hardware store.

Read more...