Possibly the best Linux find command examples

If you have been looking for a file on Mac OS X or Linux or Unix, you want to use the “find” command. The problem with the find command is that the usage information at the command line is just terrible. The solution is to bookmark this awesome website:
http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/

Here are some of my favorites:

Find a file by name in any directory starting with the root path

find / -name passwd

Find a file by name (case-insensitive) starting at the current directory and then run the command md5sum on each file that matches.

find -iname "MyCProgram.c" -exec md5sum {} \;

Find files starting in your home directory that are larger than 100 megatbytes.

find ~ -size +100M

And last, but not least, create an alias for a find command that will remove all files named “a.out” starting from the current directory

alias rmao="find . -iname a.out -exec rm {} \;"
rmao

Happy Hunting!

How to make Mac OS X and MySQL happy with Qt

Using shared libraries on Mac OS X is one of the things that is actually a lot harder than on Windows.  For example, you cannot just put the shared library for MySQL into your path or into the working directory. You have to change the plugin file itself to make it look in the correct location. You find the current value using the command “otool” and change the value using the command “install_name_tool”. Here is an example:

cd Qt/5.4/clang_64/plugins/sqldrivers/

otool -L libqsqlmysql.dylib 

libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...

install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib ./libqsqlmysql.dylib 

otool -L libqsqlmysql.dylib 

libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 18.0.0, current version 18.0.0)
...

Organized C code – Part 1 – The Headers

This is a step-by-step guide to writing code in C and keeping it organized as you go.  It will help you write code that can be reused on multiple projects and hardware platforms.  I will explain some of the finer details along the way so, technically, you don’t even need to know how to program in C to use this guide.

This first part will just go through some templates that every set of C header files will start with.  These header files are used to pre-define the C code you will be writing in a future part of this guide.  That is it for the introductions, now on to your first step writing organized C code!

Step 1

Create a directory for your files with two subdirectories: include and src.  For example, my directory structure looks like this:

directory structure

organized/
organized/include/
organized/src/

The include directory will store all of your header (.h) files and the src directory will store all of your source (.c) files.  These are the files that the C compiler will use to generate machine code (binary language) for your computer.  The C compiler has a “preprocessor” that will look through the code and make changes before attempting to generate machine code.  The C preprocessor is your friend and I will refer to it often.

Step 2

If you need a program to write files, I suggest Microsoft’s Visual Studio Code available here.

Create a text file for the public header that ends with .h to indicate it is a header file.  Save this file in your include directory. For example, the path to my file is:

organized/include/organized.h

snap_2016-10-04_13h51m22s_003_organized-h-visual-studio-code

Paste the following code into your file.  This is the code needed for every header file.  Each time you use this code, replace “ORGANIZED_H” with something that matches your file name.  The only requirement is that you make it unique.  The same name cannot be defined by any other code within a project that uses this header file and I will explain why below.

#ifndef ORGANIZED_H
#define ORGANIZED_H
#ifdef __cplusplus
extern "C" {
#endif
// public header code goes here
#ifdef __cplusplus
}
#endif
#endif // ORGANIZED_H
// empty line

Here are details on this template line by line:

  1. #ifndef is a command used by the C preprocessor that means “If not defined”.  It is used here to check for the name that uniquely identifies this header file so that the entire file can be skipped if it has already been included in the project.  There are other ways to do this, but this method is the only one that is supported by ALL C compilers.
  2. #define is a command used by the C preprocessor that means “Define this value”.  It is used here to define the name you have chosen, which means the next time this header file is included somewhere in the project, the name will already be defined.
  3. #ifdef is a command used by the C preprocessor that means “If defined”.  It is used here to check if the compiler is actually a C++ compiler.  A C++ compiler can do everything a C compiler can do (and more), but it likes to keep things separate.  That is why we will add some code only if this is a C++ compiler.
  4. extern is a keyword that tells the compiler the following code should be made available throughout the program and not just to this file.  It is used here because a C++ compiler was detected at line 3 and we want all of our header code to be made available to C and C++ alike.  The { open brace starts a group of code (code block) that will be made accessible because of the extern keyword.
  5. #endif is a command used by the C preprocessor that means “End if”.  It is used here to end the #ifdef statement from line 3.  Every #if statement requires a matching #endif
  6. // is a single line comment.  Almost all C compilers support this.  If you want to be extra careful that your code will be portable (supported by ALL C compilers), you should write all comments like this instead:
    /* public header code goes here */
  7. #ifdef is here again to ensure we only write the code below it if this is a C++ compiler
  8. } is a closed brace that ends the extern group started at line 4
  9. #endif ends the #ifdef at line 7
  10. #endif ends the #ifndef at line 1.  The single line comment // to the side of the #endif makes it easy to find the #if statement that is being ended here.  This is because there could be hundreds of lines of code between the #if and #endif so it is not easy to read without the extra comment.
  11. This line should be empty.  This webpage won’t let me show it, but this should be an empty line.  If the last line in your file is not empty, the preprocessor could accidentally put code right next to it without any indication that it should have been separate.  If any of your .h or .c files do not have an empty line at the end, go add them now.

Step 3

Create a text file for the private header that ends with .h to indicate it is a header file.  Save this file in your include directory.  For example, the path to my file is:

organized/include/organized_private.h

Paste the header template code into your file and change the #define name and the comment to indicate this is your private header.  For example, I have changed lines 1,2,6,and 10:

#ifndef ORGANIZED_PRIVATE_H
#define ORGANIZED_PRIVATE_H
#ifdef __cplusplus
extern "C" {
#endif
// private header code goes here
#ifdef __cplusplus
}
#endif
#endif // ORGANIZED_PRIVATE_H
// empty line

That is it for Part 1.  You can download the sample code here.

In the next part we will start to fill-in the public header file.

Google Gmail access via POP3 gives ERR [SYS/TEMP]

Have you ever received this error from pop.gmail.com?

-ERR [SYS/TEMP] Temporary system problem. Please try again later.

I did.  It turns out that if you try to use SSL on port 995 and login using the USER and PASS commands, you will receive this error if you either: 1. tried to base64 encode your user/password data or 2. you did not setup an “App password” and use it instead of your normal password.

You can setup an “App password” here

That’s it for now.  Good luck!

 

Skreens review

My first impression of Skreens is positive, but it is very rough around the edges because it strives to do so much in it’s first major release.

It was super easy to setup!  I connected Skreens to a switch that is connected to my wifi router.  My iPhone found the device immediately.

I rotated the phone to landscape mode and could see the layout of the HDMI sources.

The virtual track pad works, but it was not obvious for what purpose until later when I was able to open the web browser interface and add a web window.  The iPhone app cannot do as much as the web interface yet.

Here you can select the HDMI source to use for audio. I am not sure how to mix sources yet.

Here you can see my Windows PC and Wii U are on Inputs 1 and 2.  I don’t have anything to connect for inputs 3 and 4 yet.

From the settings in the web interface you can choose to do an automatic firmware update.  The message is a little unprofessional looking but the process itself worked.

I started moving things around.  It works wells but is difficult to resize windows that overlap, especially on the iPhone.

I do think it’s great I can save layouts, capture the low-level descriptor, and even get layouts shared online.  It all works really well!

Here is part of the settings window.  You can see the Skreens device on the cabinet below.

I can’t figure out how to make the device output 1080P60.  My Panasonic AE8000U is reporting only 720P.  Honestly, it still looks really good.  I can’t wait to get the full 1080P and see how much more amazing it can get!

The box has a very bright green light that changes to blue sometimes but I am not sure why.  I hope that means they can add a software feature to disable the light ::hint hint nudge nudge::

The fan is quieter than my media center PC but not just a whisper.  Although I could not tell during the unboxing, the device does have an air vent on the top.  It is not warm at this location so it must be there to pull in cool air.


If you cover this vent the noise level drops significantly to an almost imperceptible level.  The device has 2 side vents so I don’t see why this one is necessary.  Don’t worry, I am not going to keep it covered, that would probably be a bad idea 😉

Overall I am happy with Skreens.  I look forward to future firmware updates!

Add minutes using Excel

This came up at work today.  How do you add minutes to a time using Excel?  The video below shows a quick solution without all the extra math you may be seeing from people who know the intimate details of how Excel stores date/time values.

…And while I am at it, remember that to “lock” a cell reference in a formula use the $ symbol.

Pool project completed 

This is a follow-up to our pool construction story

I can finally say that the pool project is done!  The pictures look great and it is almost exactly what we wanted.

Here are some pros and cons off the top of my head:

Pros:

  • Great for swimming laps
  • Not too big to heat to a nice temperature
  • Salt chlorinator, automation system, in-floor cleaning, and screen enclosure make it easier to maintain
  • Spa gets hot quickly and is conveniently located near the house
  • Deck jets are pretty and fun for the kids and provide nice warm spots when the pool is still heating
  • The tile is beautiful!
  • Safety fence keeps the kids away from the pool so we can still just play outside without worry

Cons:

  • Deck pavers allow a lot of dirt to build up and allow bugs to burrow between
  • Pool edge (coping) is slippery when wet
  • Pool lights are too bright and cannot be dimmed
  • Autofill is nothing more than a toilet fill valve.  Autodrain is nothing more than a hole in the strainer.  These work poorly at best.
  • Quartz surface is sloppy with many imperfections and blemishes that distract from the simplicity of the pool’s design and irreversible discoloration of the coping and tile grout
  • Safety fence is installed on or near paver edges causing weakness and potential for cracks
  • Foam accents are not the stucco pillars that were promised
  • Cleaning system automated valve and 2 cleaning heads already need slight adjustment
  • It would have been nicer to have just 2 steps into the pool but it would have been against code
  • Took 8 months longer than promised and required a lot of hand holding to avoid incredibly sloppy work and, in some cases, being completely ignored

Would I do it again?  Maybe.  But I would need to put a lot of thought into how I could avoid all of the stress it has caused me.  Considering the amount of pre-planning I put in, I was extremely disappointed with how often the work was done poorly, incorrectly, or late.  Only the tile installers were able to continually impress me.  I wish everyone would take as much pride in their work as they did.

Here are a few more pictures of the end result 🙂


Skreens unboxing

I am so excited to receive the Kickstarter edition of Skreens!  The package arrived in the mail today, a short 10 months since the project was funded.  Huge congratulations to Team Skreens!

Here is what we got:

1. Nice, simple box

2.  Power supply and quick start guide on top

3.  Here is everything taken out of the box


My first impression is that this is a well thought out package.  It includes everything needed to install the device and begin using it with existing equipment: HDMI cable, power supply, power cord, and the device itself.

I am a little disappointed that the device itself is in a plastic housing, with no standard mounting options, and a strange unlabeled button in the front.  But since this is a Kickstarter edition, I am also impressed at how much this already feels like a retail product.

Here are some more details:

The device itself is 8 inches wide. There are air vents on both sides so you’ll need at least 12 inches of width to keep the air flowing smoothly.

It is 4 inches deep, but watch out for that tiny white button on the front.  It is easy to bump it so I’d suggest giving the front a good half-inch more space and the back is where the wires go, which I always leave a minimum of 3 inches.  I’d recommend at least 8 inches of depth to allow for all of the wires and space in front to avoid any accidental button press.

The heighest point in the curved face of the unit is just shy of 2 inches.  If you are really tight in space I would allow for 1 and 7/8 inches.  There is no need for any additional height.
As for the power supply.  It is a typical power brick, but it is nice that this switching supply supports a large input range for those of you outside the USA.  This one has an output rated for 5V up to 4Amps, which means you won’t be powering this off a USB port.


That’s it for now.  Here is a quick look at the quick start guide.  I plan to install and test everything as soon as possible and will report my findings in the next post.


Oh, and here is a screenshot of the Skreens app before I have the device connected.