Preparing a Site for SOPA Blackout with .htaccess

BorkWeb, like a number of other sites, will be going black this Wednesday as a protest to SOPA.  Legends of the Sun Pig has an excellent article on this exact topic.  Martin writes:

Google recommends using HTTP 503 “Service Unavailable” status codes. The 503 code indicates that the service (or page, or site) is temporarily unavailable, but that it is expected back again soon. This is better than using the 404 (not found), 302 ( moved temporarily), or 301 (moved permanently) codes, because it tells web crawlers that they should just come back and try again later.

Because I have no desire to manually make the cut-over to a SOPA Blackout .htaccess file at midnight (because I’m lazy), I took his .htaccess settings and made a modification to enable the settings for the tomorrow.  Here’s what I have:

<IfModule mod_rewrite.c>

# =====================
# SOPA Blackout
# =====================

# Set a custom error document for 503 errors
ErrorDocument 503 /503_sopa.html

# Cause all requests (except images) to generate a 503 error,
# which will produce the custom 503 error document
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteCond %{REQUEST_URI} !robots\.txt$ [NC]
RewriteCond %{TIME_YEAR} ^2012
RewriteCond %{TIME_MON} ^01
RewriteCond %{TIME_DAY} ^18
RewriteRule ^ - [L,R=503]

# =====================
# NOT SOPA Blackout
# =====================

# My other rewrite magic goes here.
</IfModule>

Additionally, I’ve shamelessly stolen the php.net SOPA 503 page because it is awesome.

Vim Undo Magic

Ever have a time when you are happily editing a script in vim and you realize you made a mistake over the course of editing? Luckily, Vim supports back in time undos.

You want to go back 10 minutes?

:earlier 10m

You want to go forward in time by 5 seconds?

:later 5s

Sweet cuppin’ cakes that’s ballsy. Armed with this tool, you step forward and backwards in your undo/redo adventure, you make an accidental edit. Whoops. Now all the code you’ve edited in the 10 minutes that you rolled back with the handy-dandy <code>:earlier</code> command is gone…right?

Nope! Undo branching is where the real awesomeness of Vim shines. If you realize your mistake, you can find a list of undo branches like so:

:undolist

Which will show you something like this:

number changes when saved

3 3 08:59:35
4 2 09:00:13

To jump to one of those branches, you can type:

:undo 3 or :undo 4

I <3 Vim

(via Life Hacker)

Sites Not Reachable After Linode Restart

I have recently moved the majority of my sites over to my CentOS Linode VPS and I was experience some load issues that prevented me from gaining SSH access.  As such, I decided to restart my VPS.  After the restart, I found that my sites were not reachable…lame.

First, I checked the firewall found here:

/usr/bin/system-config-securitylevel-tui

So…the firewall was fine.  Next, I attempted to restart the network via:

/etc/init.d/network restart

I was surprised to receive the following error:

Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring. [FAILED]

Alrighty…bizarre.  So with the help of this article, I was able to determine that eth0′s MAC address:

/sbin/ifconfig eth0

was different than the MAC address found in:

/etc/sysconfig/network-scripts/ifcfg-eth0

A simple edit to the above file and a quick network restart solved my problem and brought my sites back up! w00t!

Platypus Mascot: A Plymouth State April Fool’s Day

Yesterday (April Fool’s Day) I had a little fun and launched a prank on the entire Campus Community of Plymouth State University. The prank? PSU’s portal received a makeover in order to announce a change of the campus’ Mascot from Panther to noble Platypus due to trademark issues.  Results?  Awesome.

Before our users logged in, they were met with a happy Platypus:

A groovy platypus login

A groovy platypus login

Once logged in, the users’ eyes were attacked by custom header complete with Platypus and sun flare that read: “Announcing the new Plymouth State mascot!”

Announcing the new Plymouth State Mascot!

Announcing the new Plymouth State Mascot!

Oh, but it didn’t stop there. You can’t just change a campus’ mascot without some explanation, so forced into the top right of everyone’s layout was a nice portal channel to detail the mascot change.  It read as follows:

