Wednesday 3 October 2018

Reminder: SparkJava 2.7.2 pom.xml known to work for new projects

Problem

For SparkJava 2.7.2, I'd like a known set of POM.xml dependencies and properties that work so I can kick-start my project. The settings in the SparkJava "getting started" tutorial result in exceptions.

Example POM.xml snippet

In your POM.xml, try these to start off:

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
  
  
    <dependencies>
  
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>9.4.6.v20170531</version>
        </dependency>
  
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.21</version>
        </dependency>
 
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.7.2</version>
        </dependency>
    </dependencies>

Notes

The above dependency versions and properties were observed to work on 2018-10-03 with SparkJava version 2.7.2. Your mileage may vary.

Once you have your SparkJava project working, feel free to change versions to suit your own project needs.

References

Monday 2 July 2018

Fix 07_BoggieBot.playground errors "Cannot call value of non-function type 'NSGraphicsContext?" and "Cannot convert value of type 'NSApplication.ModalResponse' to expected argument type 'Int'"

Problem:

When trying to learn from 07_BoogieBot.playground alongside Apple's Everyone Can Code "Intro to App Development with Swift", I get errors similar to:
07_BoogieBot.playground/Sources/Recorder.swift:26:51: Cannot call value of non-function type 'NSGraphicsContext?'
07_BoogieBot.playground/Sources/Recorder.swift:33:99: Cannot call value of non-function type 'NSGraphicsContext?'
07_BoogieBot.playground/Sources/Recorder.swift:70:31: Cannot convert value of type 'NSApplication.ModalResponse' to expected argument type 'Int'
The console shows me the following:
Playground execution failed: error: /var/folders/1g/_b7g8rjd71j_mwjxdj29vllc5x9cxx/T/playground11-16e897..swift:3:8: error: no such module '_7_BoogieBot_Sources' import _7_BoogieBot_Sources
I am using XCode 9.4.1 and macOS 10.13.5

Before you start:

You'll want to make a backup of lesson 7's code first. Just make a copy of the folder in Finder. We'll be editing the code that runs the playground, so this way you can undo by restoring the backup if you've forgotten what you changed and introduced a bug.

Workaround:

You're learning coding for the first time, and you've been given a chance to debug the playground you're learning from. Cool!

Here's a few quick steps to get your BoogieBot lesson going!

Step: Have a look at the errors

In XCode you can view what errors have broken your code. In our case, click here:
You'll see a list of errors appear in the navigator in red. Try to click one:
Wow, that's more code that you've seen in the previous lessons. No worries. Just focus on the problem you're trying to solve and ignore the rest.

Step: Fix the 'context' bug

For the lines that have:
if let context = NSGraphicsContext.current()?.cgContext
Remove the (), so they look like:
if let context = NSGraphicsContext.current?.cgContext
If you save the file and the 2 errors go away, you've made progress. Congrats on debugging so far!

Why does this code change work?

Someone at Apple had changed NSGraphicsContext.current from a function to a property.

As you recall from an earlier lesson, programmers will often have to build on code made by others. In this case the code happens to be from those who worked on part of the graphics programming for macOS 10.13. These are changes you'd see if coding in XCode 9 (instead of XCode 8).

Step: Fix the Modal.Response bug

For the code that looks like:
if (savePanel.runModal() == NSFileHandlingPanelOKButton) {
Change it to look like:
if (savePanel.runModal() == .OK) {

Why does this code change work?

Without getting too technical, essentially someone at Apple had changed the way this test should work.

IF you're really curious and aren't learning to code for the first time, have a look at https://developer.apple.com/documentation/appkit/nsapplication/modalresponse

Step: Go back to the BoogieBot Playground

Now that you've debugged the code and saved it, check that no errors still exist. (The yellow warnings won't block you from lesson 7.)
Cool. Now you can return to learning about BoogieBot by clicking here and going back to your playground:
Happy boogie-ing!

Notes

This how-to was tested to work using XCode 9.4.1 and macOS 10.13.5. The bug was seen in the playground downloaded sometime June 2018. Your results may vary depending on versions, and if Apple fixed the playground by the time you read this post. Code can change pretty quickly in real life.

If you ran into this bug, hopefully you were able to fix it and learn how to make your boogie bot dance using Swift!

Friday 1 June 2018

How to fix kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)

