Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / ordinal.js
Created April 24, 2015 14:46
Get an ordinal from a number
/**
* Get ordinal value
*
* @param n {number} if a string is provided, % will attempt to convert to number
* @returns {string} th, st, nd, rd
*/
function getOrdinal(n) {
var ordArr = ['th', 'st', 'nd', 'rd'];
var modulus = n % 100;
var global = {
konami: function() {
var konamikeys = [38,38,40,40,37,39,37,39,66,65],
started = false,
count = 0;
$(document).keydown(function(e){
var reset = function() {
started = false;
@kmaida
kmaida / time-ago-twitter.php
Last active December 20, 2015 00:59
Convert a date string to UNIX timestamp and then calculate how long from now that was in the fashion of twitter.
function timeAgo($dateStr) {
$timestamp = strtotime($dateStr);
$day = 60 * 60 * 24;
$today = time(); // current unix time
$since = $today - $timestamp;
// If it has been less than 1 day since the tweet was posted, figure out how long ago in seconds/minutes/hours
if (($since / $day) < 1) {
$timeUnits = array(
@kmaida
kmaida / time-ago-github.php
Last active December 20, 2015 00:59
Calculating time between now and timestamp in the fashion of GitHub commit listings.
function timeAgo($dateStr) {
$timestamp = strtotime($dateStr);
$timeUnits = array(
array(60 * 60 * 24 * 365 , 'year'),
array(60 * 60 * 24 * 30 , 'month'),
array(60 * 60 * 24 * 7, 'week'),
array(60 * 60 * 24 , 'day'),
array(60 * 60 , 'hour'),
array(60 , 'minute')
@kmaida
kmaida / jquery-method.js
Created August 27, 2013 18:33
Create jQuery method
$.fn.methodName = function(){
return this.each(function(index, element){
$(this)
.html('A method was called on me!')
.css('background', 'green');
});
}
@kmaida
kmaida / typecasting-notnot.js
Last active December 21, 2015 19:49
Typecasting in JavaScript with !!
var typeCast = function(string) {
if (!!string) {
document.write('<p>' + string + ': true</p>');
} else {
document.write('<p>' + string + ': false</p>');
}
};
typeCast("Hello there");
typeCast("");
@kmaida
kmaida / resize-debounce.js
Last active December 25, 2015 05:49
jQuery resize() debounce
function resizedFn(){
// Haven't resized in 200ms!
// Run this code
}
var debounceResize;
$(window).resize(function(){
clearTimeout(debounceResize);
debounceResize = setTimeout(resizedFn, 200);
});
@kmaida
kmaida / inline-link-touch-targets.css
Created November 12, 2013 16:06
Inline link touch targets
@kmaida
kmaida / css-reset-normalize.css
Last active December 31, 2015 06:29
Short CSS reset and normalize
/*
* CSS Reset + Normalize
* Author: Kim Maida
* Author URI: <http://kim-maida.com>
* Source: <https://github.com/kmaida
* License: GNU Public License
*/
/*--------------------
CSS RESET
@kmaida
kmaida / animated-ng-if.scss
Last active March 9, 2016 15:00
AngularJS - Sass - Animating the height of an ng-if to achieve an expanding/collapsing effect. To animate ng-show/hide, see: http://codepen.io/kmaida/pen/QwgddQ
.animated-ng-if {
&.ng-enter {
transition: max-height 350ms ease-in; /* transition the height FROM 0 to x when entering (autoprefix or use mixin) */
max-height: 0;
}
&.ng-enter.ng-enter-active,
&.ng-leave {
max-height: 600px; /* max-height when active (adjust value to fit needs) */
}
&.ng-leave.ng-leave-active {