Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jamischarles's full-sized avatar

Jamis Charles jamischarles

View GitHub Profile
@jamischarles
jamischarles / get.js
Last active January 8, 2020 23:10
Rebuilding simple version of _.get()
function get(base, pathQuery, returnOnUndefinedValue) {
var pathArr = pathQuery.split('.');
var currentVal = base;
for (var i=0; i<pathArr.length; i++) {
var key = pathArr[i];
currentVal = currentVal[key];
if (!currentVal) {
return returnOnUndefinedValue ;
}
}
@jamischarles
jamischarles / git_commands.sh
Last active March 14, 2019 13:07
Git cheat sheet
- my normal flow?
- good commit messages ******
- searching commit messages (group by keywords)
- searching code *
- working with history (viewing, time traveling)
- rebasing (for pulling & squashing, splitting a commit) *
- undoing local commits (soft, hard reset)
- forgot to add / change message (amend)
- LOST commits? *
@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
@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 / 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 / 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 / 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 / .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 / 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 / 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
}