Batch Rename Files Recursively in Linux

April 25th, 2013

I had to recently rename a bunch of files on my web-server. They were uploaded with spaces, parenthesis, and other non-web-safe characters. I searched around and finally found the way to rename files insecurely from the command line in Linux. The below example renames all files that have space and replaced it with an underscore within the current directory.

sudo find . -type f -exec rename -v s/" "/"_"/g {} \;

Southwest’s New Cramped Interior Response

November 16th, 2012

Here is the response I got from Southwest regarding their new interior with less room. Predictably, they did not talk about the decrease in leg room, which was my only complaint. Yippy for lighter material, made from recycled content, and lower seats so small people “the average Customer” can stretch their legs. I call bull shit! How exactly does lowering the seats let someone stretch their legs?

I wish they would just admit that I’m the rare customer and they make more money by ignoring my demographic and adding a row to fit more people. I can understand that. But instead, I get some bull shit communication-marketing PR response that doesn’t answer my question.

Dear Samuel,

The focus when redesigning our aircraft interior was to increase Customer comfort while being more environmentally responsible. We’re so sorry to learn you were disappointed with your inflight experience.

Our sleek, new interior was crafted using recycled materials to maximize personal space, while enhancing the Customer experience. Among the various comfort-driven features are adapted seats (designed to foster improved posture and lumbar spine support) and fixed winged headrests for superior neck and head alignment—a gift to our cat nappers. Thinner armrests mean a little more room between seats on the same row, and the lowered seats should make it easier for the average Customer to stretch his/her legs. Another huge positive is, with each plane weighing less, we have drastically reduced fuel consumption and emissions making our aircraft hugely eco-friendly. By Evolving, we have shown our commitment to clean up environmentally.

We have received numerous positive comments from Customers and regret that, in your particular case, you didn’t find our new interior comfortable. It is our sincerest hope that you will not let these cabin changes forever deter you from choosing Southwest for your travel needs. We treasure your friendship and will always revel in the privilege of sharing greener skies with you.

Sincerely,

Courtney, Southwest Airlines

Southwest Added Row, Less Leg Room

November 15th, 2012

Southwest recently started adding another row to their airplanes and replacing their old seats. This makes what little leg room available even less. So less in fact that I, at 6 foot 3 inches, must sit with my knees pressing against the seat in front of me. Most of my friends are taller than me! Just to vent my frustration I sent an email to Southwest Airlines. I will post their response here.

Dear Southwest,

I used to enjoy flying with you. I even paid you an an extra $10 for a better chance at an exit row. But if I didn’t get the exit it, it was OK because I would still fit in the other seats. So on my long flight back from Detroit I noticed new seats. The exit row was taken, so I sat in an aisle seat. To my surprise, my knees hit the seat in front of me! I am only 6 foot 3 inches tall. And most of my friends are taller than me.

The only saving grace you guys have now is the no change fees. Which I thankfully used to cancel my next Southwest flight and go for another airline. I even bought some Southwest stock I was flying you guys so much. Sold that.

I get you need to make a profit and the average American height is a pudgy 5 foot 10, but the last airline I sat in and didn’t fit was Skybus. And no one flies them anymore.

Angry,
Sam Stevens

Liferay – Detecting Client IP Address

June 15th, 2012

Been working with Liferay portal recently and it too me a long time to finally figure out how to get the clients IP address in the portlet. VforLiferay had a good post but I was missing a few things. It must be after “<portlet:defineObjects />” and renderRequest is the request object to send to the PortalUtil. Oh and of course, don’t forget:

<%@ page import=”com.liferay.portal.util.*” %>

<portlet:defineObjects />
<%
HttpServletRequest Lrequest = PortalUtil.getHttpServletRequest(renderRequest);
String clientIp = PortalUtil.getOriginalServletRequest(Lrequest).getRemoteAddr();
out.print( clientIp);
%>

Creating and Deploying a Portlet in Liferay Tutorial

March 29th, 2012

If Liferay is not running, then go to command prompt, as administrator, navigate to:

C:\Apache\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\bin>

And run:

startup.bat

To create a portlet, use the command prompt, as administrator, go into

C:\Apache\liferay-plugins-sdk-6.1.0\portlets>

And run:

create.bat usc-test "USC Test"

This will create a directory usc-test-portlet that you can edit.

To deploy, in the same directory run:

ant deploy usc-test-portlet

It should go through the process. If it says build fails with this message:
deploy:

[copy] Copying 1 file to C:\Apache\liferay-portal-6.1.0-ce-ga1\deploy
BUILD FAILED
Target "usc-test-portlet" does not exist in the project "portlets".

But it actually does not fail, in fact it is deployed.

To add your portlet, login to the portal, and in the top bar you should see

+ Add -> More… -> Sample -> USC Test

If the portlet is already added and you are making edits, simply refresh the browser (it may take a few seconds to deploy).

Liferay Documentation:

Detect Multiple Displays in Adobe AIR

June 13th, 2011

