Skip to content

Instantly share code, notes, and snippets.

@liamcurry
Created May 4, 2012 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamcurry/2596218 to your computer and use it in GitHub Desktop.
Save liamcurry/2596218 to your computer and use it in GitHub Desktop.
HTMl/CSS/JS quickies
/* String to Number */
var hello = '1234'
parseInt(hello) // Use this when speed is a concern (see http://jsperf.com/parseint-vs-unary)
// 1234
+hello // unary operator -- use this when file size is a concern
// 1234
+hello++ // Converts `hello` to a number and adds 1 to it
// 1
/* Number to String */
var hello = 1234;
hello.toString() // Try not to use this...
// "1234"
hello + '' // Use this instead (http://jsperf.com/tostring-vs-concat-coercion)
// "1234"
[hidden] {
display: none;
}
iframe[seamless] {
border: 0 none transparent;
display: block;
}
.hide-text-classic {
overflow: hidden;
text-indent: -9999px;
}
/* http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/ */
.hide-text-zeldman {
overflow: hidden;
text-indent: 100%;
white-space: nowrap;
}
/* http://nicolasgallagher.com/another-css-image-replacement-technique/ */
.hide-text-gallagher {
color: transparent;
font: 0/0 a;
text-shadow: none;
}
(function () {}()) // Crockford way
(function () {})() // Alternative
!function () {}() // Saves one byte
<!-- http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#syntax-tag-omission -->
<!-- Tags that don't need closing tags: html, head, body, li, dt, dd, p, rt,
rp, optgroup, option, colgroup, thead, tbody, tfoot, tr, th, td -->
<!-- These are all perfectly valid HTML: -->
<ul>
<li>Foo
<li>Bar
</ul>
<dl>
<dt>Hello
<dd>World
</dl>
<p>Hello
<p>World
<table>
<thead>
<tr>
<th>Hello
<th>World
<tbody>
<tr>
<td>Hello
<td>World
</table>
<!doctype html>
<meta charset=utf-8>
<title>Best page ever</title>
<link rel=stylesheet href=css/master.css>
<div id=content>
Awww yeahhhhhhh
</div>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script>
<script src=js/main.js></script>
var hello
hello === void 0 // Faster than testing type
// true
hello === a // 'a' is just the name of any variable that doesn't exist
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment