Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
@barneycarroll
barneycarroll / posit.js
Last active August 29, 2015 13:55
Returning positive or negative of given number based on boolean.
function posit( x, positivity ){
return x * ( positivity * 2 - 1 );
}
@barneycarroll
barneycarroll / jquery.sel.js
Created February 17, 2014 13:11
Selects the text of the scoped element.
// 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 March 6, 2014 12:26
Dummy JSON for tests
{
"foo" : "bar"
}
@barneycarroll
barneycarroll / commented.json
Last active August 29, 2015 13:57
Comment JSON while keeping validity
{
"" : "// 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 / jquery.csi.js
Created March 28, 2014 16:49
A recursive version of csi.js [https://github.com/LexmarkWeb/csi.js] using jQuery. Allows nested templates!
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 April 3, 2014 18:03
Generic mixin to increase the specificity of the contents rules
// 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 April 25, 2014 12:39
Log out a tree structure of a DOM element's ancestry
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 August 29, 2015 14:00
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.
// 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 August 29, 2015 14:02
_.superMerge: Like merge, but concatenates plucked arrays (rather than overwriting with the rightmost).
_.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();
@barneycarroll
barneycarroll / SassMeister-input.scss
Created June 11, 2014 05:10
Generated by SassMeister.com.
// ----
// Sass (v3.3.8)
// Compass (v1.0.0.alpha.19)
// ----
// Placeholder using &
// ---
%C {
Z & {
property: value;