Skip to content

Instantly share code, notes, and snippets.

View jasonrhodes's full-sized avatar

Jason Rhodes jasonrhodes

View GitHub Profile
@jasonrhodes
jasonrhodes / .bashrc
Last active December 13, 2015 20:48
Mac OS X: Add these to your .bashrc or .bash_profile for a quick way to show/hide all icons on the Desktop
# Show/Hide all icons on the Desktop, even if you have 'hidden files on'
# Usage:
# $ cleandesk => hides all icons
# $ showdesk => ahem, SHOWS all icons
alias cleandesk="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesk="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
@jasonrhodes
jasonrhodes / regex_match.js
Created March 19, 2013 21:39
Showing how to set up a quick regular expression and how it works when used with string.match()
string_a = "Hello";
string_b = "Hello world";
string_c = "Hello: how are you";
string_d = "I would say Hello: to you";
/**
* Create a regular expression.
*
* The "^" character means 'must start with',
@jasonrhodes
jasonrhodes / Libraries.jsx
Last active April 10, 2019 09:49
Include the minified version at the top of any of our .jsx script files and then you can include files from adobe_scripts/lib just by calling Libraries.include("subdir/myscript")
// Assumes that your script is somewhere within a folder called "adobe_scripts" and
// that you store your includable files relative to `adobe_scripts/lib/`
// indexOf polyfill from https://gist.github.com/atk/1034425
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
var Libraries = (function (libPath) {
return {
include: function (path) {
if (!path.match(/\.jsx$/i)) {
@jasonrhodes
jasonrhodes / jqExists.js
Last active December 15, 2015 19:48
Check if jQuery is on the page and if it's at least at a certain version. Use "*" for any number at a specific point, ie (jqExists("1.8.*") or (jqExists("1.8"))
var jqExists = function (version) {
var existingVersion = jQuery && jQuery.fn.jquery;
if (!existingVersion) return false;
current = existingVersion.split(".");
required = version.split(".");
for (var i=0; i<required.length; i++) {
if (required[i] === "*") return true;
@jasonrhodes
jasonrhodes / testablePlugin.js
Created April 4, 2013 21:20
One way to build a unit-testable jQuery plugin.
var myWidgetCreator = (function ($, lib) {
var Creator = {};
Creator.create = function (args) {
// 'this' is the captured jQuery object
// because we called 'apply' from the widget
this.html(Creator.doSomething());
};
@jasonrhodes
jasonrhodes / jscacher.php
Last active December 15, 2015 20:29
A persistent cache strategy using PHP's APC object cache from a Javascript MVC framework client-side, like Ember.js or Backbone.js, etc.
<?php
// This is the index.php file with some kind of router
$router->get("/jscacher/:key", function ($key) {
echo json_encode(["cached" => apc_fetch($key)]);
});
$router->post("/jscacher", function () use ($router) {
$request = $router->getRequest();
@jasonrhodes
jasonrhodes / Scientist.js
Last active September 27, 2019 14:36
Helper library for working with Google Analytics.
/**
* Scientist.js
*
* A small helper library for working with Google Analytics.
*
* @author Jason Rhodes
* @version 0.2
*
*/
var Scientist = function (analytics) {
// Throttle: only execute callback if more than 'wait' ms have passed since last successful call
var throttle = function (wait, func) {
var last;
return function () {
var now = new Date();
if (now - last < wait {
return;
}
func.apply(this, arguments);
last = now;
@jasonrhodes
jasonrhodes / use-hub-widget.html
Last active December 16, 2015 16:09
Drop this HTML into your page where you want the widget to appear. More options: https://github.com/johnshopkins/hubWidget
<script src="http://hub.jhu.edu/assets/shared/js/hubwidget.2.0.min.js"></script>
<div id="hubWidget"></div>
@jasonrhodes
jasonrhodes / hub-jquery-widget-usage.js
Last active December 16, 2015 16:09
Use jQuery to drop the widget in any existing location on your site. More options: https://github.com/johnshopkins/jquery.hubwidget
// Assumes you have loaded the jQuery plugin found at: https://raw.github.com/johnshopkins/jquery.hubwidget/master/js/jquery.hubwidget.js
jQuery(document).ready(function ($) {
$(".my-widget-div").hubWidget({
// optional options
});
});