Skip to content

Instantly share code, notes, and snippets.

View jlittlejohn's full-sized avatar

Josh Littlejohn jlittlejohn

View GitHub Profile
@jlittlejohn
jlittlejohn / gist:7373325
Created November 8, 2013 16:07
SCSS: Truncate (Mixin)
@mixin truncate($width){
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: $width;
}
@jlittlejohn
jlittlejohn / gist:6693874
Created September 25, 2013 01:25
WP: Setting & Getting Cookies
// http://php.net/manual/en/function.setcookie.php
// functions.php
function set_newuser_cookie() {
if (!isset($_COOKIE['sitename_newvisitor'])) {
setcookie('sitename_newvisitor', 1, time()+1209600, '/', 'example.com', false);
}
}
add_action( 'init', 'set_newuser_cookie');
@jlittlejohn
jlittlejohn / gist:6311663
Created August 22, 2013 19:26
JS: Pie Chart Using Canvas Element
<!-- Add to HTML -->
<canvas id="myChart" width="400" height="400"></canvas>
<script>
// JSON Data Object
var data = [
{label: 'Example Item 1', value: 3.0, color: '#21280b'},
{label: 'Example Item 2', value: 0.18, color: '#374213'},
{label: 'Example Item 3', value: 1.96, color: '#4d5d1b'},
{label: 'Example Item 4', value: 0.01, color: '#627722'}
@jlittlejohn
jlittlejohn / gist:6224829
Last active May 1, 2019 16:03
RoR: Icon Link with Class & Data-Attribute
= link_to icon('icon-name'), '#', :class => 'class-name', :data => {'name' => 'value'}
@jlittlejohn
jlittlejohn / gist:6174665
Last active May 1, 2019 16:03
RoR: Add Modal to a View
= link_to image_tag("imageName.png", :alt => 'Image Name', :class => 'class-name'), '#myModal', :data => {:toggle => 'modal'}
#myModal.modal.fade
.modal-dialog
.modal-content
.modal-header
%button.close{:data => {:dismiss => 'modal'}, :aria => {:hidden => 'true'}}
&times;
%h4.modal-title
Title
@jlittlejohn
jlittlejohn / gist:6001772
Created July 15, 2013 17:28
SCSS: Background Size (Mixin)
@mixin background-size($background-size) {
-webkit-background-size: $background-size;
-moz-background-size: $background-size;
-o-background-size: $background-size;
background-size: $background-size;
}
@jlittlejohn
jlittlejohn / new_gist_file
Created July 12, 2013 05:25
JS: Load Script Asynchronously
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//third-party.com/resource.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
@jlittlejohn
jlittlejohn / gist:5766796
Last active May 1, 2019 16:04
HTML: Basic Page
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
@jlittlejohn
jlittlejohn / gist:5753911
Last active May 1, 2019 16:04
RegEx: Password (UpperCase, LowerCase, Number/SpecialChar & min 8 Chars)
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
@jlittlejohn
jlittlejohn / gist:5753908
Created June 11, 2013 01:24
RegEx: Password (UpperCase, LowerCase & Number)
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$