Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / convert-UNIX-timestamp.js
Last active March 16, 2023 09:31
Convert a UNIX timestamp to user's local time via JavaScript
function convertTimestamp(timestamp) {
var d = new Date(timestamp * 1000), // Convert the passed timestamp to milliseconds
yyyy = d.getFullYear(),
mm = ('0' + (d.getMonth() + 1)).slice(-2), // Months are zero based. Add leading 0.
dd = ('0' + d.getDate()).slice(-2), // Add leading 0.
hh = d.getHours(),
h = hh,
min = ('0' + d.getMinutes()).slice(-2), // Add leading 0.
ampm = 'AM',
time;
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 / expireCookie.js
Created February 26, 2014 16:10
This function finds the user's local date/time converted from EDT at a set time in the future. Useful for expiring cookies on a regular basis. By default, expires cookie once-per-day at 12:01 AM EDT the next day, every day. Modify offsets accordingly.
function findLocalExpTime() {
var curTime = new Date(),
expTime = new Date(),
baseZoneOffset = 4, // Base timezone offset from UTC (4 in this example for EDT, change as appropriate)
tmpYear = curTime.getUTCFullYear(),
tmpMonth = curTime.getUTCMonth(),
tmpDate = curTime.getUTCDate(),
tmpHrs = curTime.getUTCHours(),
tmpMin = curTime.getUTCMinutes(),
localTime;