My Experience with Owning a Tacoma TRD Sport and TRD Pro

Introduction So far, I’ve had three Toyota Tacomas, a 2nd gen and two 3rd gens. The reason I’ve had two 3rd gens is because I leased the first one. When the 2016 3rd gen was released I wasn’t sure how good it was going to be. Especially with competition from the rereleased Chevy Colorado. My boss bought the GMC Canyon (the Colorado under a different badge) so I was able to get an idea of what it was like....

May 5, 2018 · John

Byte Swapping in C

Introduction Some times you need to swap bytes. Sometimes you don’t. But right now we do. Well, we don’t but if we were implementing some sorting functions we’d need a good swap function. Sorting typically doesn’t move pointers around, instead it moves the bytes pointed to by the pointer. Generic Swap We only want to have one swap function and not one for every single possible type. We’ll use void pointers and a width (number of bytes the type occupies) to make a generic swap function....

March 15, 2018 · John

KDocker 5.1 Released

After quite some time and a few people asking, I’ve put up a new release of KDocker. The big new feature in this release is the ability to save application settings. This way you can dock an application and you don’t have to go though and configure how KDocker interacts with it. It will automatically load the last saved settings when it sees the application. As usual this release is source code only....

February 18, 2018 · John

Binary Search and Insert

Introduction When dealing with arrays it’s often necessary to keep their elements in sorted order. The easiest way is to use an insert algorithm that always puts element into the array in sorted order. That said, you don’t know where elements will end up in the array because if you already knew the order you wouldn’t need to sort in the first place. At some point you will need to pull elements back out and you will want a quick way to find a given element....

January 18, 2018 · John

Base64 Encode and Decode in C

Introduction A very popular way to encode binary data is Base64. The basis of this is an encoding table. As you might expect, there are 64 total characters that go into the tale. There are multiple implementations of base64 with slight differences. They are all the same except for the last two characters and line ending requirements. The first 62 characters are always “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789”. PEM and MIME encoding are the most common and use “+/” as the last two characters....

November 18, 2017 · John

Hex Encode and Decode in C

Introduction A very common task when working with binary data in C is, converting it to and from Hex. It’s unfortunate that C doesn’t provide a standard function that can take care of this for us. However, it’s pretty easy to implement a set of functions to handle it. Hex encoding is always twice the size of binary. Since hex is base 16 we can take any unsigned char value 0-255 and represent it in two hex digits, 0x00-0xFF....

September 24, 2017 · John

Wrapping C++ objects in C

Introduction Using C functions from C++ is very easy but going the other way isn’t. However, it can be done with a little ingenuity. Really, this isn’t as crazy as it sounds. I’ll use a simple adder for the object. It takes an integer as a starting value and has two functions for adding and getting the current value. This could be expanded later into a complex object for mathematical operations but that’s really not necessary right now....

August 18, 2017 · John

JNI is (Not) Your Friend

Introduction So far we’ve scratched the surface of using JNI when we looked at wrapping a C library and Calling Java from C. Now we’re going to look into some more complex uses. Java Class Since we’re working with JNI, we’ll need a Java class to use what we’re going to expose from C. DemoFuncs.java class DemoFuncs { static { System.loadLibrary("demo_lib"); } public enum Days { MON, TUE, WED, THU, FRI, SAT, SUN, } public static native int[] demo_array_return(); public static native int[] demo_array_copy_inc(int[] in); public static native Days demo_enum_val(); public static native Days demo_enum_field_val(); public static native void demo_exception_1(); public static native void demo_exception_2(); public static native void demo_exception_3(); public static native boolean demo_exception_4(); public static native Name demo_name(String name); } Note: This class includes an enum because one of the later examples uses them....

July 9, 2017 · John

Calling Java From C

Introduction Obviously, JNI lets you call Java functions and use Java classes in C. Typical a Java app is the one calling into C. Now Let’s say you don’t have a Java app that kicks off the process but you want your C app to still use some Java code. Okay, I know what you’re thinking, “why”? Well, there are companies out there that provide SDKs for their products only in Java....

June 17, 2017 · John

Wrapping a C library in Java

Introduction It can’t be argued that Java is popular and successful. It is consistently the number one language on TIOBE’s popularity list, above C which comes in as number two. This ranking is based on popularity and doesn’t mean Java is more used than C but that doesn’t change the fact that there is a lot of Java code out there. Unlike other languages interop with Java is not what I’d call easy....

June 6, 2017 · John