Skip to content

Instantly share code, notes, and snippets.

🤑
Looking for work

Barney Carroll barneycarroll

🤑
Looking for work
Block or report user

Report or block barneycarroll

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
@barneycarroll
barneycarroll / posit.js
Last active Aug 29, 2015
Returning positive or negative of given number based on boolean.
View posit.js
function posit( x, positivity ){
return x * ( positivity * 2 - 1 );
}
@barneycarroll
barneycarroll / jquery.sel.js
Created Feb 17, 2014
Selects the text of the scoped element.
View jquery.sel.js
// Selects the text of the scoped element.
// Courtesy of @jcubic: http://stackoverflow.com/a/21829549/356541
$.fn.sel = function selectText() {
var node = this[0];
if ( document.body.createTextRange ) {
var range = document.body.createTextRange();
range.moveToElementText( node);
range.select();
} else if ( window.getSelection ) {
@barneycarroll
barneycarroll / foobar.json
Created Mar 6, 2014
Dummy JSON for tests
View foobar.json
{
"foo" : "bar"
}
@barneycarroll
barneycarroll / commented.json
Last active Aug 29, 2015
Comment JSON while keeping validity
View commented.json
{
"" : "// Start Zepto ",
"zepto" : "../../lib/zepto/zepto",
"zepto-extras" : "../../lib/zepto/zepto-extras",
"zepto-slide-transition" : "../../lib/zepto/zepto-slide-transition",
"zepto-fx-methods" : "../../lib/zepto/zepto-fx-methods",
"" : "// End Zepto ",
"" : "// Start jQuery ",
"jquery" : "../../lib/jquery/jquery-1.10.2",
@barneycarroll
barneycarroll / target.support.js
Created Mar 25, 2014
Attempt at detecting CSS `:target` support
View target.support.js
// Determine whether or not we need to run fallback code by testing for `:target` support.
var targetSupport = ( function targetSupport(){
var iframe = document.createElement( 'iframe' );
var body = document.getElementsByTagName( 'body' )[ 0 ];
var doc;
var outcome;
iframe.tabindex = -1;
iframe.style.display = 'none';
@barneycarroll
barneycarroll / jquery.csi.js
Created Mar 28, 2014
A recursive version of csi.js [https://github.com/LexmarkWeb/csi.js] using jQuery. Allows nested templates!
View jquery.csi.js
jQuery.csi = function csi( context ){
$( '[data-include]', context || document ).each( function fetchPartial(){
var $placeholder = $( this );
var location = $placeholder.attr( 'data-include' );
$.ajax( { url : location, async : false } ).done( function injectPartial( response ){
var $partial = $( response );
csi( $partial );
@barneycarroll
barneycarroll / increase-specificity.scss
Created Apr 3, 2014
Generic mixin to increase the specificity of the contents rules
View increase-specificity.scss
// Increase class-level specificity of a rule without functionaly modifying the selector
@mixin increase-specificity( $depth: 1 ) {
$sel : '';
@while($depth > 0) {
$sel : $sel + ':nth-child(n)';
$depth : $depth - 1;
}
&#{$sel} {
@barneycarroll
barneycarroll / gist:11288260
Created Apr 25, 2014
Log out a tree structure of a DOM element's ancestry
View gist:11288260
function getParentStructure( el ){
var $el = $( el );
var indent = '';
var output = '';
_.chain( $el.parents() ).reverse().map( function convertToString( parent ){
var attributes = parent.attributes;
output += indent + '<' + parent.tagName.toLowerCase();
@barneycarroll
barneycarroll / returner.js
Last active Aug 29, 2015
returner is a convenience function that allows you to invoke mutator methods on arrays (or anything else) and return the mutated array itself rather than some arbitrary property of that array.
View returner.js
// returner is a convenience function that allows you to invoke mutator methods on arrays (or anything else)
// and return the mutated array itself rather than some arbitrary property of that array.
//
// Why?
// I have never been convenienced by the returned length of an array after pushing to it.
// I have often wanted to push to an array and return it with the same statement.
//
// Seriously? Like, when?
// Can I use a word in its own definition? At line 27, I want to modify an array and return it.
// Thanks to returner, I'm evaluating that as a function argument expression.
@barneycarroll
barneycarroll / _.superMerge.js
Last active Aug 29, 2015
_.superMerge: Like merge, but concatenates plucked arrays (rather than overwriting with the rightmost).
View _.superMerge.js
_.mixin( {
// Like uniq, but tests for equivalence rather than identity.
// Does this by running comparison on stringified representations.
// DOM nodes and other objects with circular references can't be stringified and will break.
looseUniq : function uniqBasedOnStringify( source ){
var output = _( source )
.map( function stringify( x ){ return JSON.stringify( x ); } )
.uniq()
.map( function parse( x ){ return JSON.parse( x ); } )
.valueOf();
You can’t perform that action at this time.