Launch Play in Eclipse

Sometimes its easier to watch the eclipse console instead of alt-tab into the shell window.

Fortunately you can use the external tool configuration to launch play.

http://stackoverflow.com/questions/21730926/redirect-play-framework-2-output-to-eclipse-console/22786093#22786093

The only problem is the console does not recognize control-d so you have to kill java.exe in task manager.

Play on!

Posted in Java, Play Framework

View Java Source In Eclipse for Windows – The Easy Way

In a previous post I outlined the steps to view java source code in eclipse.

I have since found a much easier way to do this.

Requirements:

Steps:

  1. Open eclipse
  2. Create a new java project
  3. Expand your project, next expand your JRE System Library
  4. eclipsejresystem
  5. Right click on rt.jar > Properties > Java Source Attachment > External Location
  6. Select External File…
  7. Browse to your jdk installation, locate src.zip
  8. eclipsejresystemsource
  9. Click OK
  10. Expand the rt.jar
  11. View Source

eclipseviewsource

Posted in Java

View Java Source In Eclipse for Windows

As my journey into java development continues, I found an opportunity to investigate core java source code. My interest was the method String.contentEquals(). Curious in the difference between String.equals() and String.contentEquals(), look to java source code.

UPDATE: View Java Source In Eclipse for Windows – The Easy Way

Please note, I am not attempting to compile my own jdk library.  Information for compiling the jdk from scratch can be found here http://openjdk.java.net/. Also the openjdk will contain more source code than Oracle JDK. http://en.wikipedia.org/wiki/Free_Java_implementations#Sun.27s_November_2006_announcement

Finally there are sites like http://www.grepcode.com/ that you can view source there if you like.

The following steps outline how I load java source code into eclipse for easy viewing.

Requirements: 

javajdklinux

Download the .gz file.  In my environment I am running x64.

The reason I am using the linux build is because the jt.jar file contains a few classes that don’t exist in the windows build.

javajdklinuxdownload

Right click on .gz file > 7-Zip > Extract Here

Right click on non .gz file > Extract Here

javajdklinuxextract

A new folder will be created, browse to new folder, locate src.zip.

Right click > 7-Zip > Extract to “\src”

javajdklinuxextractsrc

A src folder will be created.

javajdklinuxextractsrcfolder

Next, open your eclipse and create a new java project. The new java project should have a src folder.

eclipsesrcview

Right click on the eclipse src folder > Properties, take note of the Location.

eclipsesrclocation

Copy the contents of the extracted jdk src folder into the src of your java project.

In my example, I have D:\jdk\jdk1.7.0_51\src > C:\Lab\JavaSource\src

eclipsesrccopy

Refresh your project in eclipse.

eclipsesrcproblems

You will notice right away of access restriction build problems.  Lets resolve these problems.

In eclipse, right click on your project > Properties > Java Build Path > Libraries

eclipseslibraries

Click on the JRE System Library > Remove

Click Add Library > JRE System Library > Alternate JRE > Finish > OK

eclipsesaltjre

You will notice we still have a few problems.

eclipsesrcproblems2

This is the reason I am using the linux build, the jt.jar file contains the UNIXToolkit class that doesn’t exist in the windows build.

Lets resolve these problems

Right click on your project > Properties > Java Build Path > Libraries > Add External JARs…

Locate the rt.jar from your jdk download.  My locations was \jdk1.7.0_51\jre\lib.

Click OK

eclipsesrcproblems3

There should be no more problems, you are now able to inspect java source in eclipse editor.

eclipsejdksource

Posted in Java

DIY Home Network Closet

One day I got tired of my wireless network.

I have media hungry devices:

Direct TV Home Whole Home DVR (This uses internet download for on-demand content)
Two Apple TVs
Netflix enabled Blu-Ray
Netflix enabled Xbox
AirPlay enabled speakers
My Home PC
My Work Laptop
My iPad
My iPhone
My MacBook Air
Wife’s Home PC
Wife’s Work Laptop
Wife’s iPad
Wife’s iPhone
Wife’s MacBook Air
Visitor’s devices + stuff I am forgetting

Every time I wanted fast network speeds, I had to drag a network cable from my router to somewhere in my house.

This is my solution:

DIY Home Network Closet

DIY Home Network Closet

Of course this doesn’t directly affect wifi only devices, but this solution can offload to wired devices as much as possible. In this post I will recall my steps to set this up. This post is more of a brain dump than a step by step how to.

– Plan

  1. Sketch out the layout of your house. Identify each drop in each room. I wanted one coax and two network drops per room. If you can reuse the old coax drop to piggy back with new, do it. Cutting into drywall is probably the worst thing ever so avoid making brand new drops. Using old drops is great because you don’t have to fish out the wire. You can use electrical tape to the old wire and pull in the new.
  2. Find a central location in your house. I have a coat closet that is perfect in my scenario. My wife allowed me to take it over under one condition – no more flaky wifi or buffering on netflix. A win-win. You will notice that I have plywood in the closet. I did this so I wouldn’t have to find a stud every time I wanted to mount a device.
  3. Does your central location have power? I had to add an electrical outlet to my closet. This wasn’t too difficult. If you are the slightest bit scared of this, hire an electrician to set you up. Something like this – http://www.youtube.com/watch?v=CN4sxAmcRME.
