Skip to content

Instantly share code, notes, and snippets.

View lemonmade's full-sized avatar

Chris Sauve lemonmade

View GitHub Profile
@lemonmade
lemonmade / SassMeister-input.scss
Created March 25, 2015 18:30
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
@mixin foo {
@at-root {
.foo#{&} {
@content;
}
#*
# Decodes HTML entities into their regular string values.
#
# @private
# @param {String} str - The encoded string.
# @returns {String} The decoded string.
decode_html_entities = (str) ->
element = document.createElement('div')
element.innerHTML = str.trim()
@lemonmade
lemonmade / SassMeister-input.scss
Last active October 30, 2015 00:12
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
$foo: 10;
.foo {
$foo: 20;
border-width: $foo; // 20
@lemonmade
lemonmade / UIBannerInReact.js
Last active January 13, 2016 15:39
Ideas for using attributes as styling hooks in Shopify's admin
import React, {Component} from 'react';
import {UIBanner} from 'UIComponents';
export default class MyComponent extends Component {
render() {
return <UIBanner emphasized status="success" />
}
}
chai = require('chai')
beforeEach ->
this.assert = chai.assert
|- app
| |- assets
| | |- javascripts
| | | |- popover.js
| | |- stylesheets
| | | |- popover.scss
| |- helpers
| | |- ui_popover.rb
| |- views
| | |- styleguide
@lemonmade
lemonmade / FlowTester.js
Last active January 3, 2017 18:55
To type or not to type
// @flow
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
type TestDetails<T: HTMLElement> = {
node: HTMLElement,
};
type Props = {
import {DataProxy} from 'apollo-client/data/proxy';
import {
ApolloClient,
} from 'apollo-client';
import {DocumentNode} from 'graphql';
import {get} from 'lodash';
import {Status} from '../network';
import stagedFileUploadMutation, {StagedFileUploadMutationData} from './StagedFileUploadMutation.graphql';
import {Component} from 'react';
const cache = new WeakMap<Component<any, any>, Map<string, any>>();
export function toggleState<S>(component: Component<any, S>, key: keyof S) {
const cachedToggles = cache.get(component) || new Map();
if (cachedToggles.has(key)) { return cachedToggles.get(key); }
const toggle = () => component.setState((state) => ({[key]: !state[key]}));
cachedToggles.set(key, toggle);
@lemonmade
lemonmade / Component.test.js
Created April 17, 2018 23:11
Partial Jest mock
import {utility} from './support';
jest.mock('./support', () => ({
...require.requireActual('./support'),
utility: jest.fn(),
}));