Skip to content

Instantly share code, notes, and snippets.

View claviska's full-sized avatar

Cory LaViska claviska

View GitHub Profile
@claviska
claviska / parseTime.js
Last active July 8, 2023 19:53
Parse time strings input by humans
function parseTime(time, format, step) {
var hour, minute, stepMinute,
defaultFormat = 'g:ia',
pm = time.match(/p/i) !== null,
num = time.replace(/[^0-9]/g, '');
// Parse for hour and minute
switch(num.length) {
case 4:
@claviska
claviska / pretty-buttons.less
Last active October 21, 2022 22:25
A Less mixin' for pretty buttons with Bootstrap 3
.pretty-buttons(@color, @background, @text-shadow: none) {
color: @color;
#gradient > .vertical(lighten(@background, 5%), darken(@background, 5%), 0%, 100%);
border-color: darken(@background, 10%);
border-bottom-color: darken(@background, 20%);
text-shadow: @text-shadow;
.box-shadow(inset 0 1px 0 rgba(255, 255, 255, .1));
&:hover,
@claviska
claviska / form-submit-controller.ts
Last active February 15, 2022 16:52
A Reactive Controller for Custom Element Form Controls
//
// This is a Reactive Controller (https://lit.dev/docs/composition/controllers/) that allows custom elements to submit
// with standard <form> elements.
//
// The formdata event didn't land in Safari until 15.1, which is still somewhat recent. You can use this lightweight
// polyfill to make it work: https://gist.github.com/WickyNilliams/eb6a44075356ee504dd9491c5a3ab0be
//
// If your custom element shares the same API as HTMLInputElement for name/value/disabled/reportValidity, this is all
// you need to do:
//
@claviska
claviska / LICENSE.md
Last active February 7, 2022 14:12
A Reactive Controller for detecting "click presses."

Copyright (c) 2020 A Beautiful Site, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

@claviska
claviska / vertically-centered-bootstrap-modals.js
Last active May 15, 2020 06:29
Vertically Centered Bootstrap Modals
/**
* Vertically center Bootstrap 3 modals so they aren't always stuck at the top
*/
$(function() {
function reposition() {
var modal = $(this),
dialog = modal.find('.modal-dialog');
@claviska
claviska / jquery.offscreen.js
Created October 30, 2013 21:36
jQuery offscreen plugin
/*
* jQuery offscreen plugin
*
* Filters that detect when an element is partially or completely outside
* of the viewport.
*
* Usage:
*
* $('#element').is(':off-bottom')
*
@claviska
claviska / rest.class.php
Created August 30, 2012 18:20
Barebones PHP-based REST client
<?php
/*
Usage:
$rest = new REST($config);
$result = $rest->get('http://example.com/method, array(
'name' => 'value',
...
));