Skip to content

Instantly share code, notes, and snippets.

"you're right, no human being would stack books like this"

Eric Phetteplace phette23

"you're right, no human being would stack books like this"
View GitHub Profile
phette23 / bookmarkletTemplate.js
Created Jan 28, 2012
JavaScript Bookmarklet Template
View bookmarkletTemplate.js
//self-executing anonymous function
(function (window, document, undefined) {
var d=document; w=window; //aliases to save bytes
//do something
}(window, document));
//remove comments, put in a bookmark preceded by "javascript:"
phette23 / jquery-plugin-tpl.js
Created Jan 30, 2012
jQuery Plugin Template
View jquery-plugin-tpl.js
$.fn.myPluginMethod = function() {
// keep it chainable, jQuery objects
// include multiple DOM elements
return this.each(function(){
// do something
phette23 / integerBetween.js
Created Feb 3, 2012
Generate a random integer between any two values
View integerBetween.js
var integerBetween = function(x, y) {
if ( typeof x !== "number" || typeof y !== "number") {
console.log('integerBetween cannot accept NaN values');
return false;
else {
var lowerBound = Math.floor(x);
var upperBound = Math.floor(y);
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
phette23 / redirect.html
Created Feb 3, 2012
Screen-size based redirect
View redirect.html
<!-- redirect based on screen width -->
<script type="text/javascript">
console.log('Screen width: '+screen.width);
if (screen.width <= 699 && !sessionStorage.getItem("redirecting")) {
window.location.replace("./m/index.html"); //path to your mobile site
<!-- redirect bypass on the mobile site
such that users don't get caught in a redirect loop
uses jQuery cuz mobile site is jQuery Mobile
phette23 / lfm-recent-tracks.html
Created Feb 19, 2012 Recent Tracks API
View lfm-recent-tracks.html
<h3> Scrobbles</h3>
<!-- div below will be filled in with formatted contents of API response -->
<div id="recent-tracks" style="display:none;"><a href=""></a> data hasn't loaded yet.</div>
<!-- leave as display:none for the fade in effect -->
phette23 / jquery-plugin-tpl-2.js
Created Feb 21, 2012
The Mike Alsup jQuery Plugin Development Pattern
View jquery-plugin-tpl-2.js
//taken verbatim from jQuery Fundamentals
//which is at (see chap. 8)
//and has an unmaintained github repo at
// create closure
(function($) {
// plugin definition
phette23 / cookies.js
Created Mar 22, 2012
JavaScript Functions for dealing with Cookies
View cookies.js
//taken verbatim from the ever-vigilant Quirks Mode
function createCookie(name,value,days) {
if (days) {
var date = new Date();
var expires = "; expires="+date.toGMTString();
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
View modal-dialog.css
/* puts a gray overlay over the entire page
just turn on display when dialog pops up */
.modal-overlay {
display: none;
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
background-color: rgba(0,0,0,0.35);
phette23 / trim.js
Created Apr 8, 2012
Crockford's String.trim() function
View trim.js
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(
phette23 / sword.html
Created Apr 21, 2012
How to Make a Sword in HTML & CSS (no images)
View sword.html
#dagger {
/* important to have a serif font for the dagger
sans-serif will look like a cross
see: */
font-family: "Old English Text MT", "Times New Roman", Times;
-moz-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
-o-transform: rotate(180deg);
-ms-transform: rotate(180deg);