Problem:

When I try to build and deploy in XCode 9.3, I get the following error related to: "kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)"

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)
 from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Development/ELD.iOS/ELD/Scripts/generate_resources.rb:4:in `
' Command /bin/sh failed with exit code 1

Possible solutions to try:

There are several possible ways to address this issue. Two are listed here to try.

  1. Install XCode command line tools from Apple
  2. Install the gem "xcodeproj"

To install XCode command line tools...

  1. Go to https://developer.apple.com/download/more/ and login
  2. Search for the command line tools for your version of XCode, download it, then install it.

To instead install the gem "xcodeproj"...

  1. Open a Terminal window
  2. Use the command:
    sudo gem install xcodeproj

Notes:

This how-to was tested to work for a project on macOS High Sierra 10.13.4 and XCode 9.3. Your results may vary. It assumes a little working knowledge of XCode and Terminal.

Best of luck!

Tuesday 30 January 2018

Cannot type into Spotlight in macOS

Problem:

I suddenly cannot type anything into Spotlight.

It opens and closes, and even does so with the Command-Space shortcut. I just can't type in it when it's open.

Workaround:

  • Open Terminal
  • Use the following command:
    killall Spotlight
  • If all goes well, the magnifying glass for Spotlight will disappear and reappear, and you'll be able to type into Spotlight again

Notes:

This was tested to work in macOS 10.12.6.

Wednesday 24 January 2018

Seamonkey XPCOMGlueLoad error

Problem:

I updated Seamonkey on Linux Mint and it now won't launch. I am running a 64-bit version of Linux Mint.

In terminal, I tried to run Seamonkey but got an error similar to:

$ /path/to/seamonkey/seamonkey

XPCOMGlueLoad error for file /path/to/seamonkey/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.

When checking, I do have GTK 3:

$ locate libgtk-3.so.0

/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1800.9

Solution:

It may be that you're attempting to run a 32-bit version of Seamonkey on 64-bit Linux Mint. The default Seamonkey download from Mozilla as of Jan 2018 is the 32-bit version.

You can find the 64-bit version in their releases page: http://archive.mozilla.org/pub/seamonkey/releases/

For example, for 2.49.1:

Notes:

This solution worked for Seamonkey 2.49.1 running on 64-bit Linux Mint 18.1 Serena as of Jan 2018. Your mileage may vary with other versions and configurations.

Also for the system tested, the auto-update is not an issue because this browser will only be used on a local network. (You'll see the note from Mozilla when you launch the browser... at least for version 2.49.1). Keep this in mind if your situation is different and you need a browser that reliably auto-updates.

References:

http://archive.mozilla.org/pub/seamonkey/releases/ http://forums.mozillazine.org/viewtopic.php?f=40&t=3005417

Tuesday 16 January 2018

XQuartz move offscreen windows back on-screen in macOS/OS X

Problem:

I have several XQuartz/X11 windows in macOS/OS X that are offscreen. I want to move them on-screen so I can save my work.

Example scenario:

You can create an example of off-screen X11 windows when using macOS/OS X with an external monitor and a screen geometry where one monitor is higher and further left to another (scroll down to see a screenshot example).

In the lower-right monitor, when opening certain windows in programs like Inkscape, those windows will be created at coordinate that you cannot access with your mouse cursor.

Workaround:

Pre:

  • If not already installed, then install xdotool (easiest way is to use Homebrew)

To find out window ids and geometry:

  • In Terminal, you can use:
    xwininfo -tree -root
  • If you want to filter by an application, you can pipe to grep, for example:
    xwininfo -tree -root | grep "inkscape"

To move a window to a visible coordinate:

  • If not already installed, then install xdotool (easiest way is to use Homebrew)
  • Make note of a valid coordinate. Use the output of xwininfo from the above step to find a visible top-left coordinate for your window (e.g. it can be an existing window that you can already see and use with your mouse. In the screenshot below, a visible coordinate is 1070 1102)
  • In Terminal, use the following command and replace [options] [window] [x] [y] with the appropriate values:
    xdotool windowmove [options] [window] [x] [y]

Example:

Consider the following window geometry:

Inkscape has spawned the "document properties" window to a coordinate that is out of desktop 1:

Use xwininfo to find out window IDs, geometry, as well as to to find a set of on-screen coordinates:

Use xdotool to move off-screen window to an on-screen coordinate on desktop 1:

If all goes well, the window should now be visible.

Now would be a good time to save your work.

Also note that there might be some unexpected behaviour for XQuartz windows moved this way (e.g. "show all windows" still shows incorrect placement, etc.)

Where to go from here?

Some ideas:

  • write a script to automatically collect all windows of a certain app into visible coordinates if they're not visible
  • if you're able to and have the time to volunteer, contribute to the XQuartz project a feature to collect or clamp all windows to a given desktop :) (thanks in advance!)

Notes:

This workaround was verified to work with macOS Sierra 10.12.6, XQuartz 2.7.11, xdotool 3.20160805.1. Other versions may have different results.

References:

Monday 15 January 2018

Exit XQuartz Full Screen Mode macOS Sierra

Problem:

How do I exit XQuartz full-screen mode?

Solution:

When in XQuartz:

  • Press the keyboard shortcut Command-, (command + comma)
  • Uncheck full-screen mode in the preferences

References:

Friday 12 January 2018

How to take Touch Bar screenshots on Mac

Problem:

How do I take a screenshot of the Touch Bar on a Mac?

Solution:

To take a Touch Bar screenshot and...

  • ...save as a file on the desktop: Shift-Command-6
  • ...copy to clipboard: Control-Shift-Command-6

Example Screenshot:

Notes:

The shortcuts in the solution above are defaults. They can be configured by going to "System Preferences" -> Keyboard -> Shortcuts -> "Screen Shots", and setting new shortcuts.

The how-to was verified to work in macOS 10.12.6 on a MacBook Pro with a Touch Bar. Your mileage may vary with other OS versions.

References:

Thursday 11 January 2018

USB-to-Serial on OS X/macOS - an Example

Problem:

I have a USB-to-Serial adapter that I need to use on a Mac. How do I configure it, and how do I read/write to it?

I am already partially familiar with using serial ports on Linux and Windows.

Notes:

This post is written as a reminder and contains just enough information to reproduce these steps in the future. It is not thorough. A little Google may be required in order to clarify or expand on some points.

The following steps were verified to work with macOS 10.12.6, with a very specific USB-to-serial adaptor that happened to work fine with Apple's default drivers. Your mileage may vary with other configurations and devices.

Steps Overview:

  1. Before you start, if drivers do not already exist then install them.
  2. Plug USB-to-Serial adaptor into your Mac
  3. Find info in "About this Mac" - More below
  4. Setup null modem and speed using Network Preferences - More below
  5. Find the device's path to access the Linux/POSIX way - More below

Step: Find adapter info:

To find out some basic information about your USB-to-Serial adapter, use the following steps.

  1. Go to "About This Mac" and click "More Info..." or "System Report..." (depending on your OS version)
  2. Find your device in the system report under "USB", and make note of what is there. This will help you identify your device in other steps.

Step: Configure serial communication using Network Preferences

To configure your USB-to-Serial adapter speed, etc., for use with other apps on your Mac, use the following steps.

  1. Open "System Preferences" and open the "Network" preferences pane
  2. Select your USB-to-Serial adapter if it is in the list, or add it then select it
  3. Click "Advanced..."
  4. Configure as null modem with the desired baud rate. The example screenshot below shows the attached device configured to 9600 bps (as well as some other configuration)

Step: Access your usb-to-serial port the Linux/Posix way:

  • to find the path to your serial port, in Terminal type in the following command and find your device:
    ioreg -c IOSerialBSDClient | grep usb
  • in the example screenshot above, the serial port is "/dev/cu.usbserial-FTAN3DQ" and an example of its use in VirtualBox is shown in the screenshot below.
  • (optional) to test your serial port directly, you can use the "screen" command in Terminal. More on this command in Apple's screen man page

    References:

  • How to change Ubuntu timezone to UTC

    Problem:

    How can I change my timezone to UTC in Ubuntu?

    Solution:

    1. In a terminal window type:
      sudo dpkg-reconfigure tzdata
      
    2. Then select "None of the above":
    3. After that, select "UTC":

    If all goes well then the "date" command should show the date and time in UTC.

    References: