Skip to content

Instantly share code, notes, and snippets.

View mattbontrager's full-sized avatar

Matt Rose mattbontrager

View GitHub Profile
@mattbontrager
mattbontrager / Numeric Suffixes
Created September 26, 2012 21:30
Returning a numeric suffix based on the number passed.
/** If your number is 534, and you want it to return 534th,
* Use it like so:
* Suffix.init(534);
**/
Suffix: {
init: function(theNum) {
var self = this,
toCheck,
theSuffix;
@mattbontrager
mattbontrager / Calculate Duration
Created September 28, 2012 00:52
Transposing an estimated time span into milliseconds (and optionally humanizing the duration using moment.js).
/**
* @param etaTime Integer
* @param etaScope String
* @param True/False/Boolean
**/
function calculateDuration(etaTime, etaScope, humanize) {
if (typeof etaTime !== 'number') {
etaTime = parseInt(etaTime, 10);
}
@mattbontrager
mattbontrager / $.preload();
Created October 4, 2012 07:01
Preloading an array of images with jQuery
$.fn.preload = function() {
this.each(function() {
$('<img/>')[0].src = this;
});
};
@mattbontrager
mattbontrager / Spinner - User Feedback
Created October 4, 2012 23:52
Provide user feedback during asynchronous ajax requests.
$('#spinner').ajaxStart(function() {
$(this).fadeIn();
}).ajaxStop(function() {
$(this).fadeOut();
});
@mattbontrager
mattbontrager / mixins.scss
Last active October 11, 2015 21:18
My standard mixins for responsive mobile design.
@import "compass/reset";
@import "compass";
@import "compass/css3";
@mixin breakpoint($point: '') {
@if $point == iPab {
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
@content;
}
@mattbontrager
mattbontrager / process_contact.php
Created November 14, 2012 20:27
A simple script to process emails sent via contact forms
<?php
$name = (isset($_REQUEST['name']) && !empty($_REQUEST['name'])) ? $_REQUEST['name']: null;
$temp_email = (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) ? $_REQUEST['email']: null;
/* server side email address validation */
$email = (filter_var($temp_email, FILTER_VALIDATE_EMAIL)) ? $temp_email: null;
$subject = (isset($_REQUEST['subject']) && !empty($_REQUEST['subject'])) ? $_REQUEST['subject']: null;
@mattbontrager
mattbontrager / connectivity.js
Created November 20, 2012 09:16
immediately throw an error on app initialization (if connectivity is required) to prevent further errors (other unloaded CDN libraries, etc.)
var App = {
init: function(online) {
var self = this;
if (!online) {
alert('not connected');
}
}
};
$(function() {
@mattbontrager
mattbontrager / webApp-geolocation-iOS6.js
Created January 19, 2013 02:58
Working navigator.gelocation for WebApp (navigator.standalone) in iOS 6.
if (window.navigator.geolocation) {
var accuracyThreshold = 100,
timeout = 10 * 1000,
watchID = navigator.geolocation.watchPosition(function(position) {
$('#latitude').val(position.coords.latitude); // set your latitude value here
$('#longitude').val(position.coords.longitude); // set your longitude value here
// if the returned distance accuracy is less than your pre-defined accuracy threshold,
// then clear the timeout below and also clear the watchPosition to prevent it from running continuously
// $mq-mobile-portrait : 320px !default;
// $mq-mobile-landscape : 480px !default;
// $mq-tablet-portrait : 640px !default; -- changed because i want my blog content is around this wide, not 768. you should let content & design determine your breakpoints
// $mq-tablet-landscape : 1024px !default;
// $mq-desktop : 1382px !default;
$mq-mobile-portrait : 20em !default;
$mq-mobile-landscape : 30em !default;
$mq-tablet-portrait : 40em !default;
$mq-tablet-landscape : 64em !default;
@mattbontrager
mattbontrager / Email Data Pattern
Created February 15, 2013 00:39
HTML5 Email Reg Ex Pattern.
data-pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])"