Skip to content

Instantly share code, notes, and snippets.

View justinallen's full-sized avatar
🔍
Looking for it

Justin Allen justinallen

🔍
Looking for it
View GitHub Profile
@justinallen
justinallen / detectIE.js
Created June 22, 2017 22:47
IE Detection in JavaScript
// just a slimmed-down implementation of browser testing for IE in JavaScript
// based on code I found online
/**
* detect IE
* returns version of IE or false, if browser is not Internet Explorer
*/
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
/**
* Nicely format large numbers to make them readable:
* Billions to one decimal like "$1.3 billion"
* Millions to nearest million like "$346 million"
* Thousands to nearest thousand like "$144,000"
* @param {number} The number to format
* @returns {string} Readable string with dollar sign and amount
*/
function niceBigNumber(num) {
// format billions to one decimal like "$1.3 billion"
@justinallen
justinallen / wget-example.txt
Created September 17, 2016 22:53
wget download website
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--domains example.us \
--no-parent \
example.us
@justinallen
justinallen / social.html
Last active January 21, 2016 01:52
simple social buttons for an mvc template
<div class="share-bar">
<h5>Share on:</h5>
<a href="https://twitter.com/intent/tweet?text={{title}}&url={{absoluteUrl}}&via={{twitterUser}}&related={{twitterUser}}" rel="nofollow" target="_blank" title="Share on Twitter">
<img src="/images/social-icons/twitter.png" alt="twitter icon">
</a>
<a href="https://facebook.com/sharer.php?u={{absoluteUrl}}" rel="nofollow" target="_blank" title="Share on Facebook">
<img src="/images/social-icons/facebook.png" alt="facebook icon">
</a>
<a href="https://plus.google.com/share?url={{absoluteUrl}}" rel="nofollow" target="_blank" title="Share on Google+">
<img src="/images/social-icons/googleplus.png" alt="google plus icon">
@justinallen
justinallen / grab-a-hash.js
Created December 3, 2015 22:19
grab a hash
var hash = window.location.hash;
if (hash == "#hashish" || pathArray[0] == "#hashish") {
// do stuff
}
@justinallen
justinallen / validate-email.js
Created October 7, 2015 18:57
quick basic email validation in javascript
// returns false unless valid
function validateEmail(email)
{
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
@justinallen
justinallen / labels-to-placeholders.js
Created September 30, 2015 18:38
fancies up a form
// takes a parent el (like a li) and goes to work on its children
// assumes the parent has one label and one input
function labelsToPlaceholders(parent) {
$(parent).each( function(index){
$(this).children('label').css('display', 'none');
labelText = $(this).children('label').text();
labelText = labelText.slice(0,-1);
// console.log(labelText);
$(this).children('input').attr('placeholder', labelText);
@justinallen
justinallen / back-to-top.js
Last active September 30, 2015 18:33
back to top button
$("#back_to_top").click(function(e){
e.preventDefault();
$('html, body').animate({scrollTop:0}, 'slow');
});
@justinallen
justinallen / jekyll-reading-time.js
Created April 18, 2015 15:55
Jekyll Reading Time Estimator - JavaScript
// reading time
$('#reading-time').html(function(){
var wordcount = $('#wordcount').text();
timetoread = Math.round(wordcount / 200);
readmessage = timetoread + " min read";
return readmessage;
});
@justinallen
justinallen / jekyll-reading-time-template.html
Last active August 29, 2015 14:19
Jekyll Reading Time Estimator - Template Snippet
<!-- drop this into your post.html or other page template -->
<div id="reading-time"></div>
<span id="wordcount" style="display:none">{{ content | number_of_words }}</span>