programming

Tutorial: using cURLcpp to Create a C++ Web Reader in Ubuntu

  • Posted on: 8 March 2015

In this article, we're going to create a C++ application with cURLcpp that reads a webpage and prints the HTML source to stdout.

I wanted to try cURLcpp as opposed to the tried and usually true cURLpp, mostly for fun.

The bulk of the article is really a "for-dummies" guide to setting up your environment to do so. I won't really go into detail about how to use cURL or cURLcpp. In fact, we're just going to compile the first example from the cURLcpp readme. Once you've got a good cURLpp development 'environment' setup, it shouldn't be too hard to cut and try different cURLpp features and code.

Prereqs:

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.

C++ Lambda Functions with std::sort -- A Brief Tutorial

  • Posted on: 17 August 2014

C++11 added Lambda Functions to C++, a feature many developers felt was long overdue.

There are a lot of tutorials on the web already about using Lambdas in C++. These tutorials cover all the wide variety of ways which Lambdas can be used in C++, as well as possible reasons for doing so.

I thought I'd throw my hat in the mix, and try to provide an ultra-short, ultra-simple example, adapted from code you may have seen before. We're just going to use a Lambda function to extend the functionality of std::sort.

First, I'm going to use this code for a starting point for this tutorial. So make sure that that's fully digested before heading over here.

An Experiment in Converting MatLab to C++ -- Getting the Matrix Notation / Indexing Right

  • Posted on: 7 June 2014

Where I'm presently employed, I often proceed according to the following workflow:

  1. Get a Matlab / GNU Octave code of a numerical algorithm from boss, or elsewhere.
  2. Convert to C++ as part of my place of work's software packages.
  3. Over time, optimize it if it becomes oft-used, or turns out to be a bottleneck.

Obviously, Converting from Matlab code to C++ varies in difficulty based on the code. Sometimes it's easy, sometimes it's painful. The list below attempts to break down the differences between Matlab / GNU Octave and C++ into three categories. This is relatively superficial and non-technical, but here goes:

    Idea For Fast Rotation (or Vector Rotation) in Javascript -- Expanding the Rotation Matrix

    • Posted on: 28 May 2014

    Say you want to rotate a point, or a vector, through some angle. This transformation is a popular one for games, scientific applications, and much more. In fact, I used it a whole bunch when I was programming my game, Not Asteroids!. All I needed to do was right-multiply a 2d vector (x,y) by the rotation matrix shown here:

    ..and out pops the transformed vector. If you're unfamiliar with this idea, check out the links below to get up to speed. Trust me, it's not bad.

    Kwon 3d
    Dr. Math
    xkcd (just kidding)

    Easy, right?

    Okay, let's take a look at some javascript that will rotate a vector (x,y) by an angle theta, and return a 2 element array containing the rotated vector (x2,y2).:

    Block LU Decomposition Source Code (including back substitution, in MatLab)

    • Posted on: 27 May 2014

    In my last, post, I made mention of a page which contained a matlab-esque pseudo-code version of a block LU decomposition algorithm. But then, less than 24 hours after I posted it, the page was removed! That's life, I suppose.

    Luckily, I had already drafted up a MatLab version of the pseudo-code, at least to the pre-debugging point. A few hours later, I was able to create a functional version, where the results matched that of a native GNU Octave matrix solution.

    In case you didn't read the last post, and you're asking, what's the point of having my very own LU decomposition source code, here's the same response: I see your point. Libraries like LAPACK have a working, highly optimized version that's practically unbeatable on most common platforms. But what if you want to implement block LU on a new platform? Trust me, you don't want to dig through the LAPACK source -- at least not for a new version.

    NetSpice, an online SPICE simulation tool...sort of

    • Posted on: 15 May 2014

    I started working on a browser-based, netlist-based SPICE interface. Why? I'm not sure, it seemed like a cool thing to do; I'm aware that there's some good web-based, schematic-based implementations already out there.

    To start, I downloaded and compiled the original Spice3f5 from Berkeley. ( I think I'm going to make a tutorial about this later on, it took some work). Then I began creating a simple "Ajax"-based web-interface. You can take it for a spin here:

    NetSpice

    Here is an example that was saved via permalinking; anybody can do this to any circuit in order to share it or pass it around:

    NetSpice -- RC Circuit Example

    Not Asteroids! (The HTML5 Game) Pre-Alpha Release

    • Posted on: 1 March 2014

    Well, here is a very early (but semi-playable) version of the game I'm working on, Not Asteroids! Go ahead and give it a try.

    If you're a fellow programmer, do yourself a favor, and don't look at the source. It's a total mess. I just wanted to get something out there because I find if I focus on maintaining the code as I write it, I'm less likely to actually finish anything (I'd like to clean it up at some point, though). Oh, and I'm also still not actually sure how to write javascript well.

    Maybe I'll create another YouTube video later on, but for now, here are some screen shots:




    Creating General Algorithm Templates in C++, A Tutorial

    • Posted on: 15 February 2014

    Here is a brief, somewhat incomplete, tutorial on how to write some relatively general (read: re-usable) algorithms in C++. The example shown here requires an understanding of both overloading operators, and templates, so if you're a little rusty on those, take a look at these links:

    Wikipedia article on template
    A very long, but very good tutorial about C++ templates
    Wikibook section about operator overloading in C++

    Okay, you either skipped those links, or you've come back, with an understanding of templates and overloading operators in-hand.

    Pages