Skip to content

Instantly share code, notes, and snippets.

@daniellealexis
daniellealexis / toggleClass.js
Created August 18, 2016 02:25
jQuery's toggleClass Function's Second Argument
// 5 lines?! Ugh
if( isTheThing ) {
$element.addClass('new-class');
} else {
$element.removeClass('new-class');
}
// At least it's one line now..
( isTheThing ) ? $element.addClass('new-class') : $element.removeClass('new-class');
@daniellealexis
daniellealexis / FindView.js
Last active August 21, 2016 03:44
Backbone 'find' Shortcut
// Where's that thing?
this.$el.find('.thing');
// Ooh yes, that thing!
this.$('.thing');
// Let's store this thing for easy use later!
this.$thing = this.$('.thing');
@daniellealexis
daniellealexis / cssStyles.js
Created August 22, 2016 01:24
Shorthand for jQuery .css without knowing the current value
var $element = $('#myThing'),
elementPaddingLeft = $element.css('paddingLeft'),
newValue = elementPaddingLeft + 20;
$element.css('paddingLeft', newValue);
// How about all at once?
var $element = $('#myThing');
$element.css('paddingLeft', '+=20');
@daniellealexis
daniellealexis / index.styl
Created February 8, 2017 02:04
Globbing Stylus Files
@require 'sub-styles/vars'
@require 'sub-styles/header'
@require 'sub-styles/article'
@require 'sub-styles/footer'
//vs.
@require 'sub-styles/vars'
@require 'sub-styles/*'
@daniellealexis
daniellealexis / productButton.jsx
Last active January 16, 2018 00:40
Creating a custom wrapper around an imported component
import React from 'react';
import PropTypes from 'prop-types';
import RaisedButton from 'material-ui/RaisedButton';
import { BUTTON_COLOR } from 'colors';
const ProductButton = (props) => (
<RaisedButton
{...props}
/>
);
@daniellealexis
daniellealexis / coffeeShoppe.js
Last active January 28, 2018 06:37
Example of bad code
var coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
coffeeShoppe.order = function(p) {
let t = 0;
const l = p.length;
var coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
coffeeShoppe.getProductPrice = function(productName){
return this[productName];
}
var coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
/**
* Get the price of the passed-in product name
* @param {string} productName
* @return {number|undefined}
const coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
/**
* Get the price of the passed-in product name
* @param {string} productName
* @return {number|undefined}
const coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
/**
* Get the price of the passed-in product name
* @param {string} productName
* @return {number|undefined}