To find the resolution of multiple monitors, you can loop through the Screen.screens array and then get the bounding rectangle of each monitor screen. Typically AIR counts from left to right (0 index the right most monitor) but I haven’t tested this on every monitor configuration.

import flash.display.Screen;

for(var i:int = 0; i < Screen.screens.length; i++)
{
    var x = Screen.screens[i].bounds.left;
    var y = 0;
    var width = Screen.screens[i].bounds.width;
    var height = Screen.screens[i].bounds.height;
}

Firebug Tutorial: Debugging CSS

February 18th, 2011

A few of my students at a work and some other friends often come to me with CSS debugging questions. I always turn to Firebug, and amazing Firefox add-on that let’s you analyze everything about a webpage from DOM, source HTML, CSS, Javascript, AJAS request, etc.  This little tutorial will demonstrate the basic techniques I use to figure out why the styling of elements isn’t quite working how it aught to.  Of course, to do this you will need Firefox and Firebug add-on.

Once you have this, navigate to the web page in question, for this example let’s look at: http://www.sapethemape.com/debugcss.html.  Here you will notice the bullet list is very spaced out and not displaying from left to right. Hmm, I remember setting #nav to display:inline, I wonder why its not working. Let’s open up the Firebug console by clicking on the little bug icon in the bottom right corner of Firefox. Now click on the Inspect button, this will be the blue mouse pointer on top of a rectangle in the top left of the Firebug window.  After this is clicked, hover over the word “Home.” Notice how there is a blue border around that element and the firebug window changes and displays information about that element.

Notice that the #nav ul li element only has padding: 30px.  If you hover over the div #nav element, this is where the display:inline was. To make a list display from left to right, the LI elements must have the style display:inline.  Thanks to the inspect tool, we were able to see what CSS styles were assign to the element in question.

With Firebug, we can also do live edits to make sure we are correct. Double click on the area just to the right of padding: 30px and a new text box should pop up. In here type “display: inline”. Notice how Firebug auto-completes for you, as well as updates the webpage with the changes. Now the page should have a horizontal navigation bar below the header. Note that the line number of the CSS declaration is displayed in the information panel. This is very helpful in finding the actual line in the code to update.

You can also click on the HTML to the left of the style information to view that elements information. Click around and you should start to get a feel for the power of Firebug. Try adding some borders to the navigation bar, adjusting the margin and padding and see how everything is effected.

USC Employee Benefits – Tuiation Assistance Guide

January 6th, 2011

I work at the University of Southern California and one of the perks is tuition assistance.  As an employee, you are eligible for 6 credits/semester of undergraduate level courses and 4 credits/semester of graduate level courses. Children or dependents get free tuition and a spouse/domestic partner gets 50% off tuition.  I have outlined the steps to take if you would like to start taking courses, but have not been accepted into a degree program. This is called Pre-Admit or Limited Status.  You can take up to 16 credits this way that will count toward your degree.  Most of the people reading this will be interested in graduate school. The curve ball here is you are taxed on any tuition assistance over $5250 per year.  This equates to roughly 3 credits at USC.  The only way to get around this is if the course is job related.

All you really need to do is fill out the appropriate forms and turn them in.  Below is a step by step breakdown of what forms you need to fill out and where to turn them in. I wish someone had laid it out like this for me, so I passing my knowledge along.

Here is what you do for limited status, pre-admit (once you are admitted all you need to do is fill out the Tax For Graduate form and the Staff-Admitted Student form and you can take whatever you want):

  1. Fill out the Pre-Admit form and get the appropriate departments heads to sign it (details in form).
  2. Fill out the Limited Status Form to register for classes.
  3. If it’s graduate work, you need to fill out the Tax For Graduate form and see if you can get it to be Job Related or not. If the class can be signed off by a supervisor as job related, you do not have to pay taxes on the tuition. Turn that for into Payroll.
  4. Take the Pre-Admit to USC Benefits (USC Credit Union Building 2nd floor)
  5. Take the Limited Status Form to the Registrar Office, and they will enroll you in the class.

Forms:
Limited Status Registration: Form_4005a_Limited_Status_Form

Pre-Admit: TAB_PreAdmission.pdf
Job Related Audit: http://www.usc.edu/dept/Benefits/forms/tuition_assistance/TAB_Audit.pdf
Tax For Graduate: http://ais-ss.usc.edu/empldoc/forms/forms.html (all the way at the bottom)

Reference:
USC Tuition Assistance Benefit: http://www.usc.edu/dept/Benefits/edu_assistance.html
USC Tuition Assistance Forms: http://www.usc.edu/dept/Benefits/forms_tuition.html

Remove Google Everything Sidebar Firefox Greasemonkey Script

May 6th, 2010

There are a few people out there who do not like the new Google everything sidebar. I personally find it to be distracting. Since there is no way to turn that feature off, I made a Greasemonkey script to do it. The script is very simple. I removes the sidebar by default, but adds a button that lets you show or hide the sidebar. This script is hard coded with the element ID’s so it will only work as long as they keep that the same. I will try to keep it up to date. This only works on Firefox but I will see about making one for Chrome. Enjoy!

Install Google Remove Everything Sidebar