Skip to content

Instantly share code, notes, and snippets.

View adamcbrewer's full-sized avatar

Adam Brewer adamcbrewer

View GitHub Profile
@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-sass-helpers.scss
Last active August 23, 2023 23:04
SASS: Helpers and mixins for using with SASS
//============================================================
// 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 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 / node.sh
Created July 23, 2013 08:38
NODE: Run a daemon node.js server and create virtualhost to forward all site traffic to the specified port.
# 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 June 25, 2013 16:04
CSS: overflow/border-radius mask bug-thingy
/*
* 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);
@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 />");
@adamcbrewer
adamcbrewer / queryToObject.js
Created March 20, 2013 11:25
JS: Query string to object
/**
* 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 December 14, 2015 01:09 — forked from stugoo/event-tracker-modernizr.js
JS: GA tracker with support for Modernizr tests
/**
* 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 February 20, 2013 10:30
JS: Extending/merging one object with another.
/**
* 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) {