Monday, 29 September 2014

Test for shellshock bash bug vulnerability in OS X or Linux

Problem:

How do I quickly test if my computer is vulnerable to the shellshock Bash bug?

Solution:

One way to test the shellshock bug is to open a Terminal (in OS X, or any shell prompt in Linux, Cygwin, etc.), and try the following one-lined command:

x='() { :;}; echo VULNERABLE' bash -c :

If vulnerable, VULNERABLE should appear as part of the response. Otherwise if things are alright, you should get a response similar to the following:

bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'

(Note that in some versions of fixed/patched bash shells, the above error won't show up but "VULNERABLE" will also not be printed to the terminal.)

Notes:

If you're unsure of any steps of the above instructions, see if you can find a friend who may be familiar with how to use bash shell and Terminal to try the above for you.

For more detail, check out the references below.

If your system happens to be vulnerable, and you're using Linux and don't know how to update your bash shell, try this post for instructions: http://linux.about.com/od/howtos/fl/How-To-Fix-The-BASH-Shellshock-Bug-On-Your-Linux-System.htm

NOTE: I won't be able to answer any questions about shellshock as I am not enough of an expert on this bug to comfortably respond. Sorry about that! I hope that this post still comes in handy to people out there.

References:

Friday, 12 September 2014

Unable to resolve superclass android.support.v4.app.FragmentActivity

Problem:

When trying to implement an Android app using the Facebook SDK (v3.18) I get an error similar to: Unable to resolve superclass of Lcom/facebook/samples/hellofacebook/HelloFacebookSampleActivity;

In the above example, HelloFacebookSampleActivity is a subclass of android.support.v4.app.FragmentActivity.

I have already added the android-support-v4.jar to my project (found in FacebookSDK/libs) and Eclipse ADT does not show any linker errors. However, whenever the app is compiled and run on a device it crashes immediately and gives the above error in the log.

Solution:

Try the following:

  • Right click on your project in Eclipse
  • Select: Build Path -> Configure Build Path
  • Select the "Order and Export" tab
  • Make sure that "android-support-v4.jar" is checked

When you try and run the project now, the app should hopefully be able to find the linked FragmentActivity from the now-included android-support-v4.jar.

References:

Thursday, 26 June 2014

Replaced ADT Eclipse and got errors such as "The type java.lang.Object cannot be resolved"

Problem:

I've installed the Juno version of the Eclipse-based ADT from the Google Android developers site in order to replace my outdated ADT. Now all of my existing android eclipse projects from my previous workspace have many errors such as "The type java.lang.Object cannot be resolved." and will not compile in the newly-installed ADT.

Steps to try:

The following steps fixed the issue on the author's system so they might be worth trying, (however it's not guaranteed that they will work):

  • Add any add-ons that may have been on your previous ADT build: http://developer.android.com/sdk/installing/adding-packages.html
  • For each project, make sure that each has a valid Android target and Java system library
    • Right click on the project folder and click "properties"
    • Click on "Android" from the list on the left
    • Check an android version in "Project Build Target"
    • Click on "Java Build Path"
    • Click the "Add Library..." button on the right
    • Select "JRE System Library"
    • Choose an appropriate JRE and press "OK"

Explanation of the above steps:

The errors such as "The type java.lang.Object cannot be resolved" are due to the new ADT being unable to find the system's java library (or the library that is installed is currently invalid.) Pointing your project to the appropriate Java JDK should fix this problem. However, this doesn't fix everything.

The next errors regarding android.* and related means that the old ADT pointed to an Android target that likely no longer exists after the upgrade. Pointing the project to the new Android target should fix the problem (or installing the old versions should also do the trick.)

Hopefully this helped, though it definitely won't be a complete solution for everyone out there. Best of luck to you!

Other notes:

Note that the fix above worked for an upgrade to ADT version 23 using Eclipse Juno under OS X 10.9.3. Your mileage will most likely vary with different versions. The above steps were only listed in case someone out there finds them helpful.

