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 / SassMeister-input.scss
Created October 24, 2013 20:55
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.7)
// ----
$zoo: ("puma": black, "sea-slug": green, "egret": brown, "salamander": red);
@each $animal, $color in $zoo {
.#{$animal}-icon {
background-color: $color;
@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 / 01-variable-respond-to-mixin.md
Created April 25, 2012 21:20
Variable-driven respond-to mixin

What if controlling your media queries was as easy as adding on to a Sass list? What if I told you it now is?

This snippet comes from a modified version of mixins in the Aura Responsive Framework and came from me hijacking the respond-to mixin namespace but still wanting to use it for custom media queries. It's a little ugly and requires Sass 3.2+ (for now, (sudo) gem install sass --pre), but it works a charm.

There are two fairly mundane caveats to this method. First, every media query needs to be named. Second, every media query needs a size and assumes min-width and screen. If you want to change min-width, simply add your operator as another option, but if you want to change screen, you need to also include your operator even if you want it to be min-width.

Also, I haven't built in warnings yet for when you do bad things, so bear that in mind.

Without further adue, tada.

@Snugug
Snugug / image.js
Last active April 7, 2020 07:32
Image Renderer for Marked (https://github.com/chjj/marked/) to transform it into a media embed tool
var marked = require('marked'),
fs = require('fs'),
path = require('path'),
URI = require('URIjs'),
renderer = new marked.Renderer(),
file = fs.readFileSync('./foo.md', 'utf8');
// Set Marked's rendereer to the custom renderer
// optional `localVideoPath` option will be used to to find fallback videos for `.webm`. Defaults to ''
marked.setOptions({
@Snugug
Snugug / bullshit.css
Last active November 5, 2019 14:23
Add this to your user stylesheet to remove bullshit.
/**
* Bullshit
**/
[id*="social"],
[class*="social"],
[id*="addthis"],
[class*="addthis"],
[id*="share"],
[class*="share"],
[id*="yodr_net"] {
@Snugug
Snugug / server.bash
Created October 26, 2013 18:22
OS X 10.9 (Mavericks) comes with PHP 5.4.17 out of the box, allowing you to start a PHP development server in any directory by running `php -S localhost:8888` with `8888` being the port number you'd like to use. This is a little bash/zsh function to reduce that to `server 8888`. Simply add this to `bash_profile` or `zshconfig`. For more on the P…
server() {
php -S localhost:"$*";
}
@Snugug
Snugug / media-query-mixin.scss
Created April 25, 2012 15:41
Media Query Sass Mixin
//////////////////////////////
// Generalized Media Query Mixin
//
// Requires Sass 3.2+
// Until released:
// (sudo) gem install sass --pre
//////////////////////////////
@mixin media-query($value, $operator: 'min-width', $query: 'screen') {
@media #{$query} and (#{$operator}: #{$value}) {
@content;
@Snugug
Snugug / class-var.scss
Created May 8, 2012 09:39
Classes and Variables (using Color as an example)
////////////////////////
// SCSS
////////////////////////
// Define color variables
$red: #e10000;
$orange: #e18700;
$yellow: #e1e100;
$green: #00b400;
$blue: #1e00b4;
$purple: #7800b4;
@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());