Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
41 total  XML / RSS feed 

HTML stripper

// description of your code here

str = <<HTML_TEXT


Application error

Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")


Download code snippets ( from the command line and convert them to text files using man textutil (on Mac OS X 10.4).

snippet 345
snippet 1268
snippet 1281

# $ cat $HOME/.bash_login

function snippet() {
   mkdir -p $HOME/Desktop/Snippets
   cd $HOME/Desktop/Snippets
   curl -L -O -s --max-time 25"$1" || exit 1
   file="$HOME/Desktop/Snippets/$(basename $_)"
   textutil -convert txt "$file"
   rm "$file"
   sed -i "" -e '1,5d' -e 's/.See related posts.//' "$new_file"  # delete first 5 lines of file
   sed -i "" -e :a -e '1,6!{P;N;D;};N;ba' "$new_file"            # delete last 6 lines of file
   cd "$OPWD"
   return 0

JavaScript Roll Overs

// JavaScript roll overs

<script type="text/javascript">


// html code
<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image1','','2.png',1)"><img src="1.png" name="Image1" width="155" height="71" border="0" id="Image1" />a>

MailMan listserve signup template

Simple template for adding a MailMan mailing list subscribe form to a page. Found on a mailing list somewhere a long time ago and cleaned up dramatically.

Note: I almost always just include the email and digest options, but I've included the whole spiel for completeness.

<h2>Join the XYZ listh2>


Your E-mail address: "text" name="email" size="30" value="">
Your Name (optional): "text" name="fullname" size="30" value="">

You may enter a privacy password below. This provides only mild security, but should
prevent others from messing with your subscription. Do not use a valuable password as it
will occasionally be emailed back to you in cleartext.

If you choose not to enter a password, one will be automatically generated for you, and it will
be sent to you once you've confirmed your subscription. You can always request a mail-back
of your password when you edit your personal options.

Password choice: "password" name="pw" size="15">
Confirm Password: "password" name="pw-conf" size="15">

Would you like to receive list mail batched in a daily digest? (You may choose NoMail after you join.)
"radio" name="digest" value="0" checked> No "radio" name="digest" value="1"> Yes

"submit" name="email-button" value="Subscribe">

HTML link regex

// use url group and ignore case (because of something like HREF)
// based on

Standard CSS helpers

Some really common layout classes I use in almost every CSS file.

/********* helpers *********/
.floatRight { float: right; }
.floatLeft  { float: left; }
.right  { text-align: right; }
.left   { text-align: left; }
.center { text-align: center; }
.clear, .clearer { clear: both; }
.block  { display: block; }

PHP State-Array Generator

Simple array for HTML mockups.

function state_selection() {
        echo '';

US States Pop-up

Simply a pop-up form element of all 50 US States. Save you creating your own.

            <select name="state">
              <option value="" selected="selected">Select a state...option>
              <option value="AK">Alaskaoption>
              <option value="AR">Arkansasoption>
              <option value="CO">Coloradooption>
              <option value="DC">District of Columbiaoption>
              <option value="FL">Floridaoption>
              <option value="HI">Hawaiioption>
              <option value="IL">Illinoisoption>
              <option value="IA">Iowaoption>
              <option value="KY">Kentuckyoption>
              <option value="ME">Maineoption>
              <option value="MA">Massachusettsoption>
              <option value="MN">Minnesotaoption>
              <option value="MO">Missourioption>
              <option value="NE">Nebraskaoption>
              <option value="NH">New Hampshireoption>
              <option value="NM">New Mexicooption>
              <option value="NC">North Carolinaoption>
              <option value="OH">Ohiooption>
              <option value="OR">Oregonoption>
              <option value="RI">Rhode Islandoption>
              <option value="SD">South Dakotaoption>
              <option value="TX">Texasoption>
              <option value="VT">Vermontoption>
              <option value="WA">Washingtonoption>
              <option value="WI">Wisconsinoption>

Load javascript function from returned ajax HTML

Problem - calling a function in Tank! : Ruthsarian Layouts "en">

Ruthsarian Layouts




Tank! is CSS-based web page layout. The goal for this layout was to incorporate several tricks/features that help further demonstrate the versatility of CSS. These include drop-down menus, theme switching, changing font size, source ordering, transparent images, multiple columns, and hopefully some nice style.

A Work In Progress

I'm releasing this layout a little early. It's still a work in progress. IE 5.0 (for Mac OS 9 and earlier) has some severe bugs that cause the text to not appear correctly; however IE 5.2 works just fine. Netscape 7.0 has a problem with the drop-down menus where they are displayed in the flow of the document, forcing the rest of the page's content down while the drop-menu is displayed. There is no Netscape 4 specific stylesheet at the moment. NS4 users will simply see a plain page. Oh, and if you figure out my not-completely-documented dropdown system and try to apply it to the vertical menu, you may run into some problems, so I wouldn't try it right now.

Feel free to send an e-mail to ruthsarian at gmail dot com if you find other bugs that you'd like to report.

No Zip (Yet)

I'm not yet providing an archive of the layout with all the necessary CSS and JavaScript and all the paths worked out, etc.. in a single ZIP ready to go. This is because I don't consider this layout to be ready enough. If you want to take this layout for a test drive, you'll have to figure out how to pull out the CSS, HTML and JavaScript needed. This isn't hard at all, but if you don't know how then you probably aren't ready to use a layout that may still be a bit... touchy.

Short on documentation

I'll try to add more documentation to this page as I have time. Right now I'm focusing in on the more important pieces of information about this layout, rather than worry about a full write-up on all the intricacies.


Gargoyles - Season 2, Vol. 1

"">Gargoyles - Season 2, Volume 1 was released on December 6, 2005. The DVD contains the first half (26 half-hour episodes) of the second seasion of "">Gargoyles. Special features include commentary on the 4-part "City of Stone", a featurette on the making of with new interviews of several cast members, and introductions of each episode by creator "">Greg Weisman.

Support / Donations

Every so often I hear from someone who offers to make a donation or asks about ways to support my work. My position, as outlined in the content of the "">Skidoo Too: Gargoyles layout, remains the same: I don't want money. I'm not trying to make money, I just want to share with others my own bits of work with CSS. I think the knowledge I gain from my own work is its own reward (regardless of how corny that sounds).

However, if you would like to support a cause near and dear to me, I would ask that you pick up a copy of "">Gargoyles - Season 2, Volume 1. Gargoyles is a great show, well written, and entertaining to both kids and adults. I would like to see the show continued in some manner, but to do that we need to first get "">Disney's attention. That can be done through increasing salse of the latest "">Gargoyles DVD. If it sells well enough to make a blip on the radar of Disney's executives, if they think they can make money with it, Disney might just start producing new content (episodes) of the show. That would be something I would really like to see.

So I ask that you pick up a copy of the DVD if you get the chance. I think you'll enjoy it if you take the time to watch the show. This is not just a kids' show and adults will absolutely enjoy it as much as (if not more than) children. But, if you've got no interest, the least you can do is give it to a family member or friend who might be interested, or have children. It makes a great holidy gift!


Everything To The Right

Key design issue is that the typical vertical menu you see in many web pages is included here. What isn't typical is that this menu is moved to the right side of this layout. The horizontal menu at the top of the page is also right-aligned.

Why is this?

This goes back to an old lesson in a Photoshop 3 book I read a long time ago. It recommended you move the toolbar over to the right side of your window. The reason being that it keeps the scroll bars closer to your toolbar, creating less distance for the mouse to travel and, thus, less movement for your hand. It helps relieve a small amount of work (and stress) on the hand. It's also easier to navigate, in general, for right-handed people, which make up the majority of the people in the world. And it's something new and different so I wanted to give it a try.

That large margin/gutter/gap on the left of the layout is there to help reenforce the eyes to the right side of the page. The empty space also is a nice spot to catch when reading left to right and moving down a line. I also think it's visually interesting, but you can go ahead and delete it if you don't like it. It doesn't serve any critical function except to free up an otherwise busy layout.

Utility Stylesheets

Several stylesheets used in this layout are part of my "">utility stylesheets collection. The point of these stylesheets is that they provide specific functionality that I use in several layouts. Rather than keeping several different copies of (basically) the same stylesheet, I've put them into one place. That way if a bug pops up in the drop-down menu stylesheet, I can fix one stylesheet and all my layouts that use it will be immediately updated.


The goal is to rely on CSS as much as possible and to keep the layout functional even without JavaScript enabled. Despite this constant goal with all "/etribou/layouts/">Ruthsarian layouts, there is a fair amount of "/etribou/layouts/javascript/ruthsarian_utilities.js">JavaScript used in this layout. A lot of it is there to provide a helping hand to some browsers that either don't support full CSS or have a broken implementation of some CSS features.

For example, IE does not support the :hoverpseudoclass on
elements other than anchor tags. As a result, the drop-down menus don't work. JavaScript
is used to apply an extra CSS class to list items while the mouse is over the element
to emulate the

pseudoclass. Position and appearence of the drop-down
menus is handled by CSS. If/When IE supports the
pseudoclass, this
bit of JavaScript can be removed and the drop-down will function completely without
JavaScript. Drop-down menus will work fine with FireFox
and several other new generation browsers without that JavaScript.

Other implementations of JavaScript in the layout bring functionality most likely already
available through a browser menu option into the page itself. One example of this is
the style switcher. Several browsers already support the switching or application of alternate
stylesheets (if defined) to a web page. The style switcher provides a different interface to
this feature. The same with the font size changing system. Almost all browsers offer a feature
to increase the base font size of the browser. This font size system just brings that interface
into the web page.

The point is this: you can remove all JavaScript from this layout and it will still
function. The only thing you lose is some ease-of-use accessories for the user and/or
minor compatibility issues that, by themselves, will not break the layout.

Quick Bits

Cookies are used to store the prefered font size and style so it remains through each
page visit.

If the page has short content the footer will
fill in the space between the bottom of the layout and the bottom of the
browser window.

Style switcher and font size setter HTML are created via JavaScript
This way users who do not have JavaScript enabled will not see the interface for this JavaScript
dependant features.

The name Tank! comes from the song by the same name recorded by the Seatbelts. It is the
theme song to the anime series Cowboy Bebop. I was listening to that song when I decided
to finally name this layout. If you haven't, I highly recommend picking up Cowboy Bebop,
both the DVDs and the soundtracks (of which there are many).


Theme Styles


    > >ruthsarian_utilities.js >


    > > > >CSS Filters >
  • Piefecta Demo Layout > >Douglas Livingstone's 3-Column Layout > >456 Berea Street > >Explore Color >

Menu Example

  • >Layouts
      > >Tank! > >Gargoyles > >Skidoo Too >
    • >Skidoo
        > >Fixed Width > >Fluid Fixed Width > >Detached Masthead > >Border Into Masthead > >Background Images > >Gutterless > > >
      • >Experiments
          > >Plaine > >Nausicaä > >Bob > > > > > >Labs >
        • >Blog
            > >Web of Information > >Cold Fusion > >Informational > > > > >

findout browser

// the navigator object stores the browser ...

<script type="text/javascript">
document.write("Your browser is " + navigator.appName);

Mask address bar so always set to

// You can use frames to mask your address bar so it always shows when viewing your pages. Use the frameset below in your default page (index.htm). In this example, the frameset will load home.htm and start your site from there. But the address bar will stay showing

<frameset rows="*">
<frame src="home.htm">

Disable autocomplete on input fields

// Disable autocomplete on any input field with the "autocomplete" parameter in your input tag

<input name="first_name" type="text" autocomplete="off">

Disable right click

// added to diable the right click.. works on *most* browsers

<body oncontextmenu="return false">
« Newer Snippets
Older Snippets »
41 total  XML / RSS feed