Tuesday, 24 June 2014

Android CalledFromWrongThreadException

Problem:

When I try to run functions such as myView.setText(myText), I get something similar to the following error: CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

Solution:

Use Activity.runOnUiThread()

For instance, within your MainActivity (or whatever your activity class is named):


public void myFunctionCalledByAnotherThread() {
  // ... stuff ...

  runOnUiThread(new Runnable() {
    @Override
    public void run() {
      // ... code to modify ui such as View.setText() ...
    }
  });

  // ... other stuff ...
}


If you're outside of the Activity, you can also try getActivity():

getActivity().runOnUiThread( ... )

Explanation:

This error is caused by a thread other than the original thread that created the UI element/View, attempting to modify that view. An example of something that will cause this error is placing a setText() call into the run() function of a java TimerTask.

References:

Tuesday, 13 May 2014

'MySql server has gone away' with phpmyadmin using MAMP 2.0.5

Problem:

In phpmyadmin under MAMP 2.0.5, I get the error 'MySql server has gone away' when trying to import a large .sql file.

Solution:

There are a few things that can cause this issue, however one common one is the MySQL max packet size being too small. By default, it's set to about 1MB.

To fix this under MAMP 2.0.5, you can add a custom configuration setting to increase the max packet size by using the following instructions:

  • Stop MySQL Server (or stop all MAMP servers)
  • In /Applications/MAMP/conf/ create a my.cnf file if it does not exist
  • Add the following to the my.cnf file:
    [mysqld]
    max_allowed_packet = 64M
    
  • Save the my.cnf file
  • Restart MAMP servers

If this did not quite solve the problem, you can check out this Stack Overflow post for additional my.cnf configurations to try.

References:

Wednesday, 26 February 2014

In XCode 5, turn on 80-column line guide

Problem:

I am using XCode 5 and the coding style guide that I am using requires avoiding lines going past the 80-column mark, if possible.

How do I turn on the 80-column guide?

Solution:

  1. Go to the XCode Preferences (in the menu: XCode -> Preferences...)
  2. Go to the Text Editing tab
  3. Check "Page guide at column: "
  4. Change the number to 80, or to whatever column your required style guide needs

Friday, 21 February 2014

Toggle Doxygen in Eclipse Kepler CDT C/C++ Editor

Problem:

I'm working on C/C++ in Eclipse Kepler and I would like to toggle the IDE editor's Doxygen comment helpers as they appear to be turned off by default. How do I do this?

Solution:

To toggle the "automatically generate Doxygen comment" feature in Eclipse, go to:

Preferences ... -> C/C++ -> Editor

Then look for the panel labeled Documentation tool comments and change Workspace default to "None" or "Doxygen", depending on your preference.

This is illustrated in the following image:

Notes:

If you are unsure of what Doxygen is, check out this quick explanation from Wikipedia (as of Feb 21, 2014):

Doxygen is a documentation generator, a tool for writing software reference documentation. The documentation is written within code, and is thus relatively easy to keep up to date. Doxygen can cross reference documentation and code, so that the reader of a document can easily refer to the actual code.
Article link: http://en.wikipedia.org/wiki/Doxygen. It's a fairly useful tool and you should consider using it if you don't already have a consistent style for writing comments in C++ code.

References:

Monday, 3 February 2014

How to detect displays in OS X 10.9 Mavericks

Problem:

How do I detect displays in OS X Mavericks? The Systems Preferences option to detect displays seems to be missing.

Solution:

While in the "Displays" Systems Preferences panel, press the "option" key and the "Detect Displays" button will appear when using OS X Mavericks.

Image below: OS X 10.9 Displays panel with the "Detect Display" button missing by default

Image below: OS X 10.9 Displays panel after pressing the "Option" key

Notes:

This was tested to work in OS X 10.9 and 10.9.1. Your mileage may vary in other versions.

References: