Skip to content

Instantly share code, notes, and snippets.

View redoPop's full-sized avatar
☁️
cheering at clouds

Joe Bartlett redoPop

☁️
cheering at clouds
View GitHub Profile
@redoPop
redoPop / tzAbbr.js
Last active June 6, 2023 21:22
JavaScript: friendly timezone abbreviations in the client ("EDT", "CST", "GMT", etc.)
/*
Given a date, tzAbbr returns a short, friendly name for the
user's time zone on that date, or an empty string if their
client's Intl support is missing or incomplete.
For example, a user in New York might see:
tzAbbr(new Date()) // => "EST"
Time zones are locale-dependent. Users traveling outside of
@redoPop
redoPop / HashFormAuthenticate.php
Created October 5, 2011 00:22
CakePHP 2.0 Authentication object for use with better hash methods (bcrypt, etc.)
<?php
App::uses('FormAuthenticate', 'Controller/Component/Auth');
class HashFormAuthenticate extends FormAuthenticate {
/**
* Find a user record given a username and unhashed password.
*
* @param string $username The username/identifier.
* @param string $password The unhashed password.
@redoPop
redoPop / extension_specific_route.php
Created May 27, 2011 22:59
CakePHP custom Route class that restricts a route to a single extension.
<?php
/**
* Custom Route class that restricts a route to a single extension.
* Enables you to build controller actions that are only applied to specific
* extensions, e.g., '/posts.json' goes to PostsController::index_json while
* '/posts' goes to PostsController::index.
*
* To use, drop this into app/libs/routes/extension_specific_route.php and add
* the following to the top of app/config/routes.php:
*
@redoPop
redoPop / lazy_virtual_fielder.php
Created May 17, 2011 23:27
CakePHP Behavior that stops virtualFields from being selected unless they're explicitly requested.
<?php
/**
* Behavior to stop CakePHP from including virtual fields unless they're
* explicitly requested in the fields array.
*
* To find out more about virtual fields, consult the documentation in the
* manual here:
*
* http://book.cakephp.org/view/1608/Virtual-fields
*
@redoPop
redoPop / ordered_containable.php
Created April 28, 2011 13:48
CakePHP Behavior that makes ContainableBehavior respect a Model's default order
<?php
/**
* Behavior to enhance CakePHP ContainableBehavior by respecting default Model order
*
* Makes ContainableBehavior respect Model::order when no other order is specified in
* the containment. Must be placed before ContainableBehavior in the actsAs array of
* the Model being queried, like so:
*
* var $actsAs = array('OrderedContainable', 'Containable');
*
@redoPop
redoPop / jquery.loadshiv.js
Created December 10, 2010 05:35
Replacement jQuery.load() for use with innerShiv
// jQuery plugin based on .load() for use with innerShiv
// http://jdbartlett.github.com/innershiv for more info
// $('selector').loadShiv('example.html selector');
jQuery.fn.loadShiv = function (url, params, callback) {
var off, selector, self, type;
if (!this.length || typeof url !== 'string') {
return this;
}
@redoPop
redoPop / .gitignore
Created June 18, 2010 22:08
Template .gitignore file for WordPress projects
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
@redoPop
redoPop / suffix.js
Created February 24, 2010 19:39
JavaScript: integer suffixes (1st, 2nd, 3rd...)
var suffix = function(n) {
var d = (n|0)%100;
return d > 3 && d < 21 ? 'th' : ['th', 'st', 'nd', 'rd'][d%10] || 'th';
};
// suffix(1) => "st"
// suffix(102) => "nd"
// suffix(113) => "th"
@redoPop
redoPop / to12hr.js
Created December 2, 2009 22:51
JavaScript: 13.19 to "1:11 PM"
var to12Hr = function(n, r /* round to nearest r minutes */) {
if (!n || n >= 24) return '12:00 AM';
var m = (Math.round(n%1 * (r = (r ? 60/r : 60))) / r) * 60 | 0;
return ((n = (m>59 ? n+1 : n))>=13 ? (n|0)-12 : n|0) + ':' + (m>9 ? (m>59 ? '00' : m) : '0'+m) + (n>=12 && m<60 ? ' PM' : ' AM');
}
// to12Hr(6.5) => "6:30 AM"
// to12Hr(13.19) => "1:11 PM"
// to12Hr(13.19, 15) => "1:15 PM" (rounds to 15 mins)
@redoPop
redoPop / timezones.php
Created August 25, 2009 18:33
CakePHP helper to produce an array of times for various zones.
<?php
class TimezonesHelper extends AppHelper {
function show() {
$zones = array(
'Pacific/Apia' => 'Apia, Upolu, Samoa', // UTC-11:00
'US/Hawaii' => 'Honolulu, Oahu, Hawaii, United States', // UTC-10:00
'US/Alaska' => 'Anchorage, Alaska, United States', // UTC-09:00
'US/Pacific' => 'Los Angeles, California, United States', // UTC-08:00
'US/Mountain' => 'Phoenix, Arizona, United States', // UTC-07:00