Adding Swap Space to your Server

I seem to keep coming across this problem with web servers where I set something up on AWS and it runs poorly.  This is usually because I forgot to set the swap space.  Swap space is a system that the operating system uses so that it doesn’t have to keep everything in memory. It will write the least used information to disk. We all know (I hope) that disk is a factor of 1000x slower (unless you use SSDs, which it is just a factor of about 10x slower), so it’s important to keep track of how much memory your system is using. However, it’s still better than running out, which means that your applications aren’t slow… they are broken. There are a couple of other websites that document this, with some varying similarities to what I do.  So, I figured I’d share it (and thus not forget it again).

Note that you can either run this as root or add “sudo” to the front of each of these commands…

First, display the swap information for the current device.  If this is a standard AWS server, nothing will be printed.  If you or someone else has already added some swap space, it will be printed here.

Next, convert and copy a file, in this case I will use the null file, to the location where I want my swap file to be.  In this example, I will use “/swapfile”. Also, for this file should copy in block sizes of 1MB and end up copying 1024 blocks. This would be a total of (1024 blocks * 1024MB =) 1GB. Feel free to modify these numbers to match the swap size that you want.

Next, create a swap file at the location that you want (again, I’m using “/swapfile” for this example)

Next, turn on the swapping for this location

Lastly, you need to edit the file systems table (fstab) configuration file, which is usually stored at the location /etc/fstab

In the fstab file, add the following line (again, assuming that the location is “/swapfile”) to the last line and save

At this point, there should be no need to restart your system, as Linux knows to adjust using this file.

The New Hotness – Spring 4’s Spring Boot

The guys who make the Spring framework libraries are no slouches.  They know the ups and downs of their own framework, as well as Java as a whole.  They are also on top of all of the newer JVM technologies, such as Groovy, Scala, Gradle, Spock, etc.  Heck, if they weren’t making money hand over fist, I’d think they would be great core language developers.  The would progress the language to a point that I’d love using it again.

The reason I say all of this is because the developers of the Spring framework realized that there are a couple other frameworks out there (Ruby on Rails, Grails, Django, etc.) that favor convention over configuration.  Meaning, I don’t want to have to set up 50 XML files to configure a project just so that I can get it running as a simple web service.  It shouldn’t be that complicated.  Spring 4 has some answers for you.  Spring introduced Spring Boot, a group of annotations that will favor convention over configuration… at least until you need to change it to something more complicated. The way it acts, I think they may have backported some of the stuff they did for Grails right into Java. Continue reading

Want to use Spotify, but Apple trying to force you to use iTunes?

OK, it’s not a secret that I’m not the biggest fan of the iTunes program. A flat layout for my hundreds of Gigabytes of mp3s… seems like a poor layout. Plus, I spend more time listening to music at work than at home, where my music collection is. Fortunately, I have access to a bunch of music through Spotify, which has a pretty large collection to draw from. I’m not going to argue with folks about the upsides and downsides to Spotify. I do understand that plenty of musicians get screwed and plenty of musicians make a mint. I also understand that the one making most of the profit is Spotify. But, being a consumer of music (at this point in my life) more than a producer, I definitely enjoy the freedom of being able to explore new music without dropping huge amounts of cash, or like many of the less fortunate, downloading illegally. So, bitch all you want, this is what the people want, so we’ll all figure out how to make money off of it. Oh, and please support local talent as much as you can.

That being said, I did research to disable the opening of iTunes and found a wonderful little script created by Farhan Ahmad (aka “thebitguru”) which disabled it. Even though this was nice, I wasn’t quite satisfied. I wanted Spotify to come up when I hit “Play”, because when I hit “Play,” I probably want to listen to music. So, I forked his code and modified the python script to change the default program that is opened whenever you hit the “Play” button on your keyboard. It’s not too complicated, and truthfully, you can adjust it to open any other program you want. You would rather use VLC? Just edit the string in the python script (very little editing using the Applescript language) and off you go! So, if you want to change the default behavior of apple, go over and follow the instructions on my github project, or if you just want to disable it, go on over to Farhan’s github project

