Skip to content

Instantly share code, notes, and snippets.

Jamis Charles jamischarles

  • PayPal
  • near Boulder, CO
View GitHub Profile
@jamischarles
jamischarles / mdx
Created Feb 20, 2019
Generated mdx file
View mdx
---
slug: introducing-the-react-testing-library
date: 2019-02-18
title: Introducing the react-testing-library 🐐
description: "NOTE: This is a cross-post from my newsletter. I publish each email two weeks after it’s sent. Subscribe to get more content like this earlier right in your inbox! 💌 Two weeks ago, I wrote a new…"
categories: ['React']
keywords: [React,JavaScript,Testing]
banner: './images/banner.jpg'
---
@jamischarles
jamischarles / chainMiddleware.js
Last active Dec 9, 2017
Simple example showing how to chain functions similar to how middleware is chained in express.js
View chainMiddleware.js
// simple example of how to create a function that calls a middleware chain, similar to express middleware
var req = {type: "req"};
var res = {type: "res"};
// 3 middlewares
var first = function(req, res, next) {
req.first = true; //easy way to verify that all have been executed
res.first = true;
return next();
@jamischarles
jamischarles / main.js
Last active Nov 26, 2017
node debugging via inspector api
View main.js
var http = require('http')
// Expectation: When I curl localhost:3000, I want to be able to
var server = http.createServer(function (req, res)
res.statusCode = 200;
res.write(e.stack); // throws exception
res.end()
})
@jamischarles
jamischarles / node_invalid_ssl.js
Created Jun 22, 2016
Node https request to server with invalid SSL certs
View node_invalid_ssl.js
// use this when you can curl an https server, but node request() will return 'econnreset: socket hang up'
var options = {
url: 'https://some/site',
method: 'POST',
// these 3 lines matter
strictSSL: false,
secureProtocol: 'TLSv1_method',
rejectUnhauthorized: false
}
@jamischarles
jamischarles / npm_install_autocomplete_zsh
Last active Jul 4, 2016
npm install autocompletion for bash & zsh. Provides content of `~/.npm` as autocomplete options for `npm install` https://medium.com/@jamischarles/adding-autocomplete-to-npm-install-5efd3c424067#.8w0jzkh3w
View npm_install_autocomplete_zsh
#!/usr/bin/env zsh #adding this to force silly gist highlighting. REMOVE THIS
# ZSH standalone npm install autocompletion. Add this to ~/.zshrc file.
_npm_install_completion() {
local si=$IFS
# if 'install' or 'i ' is one of the subcommands, then...
if [[ ${words} =~ 'install' ]] || [[ ${words} =~ 'i ' ]]; then
# add the result of `ls ~/.npm` (npm cache) as completion options
View npm_completion_with_install
#!/usr/bin/env bash #adding this to force silly gist highlighting. REMOVE THIS
# This is a modified version of the script generated by https://docs.npmjs.com/cli/completion to include `npm install` autocompletion.
# Basically we added `if` blocks to check for `install` subcommand.
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
@jamischarles
jamischarles / .npm_install_autocomplete
Last active May 27, 2016
Make these changes to augment your local npm autocompletion to include autocomplete for `npm install`
View .npm_install_autocomplete
#!/usr/bin/env bash #adding this to force silly gist highlighting
# If you are already using npm autocompletion via (https://docs.npmjs.com/cli/completion), I assume that you have some code in
# your .bashrc/.zshrc file. Follow the instruction below to avoid clobbering the npm autocomplete script.
#####################
#### FOR BASH change THIS (in your .bashrc file)
#####################
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
@jamischarles
jamischarles / .npm_install_autocomplete_bash
Last active Jul 13, 2016
npm install autocompletion for bash. Provides content of `~/.npm` as autocomplete options for `npm install` https://medium.com/@jamischarles/adding-autocomplete-to-npm-install-5efd3c424067#.8w0jzkh3w
View .npm_install_autocomplete_bash
#!/usr/bin/env bash #adding this to force silly gist highlighting. REMOVE THIS
# BASH standalone npm install autocomplete. Add this to ~/.bashrc file.
_npm_install_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
@jamischarles
jamischarles / es6_functions.js
Created Oct 13, 2015
es6 functions explained...
View es6_functions.js
// method shorthand. ES6 version.
{
initialize() {},
doSomething() {}
}
// replaces (ES5)
{
You can’t perform that action at this time.