Skip to content

Instantly share code, notes, and snippets.

View btpoe's full-sized avatar

Brandon Poe btpoe

View GitHub Profile
@btpoe
btpoe / routes.js
Last active October 31, 2018 15:19
i18n example
import text from 'text_en.json?i18n';
export default [
{
path: `/:country(${text.country})/:state/:city/${text.profile}/:category/:name-:bbbId-:businessId`,
id: 'businessprofile',
component: BusinessProfile,
},
{
path: `/:country(${text.country})(/:state)(/:city)/${text.categories}(/:letter)`,
Typekit.load({async:true,active:function() {
Array.prototype.some.call(document.head.children, function (node) {
if (node.tagName === 'STYLE' && node.innerHTML.indexOf('typekit.net') > -1 && node.innerHTML.indexOf('@font-face') > -1) {
window.localStorage.setItem('ts.fontFace', node.innerHTML);
return true;
}
return false;
});
}});
<?php
namespace vendorName\pluginName\controllers;
use Craft;
use craft\helpers\Assets;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\web\Controller;
class ExampleController extends Controller {
@btpoe
btpoe / LowLevel.js
Created April 12, 2017 16:07
React Service Layer
import React, { Component, createElement } from 'react';
import items from './items-service.js';
function handleRemoveItem(name) {
return () => {
items.remove(name);
};
}
export default props =>

Imports

  • can not be conditional ( if (someVar) { import 'path' }
  • can not be evaluated ( import 'path-' + someVar )
Feature Node.js Browserify ES Import
Conditional require yes yes no
Dynamic path yes no no
@btpoe
btpoe / _slope-calc.scss
Last active February 8, 2017 18:47
Smooth transitions for different screen widths
////////////////////////////
// Slope Calc Mixin //
////////////////////////////
//
// Usage:
//
// .my-widget {
// @include slope-calc(padding, 20px 320px, 60px 1440px, 60px 1441px);
// }
//
// # Anatomy of an ES2015 Javascript Module
// *for older modules, see:* [ES5 Javascript Module](https://gist.github.com/btpoe/de6fd193b7dc822ef3a6)
// ## Module Defaults
// Important to note: These are shared across all instances and will only be calculated once.
// Export the defaults so that other modules can read them if necessary.
export const DEFAULTS = {
param: 'default_value'
};
@btpoe
btpoe / _variables.scss
Created January 29, 2016 19:27
Example SCSS breakpoint variables
// takes a em value and returns the value 1 less pixel
@function rev($unit) {
@return $unit - (1/16);
}
// ****************** //
// * Breakpoints * //
// ****************** //
// # Anatomy of a Javascript Module
// *for newer modules, see:* [ES2015 Javascript Module](https://gist.github.com/btpoe/55470d6b4b8bfca56e8f)
// ## The Constructor
// First, define a constructor function. The goal is to keep this function as lightweight as
// possible. For the first argument, we're going to receive an HTMLElement. This element is
// critical because it is essentially the key to this module instance. The second argument is all
// of the developer defined options for this particular instance. For any option used, we should
// declare a default (seen below) to prevent the module from breaking if certain options are not
// provided.