Two cat5e and one RG6 connetions

Two cat5e and one RG6 connetions

– Design

Sketch out your new network closet. Ask yourself – how are my devices and wires going to be positioned? This will also help you create a materials list of things you need to buy. My setup is for 24 Gigabit network connections. I will probably never be 100% populated, but I have plenty of space for growth.

Network Closet Reference

Network Closet Reference

  1. Direct TV big splitter. I like the idea of running all my coax inside my house from the attic. I hate seeing coax running down the side of a house with a hole drilled through from outside. These RG6 coax feeds all my rooms + garage :).
  2. Inlet from attic. I used a PVC tube as a conduit to the attic. This is where all my wires are fed in. I stuffed some installation in the attic side tube to keep it airtight.
  3. A normal netgear router. I do have it flashed with http://www.dd-wrt.com/site/index. Dd-wrt is awesome. It makes your $100 router into a $500 feature rich device. You can do ip reservations, vpn, internal dns, and much more.
  4. SURFboard DOCSIS 3.0 High-Speed Cable Modem. Stop paying $8 a month to comcast to lease their modem. This will pay for itself in 1 year or less.
  5. Lowe’s IRIS Home Automation Hub. There are probably more sophisticated home automation systems out there, but it works for me.
  6. Surge protector
  7. My sketch of the layout of my house. This shows all my drop locations.
  8. Motion sensor. This is part of IRIS, it senses when I open the door and turns on the closet light automatically. It also senses the temperature. It will send me a text if the closet reaches 80+ degrees.
  9. Monoprice Wall Mount Bracket, 3.5X19X4 (inch) , 2U (8624). This has a swivel opening on the left side, making maintenance easy.
  10. 3/4 inch plywood layer. Used for easy device mounting. No stud finder needed.
  11. Monoprice Cat5 Enhanced Patch Panel 110Type 24 port (568A/B Compatible) (7255). My punch down for my cat5e wires from my drops. The main reason to use cat5e is the ease of running the network cable through my house. Cat5e is thinner than Cat6. I don’t have to drill bigger holes in my house to fit the cable through to my drops. Personal preference is all.
  12. Rhino Black 4′ Metal Power Strip Frys Electronics. Plug all you stuff in here. It has a nice kill switch at the top to reset all your devices at once.
  13. Iris 110 Volts-Volt White Iris Smart Plug. This is controlled by the motion sensor to turn off and on the light.
  14. TRENDnet 24-Port Gigabit GREENnet Switch with Rack Mount Kit. This switch is great. There is no fan so there is no noise coming from the closet. It runs cool, even in the summer time.
  15. Monoprice Wall Mount Bracket, 7″X19″X12″ (4U) – 40lbs (8627). This holds the switch. I purchased the 4u in case I want to add on with rack mount devices.
  16. 3ft Cat5e Network Ethernet Patch Cable (10 Pack) – Blue. Purchased this on amazon. This is to link the patch panel to the switch.
  17. Velcro strips. These are used to keep your cables organized. I like using velcro strips instead of cable ties most of the time for easier maintenance. Find them on amazon.

– Materials not shown

1000ft of RG6 Digital Analog/QS Coax Cable – for your Direct TV or Cable drops.

Monoprice 1000FT 24AWG Cat5e 350MHz UTP Solid, Riser Rated (CMR), Bulk Ethernet Bare Copper Cable – Blue (880) – for your wired network drops.

Monoprice 1-Gang Low Voltage Mounting Bracket (7013) – Mounting bracket for your wall plates. You will need 1 per drop.

Monoprice Wall Plate for Keystone, 3 Hole – White (6729) – You will need one per drop.

Monoprice Cat5E Punch Down Keystone Jack – White (5376) – This is the network connection jack needed to mount in your wall plate. You will need two per wall plate per drop.

Monoprice Keystone Jack – Modular F Type (White) (6542) – This is for your coax connections needed to mount to your wall plate. You will need one per drop. These are actually pretty bad. Find better ones elsewhere.

14FT 24AWG Cat5e 350MHz UTP Bare Copper Ethernet Network Cable – White (139) – Network patch cables to your devices from your room drops.

– Tools

Amazon Network LAN / Ethernet / Telephone Cable Wire Tracker & Tester (Battery Included) – You need to test each drop.

Amazon TRENDnet Punch Down Tool with 110 and Krone Blade, TC-PDT – You will need this to punch down your network wires to your cat5e punch down block and your Keystone jack. This thing was pretty bad. It works, but if you have a friend with professional tools, borrow them.

Amazon PPC Ex6xl Rg-6 Snap & Seal Compression Connector – These are the connector ends for your coax.

