Skip to content

Instantly share code, notes, and snippets.

@daniellealexis
daniellealexis / GeneratedExampleProvider.tsx
Last active September 5, 2021 02:51
Generate Typescript React Provider
import React, { useContext, useState } from 'react';
type GeneratedExampleContextValue = {};
type GeneratedExampleContextType = [
GeneratedExampleContextValue,
React.Dispatch<React.SetStateAction<GeneratedExampleContextValue>>
];
const defaultProviderValue: GeneratedExampleContextValue = {};
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}
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}
var coffeeShoppe = {};
coffeeShoppe.coffee = 5.25;
coffeeShoppe.latte = 4.25;
coffeeShoppe.cheesecake = 4.00;
coffeeShoppe.getProductPrice = function(productName){
return this[productName];
}
@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;
@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 / 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 / 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 / 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');