September 22, 2021

How to disable dark-mode for java applications on OSX

As a software engineer, I've been a big fan of the dark-mode that was added to BigSur OSX.  The only problem is that one of my frequently used apps didn't like the new color schema. For instance, if you look at the following screen capture, you'll notice that the menu bar and table headers are black on black.

I did some research and found the following workaround. In OSX, you can disable dark-mode for a specific application. 

To do this, you will need to run the following command:

        defaults write <BundleID> NSRequiresAquaSystemAppearance -bool yes

But before you run that command, you need to find the <Bundle ID>. I found using the lsappinfo command the easiest way. When you run this command it displays a bunch of information about the current applications that are running. So for me, I just looked for the Luke and found the following?


70) "LukeMain" ASN:0x0-0x305305:
    bundleID="net.java.openjdk.cmd"
    bundle path="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java"
    executable path="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java"
    pid = 70611 type="Foreground" flavor=3 Version="1.0" fileType="APPL" creator="java" Arch=x86_64
    checkin time = 2021/09/21 18:01:54 ( 9 minutes, 12.5975 seconds ago )

Since my application was Java bases this command did the trick for me. 

        defaults write net.java.openjdk.cmd NSRequiresAquaSystemAppearance -bool yes

And.... back to normal...



 


May 4, 2017

Setup Motion on raspberry pi

Use the following procedure to setup motion on a raspberry pi zero w.


  1. Setup raspbian on SD card via https://www.raspberrypi.org/documentation/installation/installing-images/README.md
  2. Update config to enable it to boot as a network gadget https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a
  3. ssh pi@rasberrypi.local
  4. run raspi-config
    1. reset password
    2. rename host zero
    3. enable camera module (under interfaces)
    4. Reboot
  5. ssh pi@zero.local
  6. sudo apt-get update
  7. sudo apt-get upgrade
  8. sudo apt-get install motion
  9. Edit /etc/default/motion
    1. start_motion_daemon=yes
  10. Add /etc/modules
    1. # camera with v4l2 driver
    2. bcm2835-v4l2
  11. restart



March 24, 2017

How to expose a port to the internet

I recently discovered localtunnel which is a slick little tool to expose a port to the internet.
https://localtunnel.github.io/www/

To Setup:

  • brew install npm
  • npm install -g localtunnel
  • lt --port 8080


January 3, 2016

How to workaround Kindle Fire's FreeTime App categories.



We recently got our kinds the Kids version of Kindle Fire and was really disappointed to find that  some Apps are flagged as Entertainment. In particular, our schools use RazKids and because of the categorization with FreeTime there isn't a way for us to allow our kinds to read using RazKids without giving them access to all games.

I was searching around for workarounds but didn't find anything so I'm posting the workaround that I came up with.

The solution that I found was:

  1. Create a New Child Profile named RazKids
  2. Under "FreeTime Unlimited", tap the "Manager Your Subscription" and uncheck the RazKids. This will disable all the standard content that is provided by FreeTime.
  3. Now Tap, Add Content and select the "RazKids" app. This grants them permission to the RazKids app.
  4. Now Tap, "Set Family Goals & Time Limits" and set whatever restrictions you would like to apply.

By doing this, you'll now see a second profile that has access just to RazKids. The kids can now switch between the regular profile with full FreeTime access and this special profile to use RazKids.


December 15, 2015

Jersey API Exception Handler


In Jersey, you can register your own exception handler so can return an appropriate HTTP response for any exception In the handler, you can set the error response or convert it to any JSON object.



September 22, 2015

Using awk to filter by value



Here's a simple example of an awk script that will find rows where there value is greater than 1000. I often forget the syntax of this command but in the following example, I'm trying to find rows where the 11th column is greater than 1000.

awk '{if ( int($11) >= 1000 ) print $7, $11;}'

June 15, 2015

Creating a custom generic GWT event


