Debugging Custom C++ Types in Codeblocks (Code::Blocks)

  • Posted on: 14 December 2014

When I develop C++ on Linux, and I'm not in a purist/makefile/command-line mood, I like to use Code::Blocks. It doesn't quite have the feature set that Eclipse does, but Eclipse always feels a bit cumbersome to me. On the flipside, Code::Blocks seems much more lightweight.

In this article, I'm going to explain how to debug custom types with Code::Blocks. First, let's look at a motivating example. Here's a cpp file that defines and uses a simple array class, myarray:

#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cstdlib>

class myarray

    myarray(int sz):
        arr( new double[sz] )

    ~myarray(){ delete[] arr;}

    double* arr;
    int     n;


int main ()
    std::cout << "custom type test" << std::endl;

    int n = 5;

    myarray the_array(5);

Alpha-Surf, my half-baked Google Chrome Extension

  • Posted on: 9 December 2014

A while ago, I hurt my wrist in a way that made it painful to use the mouse. This obviously put quite a hindrance on my ability to effectively surf the internets.

I was able to get around on most websites pretty easily with keyboard shortcuts, but I found that tabbing through links was still pretty tedious and time consuming.

I was using Google Chrome at the time, so I decided to try to write up an extension to help me 'tabigate' through links on a page more effectively. The extension would let me tab through links based on the first letter of the text in the link. For example, if you wanted to get to this link:

Blog Home

You could hold down the 'X' key to activate the letter-based tabbing, and then press the 'b' key. Only links that began with 'B' would be tabbed through. Maybe 'X' is a poor choice for activation, but most of the special keys have functions I didn't want to hijack.

A 10-Minute Introduction to Multipole Methods, with MATLAB Code

  • Posted on: 16 November 2014

As someone who's more of a mathematics fan than a practitioner, multipole methods at first seemed like straight-up black magic to me. Problems that canonically have an $O(n^2)$ complexity being solved in $O(nlog(n))$ or $O(n)$ time a lie. But I was able to get a grip on the simplest case, and now, I'm a believer.

In this article, we won't outline a complete multipole algorithm, but we will aim to outline the cause or means of the reduced computational effort advertised by these types of algorithm.


Javascript Tutorial: Reading Binary Files using Typed Arrays

  • Posted on: 16 November 2014

In my last post, I briefly mentioned that building my STL file viewer required that I learn a thing or two about binary file reading in Javascript. In this post, I'm going to recreate a stripped-down version of the reader, and focus on the binary I/O. Well, really just I.

Getting the File From the Client Filesystem

The STL reader is entirely client side. It uses Javascript's Filereader object to get the file from the user's filesystem, and then uses three.js for rendering. Now, we'll cover getting the file's contents from the filesystem to the browser.

First, we need an html input of type file:

THREE.js-based Online STL File Viewer

  • Posted on: 28 October 2014

After the tinkerings of my last post, I started thinking about how I could read a binary STL file in javascript, and display the model in the browser. Yeah, yeah. GitHub has a browser-based STL viewer, and GrabCAD has something similar, but I wanted to see what would be involved.

I started tinkering with things like ArrayBuffers, Float32Arrays, and related built-in objects related to reading binary and/or interpreting binary data. I'll probably expand on these objects in a later post -- they're very interesting!

I also had very little experience with graphics programming, let alone THREE.js. It turned out THREE.js couldn't have been simpler to learn. A hearty stick-tap to those folks for creating such a useful piece of javascript.

Reading an STL File With C++

  • Posted on: 21 October 2014

STL is a widely used 3D CAD-related filetype which, essentially, represents one or more surfaces as a bunch of triangles. Each triangle is represented by a unit normal and its three vertices.

Here’s a synopsis of the entire (binary) format, adapted from Wikipedia:

char[80] (80 bytes) – Header
unsigned long (4 bytes) – Number of triangles

foreach triangle
    float[3] (12 bytes) – Normal vector
    float[3] (12 bytes) – Vertex 1
    float[3] (12 bytes) – Vertex 2
    float[3] (12 bytes) – Vertex 3
    short (2 bytes) – Attribute byte count

Pretty simple. Just read the header, read the number of triangles, and then start reading the triangles. Each triangle's data is 50 bytes long, but the last 2 bytes are rarely used, so they could be cased to anything, really.

Triangle and Vector Classes

It'll make things simpler if we have a triangle and vector class. Here's the declaration for the 3d vector class:

Design Tutorial: Common Emitter Amplifier in LTSpice

  • Posted on: 17 October 2014

Earlier, I posted about my delightful experience installing LTSpice on my Linux system via WINE here at home. I'm not sure why I was so surprised -- WINE is pretty good these days -- but it certainly felt cool to get up and running so quickly.

Anyway, I decided I'd revisit some ideas long forgotten, and try to design a run-of-the-mill common emitter amplifier from the ground up. I certainly left some aspects out (like gain, input and output impedance), but here is a brief overview of how the design went:

Picking a Q-Point for the Transistor

Parameter Sweep in LTSpice using the .PARAM directive

  • Posted on: 6 September 2014

In this video, I demonstrate an example of performing a parameteric sweep in LTSpice.

As can be seen in the video, a combination of LTSpice's .PARAM directive and .STEP directive can be used to generate a series of simulations -- each one corresponding to a different value for a particular component value or other parameter.

In this particular example, we'll vary the value of a capacitor to alter the respone of an active low-pass filter.


Converting MATLAB to C++ -- LU Decomposition Example

  • Posted on: 24 August 2014

Some time ago, I talked about a way to convert matrix-operation-heavy MATLAB code to C++ code. Here's an outline of the method:

  1. Most importantly, there's really no conversion at all. My idea was to create some C++ which would allow MATLAB to be directly compiled as C++ -- with minimal manual changes to the original source.
  2. This is a work in progress! There are still some kinks to work out, and we make no attempt to convert code for which there is no native equivalent, like MATLAB's roots() function. We also can't fix fundamental differences in the languages, ie, in C++, variables have to be declared.
  3. You can download all the code (and a Code::Blocks project) for the example demonstrated here, here.

Running LT Spice under Linux (Ubuntu) with Wine

  • Posted on: 17 August 2014

I used to use Linear Technology's LT Spice quite often, but I haven't used it much since my semi-permanent and complete switch to Linux. I thought I'd try to install LT Spice under wine -- it turns out, it works pretty well!

For the record, I installed Wine 4.21q under Linux Lubuntu 14.04. The video of the installation is shown below, followed by me fumbling my way through an Op Amp circuit -- hey, it's been a while.