Code Nest
Software issues and opinons by Darin Tanaka
June 26th, 2014 Comments: 0

I just figured out how to insert email into a Google Apps domain using Google's email migration API. It took me an entire day to figure out how to insert mail that included attachments. Now granted I have no experience with RFC messages or MIME so that's probably why. However I couldn't find any examples online on how to do this. This is the main reason why it took me forever to figure out. The problem with Google's documentation is that the examples they show you are for the simplest of cases possible. Anyway in order to upload mail with the migration API with attachments you need to use MIME multipart messages. This is an extension of a standard RFC822 message. You can read about MIME here. Basically email attachments are nothing more than the file being base64 encoded into the raw message itself. Also with the Google Migration API you can specify certain metadata like whether the message should be in the inbox, starred, or deleted and sent straight to Google Vault. Anyway here is an example of a POST to Google migration api that contains an email with an attachment. It's basically the same as the example from Google's Migration API. The only difference is that instead of the Content-Type being 'text/html' it must be 'multipart/mixed' to include the attachment data.

POST https://www.googleapis.com/upload/email/v2/users/liz@example.com/mail?uploadType=multipart

Content-Type: multipart/related; boundary=\\"part_boundary\\"

--part_boundary
 Content-Type: application/json; charset=UTF-8

{
 'isInbox': 'true'
}

--part_boundary
Content-Type: message/rfc822

Date: Wed, 03 Jan 2013 02:56:03 -0800
 From: admin@example.org
To: liz@example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=frontier

--frontier
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit

And I think to myself... What a wonderful world!

--frontier
Content-Type: text/plain; name="test.txt"
 Content-Disposition: attachment; filename="test.txt"
Content-Transfer-Encoding: 8bit

Hello A!

--frontier--

--part_boundary--

 

March 13th, 2014 Comments: 0

Hello World

This is the text that we all saw when we were just starting to learn how to program. The excitement when we got our first BASIC/FORTRAN/PASCAL application to do something we wanted to do! I will never forget that feeling of accomplishment when first fiddling with world of programming. But now after 4 years of college and almost 4 years of working it feels like such a distant memory I can't even remember if those feelings are real anymore. The fantasies of adventure and discovery were all I cared about when I decided to make this my career. However the stark reality is that in the real world programming is about none of these things for the most part. Money and fame are the key. I was foolish into thinking people did things for the love of it. I still love coding and solving programming problems, but now I see another world.

This brings me to a new notion I call the 'New Age Programmer'. The odd part is that even though I'm still very young I don't consider myself a new age programmer. In fact there are older people that I could consider new age. When I was in high school programming was non existent. I think I was the only person in the entire school who cared. I would go to the library after school and dig up BASIC and C programming books and read about them. I felt alone in my interest and hobby. Contrast that to today, where programming is now considered 'hip'. You often hear the term 'Brogrammer' now, which refers to young programmers who like to party and workout. This ain't no joke, I see these type of programmers all the time. With things like Facebook, Snapchat, Instagram, etc there's also this lure that one day you'll be a millionare if you make an awsome app. Again it circles back to money and fame. This is the reason new age programmers exist. Don't get confused with new age programmers with brogrammers. Brogrammers can still love coding. New age programmers don't. They could careless about using a Prefix tree to solve autocomplete for an instant messaging service. All they care about is the end product and the money.

At first these type of programmers bothered me a lot but then I realized something. Most people period only care about money and fame. It doesn't matter what profession, people in general work for these reasons. I've learned to do what I want to do in my career. What other people want to do and for what reasons is up to them.

December 17th, 2013 Comments: 0

This is my first post since moving to Los Angeles. It's been a busy couple of months to say the least. That's why I haven't posted in a while in case you were wondering. I'm currently working at a cloud computing consulting company. However I'm mostly working on java applications including a JBoss application server. My previous job back in Virginia where I worked on flight aviation software also required me to work with a JBoss application server. To be honest, even though I worked on it for over a year I never really understood JBoss really. Ok I know there is an ApplicationContext, and that there are components like JMS, JMX, etc. I understood the basic concept of an application server but I never really had to setup one up before or deal with any of the configuration of it. Usually I just modify some code, replace the war file on the server, and then kill the java process with the good old fashioned:

> ps -ef | grep java

and then kill that JBoss java process. After that just use some JBoss start up script that someone has already wrote for me. But for my current job now I actually needed to modify some actual JBoss configuration files and understand how to setup a JBoss server. All I can say that I thought I was a big fan of application servers but after going through that I now hate them with a passion. Application servers are great, if everything is already setup for you and you only add or modify current functionality.

Very easy, everything is abstracted for you since you can use Spring to do dependency injection. Oh also there's Apache Axis to abstract web service modules. Oh yeah also there's JNDI to make configuration easier. Oh yeah there's JMS to make communicating between components easy, they have an interface for that. Oh yeah there's an ORM database framework like Hibernate that way you can use DAOs instead of using that evil horrific SQL language. You just need to use the JDBC template with the EntityManager and make sure all your config files are setup correctly.

JBoss sounds nice in theory and a one size fits all package where it's basically all you need to create a web application. I'm not very old so it's going to sound strange saying this but I miss the old days where I can understand what an application is doing by reading code. But with JBoss or any application server for that matter it feels like reading code is only the beginning. The real battle is crawling your way though XML files trying to find what the heck is going on. And you can't hook up a debugger to XML files. I don't know maybe call me old school but I don't like too much abstraction. What usually happens with these application servers is that feature after feature is added like Spring, Axis, JMS, JNDI what have you, and then the application becomes bloated with ridiculous amounts of configuration files. Getting Hiberante to work with Spring JDBC templates is probably the most confusing thing in the world. Why can't I just do

SELECT * FROM MY_TABLE

Nope gotta abstract that, and make you jump through lots of hoops to get there because ABSTRACTION, have to be ABSTRACT or else we might as well go back to the caveman time and drive our car with our feet.

Even to this day, I worked on a JBoss application server for almost two years, I still don't really understand what was actually happening. I could get things do what I wanted after a while but still never understood why it was working. I hate that.

Maybe I'm just too angry right now and that JBoss, Spring, Application servers are the greatest things in the world and I'm just a bitter old man.

May 31st, 2013 Comments: 1

I notice a lot of developers use the static modifier a lot, I feel like they do this because it's easier or more convinient rather than have to change their OOP design to add their new variables. These are questions I like to ask myself before making a variable "static":

  • Is this variable ever going to change after being intialized?

                If the answer is yes I tend to stay away from using the static modifier. It's only my personal preference but I only like to use static for objects that remain constant throughout the entire program. If the static object is changing throughout the program process it makes writing new code for this variable difficult as you need to keep track everywhere it's being used. Also this is just plain bad OOP practice. Although nowadays what good OOP practice is still fuzzy to me I'm pretty sure this is bad.

  • Is this object thread-safe?

               This is a big mistake a lot of developers do when making object static. Developers try to be clever and save heap space by making things static. Remember this object now can now be accessed anywhere from the VM and if there are multiple threads bad things will happen if this object is not thread-safe. Good example is people making SimpleDateFormat static because "why would want to recreate a new object every time you need to format a date?" However many people don't realize this object is not thread-safe which creates random and weird results when using it. Even if the program your writing is single-threaded it's still good practice to not use the static modifier for non-thread-safe objects as it might create threading issues in the future if someone were to make a multi-threaded extension to your code.

Static variables have a place in the Java world, for variables that don't change like you know being STATIC!  

February 4th, 2013 Comments: 0

My blog is back! My site has been down for a while as I decided to switch hosts along with getting off of wordpress to write my own CMS. Since my site is back I'll try to update this blog more often (I know I always say that but this time I really mean it). I'll explain why I decided to make all these changes.

iPage sucks

iPage has got to be one of the worst web hosting sites out there. I should've realized this when their prices were way too good to be true. Their database servers are ridiculously slow. It would take forever for MySQL queries to complete making wordpress even slower than it already is (I'll get to that). iPage from what I've read is meant for the "simple" user but I'm pretty sure any user wants fast data access and doesn't want their page taking 20 seconds to load their blog. Another thing I hate is that it doesn't support SSH access. Again they claim it's because it's for simple users but this makes editing files on your site a pain because then your forced to use their crappy CPanel web based file editor or you have to use FTP to upload the new files. This makes quick touch editing very troublesome. I honestly can't think of one positive thing about this site in comparison to other webhosts. It's slow so "simple" users will hate it. It has no advanced features so advanced users will hate it. It's cheap I guess.

SiteLock sucks

Getting away from SiteLock is one of the reasons I switched webhosts, although I know SiteLock is available for other webhosts I just don't like how they do business. When I was on iPage I got a call from a SiteLock representative saying that my wordpress installation had been compromised. This person wanted to charge me $100 to delete a couple of files! I was shocked when this person told me this. Also he wanted to charge me $500 dollars to "harden" my wordpress installation. So I went to look up what exactly is "hardening", and there is a clear tutorial on the wordpress page http://codex.wordpress.org/Hardening_WordPress. This was probably what they were going to do. He was going to charge me $500 to do this. I was able to catch this however I feel bad for people that aren't that familiar with computers. With these kind of people SiteLock will use scare tactics to make them think that they're precious personal blog is under attack and if you don't remedy this immediately BAD things will happen. And then overcharge and make them think they are saving them from disaster when in reality they just need to delete a few files and/or reinstall wordpress.

Wordpress sucks

The biggest reason I decided to write my own CMS than use Wordpress because I found so many problems with Wordpress. First of all Wordpress is SLOW. I mean everything is slow, from the blog page all the way to the admin panel. I feel like I'm working in slow motion whenever I use Wordpress to do anything. Also making small changes to your blog in Wordpress becomes really painful. Oh but don't worry you can choose from 1000s of plugins to fit your every need possible. Pretty soon you'll have like 10 plugins where you have no idea if they're conflicting with each other or causing security issues. Oh yeah that's another thing Wordpress security sucks. You HAVE to do yearly "hardening" for your Wordpress or else hackers can get into it. This is because Wordpress plugins/themes are security risks! Oh wait they're plugins to fix that to. So after a while your going to have 20-30 plugins for your blog. Don't get me wrong wordpress is great if you just want a simple blog that doesn't need to be customized to fit an exact requirement. However if you want a serious website used for business or personal use I would stay away from Wordpress mostly for the fact that customizing becomes a big plugin/security fest.

August 22nd, 2012 Comments: 1
Execute failed: java.io.IOException: Cannot run program "xjc": CreateProcess error=2, 
The system cannot find the file specified

What is this error I got from my ant build script? A CreateProcess error code 2 means that the command specified in the ant build script does not refer to any executable file on ant's lookup path. A common mistake is that the ant's build path in Eclipse is set to a JRE rather than a JDK. In order to fix this right click the build.xml file in the package explorer, then goto 'Run As' -> 'External Tools Configuration'.

In the external tools configurations window click on the JRE tab, be sure that it's currently on a JDK

After this Ant build scripts shouldn't complain about java executables anymore

April 15th, 2012 Comments: 0

Notice in my title I say "REALLY" shutdown or restart, that's because every source I could find on how to do this never actually gave me an answer. They would basically be telling me how to shutdown/restart using remote desktop, as if I didn't know how to do this myself.

AFTER REMOTE DESKTOPING IN PRESS CTRL+ALT+END TO BRING UP SHUTDOWN MENU...... NOW GO READ ABOUT HOW TO COPY AND PASTE WITHOUT RIGHT CLICKING!!111

Anyway I needed to find a way to force a computer to restart without a GUI because my explorer.exe had froze on my remote machine and I couldn't open any windows or prompts. I couldn't even get CMD to open , all of this was using remote desktop. However I noticed the "shutdown" command for windows had a "/m" option which could be used for remote machines. So this is how I was able to force a restart on my frozen remote machine.

1. Before even attempting this you MUST know the administrative account and password on the remote machine (If you don't know it go back to Google......)

2. Establish admin rights to the remote machine, to do this simply just open a windows explorer window, and enter in your remote machine's hostname or ip address. A login prompt will open and here is where you will enter the admin username/password for the remote machine

3. Open the command prompt (cmd.exe) enter this command (this will force a restart)

shutdown /r /f /m \\myremotemachinename

To see what the options mean you can view this link here That's all there is to it, be sure you do these steps in order because trying to run the shutdown command before establishing admin rights will cause an access denied error.

Older