Amazon Coax Compression Connector Adjustable Tool for RG59 RG6 F BNC RCA – You will need this tool to make the ends for your coax. This will take some practice. Follow some youtube tutorials. http://www.youtube.com/watch?v=lNHLG4QdyZ0.

DataShark 70029 Universal Cutter/Stripper for Flat or Round TV/UTP Cable – You will need this to strip your cat5e and coax.

Brother Label Maker – Use this to create tape labels for each wired connection in your network closet

– Finally, Get to work

The hardest part of this job is getting your hands dirty. You will have to crawl around in your attic. If you have a dedicated helper, that would make things go faster. I had the spools of wire in my garage and pulled up to the attic. I then taped the new wire to the old and ran back inside the house. I pulled the old wire from the old drops until the new wire came through.

Next I made sure I had a enough slack and dropped the new wires through the PVC into my network closet. Once all the wires were dropped I started my punch down in my closet. I then punched down at the room drop. Once I completed each termination I used my tester tool to verify good connections.

Coax was similar except I used a coax crimp tool instead of the punch down tool.

As a final test I connect my laptop to test each drop to verify internet connectivity.

– Conclusion

I now have great speed to all my devices. The best part – great quality netflix streams and fast on-demand downloads. Please leave any comments if you have questions or if it seems I left something out. Thanks.

bigfile

File copy across the wired network

speed

Internet Speed

Posted in Home, Network, Over Engineered

Responsive Bootstrap Header

In this jsfiddle I have created an example on how to create a custom image header for medium and small devices.

http://jsfiddle.net/afarris/U87eb/15/embedded/result/

The key to this header is it only uses two images. The main logo and a simple 1px slice. Since the the logo is high resolution it can be scaled down depending on your media queries. This makes maintaining the header easy since you don’t have to deal with multiple size/files graphics.

The logo is 144×144. The important thing to realize is the ratio. This logo is a 1/1 ratio so scaling down is easy. As long as your graphic has high physical resolution, it will look good on your retina device.

bootstraplogo

bootstraplogoslice

The header will be 100px tall if between 479px and 991px. If under 479px it will be 50px tall.

A final item to mention is I adjusted the @grid-float-breakpoint from @screen-sm-min to @screen-md-min in http://getbootstrap.com/customize/. This is to allow the nav to collapse on medium devices.

grid-float-breakpoint


body {
padding-top: 50px;
}

.navbar-header {
background-image:url("bootstraplogo.png", "bootstraplogoslice1.png")
background-repeat:no-repeat, repeat-x;
background-position:center;

}

@media only screen and (min-width:479px) and (max-width:991px){
body {
padding-top: 100px;
}
.navbar-header {
background-size: auto 100px, 1px 100px;
}
.navbar-header {
height:100px;
}
}

@media only screen and (max-width: 479px) {
.navbar-header {
background-size: auto 50px, 1px 50px;
}

.navbar-header {
height:50px;
}
}

Posted in CSS, Design Patterns, Responsive Design, Twitter Bootstrap

State behavioral design pattern with previous state

I am always interested in utilizing design patterns in my development tasks.  I finally had the need to check if the state of something changed from it’s previous state.  I thought this would be the perfect use of the state design pattern.  I made a small modification but it worked perfectly.

I followed the java example from http://en.wikipedia.org/wiki/State_pattern and changed a few things to fit my needs. The complete code and tests are here: https://github.com/abefarris/stateDesignPattern

In order to get the previous state I modified the context class:

public class StateContext {
	private Statelike currentState;
	private Statelike previousState;
	

	public Statelike getCurrentState() {
		return currentState;
	}

	StateContext() {
		setState(new StateOther());
	}

	void setState(final Statelike newState) {
		previousState = currentState;
		currentState = newState;

	}
	
	public boolean isStateChanged(){
		return !(previousState.getClass().equals(currentState.getClass()));
	}

	public void setMode(final String mode) {
		currentState.setMode(this, mode);
		
	}
}

Example of tests:

testOpenOpen – the state never changes
testOpenOther – the state changed

@Test
public void testOpenOpen() {
	final StateContext sc = new StateContext();
	sc.setMode("open");
	sc.setMode("open");
	assertFalse(sc.isStateChanged());
	assertTrue(sc.getCurrentState() instanceof StateOpen);
}

@Test
public void testOpenOther() {
	final StateContext sc = new StateContext();
	sc.setMode("open");
	sc.setMode("other");
	assertTrue(sc.isStateChanged());
	assertTrue(sc.getCurrentState() instanceof StateOther);
}
Tagged with: ,
Posted in Design Patterns, Java

Play Framework 2 Todolist with JPA and PostgreSQL

In order to learn more about creating a Play application with JPA and PostgreSQL, I followed the todolist application instructions:

http://www.playframework.com/documentation/2.2.x/JavaTodoList

The key difference from the original tutorial is I changed the backend to use JPA with PostgreSQL instead of the default ebean configuration.  The code can be viewed here:

https://github.com/abefarris/todolist

Posted in JPA, Play Framework, PostgreSQL, WordPress