Skip to content

Instantly share code, notes, and snippets.

View mdahlke's full-sized avatar
👋
Working from home

Michael mdahlke

👋
Working from home
View GitHub Profile
@mdahlke
mdahlke / arrow.scss
Created January 11, 2017 02:55
Create arrows quickly with a SCSS mixin Raw
@mixin arrow($direction: 'up', $size: 5px, $color: black) {
width: 0;
height: 0;
@if ($direction == 'up') {
border-left: $size solid transparent;
border-right: $size solid transparent;
border-bottom: $size solid $color;
} @else if ($direction == 'down') {
border-left: $size solid transparent;
@mdahlke
mdahlke / best-fit-image.php
Created January 10, 2017 21:09
Find the image that best fits a particular area of the page
<?php
$knownBestFits = [];
/**
* Find the smallest image to use in a given space with the minimal dimensions provided
* If width is the main decider, leave the height set at 0, and vice versa if the height is the main decider
* You may use both if a minimum height/width is needed
*
* @param $imageObj WP Image Object
* @param int $minWidth Minimum width the image needs to be
@mdahlke
mdahlke / implode-associative-array.php
Created January 10, 2017 20:59
Implode an associative array on specified key
function implode_aa( $glue, $array, $key ) {
$keep = array();
foreach ( $array as $firstKey ) {
foreach ( $firstKey as $k => $v ) {
if ( $k === $key ) {
$keep[] = $v;
}
@mdahlke
mdahlke / vertical-flow.scss
Last active January 10, 2017 21:00
Create consistent vertical with classic bootstrap style selectors
/*scss/SCSS-Mixins-Functions/_mixin-vertical-flow.scss*/
// @function explode() -- split a string into a list of strings
// {string} $string: the string to be split
// {string} $delimiter: the boundary string
// @return {list} the result list
@function explode($string, $delimiter) {
$result: ();
@if $delimiter == "" {
@for $i from 1 through str-length($string) {
@mdahlke
mdahlke / wp-custom-pagination__archive.php
Created January 9, 2017 19:28
Create custom pagination for custom WP queries
<?php
$paged = (int) ( get_query_var( 'result-page' ) ?: 1 );
$postsPerPage = get_option('posts_per_page');
$args = array(
'post_type' => 'news',
'posts_per_page' => $postsPerPage,
'paged' => $paged,
'orderby' => receive( 'news_orderby', 'date' ),
$breakpoints: (
'xs': 0px,
'sm': 768px,
'md': 992px,
'lg': 1200px,
);
$gutters: (
'no': 0,
@function px2em($px, $unit: 'em'){
@return #{$px / $baseFontSize}#{$unit};
}
@function first($list) {
@if type-of($list) == 'list' {
@return nth($list, 1);
} @else {
@return $list;
}