Skip to content

Instantly share code, notes, and snippets.

View ourmaninamsterdam's full-sized avatar

Justin Perry ourmaninamsterdam

View GitHub Profile
@ourmaninamsterdam
ourmaninamsterdam / gist:6079009
Created July 25, 2013 12:01
jQuery waypoints
Setup waypoints for each block
$('.js-block').each(function(){
addWaypoint( $(this), 'down' );
addWaypoint( $(this), 'up' );
});
function addWaypoint( $elem, direction ){
var thisID = that.formatID( $elem.attr('id') ),
nextID = $elem.next('.js-block').attr('id') || null;
@ourmaninamsterdam
ourmaninamsterdam / gist:6074905
Created July 24, 2013 21:50
RegEx - Gets any Link that contains the word Yahoo. Needs some work
(^<[a-z]+.[a-z\"=\s:/.\<]+[>])+(?=[^\<])(?=Yahoo).+?$
@ourmaninamsterdam
ourmaninamsterdam / gist:6074841
Created July 24, 2013 21:43
In progress. Gets innerText from any tag
(^<[a-z]+.)[a-z\"=\s:/.\<]+[>]+([^\<]+)
<a href="http://www.google.com">Google</a>
<a class="myclass" href="http://www.bbc.co.uk">BBC</a>
<a id="myid" href="http://www.yahoo.com" class="myclass">Yahoo</a>
<div><a href="http://www.google.com">Google</a></div>
@ourmaninamsterdam
ourmaninamsterdam / gist:6074735
Created July 24, 2013 21:27
RegEx for filtering href attr
(^<[^a-z]+|)+(href=\".+?")
Returns href attr from...
<a href="http://www.google.com">Google</a>
<a class="myclass" href="http://www.bbc.co.uk">BBC</a>
<a id="myid" href="http://www.yahoo.com" class="myclass">Yahoo</a>
<div><a href="http://www.google.com">Google</a></div>
@ourmaninamsterdam
ourmaninamsterdam / gist:6074635
Created July 24, 2013 21:17
RegEx to get the value from an MS CSS filter
^filter:.[a-z]+=\([^)]+\);
@ourmaninamsterdam
ourmaninamsterdam / gist:5964521
Created July 10, 2013 08:39
Converts a HEX to RGB and vice versa. Takes a 6 character HEX or a single R/G/B value.
/**
* convert_color()
* Converts a HEX to RGB and vice versa
* @param {String or Integer} color Takes a full 6 character HEX "ff5500" / RGB colour value 167 (< 255)
* @return {str} returns a HEX or RGB (space delimited), depending on input
*
*/
function convert_color(color) {
var tmp = "";
@ourmaninamsterdam
ourmaninamsterdam / gist:5823736
Created June 20, 2013 15:26
Gets the href from anchor tag regardless of positon of href attr. Sort of. Needs some work to exclude last part of string
<a[^>]*? (href=\")(.*)(")
@ourmaninamsterdam
ourmaninamsterdam / gist:5388493
Last active December 16, 2015 05:59
Lookup table-like mixin for retrieving data from a linked list. Ideal for including predefined font stacks and media queries, by name. Great way to avoid lengthy conditional statements when you require multiple outcomes from a mixin.
@function get-item-by-name( $name, $names-list, $items ){
@return #{ nth( $items, index( $names-list, $name ) ) };
}
$font-stack-ids: proxima-light, proxima-regular, proxima-semibold
$font-stacks: "'Proxima Nova Light', Tahoma, Arial, Helvetica, sans-serif",
"'Proxima Nova Regular', Tahoma, Arial, Helvetica, sans-serif",
"'Proxima Nova Semibold', Tahoma, Arial, Helvetica, sans-serif";
@function font-stack( $name ){
@ourmaninamsterdam
ourmaninamsterdam / gist:5370671
Last active December 16, 2015 03:29
Filters an array based on filter. Accepts regex or simple string. Returns a filtered array.
var filter = '.png';
var list = ['userimage105325.png','userimage669.jpg','userimage6929.png','userimage85818.gif'];
function filterArray(array, filter){
var i, filteredArray = [];
filter = new RegExp(filter, 'g');
for( i = 0, len = array.length; i < len; i++ ){
if( array[i].toString().match(filter) ){
filteredArray.push( array[i] );
}
@ourmaninamsterdam
ourmaninamsterdam / gist:5370657
Last active December 16, 2015 03:29
Debug list. Accepts primitive values and arrays.
function log(){
var debug = document.getElementById('debug'),
reverse = true,
log = Array.prototype.slice.call( arguments, 0 ).join('{join}').replace(/{join}/g, '<br>');
debug.innerHTML = (reverse)? log + '<br>' + debug.innerHTML : debug.innerHTML + '<br>' + log;
}
log(myObject.name, myObject.thing, 'With a label: ' + myObject.label);