Plymouth State has been proud to display the Panther as the University Mascot for many years but effective June 1st, 2009 the Panther will be retired.

Why the new Mascot?

Due to recent trademark disputes, PSU has been asked to select a new symbol for the University. While the change may come as a shock to some, change is a great thing! The adoption of the new mascot is a refreshing and invigorating change that we hope will inspire the campus as the Panther does.

The selection process for the new mascot was a lengthy one where we reviewed over 75 animals that were submitted by the campus community in the recent poll sent out to all students! The top contenders were: Newt, Badger, Elk, Moose, Platypus and Narwhal.

After much discussion, we are excited to announce that the Noble Platypus will be the new mascot!

Why the Platypus?
platypusThere are many attributes of the Platypus that resonate well with Plymouth State ideals. The following were the deciding factors:

  1. Mammal: As we planned the transition from the Panther to the new mascot, the desire that the new animal remain mammalian in nature rang clear with the selection committee. The Platypus fits the bill! (Yes, that was a pun)
  2. Versatile: The Platypus is an extremely versatile mammal which represents Plymouth State’s versatility in it’s educational, athletic, and extra-curricular programs.
  3. Egg Laying Semi-Aquatic Monotreme: The fact that the Platypus is the only semi-aquatic monotreme that lays eggs truly makes it unique. Uniqueness is an attribute in our students that we prize greatly and believe each and every one of you stand out from the crowd.
  4. Venomous: Venom in ankle spurs. This is just an extra bonus.

A change like this cannot be complete without gauging user opinions, so a poll was put together that received almost 1200 votes in 24 hours!

myPlymouth April Fools Day Poll

myPlymouth April Fool's Day Poll

Various end offices received a number of calls from end users ranging from excitement that PSU played an April Fool’s Day prank to frustration that we were switching away from the Panther (those people obviously didn’t know it was the 1st). All in all, I would consider this a successful holiday!

Now…what should I do next year?

Guest Lecture: JavaScript, Ajax & DOM Manipulation

Zach has asked me to give a JavaScript guest lecture in his Web Programming class. We’ll cover: JS basics, node manipulation, DOM traversal, AJAX, JavaScript libraries, and myPlymouth implementations of those topics. Here are the slides (get the .ppt here):

A few resources that are mentioned:

Note: this is an updated talk on the workshop I led two years ago

CSS Selector Browser Support

As many web developers know, CSS support is highly varied amongst browsers. I often find myself hunting for which selectors are more heavily supported. As such, I thought I’d post a direct link to a quality resource here so I wouldn’t have to hunt anywhere besides on BorkWeb.

Here’s some decent resources:

Oracle 10g: Using The Returning Clause With ADOdb

Plymouth State University uses Oracle heavily due to its Student Information System of choice – SungardHE Banner. As such, I play around in Oracle a lot (sometimes a lot more than I’d like) and I occasionally find functionality that seems more cumbersome than it should.

One such item is selecting the last inserted value on an auto-incrementing column.

Historically, when you are inserting into a table with auto incrementing values (via a sequence) you have always been able to grab the last value with a simple SELECT statement (line 22):

-- setup a table
CREATE TABLE bork (id INTEGER NOT NULL PRIMARY KEY, data VARCHAR2(10) NOT NULL);

-- create the sequence
CREATE SEQUENCE sq_bork INCREMENT BY 1 START WITH 1; 

-- create a trigger for auto-incrementing the sequence'
CREATE OR REPLACE TRIGGER tr_sq_bork
BEFORE INSERT
ON bork
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT sq_bork.NEXTVAL INTO :NEW.id FROM DUAL;
END;
/

-- insert a record into the table
INSERT INTO bork (name) VALUES ('Matt');

-- retrieve last inserted id
SELECT sq_bork.CURRVAL FROM dual;

As you see there, two statements must be executed to get that new id. The INSERT and the SELECT. Well, as of Oracle 10g you can utilize the RETURNING clause like so:

INSERT INTO bork (name) VALUES ('Matt') RETURNING id INTO i_id;

That statement inserts a record into “bork” and returns the value of “id” into the “i_id” variable. Pretty sexy and all with one DML statement. Here’s what we do at Plymouth to utilize the RETURNING clause with the PHP library ADOdb:

< ?php
//do your database object initialization here:
//$db = new ADONewConnection...

$sql = "BEGIN INSERT INTO bork (data) VALUES ('Matt') RETURNING id INTO :i_id; END;";
$stmt = $db->PrepareSP($sql);
$db->OutParameter($stmt, $inserted_id, 'i_id');
$db->Execute($stmt);
?>

Yup. 4 lines of PHP but only 1 statement sent to the database! I’d take the extra lines any day over the latency of data retrieval.

Delete/Backspace Stops Working in Oracle SQLDeveloper

I a huge fan of Oracle SQL Developer but I ran into an issue a while back that left me scratching my head and re-installing. The issue? Most key strokes other than letters and numbers failed to function. Yeah…no delete or backspace.

When this issue happened a second time I did a little playing with the app and figured out what to do. If you find yourself in a similar predicament simply do this:

  1. Open SQL Developer
  2. Click on the Tools > Preferences menu
  3. Click on Accelerators on the left
  4. Click the Load Preset… button

Yup. That’s it. The only lame part about that is all your custom key bindings go away and must be re-done. But that is much nicer than re-installing!

Google Chrome on the Mac – a la CodeWeavers

Google launched its new browser Chrome on September 2nd and the web was abuzz with talk of a new contender in the browser space. My choice to pepper my house and cube at work with Macs rather than Windows boxes left me complaining about the lack of a native Mac version of Chrome…which Google assures us is coming.

Code Weavers, however, has just released Crossover Chromium built from build 21 of the Chromium Open Source browser.

Chromium

The initialization of Chromium the first time I opened it took a while but once it was up and running, things were pretty solid. The browser has all the JavaScript and DOM debugging tools but it seems the process manager tool isn’t fully functional..which is really my draw to the browser (when I get dead set on playing with the Process Manager tool, I’ll break down and install Chrome with Parallels). I suppose I’ll be following CodeWeaver’s suggestion:

Q. Should I run CrossOver Chromium as my main browser?

A. Absolutely not! This is just a proof of concept, for fun, and to showcase what Wine can do. Chromium itself is just beginning. As the Chromium project progresses, they will be providing more compelling support for Mac OS and Linux, particularly with process security and memory management. Those future versions from Chromium will be better suited for daily use than this version.

Until Google launches its official Mac native Chrome, Chromium will satisfy me for now.

iPhone App: pTerm

pTerm At long last a Terminal application is available on the iPhone, and pTerm is its name! Based on the desktop client PuTTY, you can SSH, Telnet, and raw TCP from your iPhone/iPod Touch!

Its features are:

  • xterm terminal emulation
  • Standard 80×24 screen
  • SSH, Telnet, or “raw” TCP connections
  • Ctrl key support
  • Landscape and Portrait modes
  • Works over Edge, 3G, or WiFi
  • Stores your list of host/port/protocol for convenient access
  • Terminal supports pinch and zoom
  • Based on PuTTY, a stable and feature-rich code base

All in all, the app seems pretty solid. My only gripe is the lack of a tab key for tab completion. Now I’ll be able to debug stuff remotely WITHOUT using VNCLite for the iPhone. Check pTerm out, it is well worth the $4.99.

Update:
There are some more things that I find annoying:

  • No tab key – no tab completion…
  • No arrow keys – this makes navigating around a line a little bit of a pain.
  • You can’t hide the keyboard. It’d be nice to see a full screen of top.
  • No color customization

Despite the annoyances, the app is still pretty solid. Lets just hope new versions come out sooner than later with some of my hopes and dreams attached.

IMG_0004.PNGIMG_0004.PNG

Compiling Invalid Objects in PL/SQL

While I do a lot of and prefer PHP and JavaScript development, my daily job has a darker side…PL/SQL. At times the packages that I oversee invalidate during upgrades or poor compilations of a package that ends up having a ripple effect.

Here’s a query I wrote to find the invalid objects and generate compile statements to attempt to fix whatever is busted.

SELECT CASE object_type
       WHEN 'PACKAGE' THEN
        'ALTER '||object_type||' '||owner||'.'||object_name||' COMPILE;'
       ELSE
        'ALTER PACKAGE '||owner||'.'||object_name||' COMPILE BODY;'
       END
  FROM dba_objects
 WHERE status = 'INVALID'
   AND object_type in ('PACKAGE','PACKAGE BODY','FUNCTION','PROCEDURE');

Luminis: Forcing CSS/JavaScript Updates to Clients

[[innerindex]]

Introduction

I gave a talk at SunGard Summit in Anaheim this spring on Plymouth State‘s portal (myPlymouth). There were a number of really great questions that came up following my presentation, one of which is the topic of this post:

“How do you force a client’s browser to always use the correct version of CSS and/or JavaScript in Luminis?”

When upgrading Plymouth State’s Luminis installation from III to IV, we had to tackle this same issue and after banging my head against the wall a number of times, I found our answer. I wanted to:

  1. Ensure that the JavaScript and CSS that is being served up to our users can be cached by their browser in order to optimize their download speeds.
  2. Control when a user’s browser has to re-download a new version of the code.
  3. Do the above within the bounds of the very restrictive caching provided by the Luminis product.

All of it was super easy to do, although I must admit I knocked my head against the wall a few times coming up with the solution to the 3rd in that list.

Step 1: Basic Browser Caching

When I sat down to tackle this problem, I knew that the inline JavaScript within nested_tables.xsl was an unforgiving issue – if I wanted to make a change to some of the inline JavaScript, those changes would not be forced upon the users until Luminis decided to let go of its cached nested_tables.xsl.

That didn’t work for me. So I ripped the inline styles out and combined a few JavaScript files into one…called combined.js.

My header within the regularLayout template in nested_tables.xslnow looked something like this:

<head .......>
   <title>.........</title>
   <script type="text/javascript" src="/js/clientsniffer.js"></script>
   <script type="text/javascript" src="/js/util.js"></script>
   <script type="text/javascript" src="/psu/js/combined.js"></script>
   <script type="text/javascript" src="/psu/js/behavior.js"></script>
   <link rel="stylesheet" type="text/css" href="/psu/style.css"/>
</head>

The files clientsniffer.js and util.js are SunGard delivered and I did not touch those two. As I mentioned before, I yanked out all the inline JavaScript (provided by SunGard) and dropped that into combined.js along with a number of jQuery code. Our own custom Luminis JavaScript that controls a lot of our Ajax-like functionality in myPlymouth is in behavior.js. And of course, style.css holds the CSS for our portal.

All of these files could now be cached by users’ browsers. Yay. I bounced the development portal and saw my changes in all their glory. Life was good.

Step 2: Browser Cache, Code Changes, and You

Invigorated by my recent success of effectively doing nothing, I grabbed a soda and began tackling the next objective. I had done this numerous times in my PHP applications and it was as simple as placing a version number at the end of the URLs used in the link and script tags. As such:

<head .......>
   <title>.........</title>
   <script type="text/javascript" src="/js/clientsniffer.js"></script>
   <script type="text/javascript" src="/js/util.js"></script>
   <script type="text/javascript" src="/psu/js/combined.js?v=1.0.0"></script>
   <script type="text/javascript" src="/psu/js/behavior.js?v=1.0.5"></script>
   <link rel="stylesheet" type="text/css" href="/psu/style.css?v=1.0.5"/>
</head>

Once again, I bounced our portal, saw the changes, and danced around the room. Step 2. Accomplished.

Step 3: Taming Versioning/Cache Expiration in Luminis

The goal of taming this versioning/cache expiration was to do so without the need for bouncing the portal so I could make changes on the fly without planning for down times. Step 2 – as I detailed above – only gets you so far. With Step 2 in place, I could easily make a change in my CSS file and edit nested_tables.xsl to one-up my version number. But, because nested_tables is cached by Luminis, that wasn’t good enough. Here’s what I came up with:

I removed the script and link tags in the header of the regularLayout template in nested_tables, created a file called load.js, and dropped the homeless script/link tags as document.writes in load.js…as so:

Start of a Solution: load.js

document.write('<script type="text/javascript" src="/js/clientsniffer.js"></script>');
document.write('<script type="text/javascript" src="/js/util.js"></script>');
document.write('<script type="text/javascript" src="/psu/js/combined.js?v=1.0.0"></script>');
document.write('<script type="text/javascript" src="/psu/js/behavior.js?v=1.0.5"></script>');
document.write('<link rel="stylesheet" type="text/css" href="/psu/style.css?v=1.0.5"/>');

But wait…

This gave me a file with all of my script/link tags and their appropriate versions. However…I couldn’t simply replace all those script/link tags with a script tag that pointed at load.js because load.js itself would be cached by users’ browsers. So this got past the Luminis caching, but not our end users. So I came up with this:

Final Solution: pre_load.js

So…I wanted to cache all my sub-files and prevent load.js from caching so that I could version my scripts easily without bouncing the portal. The solution? Yet another file! I called it pre_load.js and it looks something like this:

document.write('<script type="text/javascript" src="/psu/js/load.js?nocache=' + (new Date()).getTime() + '"></script>');

A simple document.write of a script tag with an appended variable based on time in order to prevent caching on the browser side. Yup…load.js is never cached, but it is a small price to pay.

Now my header in the regularLayout template in nested_tables.xsl looks like this:

<head .......>
   <title>.........</title>
   <script type="text/javascript" src="/psu/js/pre_load.js"></script>
</head>

How it works

  1. Luminis happily caches the pre_load.js script tag in the nested_tables.xsl.
  2. The JavaScript within pre_load.js writes another script tag to the document at render time. That script’s URL is a call to load.js along with a variable that changes each page load thus preventing load.js from being cached.
  3. load.js then document.writes the appropriately versioned script/link tags into the document.
  4. The individual script/link tags load the associated JavaScript/CSS files. If the browser has already cached that script/link URL (remember, we change the version numbers when we make changes to the JS or CSS), then the cached file is loaded…otherwise the new version is retrieved from the server.

Summary

The set-up is fairly basic but the results just what we were hoping! And all it took was:

  1. Placing inline JavaScript into a file (combined.js)
  2. Creating load.js to document.write script/link tags
  3. Creating pre_load.js to document.write a script tag that uses a cache-free URL call to load.js

To date, we have not had any reported issues with local or server-side caching of our JS/CSS files using this method! You just need to make sure you remember to version your URLs in load.js!

myPlymouth: Thanksgiving Theme

Thursday before Thanksgiving, users of the myPlymouth portal at Plymouth State were greeted by an altered header graphic similar to that of the Halloween theme I had done for the previous month.

This one, however, changed daily for 9 days. Here’s the sequence:

Thursday:
Thanksgiving in myPlymouth

Friday:
Thanksgiving in myPlymouth

Saturday:
Thanksgiving in myPlymouth

Sunday:
Thanksgiving in myPlymouth

Monday:
Thanksgiving in myPlymouth

Tuesday:
Thanksgiving in myPlymouth

Wednesday:
Day 7

Thursday (The flames flickered ever so slightly):
Thanksgiving Day

Friday – Monday:
Day 9

Now, once I finished that final graphic Dan approached me and made a funny request. He wanted a special little violent ending for himself. The thought of a custom final header for a few sketchy people sounded fun…so I obliged with this header that showed for a mere 5 people on campus:

Day 9 Alternate

In addition to the internal alteration of the header, I did another alteration on the login page for the Tuesday and Wednesday before as well as the Thursday of Thanksgiving. My pal, the turkey, showed up in place of the random image. Here he is:

Thanksgiving in myPlymouth

Overall, the header was well received be the campus feuling my desire to come up with something nifty for the coming holidays! A special thanks to Ken, Zach, and Dan for giving good content suggestions and allowing me to bounce ideas off them!

Plymouth State: JavaScript Workshop

Tonight I led a workshop on JavaScript for some PSU Employees. We discussed JS basics, node manipulation, DOM traversal, AJAX, JavaScript libraries, and myPlymouth implementations of those topics. Here are the slides:

A few resources that were mentioned: