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

Keybase proof

I hereby claim:

  • I am redopop on github.
  • I am redopop (https://keybase.io/redopop) on keybase.
  • I have a public key whose fingerprint is BD5E 80B7 1064 E817 8170 6D51 CF73 4474 7775 9DD1

To claim this, I am signing this object:

@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 / 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 / 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 / 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 / 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 / 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 / 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 / file-actions.applescript
Last active May 10, 2017 19:19
Alfred workflow to show file actions for an open document.
on alfred_script()
-- Replace with path to dir where your nvALT notes are kept as individual files
set nvFolder to "/Users/redoPop/Dropbox/Notes"
set docPath to false
try
tell application "System Events"
set frontApp to (name of first process whose frontmost is true)
end tell
@redoPop
redoPop / gist:9050999cebcd7e50934a
Created September 8, 2014 14:15
IE10 & IE11 don't trigger touch events (e.g., touchstart). If you want to differentiate touches from clicks, you must use the pointer events API and the event object's pointerType property:
function onPointerDownHandler (event) {
if (event.pointerType === 'touch') {
// Equivalent to a touchstart on MS Surface
}
}
// For IE 10
element.addEventListener('MSPointerDown', onPointerDownHandler);
// For IE 11+