Bash and Zsh Shortcuts

I’m not going to beat you up with the benefits of using zsh over that of bash. You really should know both, since bash is everywhere. Zsh is the newer version that is a powerhouse, though. So if you should decide to use this, I suggest checking out the program oh-my-zsh, which gets all of the common shell configurations set up for you and keeps it up to date.

But, what I really wanted to share was a good reference for bash/zsh shortcuts.  There are others out there, but they seem to be incomplete.  If I’ve missed anything, let me know and I’ll add it.

Command What it Does
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + F or → Forward one character.
Ctrl + B or ← Backward one character.
Meta + F (in OSX this is ESC, F or ALT+ →) Move cursor forward one word on the current line
Meta + B (in OSX this is ESC, B or ALT+ ←) Move cursor backward one word on the current line
Ctrl + P or ↑ Previous command entered in history
Ctrl + N or ↓ Next command entered in history
Ctrl + L Clears the screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Lets you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Kill the line after the cursor
Ctrl + Y Yank from the kill ring
Ctrl + _ Undo the last bash action (e.g. a yank or kill)
Ctrl + T Swap the last two characters before the cursor
Meta + T (in OSX this is ESC, T) Swap the last two words before the cursor

 

Update 7/22/2013 – My buddy David Souther liked this one so much he created a little worksheet from it and added some sed commands.  It’s great for a reference.  Check it out here!

Understanding Software Workflows

As Computer Engineering progress, it is foraging a new path in the world.  Companies that used engineers in the past, such as the automotive and aviation industries, have been focused on figuring out why the world is changing so quickly around them.  Computer engineers are forcing this change due to the fact that they are doing things faster and requiring much more transparency than ever before for products to be successful.

The eclipse development teams have been paying attention to this as well.  Mike Kerston covers how Eclipse is taking this problem head on at EclipseConn.  The video below also covers some of the common threads in the open and closed source communities at present.  Definitely a good watch.  Even if you don’t want to watch the whole thing, everyone should be adopting these tools (or an acceptable alternative) into any new project going forward, and if possible, retrofitting older projects to use this as well. Continue reading

Making the Maven Version and Subversion Version Match

Let me start this out – this is strongly discouraged. Not only by me, but by Maven and any standards that you will ever come across. Your release version should almost never be your SCM version. Some tools allow you to pull in the SCM version as a variable and use it as a maven variable. This is great, because you can inject it into places to tie your release version to your project. Note the difference. I even wrote a great article about injecting variables into WAR files here and you can use the buildnumber plugin to inject your build numbers!

But, some groups (we’ll just nickname them “Oogle” for now) are being annoying and don’t want to do full blown releases, as that might mean that they have to support old releases. I totally understand that principle, so I’m not going to knock it. But, if you don’t have a release, how does one differentiate between versions?

Well, at this mythical company Oogle, they have stated you should use their subversion revision as the way to refer to their releases. Well, we can do that, but God help us if you switch to Git or some other form of DVCS. One thing about release numbers is that they should be sequential, so that you know which version precedes another, and human readable. In many of the new DVCS flavors, they use the SHA-1 hash, which is some long string of numbers and letters that is not sequential, nor human readable. But, for now, we can work with Subversion. Continue reading

jQuery and ImpressJs

So my buddy did a JQuery rehash for people in our company.  In my opinion, it doesn’t need to be sold.  People like JQuery cause it is easy and the learning curve to do some things is easy.  It follows the old Perl mantra: “Try to make simple things easy, and complex things possible”.  Few folks can argue with that.

More interesting, in my opinion, than the subject material, was his choice of presentation tools.  He chose to use the Impress JS library. It functions like prezi, but with WAY more configuration options (pretty much anything you can think of doing to the DOM).

He posted his presentation on his website here and put the code up on GitHub here.