Skip to content

Instantly share code, notes, and snippets.

Shane Duff drainpip

Block or report user

Report or block drainpip

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@drainpip
drainpip / getQueryParameters.js
Created Sep 26, 2017
JS get query string as object
View getQueryParameters.js
getQueryParameters : function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
@drainpip
drainpip / Social-Defs.svg
Last active Aug 29, 2015
A snippet to include the most common social networking icons as SVG defs
View Social-Defs.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View modernscale.css
body {
font-size: 100%;
}
body, caption, th, td, input, textarea, select, option, legend, fieldset, h1, h2, h3, h4, h5, h6 {
font-size-adjust: 0.5;
}
#page {
font-size: 1em;
@drainpip
drainpip / collect-fb-graph.php
Created May 13, 2013
Class that returns array of Facebook Graph information.
View collect-fb-graph.php
<?php
class facebook_graph_json
{
public function query($page_username) {
$url = file_get_contents('http://graph.facebook.com/'.$page_username);
$json = json_decode($url);
return array(
'page_name' => $json->name,
'page_id' => $json->id,
'page_url' => $json->link,
View wordpress-sharing-meta-tags.php
<?php if(is_single() || is_page()) { ?>
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="TWITTER_USERNAME">
<meta name="twitter:creator" content="TWITTER_USERNAME">
<meta name="twitter:url" content="<?php the_permalink(); ?>">
<meta name="twitter:title" content="<?php the_title(); ?>">
<meta name="twitter:description" content="<?php the_excerpt_rss(); ?>">
<?php if (has_post_thumbnail()) { ?>
<meta name="twitter:image" content="<?php the_post_thumbnail(); ?>">
<?php } ?>
@drainpip
drainpip / affix-to-top.js
Created Apr 19, 2013
Assumes jQuery. This will detect the position of your ID, check if it's got a margin on the top and remove it. If the ID reaches the top of the screen, then it will add a class fixed. Obviously you would need to make position:fixed; part of the fixed class, plus add in the actual fixed position.
View affix-to-top.js
$(function () {
var top = $('#ID').offset().top - parseFloat($('#ID').css('margin-top').replace(/auto/, 0)); // math is there in case the element has margin-top and removes it
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#menu').addClass('fixed');
} else {
@drainpip
drainpip / animate-to-object.js
Last active Dec 16, 2015
Assumes jQuery. Simply use class slide for any anchor to move to an ID, eg. <a href="#home" class="slide">Back to top</a>. Adjust duration for length of time. You could also do some math on the duration to make the speed constant based on distance. Remove "return false;" if you want to hashtag to show on the URL.
View animate-to-object.js
$(document).ready(function() {
$(".slide").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
@drainpip
drainpip / accordion.html
Last active Dec 16, 2015
Super simple accordion. Assumes jQuery. Style it for bad ass options. The script as written will close anything that's open upon clicking any .accordion-button object. Adding an extra if statement to check will stop that if you wish, but then it's technically not an accordion.
View accordion.html
<style>
.accordion-button {cursor:pointer;} /* visual cue for user */
.accordion-button.on { /* insert style for on state */ }
.accordion-content {display:none; overflow:hidden;} /* Hide on page load, overflow:hidden is to keep things from hopping around */
.accordion-content.open {display:block;} /* allows to set one open on page load
</style>
<ul>
<li class="accordion-button">Title / heading here</li>
<li class="accordion-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam in nibh eget augue tincidunt elementum nec vel tellus. Fusce vestibulum dictum leo, ac varius nisi sagittis vel. Aenean sed est id arcu adipiscing semper eu vel mi. In bibendum est sit amet urna gravida vel hendrerit sapien pharetra.</li>
@drainpip
drainpip / last-child-section-padding.js
Last active Dec 11, 2015
Updates last section bottom padding inside a sticky footer design. This allows the top of the section to fit into the top of the viewport when the page would end at the top of the footer.
View last-child-section-padding.js
function updateHeight() {
if (($(window).height()) > $("section:last-child").height()) {
$("section:last-child").css("padding-bottom", $(window).height() - ($("section:last-child").height() + $("#footer").height() + 30) + "px"); // adjust the number for extra padding depending upon your site
} else {
$("section:last-child").css("padding-bottom", "0px");
}
}
// call on DOM load
updateHeight();
@drainpip
drainpip / wordpress_songkick.php
Last active Dec 10, 2015
Raw PHP for Wordpress / Songkick integration. Further work is needed on making this into a more robust function using Wordpress' current features.
View wordpress_songkick.php
<?php
// Artist is custom field key for post
$key_songkick = "Artist";
// Check post to see if Artist custom field exists
if ( get_post_meta($post->ID, $key_songkick, true) ) :
// Need to search by Artist name since we don't know ID, need ID to get the artist calendar.
// Using urlencode since we can't send a space to the Songkick JSON request
$Artist = urlencode(get_post_meta($post->ID, $key_songkick, true));
// Use your API key here
You can’t perform that action at this time.