Skip to content

Instantly share code, notes, and snippets.

View Snugug's full-sized avatar

Sam Richard Snugug

View GitHub Profile
@Snugug
Snugug / ElementHelper.ts
Last active February 9, 2024 15:23
A little helper function to create an element with relevant attributes and optional nesting. Should be a fairly easy replacement for using innerHTML where that's not reasonable.
// Create an element with attributes, and optionally append children to it
// Public Domain licensed, if you're interested.
function e(
elm: string,
attrs: Record<string, string> = {},
...children: (string | Node)[]
): Node {
// Create element and add relevant attributes
const elem = document.createElement(elm);
for (const [k, v] of Object.entries(attrs)) {
@Snugug
Snugug / flexbox-1-column-to-2-columns-no-media-queries.markdown
Created March 24, 2022 19:09
Flexbox 1 column to 2 columns, no media queries
@Snugug
Snugug / performance.js
Last active March 15, 2019 18:26
A Chrome DevTools Snippet to get page performance numbers. Returns interesting Navigation Timings and Resource Sizing. Unfortunate workaround for content types until https://github.com/w3c/resource-timing/issues/203 hits
function getExt(filename, opts) {
if (!opts) opts = {};
if (!filename) return "";
var ext = (/[^./\\]*$/.exec(filename) || [""])[0];
return opts.preserveCase ? ext : ext.toLowerCase();
};
async function typeMap () {
const db = await fetch('https://unpkg.com/mime-db/db.json').then(t => t.json());
@Snugug
Snugug / instance.js
Last active June 20, 2018 15:02
Need a way to type provider:SOMETHING so I can `new` its children
import { validate, IsInt, IsEmail, IsIn, IsNotEmpty } from 'class-validator';
import { Provider } from './provider';
export class InstanceConfig {
[key:string]: number | string;
@IsEmail()
@IsNotEmpty()
email: string;
@Snugug
Snugug / README.md
Last active February 12, 2018 22:29
Progressively Enhanced Lazy Loading Images in 40 lines of code

Lazy Load Images in 40 Lines of Code

Behold! Intersection Observers at work!

Usage

First, update your source code to move your image sources in to data attributes.

@Snugug
Snugug / detect.js
Last active January 24, 2017 21:54
Feature Detection!
(function () {
'use strict';
var detect = function detect(property, value) {
if (window.CSS && window.CSS.supports) {
return window.CSS.supports(property, value);
}
else {
return false;
}
@Snugug
Snugug / SassMeister-input-HTML.html
Created January 4, 2016 22:39
Generated by SassMeister.com.
<div id="container">
<div class="first">First</div>
<div class="second">Second</div>
<div class="third">Third</div>
<div class="fourth">Fourth</div>
</div>
@Snugug
Snugug / SassMeister-input.scss
Created November 29, 2015 17:22
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
@import "breakpoint";
@import "toolkit";
@import "singularitygs";
@include sgs-change('debug', true);
@include sgs-change('mobile first', true);
@Snugug
Snugug / SassMeister-input-HTML.html
Created October 10, 2015 17:44
Generated by SassMeister.com.
<div class="grid-4">
<h3>Item 1</h3>
</div>
<div class="grid-4">
<h3>Item 2</h3>
</div>
<div class="grid-4">
<h3>Item 3</h3>
</div>
<div class="grid-4">
@Snugug
Snugug / SassMeister-input.scss
Created September 9, 2015 16:21
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
$a: 'test';
$b: test;
.foo {
content: is-quoted($a); // true
content: is-quoted($b); // false