Skip to content

Instantly share code, notes, and snippets.

View jamischarles's full-sized avatar

Jamis Charles jamischarles

View GitHub Profile
@jamischarles
jamischarles / es6_functions.js
Created October 13, 2015 16:51
es6 functions explained...
// method shorthand. ES6 version.
{
initialize() {},
doSomething() {}
}
// replaces (ES5)
{
@jamischarles
jamischarles / .npm_install_autocomplete
Last active May 27, 2016 15:46
Make these changes to augment your local npm autocompletion to include autocomplete for `npm install`
#!/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 / node_invalid_ssl.js
Created June 22, 2016 22:52
Node https request to server with invalid SSL certs
// 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 July 4, 2016 07:23
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
#!/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
@jamischarles
jamischarles / .npm_install_autocomplete_bash
Last active July 13, 2016 03:58
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
#!/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 / functions.php
Created April 25, 2012 11:34
Display links to WordPress blog posts on non-WP pages using the WordPress API.
//add this code at the end of "functions.php" (Theme Functions). This can be accessed through the WP admin menu under Appearance -> Editor -> Theme Functions
//this is the logic to get the posts you want
function displayHomePosts(){
//default values obj from post.php.
//pass these in as args that you really want
$defaults = array(
'numberposts' => 5, 'offset' => 0,
'category' => 0, 'orderby' => 'post_date',
@jamischarles
jamischarles / main.js
Last active November 26, 2017 05:58
node debugging via inspector api
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 / chainMiddleware.js
Last active December 9, 2017 04:45
Simple example showing how to chain functions similar to how middleware is chained in express.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 / mdx
Created February 20, 2019 16:13
Generated mdx file
---
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 / gitmove.sh
Last active February 21, 2019 21:34
Git move - Move file to new repo and preserve history
#!/bin/bash
# $ ./gitmove [destGitRepo] [src_file]
DEST_FOLDER=$1
SOURCE_FILE=$2
# get the earliest hash of a source file to copy
HASH=$(git log --format=%H $SOURCE_FILE | tail -1)
# echo $HASH