Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View adamcbrewer's full-sized avatar

Adam Brewer adamcbrewer

View GitHub Profile
@adamcbrewer
adamcbrewer / sortBy.onEdit.gs
Created February 1, 2014 14:43
GS: Automatically sorts the 1st column (not the header row) Ascending.
/**
* Automatically sorts the 1st column (not the header row) Ascending.
*/
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 1;
var tableRange = "A4:Z99"; // What to sort.
@adamcbrewer
adamcbrewer / totype.js
Created November 21, 2013 12:42
JS: A Better typeof operator
/**
* A better, more reliable way to handle `typeof` checking.
*
* @source http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
*
*/
Object.toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
@adamcbrewer
adamcbrewer / interval.js
Created November 21, 2013 12:50
JS: A better interval handler
/**
* setInterval has some issues:
* 1. Doesn't care whether the callback is still running or not
* 2. Ignores errors
*
* @source http://www.thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/
* @param func The function to call
* @param wait The interval to wait
* @param times The total number of repititions, instead of infinite
*
@adamcbrewer
adamcbrewer / hd-media-query.css
Created January 18, 2014 15:34
CSS: HD Media Query Snippet
@media (-webkit-min-device-pixel-ratio: 2),
(min--moz-min-device-pixel-ratio: 2),
(min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
.logo {
background-image: url(../img/logo@2x.png);
}
}
@adamcbrewer
adamcbrewer / typo-transforms.css
Created May 22, 2014 09:19
CSS: Fixing Typography Inside of CSS 2D Transforms
/* This should hopefully fix crappy typography inside of rotated elements.
Taken from http://flippinawesome.org/2014/05/21/fixing-typography-inside-of-css-2-d-transforms/ */
.rotated-typography {
transform: perspective(1px) rotate(-10deg);
/* Using `translateZ(0)` forces GPU rendering (and only fixes -webkit), but `perspective(1px)` does the job nicely. */
/* Don't use -ms prefix, however, as Presto engine in IE9 lacks 3D transform support. */
}
@adamcbrewer
adamcbrewer / share-intents.md
Last active November 9, 2017 07:14
SOCIAL: Share intents on major platforms

Twitter

<a href="http://twitter.com/intent/tweet?url={url_encoded_url}&amp;text={url_encoded_text}&amp;hashtags={url_encoded_hashtags}">Tweet This</a>

Tumblr

<a href="http://www.tumblr.com/share/link?url={url_encoded_url}&amp;name={url_encoded_post_title}&amp;description={url_encoded_post_text}">Share on Tumblr</a>
@adamcbrewer
adamcbrewer / getCarat.js
Last active December 23, 2015 19:59
JS: Get and set the position of a carat/cursor for an element.
function _getCarat(el) {
if (el.selectionStart) {
return el.selectionStart;
} else if (document.selection) {
el.focus();
var r = document.selection.createRange();
if (r == null) {
return 0;
@adamcbrewer
adamcbrewer / css-less-helpers.less
Last active December 22, 2015 22:19
LESS: Helpers and mixins for using LESS
//============================================================
// Structure, Flow and Layout
//============================================================
// inline-block fix incl. ie7 support
.inline-block {
display: inline-block;
*display: block;
*zoom: 1;
}
@adamcbrewer
adamcbrewer / stripProtocols.js
Created March 20, 2013 11:38
JS: Strip protocols
/**
* Strips protocols off strings.
* Usefull for ensuring a consistent base where user input is involved.
*
* Matches:
* http://
* https://
* ftp://
* mailto:
* www.
@adamcbrewer
adamcbrewer / nl2br.js
Created March 20, 2013 11:33
JS: Newline to <br>
/**
* Converts newline characters to HTML <br /> elements
*
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com
*
* Usage: "String goes\n\rhere".nl2br();
*
*/
String.prototype.nl2br = function () {
return this.replace(/(\r\n|\n|\r)/gm, "<br />");