Skip to content

Instantly share code, notes, and snippets.

View gabemeola's full-sized avatar
🐛

Gabe gabemeola

🐛
View GitHub Profile
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Loading } from 'components';
export default class Enabler extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
/**
* Bootstrap function to run.
@gabemeola
gabemeola / chunkedEncoding.js
Created January 25, 2018 07:40
Slow-mo Nodejs Chunk Encoding Test
const http = require('http');
const PORT = process.env.PORT || 8080
http.createServer((request, response) => {
response.setHeader('Content-Type', 'text/html; charset=UTF-8');
response.setHeader('Transfer-Encoding', 'chunked');
response.write((
'<!DOCTYPE html>' +
@gabemeola
gabemeola / Queue.js
Created February 6, 2018 18:54
Queue
/**
* Simple Que using linked lists.
* Pushed value can be anything.
*/
class Queue {
constructor() {
this.first = null;
this.last = null;
this.length = 0;
}
@gabemeola
gabemeola / createReducer.js
Created February 7, 2018 00:13
Create a reducer with the cruft cut off
/**
* Creates a reducer with generic reducer logic handle for you.
* For any cases not matched from an `action.type`, the passed state is returned.
*
* @author Gabe M.
* @param {string} name - Name of the Reducer. Redux will use this for store and serialization
* @param {Object} initialState - Initial State Object
* @param {Object} cases - Cases is an object with describe your mutations.
* Key is a matching action.type from a dispatched action.
* Value is a function that accepts state, and action. This should return new non mutated state.
@gabemeola
gabemeola / fetchImage.js
Created April 5, 2018 21:49
Fetches and resolves an image
/**
* Fetches image and returns promise after fetch.
*
* @param {string} imageUrl - Image SRC to fetch
* @return {Promise} Returns promise of imageUrl that was successful
*/
export default function fetchImage(imageUrl) {
return new Promise((resolve, reject) => {
if (imageUrl == null) {
reject('Image is null or undefined', imageUrl);
@gabemeola
gabemeola / validateImage.js
Last active April 5, 2018 22:33
Validate All Images in Array.
import fetchImage from 'https://gist.githubusercontent.com/gabemeola/27e8fd9148f9ae7541d88d54d87f5113/raw/97138b8039f3b598c41832ef4bfdd4e48bcb3ab6/fetchImage.js'
const noop = () => {}
function removeUrlProtocol(url) {
// Split the image to not include protocol
const srcSplit = url.split(':');
// Use the second part of the protocol string
// split, if it exists.
@gabemeola
gabemeola / externals.js
Created May 14, 2018 21:17
Grab all external dependencies from package.json
/**
* Usage:
* import package from './package.json'
*
* externals(package)
*/
function externals(pkg) {
return Object.keys(pkg).reduce((accumulator, key) => {
if (key.match(/dependencies/i)) {
const value = pkg[key];
@gabemeola
gabemeola / main.go
Created May 31, 2018 01:09 — forked from filewalkwithme/main.go
Listening multiple ports on golang http servers (using http.Handler)
package main
import (
"net/http"
)
func main() {
go func() {
http.ListenAndServe(":8001", &fooHandler{})
}()
class SafeURLSearchParams extends URLSearchParams {
static isGarbageBrowser = (() => {
try {
new URLSearchParams(new URLSearchParams('a=a'));
return false;
} catch (e) {
return true;
}
})()
constructor(init) {
@gabemeola
gabemeola / request.js
Created July 18, 2018 20:34
Fetch for old browsers
/**
* Small request wrapper for XMLHttpRequest
* with an API similar to fetch.
*
* @author Gabe M.
* @param {string} url - Resource Url for Request
* @param {Object} config
* @param {string} [config.method=GET] - REST request method
*/
function request(url, { method = 'GET' } = {}) {