Skip to content

Instantly share code, notes, and snippets.

View droid001's full-sized avatar

droid001

View GitHub Profile
@droid001
droid001 / resizeIframe
Created September 4, 2019 11:07
resize iframe listener
// child.html
let height;
const sendPostMessage = () => {
if (height !== document.getElementById('container').offsetHeight) {
height = document.getElementById('container').offsetHeight;
window.parent.postMessage({
frameHeight: height
}, '*');
console.log(height);
}
@droid001
droid001 / _mixins.scss
Created April 17, 2018 11:54
media queries min/max/min-max mixins
@mixin break-min($min) {
@media only screen and (min-width: $min) {
@content;
}
}
@mixin break-max($max) {
@media only screen and (max-width: $max - 1px) {
@content;
}
@droid001
droid001 / time-difference.js
Created April 4, 2018 20:32
Creates a more user friendly time stamp string.
function timeDifference(current, previous) {
const milliSecondsPerMinute = 60 * 1000
const milliSecondsPerHour = milliSecondsPerMinute * 60
const milliSecondsPerDay = milliSecondsPerHour * 24
const milliSecondsPerMonth = milliSecondsPerDay * 30
const milliSecondsPerYear = milliSecondsPerDay * 365
const elapsed = current - previous
@droid001
droid001 / _grid.scss
Created February 1, 2018 07:56
css grid and grid-child for Edge/IE11/IE10 compatibility
// CSS Grid
@mixin gridcontainer($columns: $site-columns, $rows:false, $gutter: false, $guttertype: "padding") {
display: -ms-grid;
display: grid;
// TODO: make the ms declaration a loop based on colums. -LR
-ms-grid-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
grid-template-columns: repeat($site-columns, 1fr) ;
@include container($guttertype);
@droid001
droid001 / _helper.scss
Created February 1, 2018 07:41
break points min, max, min-max
@mixin break-min($min) {
@media only screen and (min-width: $min) {
@content;
}
}
@mixin break-max($max) {
@media only screen and (max-width: $max - 1px) {
@content;
}
@droid001
droid001 / _typography.scss
Last active February 6, 2018 15:48
transform font size to rems, optional line height
@mixin fontsize($font-size, $line-height:false) {
$size: strip-unit($font-size);
font-size: #{$size}px;
font-size: #{$size/strip-unit($base-font-size)}rem;
@if $line-height {
// line-height:ceil($font-size / $base-line-height) * ($base-line-height / $font-size);
line-height: $line-height;
@droid001
droid001 / _typography.scss
Last active February 1, 2018 07:25
Responsive header with sliding font-size scale
@mixin responsive-header($size-min, $size-max, $lineheight:false, $marginbottom:false, $breakMinTypoWidth:$break-min-typo-width, $breakMaxTypoWidth:$break-max-typo-width, $font-weight:bold ) {
$breakmin: strip-unit($breakMinTypoWidth);
$breakmax: strip-unit($breakMaxTypoWidth);
@include font-size($size-min);
@include break-sliding-typo-size($size-min, $size-max, $breakmin, $breakmax);
@media only screen and (min-width: #{$breakmax}px - 1px) {
font-size: #{$size-max}px;
}
@droid001
droid001 / _mixins.scss
Last active February 1, 2018 07:17
Strips unit from number string
// From https://css-tricks.com/snippets/sass/strip-unit-function/
@function strip-unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}
@droid001
droid001 / ngramwriter.js
Created January 25, 2018 13:39
Largest number in array using .reduce
return arr.reduce(function(acc, curr) {
return acc > curr ? acc : curr;
});
@droid001
droid001 / ngramwriter.js
Created January 25, 2018 13:30
Largest number in array
var max = Math.max.apply(null, numbers);