Blog Archives

heroku cheat sheet quick start

#note requires java 8. add the ppa repo for oracle and install this if you dont have it already. check your local with: java -version

#create auth token for subsequent commands
heroku login

#from within a local git cloned app root, to create a new dyno
heroku create

git push heroku master

#check if dyno is running
heroku ps:scale web=1

#shortcut to open the dyno. if you are running these in a remote SSH you will need to X11 forward for this to work
#or simply, just open the address indicated after you push
#this uri is also visible using the logs command below
heroku open

#tail logs for running dyno. refresh the browser while you are viewing the app to verify new log entries added
heroku logs --tail

#procfile declares what command is executed at start of app. this is likely web.
#for windows: this is different. see heroku docs and make and use heroku -f

#general note regarding the “free-ness” of heroku on your first app
“By default, your app is deployed on a free dyno. Free dynos will sleep after a half hour of inactivity and they can be active (receiving traffic) for no more than 18 hours a day before going to sleep. If a free dyno is sleeping, and it hasn’t exceeded the 18 hours, any web request will wake it. This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally”

#pom.xml specifies dependencies in the case of java determines version of java to use

#pull in dependencies to target/dependency and store this in pom.xml
mvn clean install

#to start heroku locally
heroku local web

#install add-ons
heroku addons:create papertrail

#list add-ons
heroku addons

#open add-on logs
heroku addons:open papertrail

#test a command on a one-off dyno, e.g. run bash in local dyno
heroku run bash

#set environment variables
heroku config:set ENERGY="20 GeV"

#view environment variables
heroku config

#show database info, e.g. postgres
heroku pg

#run tsql commands
heroku pg:psql


javac invalid target release maven ant intellij netbeans eclipse

You may see the following error when running maven or ant command or from intellij:
javac: invalid target release: 1.8

This occurs because you are running a build target for a version of java that you do not have set as your default in JAVA_HOME.

If you do not have java 8 installed, in ubuntu this is as simple as:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

This is similar in other flavors of linux, simply add the official oracle repo and install. Installation in Windows requires browsing to the JDK/JRE pages on Oracle and downloading/installing. Avoid OpenJDK. This is outside the context of this blog post, but you can google “openjdk vs oracle jdk performance” to learn more.

If you see this error in an IDE such as intellij, netbeans or eclipse, this can be fixed by setting the java compile in your Settings to Java 8. E.g. if the error above said 1.9, change this to Java 9.

If you are upgrading from 7 to 8, the last oracle install step when installing the package should set JAVA_HOME:
(ubuntu) sudo apt-get install oracle-java8-set-default

If the above install command or corresponding install script on your system does not work, to fix you can also manually set JAVA_HOME, such as:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle

echo the current $JAVA_HOME and the new oracle java home should be alongside it.

In my scenario I actually ran the oracle provided install script but it failed to set the java home correctly so I still had to do this manually.


How to Create a new Java Applet in Netbeans

First create a new project. Make sure you select “Java Application” not Desktop Application or other types.

On the left hand of the screen you should see “Source Packages” and your project name in lower case underneath. If you don’t see this in the little window on the left, expand the coffee icon with your project name.


Right click your package (mine is javafileuploader in the screenshot above) and select New->Java Class.

Make sure your new class is selected, and then referencing my code snippet below, import java.applet.* and java.awt.* then add new functions for “paint” and “init”.

(code snippet courtesy of ehow link in references)

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package javafileuploader;

import java.applet.*;
import java.awt.*;

 * @author fedora
public class NewClass extends Applet {
int m_height, m_width;

public void paint(Graphics m) {
for (int i=0; i<10; ++i)m.drawLine(m_width,m_height,i*m_width/10,0);

public void init() {

Once you have this typed/pasted in, select run->file and voila! you should see a little applet window appear with a green background and oblique lines. You’re now ready to begin. Enjoy!


Android Launch Browser from App to handle external URLs

Upon googling for this one, I found some good relevant links on stack overflow as well as the android webview documentation, but no singular solution that tied everything together.

First, I created a custom WebViewClient class. Note that this is optional as you can do inline class declarations in this environment.

package com.example.testapp;

import android.content.Context;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.content.Intent;

public class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url != null &amp;amp;&amp;amp; url.startsWith('')) {
            return false;
        } else {
                    new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;

Then, in the main activity, use code within onCreate to support for multiple windows and to set the web view client to your own custom client.

package com.example.testapp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;

public class MainActivity extends Activity {

	private WebView webView;
    public void onCreate(Bundle savedInstanceState) {
    	final Context context = this;

    	webView = (WebView) findViewById(;

    	webView.setWebViewClient(new MyWebViewClient());

If you want to use an inline class declaration instead of defining a seperate mywebviewclient class, you can also use something like:

    	webView.setWebViewClient(new WebViewClient() {
    	      public boolean shouldOverrideUrlLoading(WebView view, String url) {
//etc, same code as above

If you have not already addressed the question of handling the android back button within your webview, the android documentation has a good quick simple code reference on how to accomplish this.

Enjoy. 🙂



Android Documentation,