Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"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
phette23 / integerBetween.js
Created February 3, 2012 00:10
Generate a random integer between any two values
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
phette23 / jquery-plugin-tpl-2.js
Created February 21, 2012 23:54
The Mike Alsup jQuery Plugin Development Pattern
//
//taken verbatim from jQuery Fundamentals
//which is at http://jqfundamentals.com/ (see chap. 8)
//and has an unmaintained github repo at https://github.com/rmurphey/jqfundamentals
//
// create closure
//
(function($) {
//
// plugin definition
@phette23
phette23 / cookies.js
Created March 22, 2012 16:18
JavaScript Functions for dealing with Cookies
//taken verbatim from the ever-vigilant Quirks Mode
//www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
@phette23
phette23 / modal-dialog.css
Created March 26, 2012 23:19
Modal Dialog Box
/* 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
phette23 / trim.js
Created April 8, 2012 18:04
Crockford's String.trim() function
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(
/^\s*(\S*(?:\s+\S+)*)\s*$/,
"$1");
};
}
@phette23
phette23 / sword.html
Created April 21, 2012 20:24
How to Make a Sword in HTML & CSS (no images)
<style>
#dagger {
/* important to have a serif font for the dagger
sans-serif will look like a cross
see: http://en.wikipedia.org/wiki/File:Daggers.svg */
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);
@phette23
phette23 / is_on_campus.php
Created June 20, 2012 15:17
PHP function to check if IP falls within a range
<?php
function is_on_campus($IP = false) {
// If no IP is passed grab it from $_SERVER[]
$IP = $IP ? $IP : $_SERVER['REMOTE_ADDR'];
// Convert IP to long integer
$IPnum = ip2long($IP);
@phette23
phette23 / clearfix.css
Created July 16, 2012 19:03
Clearfix CSS Class
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
@phette23
phette23 / share-this-social-media-block.html
Created July 26, 2012 01:11
Social media icons w/ links to sharing services
<!-- not entirely necessary, rewriting this in raw JS would be trivial -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#shareThis a {
display: inline-block;
text-decoration: none;
width: 16px; height: 16px;
/* you can grab & reuse this sprite if you like or use your own */
background: url(http://dl.dropbox.com/u/50206550/sharing-sprite.png) 0 -16px no-repeat;
}
@phette23
phette23 / assert.js
Created September 7, 2012 21:52
JavaScript Assertion
// debugging technique
// via: http://www.learncomputer.com/javascript-tricks-you-may-not-know/
function AssertException( msg ) {
this.msg = msg;
}
AssertException.prototype.toString = function() {
return 'AssertException: ' + this.msg;
}