Thursday, December 18, 2014

Objective-C Auto Reference Counting

There is a lot of code out in the wild that uses automatic reference counting (ARC). You'll see this error when trying to build such a project with Xcode: "NSAutoreleasePool is unavailable"

You can disable ARC on an existing project in build settings.
  • Click on the project, in the left hand window of Xcode.
  • Select the target.
  • Select the Build Settings tab at the top.
  • Search for "Objective-C Automatic Reference Counting"
  • Change to yes or no depending on what you want.

Wednesday, December 17, 2014

Programming Language and Development Environments

Many developers find one programming language and one development environment they like and stick with it. Some switch once in a while. Others, like me, use a lot of different ones daily. Everyone has different reasons for this, many just like to dabble. Discussing programming languages can be like discussing politics, but I'm going to do it anyway.


I learned Commodore BASIC as my first programming language in 4th grade. It was awesome once my school got a cassette tape so I could save my programs! Years later I learned C/C++ and assembly, and from there I can't recall the order but Pascal must've been next. Java, C#, Fortran, Prologue at some point, Perl, Python, PHP, Javascript, Lua, Bash, Swift, etc etc. Now on a daily basis I use Visual Studio, Xcode and NetBeans, (I prefer IntelliJ) and various other things that aren't really worth mentioning like Eclipse, Delphi, C++ Builder, JDeveloper and Xamarin Studio.

Delphi and C++Builder used to be my favorite, but their market is so small compared to anything else out there I'm sorry to say they are hardly worth mentioning. Visual Studio is by far the best IDE available. Xamarin is actually pretty good and getting better. So is Xcode. Although I wish the debugger were better because I really can't stand gdb.

I really like a strongly typed programming language. When I'm sitting holding an object and I don't know what it is, I guess it doesn't matter but sometimes it really does and I don't like it. I find this problematic with Swift. But swift has been growing on me. Programming languages are pretty much the same. I like Delphi, but C++ is my favorite go to language, C# and Java are both very good. They both have huge amounts of support code out there so you can do just about anything. Microsoft's recent announcement to bring .NET to every platform is really cool. Nobody should write real software with Perl, Python, PHP or Bash (even thought I've seen it done). Javascript is a necessary evil.

So there you have it. My quick thoughts on programming languages and development environments.

Tuesday, December 16, 2014

Dividing Into Even Parts

One problem that comes up when doing wood work is dividing some odd number evenly into parts. This video shows an easy method at index 1:42 how to do this with very simple math by measuring across at an angle using a number that can be divided very easily. Just watch the video, it makes a lot more sense than my describing.

https://www.youtube.com/watch?v=gSXrmGaSxLU

Monday, December 15, 2014

Synchronizing VMWare guest Operating System Time

I run Ubuntu as a VM on my Mac using VMWare Fusion and it has problems synchronizing the time with the host operating system. The VMWare commands are to do this are:

vmware-toolbox-cmd timesync status
vmware-toolbox-cmd timesync enable
vmware-toolbox-cmd timesync disable

And they simply don't work. So I had to find another way to get the time synced. Running the command:

sudo ntpdate -s time.nist.gov

Syncs the time splendidly, so the question is how to do this at boot time automatically. After all automatic is what computers are all about. To do this, edit the file /etc/rc.local and add following anywhere in the file before the "exit 0":

ntpdate -s time.nist.gov&

And that should keep your clock synced. If you sleep your VM, the time could get out of sync and I haven't come up with a automatic solution for that but I don't usually sleep because shared directories are sometimes gone when it wakes and the VM has a big problem with that.

Thursday, December 11, 2014

Make Bootable OSX Yosemite USB Install Drive

1. Format drive with the defaults using Disk Utility and name it "Untitled"
2. Download OSX Installer App from Mac App Store (Note: If you use this installer it will not be usable again, so make a copy to ~/Documents)
3. Open Terminal and run:


sudo ~/Documents\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction

4. Go do the computer you want to install Yosemite to
5. Plug in the USB drive
6. Turn the machine on and hold down the Option (ALT) key until you get a list of drives
7. Choose the installer, and follow the directions

Viola!

Tuesday, December 9, 2014

Google Maps Feature

I would like to be able to scrub back in time the history of the traffic. This would be very handy to see traffic patterns when for instance planning a trip or driving somewhere you don't ordinarily drive. Google already has all the information needed, it just needs to come up with a way to display that information that is easy to use. It could be as easy as a "traffic history" button when in traffic mode, that puts a slider bar at the bottom of the maps page. The slider starts on the right which is Now, and sliding it to the left changes the red/orange/green traffic lines back to that time. This could be further enhanced when getting directions. At the moment directions reports how long it will currently take, but there could be two other smaller numbers to either side, the shortest and longest times. If you click on either one it could suggest alternate times of the day to leave or days of the week.

Monday, December 8, 2014

Tokenize a C++ std::string

There are a lot of ways to tokenize a string, and this isn't necessarily the best but it works easily for what it does.

std::list Split(std::string Value, std::string Delimiter)
{
    std::list result;
    std::vector buffer(Value.c_str(), Value.c_str() + Value.size() + 1);
    char *p = strtok(&buffer[0], Delimiter.data());
    
    while (p != NULL)
    {
        std::string token = p;
        result.push_back(token);
        p = strtok(NULL, Delimiter.data());
    }
    
    return result;
}

Call this like this:


    std::list items = Split("foo/goo/boo/foo", "/");

    for (std::list::const_iterator iterator = items.begin();
         iterator != items.end();
         iterator++)
    {
        std::string line = *iterator;
        printf("%s\n", line.c_str());
    }

And it will print out this:

foo
goo
boo
moo


Note: Yes, I do like to mix C and C++ :)

Thursday, December 4, 2014

Ergonomics of Using a Cell Phone


This Is What Looking Down at Your Cell Phone Does to Your Spine is a very interesting article. Ergonomics of everything we do every single day are so important. Ergonomics comes up so much I might start talking about it a lot more than I already do. Would anyone like that?

Wednesday, December 3, 2014

javah

This always gets me and I've seen a number of questions on the internet so I thought I'd write a simple post how to use javah.

If you have the file Foo.java:


package com;

public class Foo {
    static {
        System.loadLibrary("foo");
    }

   public static native boolean test();
}

And the directory structure is:


TestProject/build/classes/com/Foo.java

from the command prompt, change directories to "TestProject/build/classes", then run:

javah -jni com.Foo

Out will come:



/* DO NOT EDIT THIS FILE - it is machine generated */
#include 
/* Header for class com_Foo */

#ifndef _Included_com_Foo
#define _Included_com_Foo
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_Foo
 * Method:    isdebugged
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_com_Foo_isdebugged
  (JNIEnv *, jclass);

/*
 * Class:     com_Foo
 * Method:    getpid
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_Foo_getpid
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif

Monday, December 1, 2014

How Do I Print a List of Symbols Exported From a Library

The tool you want on Mac or Linux is called "nm". Best place for directions is to get it from the man pages:

man nm

I run it like this on Mac:

nm mylibrary.dylib > out.txt

On Windows use "dumpbin" (tdump if you use Borland tools, although dumpbin will work too). Here is a link to the help on dumpbin.

Wednesday, November 26, 2014

Cygwin and Batch files

The two hardly mix, but sometimes they must. To invoke a batch file from cygwin run:

cmd /c mybatchfile.bat

And it's probably worth mentioning to invoke a batch file from a batch file use:

call mybatchfile.bat

Monday, November 24, 2014

Safety Razor


For all those that shave, I have started down the safety razor journey. Gillette gave me my first razor when I turned 18, and I've tried other razors but the Mach 3 has been my go-to razor ever since. I'm still a total newb to safety razors only having tried one twice to date, but those two shaves have been the best shaves of my entire life! I remember the day when my Grandfather switched from a safety razor to an electric for convenience. Old stuff is sometimes the best.


This safety razor thing seems to be very up coming hipster and there are a lot of options and sky is the limit on what you can spend. I settled on the Merkur Long Handled Safety Razor 38c. Blades are about 6 cents vs $2 or more for Gillette cartridges. Harry's is an interesting option that I might try one day.

The safety razor shave is better for sensitive skin and there are a lot of options for shaving creams which I've just started to research.