Skip to content

Instantly share code, notes, and snippets.

🥑
Made in California

Justin Allen justinallen

View GitHub Profile
View typographic-widow-control.js
// great little typographic widow control script from chris coyier
// https://css-tricks.com/preventing-widows-in-post-titles
$("h2 a").each(function() {
var wordArray = $(this).text().split(" ");
if (wordArray.length > 1) {
wordArray[wordArray.length-2] += " " + wordArray[wordArray.length-1];
wordArray.pop();
$(this).html(wordArray.join(" "));
}
@justinallen
justinallen / shortcode.php
Created Sep 13, 2018
simple boilerplate wordpress shortcode
View shortcode.php
/**
* Boilerplate WordPress shortcode - can drop into functions.php
* Use: [bananify this="thing to add a banana to"]
*/
function bananify_func( $atts ) {
$a = shortcode_atts( array(
'this' => 'something'
), $atts );
@justinallen
justinallen / wordpress-image-classes-on-captioned-images.js
Created Sep 12, 2018
WordPress / jQuery snippet for moving custom image classes up to the caption on captioned images
View wordpress-image-classes-on-captioned-images.js
/**
* Hoist custom image classes up to the caption that wraps it
*/
$('figure.wp-caption').each(function() {
var caption = $(this);
caption.removeAttr('width').css('width', ''); // remove width attribute
var img = $(this).find('img');
var imgClasses = img.attr('class').split(/\s+/); // list of classes
imgClasses.forEach(function(element) {
img.removeClass(element); // remove from image
@justinallen
justinallen / unix-human-dates.py
Created Apr 17, 2018
Unix dates to human readable and back again, in Python
View unix-human-dates.py
# cribbed / adapted from here http://partiallyattended.com/2011/10/13/managing-unix-time-in-python
from time import strftime
from datetime import datetime
from datetime import date
from time import mktime
# convert unix to human-readable
def unix_to_human(unix_date):
human_date = datetime.fromtimestamp(int(unix_date/1000.0)).strftime('%Y-%m-%d %H:%M:%S')
return human_date
@justinallen
justinallen / pretty-json.sh
Created Nov 21, 2017
pretty format a json file
View pretty-json.sh
python -m json.tool my_json.json > my_pretty_json.json
@justinallen
justinallen / notification.py
Created Nov 3, 2017
stupid simple email notification in python
View notification.py
# all thanks to nael shiab's post here: http://naelshiab.com/tutorial-send-email-python
# adding gist for my own reference / ease remembering
import smtplib
from_email = "########@gmail.com"
from_email_password = "somethingsecure"
to_email = "#######@some_email.com"
server = smtplib.SMTP('smtp.gmail.com', 587)
@justinallen
justinallen / x.svg
Created Sep 16, 2017
Simple SVG Shape: X
View x.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View fb-metatags.html
<!-- Facebook meta tags -->
<meta property="og:title" content="My Webpage"/>
<meta property="og:description" content="In 2017, a webpage was created by me."/>
<meta property="og:image" content="http://website.com/image.jpeg"/>
<meta property="og:url" content="http://website.com/my-webpage.html"/>
<meta property="og:site_name" content="Webpage"/>
@justinallen
justinallen / detectIE.js
Created Jun 22, 2017
IE Detection in JavaScript
View detectIE.js
// 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) {
View bigNumberFormat.js
/**
* 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"
You can’t perform that action at this time.