Skip to content

Instantly share code, notes, and snippets.

@zzzzBov
zzzzBov / index.html
Created July 9, 2012 17:43
A web page created at CodePen.io
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple button &middot; CodePen</title>
<!--
Copyright (c) 2012 zzzzBov, http://codepen.io/zzzzBov
Permission is hereby granted, free of charge, to any person obtaining
@zzzzBov
zzzzBov / index.html
Created August 10, 2012 17:12
A web page created at CodePen.io.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- IF PEN IS PRIVATE -->
<!-- <meta name="robots" content="noindex"> -->
<!-- END -->
@zzzzBov
zzzzBov / resizeelement
Created June 2, 2013 18:28
resizeelement cutsom jQuery event
(function (root, $) {
"use strict";
$.event.special.resizeelement = {
setup: function () {
var $this,
interval,
width,
height;
$this = $(this);
width = $this.width();
@zzzzBov
zzzzBov / Saveable Form
Last active December 18, 2015 00:09
Flag unsaved changes when a user leaves a page with a saveable form
(function (root, $) {
"use strict";
$('[data-saveable]').on('change', ':input', function () {
//flag the form as having changed
$(this).closest('[data-saveable]').data('saveable', true);
}).on('submit', function (e) {
//if the form is successfully being submitted, it's probably being saved
if (!e.isDefaultPrevented()) {
//force the saveable input to lose focus
//to trigger any possible change events
@zzzzBov
zzzzBov / JavaScript Profiler
Last active September 16, 2017 03:34
A small script to profile JS and dump the data to the console.
class Profiler {
constructor (name) {
this._name = name
this._profiles = []
this._activeProfiles = this._profiles
}
profile (name, fn) {
if (typeof name !== 'string') {
throw new TypeError('"name" must be a string')
toFixed = (value, fractionDigits) => {
const f =
fractionDigits === undefined
? 0
: +fractionDigits
console.log('1. f:', f)
if (f < 0 || f > 20) {
console.error('2. throw a RangeError')

Keybase proof

I hereby claim:

  • I am zzzzbov on github.
  • I am zzzzbov (https://keybase.io/zzzzbov) on keybase.
  • I have a public key ASCm3sWFZGZjBe02ULVLFL8z5Ol7QjOurYanaep5_uwceQo

To claim this, I am signing this object:

@zzzzBov
zzzzBov / machine.js
Last active January 24, 2021 21:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@zzzzBov
zzzzBov / luminance.ts
Last active October 7, 2021 19:41
W3C Relative Luminance
// Get the luminance of an RGB color [0x000000, 0xFFFFFF] using the w3c procedure for relative luminance
// https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
//
// This code is untested
const getChannelLuminance = (color: number, shift: number) => {
let result = color;
result &= 0xff << shift;
result >>= shift;
result /= 255;
@zzzzBov
zzzzBov / controllers.application\.js
Last active November 30, 2021 23:55
Prevent Default <LinkTo>
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
interceptA(event) {
event.preventDefault();
alert('preventDefault should ideally stop this link from proceeding to the example page while still allowing the parent handler to occur.');
}