Skip to content

Instantly share code, notes, and snippets.

View davidpaulsson's full-sized avatar

David Paulsson davidpaulsson

View GitHub Profile
@davidpaulsson
davidpaulsson / foundation.pagination
Created October 18, 2012 06:32
Foundation 4 pagination for WordPress
function foundation_pagination( $p = 2 ) {
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 ) return;
if ( empty( $paged ) ) $paged = 1;
if ( $paged > $p + 1 ) p_link( 1, 'First' );
if ( $paged > $p + 2 ) echo '<li class="unavailable"><a href="#">&hellip;</a></li>';
for( $i = $paged - $p; $i <= $paged + $p; $i++ ) { // Middle pages
if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<li class='current'><a href='#'>{$i}</a></li> " : p_link( $i );
@davidpaulsson
davidpaulsson / jQuery.maxHeight
Created June 27, 2013 11:47
Equalize heights of div elements
var maxHeight = 0;
$('div').each(function(){
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
});
$('div').height(maxHeight);
@davidpaulsson
davidpaulsson / bash_profile open in chrome
Created February 19, 2014 07:17
.bash_profile candy
# open a file in chrome
# usage: $ chrome index.html
function chrome() {
open $@ --args --allow-file-access-from-files
}
@davidpaulsson
davidpaulsson / wp-get_id_by_slug
Created February 26, 2014 06:20
WordPress: Get page ID from slug
// Usage:
// get_id_by_slug('any-page-slug');
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
@davidpaulsson
davidpaulsson / render_time.rb
Last active August 29, 2015 13:57 — forked from blakesmith/render_time.rb
Displays the time a Jekyll page was generated in format "Month DD, YYYY"
# An example Jekyll Liquid tag. Utilizes the new plugin system.
#
# 1. Make a _plugins directory in your jekyll site, and put this class in a file there.
# 2. In anyone of your pages, you can use the 'render_time' liquid tag like so:
# {% render_time Page generated at: %}
module Jekyll
class RenderTimeTag < Liquid::Tag
def initialize(tag_name, text, tokens)
@davidpaulsson
davidpaulsson / rwd-lazy-loading.js
Last active February 3, 2016 03:24
Lazy loading with padding-bottom hack for responsive images
/**
* Place this inline at the bottom of the html document, right before
* closing `</body>`. It's important to have this inline as we want to
* display images asap.
*
* Markup example for the actual images. It also calculates the image
* container using the [padding-top hack](https://gist.github.com/davidpaulsson/10101985),
* please do this calculation on the back end, before drawing the DOM.
* Current example can load three images sizes, customize to fit your needs. It
* also adds the calculated image URL as an data-original tag on the img element it creates,
@davidpaulsson
davidpaulsson / padding-bottom-hack.css
Last active August 29, 2015 13:58
CSS needed for padding-bottom hack
/*
* CSS needed for https://gist.github.com/davidpaulsson/10101172
*/
img {
max-width: 100%;
height: auto;
}
/* Non-fluid images if you specify `width` and/or `height` attributes. */

Keybase proof

I hereby claim:

  • I am davidpaulsson on github.
  • I am davidpaulsson (https://keybase.io/davidpaulsson) on keybase.
  • I have a public key whose fingerprint is 7F6E 0C62 26CB 9F49 B685 3C63 2246 ACB6 100C 1333

To claim this, I am signing this object:

Verifying that +davidpaulsson is my openname (Bitcoin username). https://onename.com/davidpaulsson
/*--------------------------------------------------------------
Flexbox grid
--------------------------------------------------------------*/
// Wrapper
.grid {
display: flex;
}
// Alignment per row