Skip to content

Instantly share code, notes, and snippets.

@djpogo
djpogo / fakeWindowLocalStorage.js
Created February 7, 2020 18:01
a unit testable localStorage mock
const fakeWindowLocalStorage = {
localStorage: {
data: {},
length: 0,
setItem(name, value) {
this.data[name] = value.toString();
this.length = Object.keys(this.data).length;
},
getItem(name) {
return this.data[name];
@djpogo
djpogo / fakeDocumentCookie.js
Last active February 7, 2020 18:00
a unit testable document.cookie mock
// idea from here @see https://stackoverflow.com/questions/6456429/is-it-possible-to-mock-document-cookie-in-javascript
const fakeDocumentCookie = {
cookies: '',
get cookie() {
return this.cookies;
},
set cookie(cookieValue) {
const cookies = this.cookies.split(' ');
<!DOCTYPE html>
<html lang="de">
<head>
<title>I'm in the mode</title>
<meta charset="utf-8">
<meta name="description" content="Sometimes I ran…">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Big+Shoulders+Text&display=swap" rel="stylesheet">
<script>
@djpogo
djpogo / dark-mode-media-query.html
Last active February 15, 2020 20:42
CSS Dark Mode Media Query with Custom Property usage
<!DOCTYPE html>
<html lang="de">
<head>
<title>I'm in the mode</title>
<meta charset="utf-8">
<meta name="description" content="Sometimes I ran…">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Big+Shoulders+Text&display=swap" rel="stylesheet">
<style>
@djpogo
djpogo / _bg-url.scss
Created January 27, 2019 11:26
scss background-image: url() mixin
@mixin bg-url($url, $url2x: false, $webp1x: false, $webp2x: false) {
background-image: url($url);
@if $webp1x {
.webp & {
background-image: url($webp1x);
}
}
@if $url2x {
@media
screen and (-webkit-min-device-pixel-ratio: 2),