Skip to content

Instantly share code, notes, and snippets.


Brett brettinternet

Block or report user

Report or block brettinternet

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
brettinternet / CatchOrCallback.js
Last active Dec 10, 2019
.Then Callback vs .Catch and how they're scoped
View CatchOrCallback.js
.then(() => {
throw new Error('This will be handled in the next .then(, err), OR in a .catch'); // comment this line to see the next error handled
.then(() => {
throw new Error('This will only be handled in a .catch');
}, error => {
// an alternative to .catch with less scope
// thus, with this method there's a block of code where errors could be left unhandled
brettinternet /
Created Nov 12, 2019
Event Delegation example

Event delegation is a technique involving adding event listeners to a parent element instead of adding them to the descendant elements. The listener will fire whenever the event is triggered on the descendant elements due to event bubbling up the DOM.

The benefits of this technique are:

  • Memory footprint goes down because only one single handler is needed on the parent element, rather than having to attach event handlers on each descendant.
  • There is no need to unbind the handler from elements that are removed and to bind the event for new elements.
View docker-compose.yml
version: "3.7"
name: traefik_proxy
driver: bridge
brettinternet / copyStyles.js
Created Dec 18, 2018
Copy styles from current document to a new document
View copyStyles.js
// from
function copyStyles(sourceDoc, targetDoc) {
Array.from(sourceDoc.styleSheets).forEach(styleSheet => {
if (styleSheet.cssRules) { // true for inline styles
const newStyleEl = sourceDoc.createElement('style');
Array.from(styleSheet.cssRules).forEach(cssRule => {
brettinternet / cssConcat.js
Created May 9, 2018
Concatination helper, which can merge class names together. Skips over falsey values.
View cssConcat.js
function css() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
var classes = [];
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
var arg = args_1[_a];
if (arg) {
if (typeof arg === 'string') {
brettinternet / App.js
Last active Feb 15, 2018
Fast API call with Create-react-app
View App.js
import React, { Component } from 'react';
import { BrowserRouter, Route, NavLink, Link, Switch, Redirect } from 'react-router-dom';
import axios from 'axios';
class HomePage extends Component {
View ReactBindingApproaches.js
// Approach 1: Use React.createClass
var HelloWorld = React.createClass({
getInitialState() {
return { message: 'Hi' };
logMessage() {
// this magically works because React.createClass autobinds.

Static fields (as class properties)

class UserSerializer(serializers.Serializer):
  email = serializers.EmailField()
  name = serializers.CharField()

Dynamic fields (overriding fields property)

class UserSerializer(serializers.Serializer):


URL Method Query Body Data returned Permissions Description
api/users/ GET List of users List users for requesting user's company
company=# filter by company Admins only



brettinternet /
Last active Nov 15, 2018
phone number regex validator
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.core.validators import RegexValidator
# ...
class User(AbstractBaseUser):
# ...
phone_number = models.CharField(
You can’t perform that action at this time.