Monday, October 7, 2013

The tread desk in my closet.. and other fun projects I've done this year.




I mentioned this to a few friends at work the other day, and they got a good laugh out of me describing my office. It's a little odd.. I own two houses, yet live in a two bedroom apartment. What can I say.. I hate mowing grass and dealing with home maintenance.

 Anyways, I needed an office when I started working from home. I had previously used a standing desk in my cube, which was quite common in my previous employments. When I decided to work from home - I knew I had to have a tread desk (The noise had prevented me from doing it in an office environment) in my home office.

 I had a rather large walk in closet that stems off the master suite, so I turned it into my office. One of the things I noticed from working in cube land was that I never had enough writing space, so most of my office became a whiteboard.

You can pick up whiteboard paint at your local hardware store or online at Amazon: Whiteboard Paint

 It's cheap and makes for a washable surface. It doesn't do well on textured walls, but other than that - it's awesome!

Second.. I wanted a standing desk. I couldn't find one that was an exact fit, so I built one. Plus, this allowed me to make the surfaces of the desk a whiteboard. (See the pics below) All total, it cost about $100 for the desk materials. Third.. I needed a treadmill - so I found one on amazon for cheap ($200 - Amazon Treadmill) and built an enclosure around it.

The wood for the enclosure cost about $50 total.. so I ended up with a small cozy office that has lots of writing space, four monitors and all the walking I do should help offset the late night drinking and rockstar lifestyle!

The initial framing of the enclosure around the desk:

4 - 2x4's @ 2.50
12 - 1x4's @ 1.25
Box of 2" molding nails @ 3.50
Box of #10 2" screws @ 2.00


I used .49 sqft fake wood flooring to cover it - it was about $15.00 for a box at Floor & Decor

The finished enclosure with flooring overlay:















The semi-finished office:
Cozy.. Just enough for one dev


















The whiteboard desk surface















Just for my buddy Randall.. I've thrown in a picture of my projector gaming screen too. You can't go wrong with 300" of gaming bliss. (All projects were done in a weekend.. so it's not a big time sync)



Also.. One other fun weekend project - I converted my stock navigation in my 350z Roadster into a tablet config using a Nexus7:






































It allows full pc config of the car's board, plus it passes emission checks! Best of both worlds.. Entertains the girlfriend too.. she watches Netflix at the car meets.

Just some of the fun little projects that I've encountered over the last year - Always tinkering with things that are probably ok as they are, but never good enough for me. If it's not broken, add some more features.


Tuesday, September 10, 2013

Encrypt URL parameters using AES in Java using Spring MVC

Why on earth would you want to do this...  Well, this is one of those crazy requirements that come up with limited resources.

Well.. I do charity work for a 5013C, which has limited resources and one of the requirements they asked of me was to be able to embed data in a static url..  Normally, this would just be a request parameter and my day would proceed on in a rather bland fashion.

This time, it was unique in that some of the data was sensitive (It applied a discount code to the price of a few items) - so manipulating that data would be impactful to the operational integrity of the application. So, how do you secure data when all you have is a url string (SSL and Post options were off the table as this was being embedded as a link in numerous other websites).

So, I decided to use a json payload and encrypt it using AES.. base64 encode it, urlEncode it... and dump that value along with the initial vector into the url as params. It was a rather small payload with only a few sensitive fields, so it was effective, yet crude..

I would be interested in knowing how others would handle this using only a url String making a RESTful call to a server.

The basic requirements:

1. It must be a RESTful url..  All the data is contained in the url.
2. Flat files and database stores are out of the question.. no way to persist data (This was the kicker for me)
3. It has to be embeddable and a direct call.. no middle man url's, etc..

I hope someone reads this and presents a graceful answer.. I don't feel that mine was the best answer, but given my tools in my toolbox.. I didn't see a better way.

Below is the code that does the lifting..  It's fairly straight forward:

Encrypting:
1. The object is serialized to a byte[]
2. Create a Cipher and a random initial vector
3. Hash the key using SHA-256 then trim it to 128-bit for the key
4. Base64 encode the encrypted value
5. Encode the Base64 value to a url friendly format
6. Return the encoded values to include as request parameters in the link

The link will look something like:
http://www.foo.com/view?a=PM90%2B0mzlDLpK5NKlG7CP5lgafMzn5qsrHulCRLR9ZkXnq9L5v7SMuEp%2BPWFtdNR1UxHGw%2Fxh7NzZSPtwSKNRCmQe8fNEMkJJuI4lJ3uvg0DrbI9xXALFZpUs6gAbO7SW5UCeHd6SYWMSWnM9agH9Mw13yfiCKNdiWPiW9j%2BhJa0J5lPraqF1x8srdfm48JaMEg1IaHtRLXukH3VjPTN8sGRUE8nzsu%2BGIyRLaHlXNKt5nZ4wAKtd9Dtfmwe4bgX4k7aEUpaYr90nCU67a%2BxX0NtDB6z7n5lkCQ7bQTNzSA%3D&b=Jux7I3tv%2Ff6HXXFrGOozZA%3D%3D

Decrypting:
1. We decode the request param from Base64 into the raw format. (The container takes care of the url encoding conversion.. so this is not a factor in TC Server)
2. Decode the intial vector value from Base64 into the raw format.
3. Configure the cipher using the secret and the initial vector that was passed in the url
4. Decrypt the encrypted data
5. Serialize the decrypted bytes back into the expected object

