Skip to content

Instantly share code, notes, and snippets.

View webinista's full-sized avatar

Tiffany Brown webinista

View GitHub Profile
@webinista
webinista / has3d.js
Created September 4, 2012 21:42
Testing for CSS 3D Transforms Support
function has3d(){
var el = document.createElement('p'), t, has3d,
transforms = {
'WebkitTransform':'-webkit-transform',
'OTransform':'-o-transform',
'MSTransform':'-ms-transform',
'MozTransform':'-moz-transform',
'transform':'transform'
};
@webinista
webinista / datalist.html
Last active October 12, 2015 14:48
Datalist in action
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title><datalist in actino></title>
<link rel="stylesheet" href="s.css" media="screen">
<style media="screen">
p{
font: bold 100% / 1.5 sans-serif;
}
@webinista
webinista / atsupports.js
Created December 3, 2012 14:10
Testing for @supports support
function hasAtSupports(){
return (window.CSSRule !== undefined) && (window.CSSRule.SUPPORTS_RULE !== undefined)
}
@webinista
webinista / pagevis.js
Last active December 11, 2015 20:08
This script adds a wrapper around prefixed versions of document.visibilityState and document.hidden so that you can use a single syntax and listen for a single event.
/*
Page Visibility wrapper
Tiffany B. Brown <http://tiffanybbrown.com/>
Released under an MIT license.
This script adds a wrapper around prefixed versions of
document.visibilityState and document.hidden so that you can use a
single syntax and listen for a single event.
Permission is hereby granted, free of charge, to any person obtaining
@webinista
webinista / _transparent-placeholder-mixin.scss
Last active August 29, 2015 13:57
Clear placeholder input on focus using transparent keyword
@mixin placeholder{
&:focus::-webkit-input-placeholder{
color: transparent;
}
&:focus::-moz-placeholder {
color: transparent;
}
&:focus:-ms-input-placeholder {
color: transparent;
@webinista
webinista / zeropad.js
Last active August 29, 2015 13:57
Add zeroes to the left of a digit. Useful for date and time applications.
/*
input = number or numeric string.
length = pad with zeroes until it hits this length.
*/
function zeroPadLeft(input, length){
var zero = '0', pad = '', len, padded, inp, extract;
/* Convert to string */
inp = input+'';
@webinista
webinista / median.js
Created April 1, 2014 19:43
A simple function for finding the median value in an array of numbers.
var median = function(array){
var med, a, len;
len = array.length;
/* Sort by numeric value */
a = array.sort(function(a,b){return a - b});
med = Math.floor(len / 2);
@webinista
webinista / mean.js
Created April 1, 2014 19:46
A method to finding the mean (average) value from an array of numbers.
var mean = function(array){
var len, sum;
sum = array.reduce( function(a,b){
return a + b;
});
len = array.length;
return sum / len;
}
mean([2,4]); // 3
@webinista
webinista / formattime.js
Created April 1, 2014 23:32
Formatting time from timestamps. Takes seconds and returns a time string.
function formattime(timeinseconds){
var zeroes = '0', hours, minutes, seconds, time;
/*
Create a new date object and pass our time in seconds as the seconds parameter
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
*/
time = new Date(0, 0, 0, 0, 0, timeinseconds, 0);
hours = time.getHours();
@webinista
webinista / formatUSPhoneNumber.js
Created April 7, 2014 02:43
Format a numeric string as xxx-xxx-xxxx
function formatUSPhoneNumber(number) {
var x = 0, groups = [], len, num;
/* Force string conversion */
num = number+'';
/* Remove non numeric characters */