I keep having trouble setting up a GWT event handler which is parameterized. All of the magic needs to happen in the GwtEvent class itself.


April 2, 2015

GWT Custom Serializer

GWT allows you to build your own customer serializers. In the past, I've found issues/bugs with certain serialization of classes and this allows you to provide your own implementation. The key to this is that you have to put your class in the com.google.gwt.user.client.rpc.core + your class package.

The following example you be to create a custom serializer for the my.package.ApiException class.



March 19, 2015

Prevent HTTP 304 for GWT's nocache.js files.



I recently deployed a release of our product which caused a majority of our users to clear their browsers cache in order to access our sites. Of course, this is quite embarrassing and I was asked to identify the problem.  Since day one we've always had the standard solution of deploying a ServletFilter which sets the standard Cache-Control headers so it was confusing why all of a sudden a large percent of users were reporting this issue.


The good news is that I believe I've solved my problem and since I've never seen any reference to it I figured it would write it down.


Disclaimer: You'll have to forgive me but we're running Tomcat 7.0.22 (yeah, I know) so this might have changed in more recent versions.


So the first thing that I noticed is that in the tomcat access logs there are HTTP 304 (File Not Modified) being returned for my nocache.js files.   After many hours of Googling and debugging, I found that the DefaultServlet. checkIfModifiedSince() compares the files timestamp with the "If-Not-Modified" header to determine if that file has changed.   We're deploying our app as a WAR file which means that files timestamp gets set to the time that is stored in the WAR.  Now to further complicate this issue GWT seems to be caching this file someone (not the GWT working directory) so in our build it was getting set to the time when we created the branch and jenkins plan.


So to summarize, my problem was the timestamp of this file was being set to the time of the branch creation (which was days before deployment).  So anyone who used the application between the time we branched and them time we deployed would cache a copy of the nocache.js file with the current timestamp. When the WAR was finally deployed, the timestamp was updated to branch time and new request would start getting 304s because they were passing in "If-Modified-Since" headers that were greater than the time of the branch.


So how do you fix this problem?  A simple unix command:

find -name '*.nocache.js" -exec touch {} \;

Now, I also went a step further and wanted to try to fix the programmatically. The only workaround that I could find was to build an HttpServletRequest interceptor that prevents that header from being returned.






September 29, 2014

HOW-TO Use GWT SuperDevMode

GWT 2.5 introduced a concept of SuperDevMode which is a pretty awesome concept but I found it almost impossible to get it to work. The documentation just didn't explain enough of the missing pieces.
So before I get started, let me explain what it is/does. Recently a bunch of the browsers started to support the concept of source code maps. This feature has nothing to do with GWT and it just a way for someone to debug javascript that has been optimized/generated. These maps contains a mapping of the compiled source to the original source which then allows the debugged to display the original source.

So what GWT has done is provided a mechanism to integrate with this browser debugging feature to provide a way to debug through the compiled javascript BUT see the original java code. Awesome right!

The key thing I found extremely confusing is that you need to build and deploy the production version of your application. I use maven/tomcat to do this but you could use anything.
  1. Compile your application as normal (mvn clean install -DskipTests)
  2. Install the war into your local tomcat and start tomcat
  3. Execute java program at the bottom which will start the Code Server
  4. Go to http://localhost:9876/ and copy the bookmarks to you bookmark directory
  5. Go to the location version of the app (http://localhost:8080/yourwar/
  6. Click the "Dev Mode On" bookmark

You should now see the a SDM dialog come up and ask you to compile the app.  Once it is done compiling the app, you now are running a newly compiled version of the app within the browsers debugger. So you're not going to use the IDEs debugger anymore. Now you'll can open Chromes debugger and you should see the JAVA source instead of the javascript sources. You should be able to set a breakpoint.

While this is an awesome feature, I've found that using the standard mode still more useful for day-to-day debugging.  I do run into cases where its been essential. Recently, I had a race condition which never showed up in the standard debugger because it always executed so slowly.

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