All this work.. due to a few limitations. Bleh.. But, it was a fun little traversal in cryptography in Java.

Below is a code sample setup to run in Spring MVC:

Wednesday, September 4, 2013

Dojo App - loading a template from a url.



One of the features that I would love to see added to the dojo app project is the ability to support restful templates. Currently, it only loads templates from inside a static directory versus fetching a template from a restful endpoint.

So, If you want to be able to add this functionality, below is an example of how to do it. It currently works with the 1.9 dojo version, and is an extension of the current functionality, so all current features will continue to work.

The idea is that if a template is prefixed with the dollar sign - such as:  template: "$/foo/view",  then it will use
dojo/request to do a get on that end point for the returned content and load it into the view. Otherwise, it will  process it normally.

A normal config.json file would look something like:

  "views": {
        "header": {
            "constraint": "top",
            "controller": "foo/controllers/header",
            "template": "foo/views/header.html",  
            "dependencies": [
                "dijit/layout/BorderContainer",
                "dijit/layout/ContentPane",
                "dojox/app/widgets/Container",
                "ontrac/widgets/Navigation"
            ]
        },
        "dashboard": {
            "constraint": "middle",
            "controller": "foo/controllers/dashboard",
            "template": "$/foo/view/dashboard",        
            "dependencies": [
                "dijit/layout/BorderContainer",
                "dijit/layout/ContentPane",
                "dojox/app/widgets/Container"
            ]
        }

Below is the Gist of the code - Hope it helps, as it wasn't difficult to add the functionality. I don't make guarantees on cross domain requests.. I've not tested that, so if you need that functionality, you'll need to handle the issues/security that is involved in that.

Make sure you include the following dependencies in the AMD loader when overloading:

"dojox/app/View", "dojo/Deferred", "dojo/when", "dojo/_base/lang", "dojo/request"


Thursday, July 18, 2013

JQuery UI - Date Range Selection

I spent the last few days playing around with changes to make the DatePicker in JQuery work a little more like a range selection tool.

I initially expected this to be a simple extension to JQuery UI's widget structure, but datepicker seems to be a variant and relies upon an instanced configuration. So, it took a bit more work than I originally anticipated.

There was a couple of posts on this, but nothing with a gist or fiddle project to actually learn from - so I've added a fiddle for anyone who would like to see it in action. Hopefully, it will assist anyone what wants a Hotel or Airport style date range selection tool using an existing datepicker configuration.

It's modified from it's base form a bit.. so you'll have to overlook the hacks in there (These were added to support some external requirements to the original design).


Hope it helps in building your little slice of heaven.

http://jsfiddle.net/dacrazycoder/4Fppd/

Monday, November 12, 2012

The best math teacher pickup line!

So.. This is what I do at work!

I'm currently dating a very cute math teacher - so being the fun guy, I found an interesting post showing that the function of e to the power of times y spells the word sexy and sent it over to her.

I was so impressed by my smooth moves, I decided to show it to some of the guys on my whiteboard and then noticed that.. while impressive.. it was lacking a bit! Thus, I've updated it to be the best pickup line for a math/intellectual lady.

 In order to pull this off.. start with U and I - u/i.. where i is the derivative of u. Then you can move in to throw down the sexy.. saying that u being sexy and i being the derivative of sexy, then I would always be able to lie tangent to your curves!

It's the perfect combination of two classic geek pickup lines.. combined with a bit of my own touch to become epic.. If she gets it, she sounds like a winner - if it flies over her head, well.. atleast she's cute!

Have fun in the world of dating!

Friday, September 28, 2012

Tweenable Slider

It's been a while.. but I figured I'd take the time to share one of my fiddle projects to build a simple, clean slider that translates based upon it's container. Here's the fiddle project - the code is pretty much self explanatory. http://jsfiddle.net/dacrazycoder/ZMXVu/25/

Friday, December 2, 2011

SmartFox Server + Unity3d + Hibernate + JPA

This is intended as a post for anyone who's familiar with Hibernate & JPA, as its not very obvious as to where everything goes, you can find all the info, but its spread across numerous posts that don't seem to include all of the relevant information.

So.. here's the quick and dirty of how to set this up to get it to work in SmartFox 2x.

1. Track down the following jars and place them in your SFS2X/lib directory.

antlr-2.7.6.jar
dom4j-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar
javassist-3.12.0.GA.jar
jta-1.1.jar

2. Add your jdbc driver to the SFS2X/lib directory

3. Create a new project to hold your entities and add your entities to it.

4. Export the Entity project as a jar to the SFS2X/lib directory.


5. Create a META-INF/Persistence.xml file under the SFS2X directory

6. Ensure that you add the jar-file attribute to the persistence.xml. It is referenced from theSFS2X root.. not the META-INF directory, so you simply need to reference the lib/foo.jar file in the persistence.xml in order for Hibernate to scan your classes.

<jar-file>lib/gameEntities.jar</jar-file>

7. Add your game project jar to the SFS2X/extensions/{project} directory.

8. Add an appender for hibernate to the log4j properties file at SFS2X/config/

log4j.category.org.hibernate=INFO,consoleAppender

It's really that simple... Hopefully, this will save a few others some time when working with this configuration.

If you notice a magic number exception.. you are probably running RC3, which seems to have a classfile conflict. Use RC1b and that should solve the problem..