Skip to content

Instantly share code, notes, and snippets.

Adam Brewer adamcbrewer

Block or report user

Report or block adamcbrewer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamcbrewer
adamcbrewer / getCarat.js
Last active Dec 23, 2015
JS: Get and set the position of a carat/cursor for an element.
View getCarat.js
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-sass-helpers.scss
Last active Aug 2, 2018
SASS: Helpers and mixins for using with SASS
View css-sass-helpers.scss
//============================================================
// Typography
//============================================================
// An rem font-size mixin providing fallback to px
@mixin font-size($sizeValue: 1.4) {
$remValue: $sizeValue;
$pxValue: ($sizeValue * 10);
font-size: #{$pxValue}px;
font-size: #{$remValue}rem;
@adamcbrewer
adamcbrewer / css-less-helpers.less
Last active Dec 22, 2015
LESS: Helpers and mixins for using LESS
View css-less-helpers.less
//============================================================
// Structure, Flow and Layout
//============================================================
// inline-block fix incl. ie7 support
.inline-block {
display: inline-block;
*display: block;
*zoom: 1;
}
@adamcbrewer
adamcbrewer / node.sh
Created Jul 23, 2013
NODE: Run a daemon node.js server and create virtualhost to forward all site traffic to the specified port.
View node.sh
# This command will make sure the process persists
# even after you log out of a session
node server.js >/dev/null 2>&1 &
@adamcbrewer
adamcbrewer / webkit-css-mask.css
Created Jun 25, 2013
CSS: overflow/border-radius mask bug-thingy
View webkit-css-mask.css
/*
* There's a bug in Chrome/Safari using overflow:hidden with border-radius. This mask fixes it.
* Solution: http://stackoverflow.com/questions/5736503/how-to-make-css3-rounded-corners-hide-overflow-in-chrome-opera/10296258#10296258
*/
.masked {
position: absolute;
border-radius: 10px;
overflow: hidden;
/* this fixes the overflow:hidden in Chrome */
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
View stripProtocols.js
/**
* 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 Mar 20, 2013
JS: Newline to <br>
View nl2br.js
/**
* 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 />");
@adamcbrewer
adamcbrewer / queryToObject.js
Created Mar 20, 2013
JS: Query string to object
View queryToObject.js
/**
* Converts a URL query string to a javascript object
*
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com
*
* Usage: "?test=true&something=false".queryToObj(?);
*
* Output: {test: true, something: false}
*
*/
@adamcbrewer
adamcbrewer / ga-tracker.js
Last active Dec 14, 2015 — forked from stugoo/event-tracker-modernizr.js
JS: GA tracker with support for Modernizr tests
View ga-tracker.js
/**
* A Google Analytics event tracking proxy.
*
* This lobal allows us to do tests for the instantiation of _gaq
* and also allows us easier debugging in a test environment.
*
* Hat-tip to @stugoo for most the self-invoked function features!
*
*/
window.track = function (args) {
@adamcbrewer
adamcbrewer / extend.js
Created Feb 20, 2013
JS: Extending/merging one object with another.
View extend.js
/**
* An extend function to merge some default arguments
* with those passed in from the user.
*
* @param {object} obj The default settings
* @param {object} extObj Arguments from the user
* @return {object} A merged object
*
*/
var extend = function (obj, extObj) {
You can’t perform that action at this time.