Skip to content

Instantly share code, notes, and snippets.

View flesch's full-sized avatar

John Flesch flesch

View GitHub Profile
# ~/.config/starship.toml
format = """
[♥](bold red)\
${custom.git_user}\
${custom.ip}\
$ruby${custom.bundler}\
$golang\
$nodejs${custom.npm}${custom.yarn}\
$terraform\
@flesch
flesch / findMissingLetters.js
Created July 24, 2019 17:52
JavaScript Interview Code Challenge Solution
// A "pangram" is a sentence that includes every letter of the alphabet.
// Write a function that will return what letters of the alphabet are
// missing from a sentence (thus meaning it is not a pangram).
// "A quick brown fox jumps over the lazy dog" includes every letter, returning ""
// "Lions, and tigers, and bears, oh my!" does not include every letter, returning "cfjkpquvwxz"
function findMissingLetters(str) {
const alphabet = 'abcdefghijklmnopqrstuvwzyz';
if (str.length) {
const reducer = (memo, letter) => {
@flesch
flesch / README.md
Last active July 6, 2019 12:45
📈 Calculate a “Net Promoter Score” from an array of integers. (Array.reduce)

@flesch/net-promoter-score

Calculate a “Net Promoter Score” from an array of integers.

Install

$ npm install --save gist:34e4f906939ee1bafc74b82e64d4cc48
@flesch
flesch / pre-commit
Created August 21, 2018 12:34
Git pre-commit hook to ensure the version in package.json has changed
#!/bin/bash
set -o nounset
if [ "$(git status -s | wc -l | bc)" -gt "0" ]; then
if [ "$(git diff --cached master -G '"version":' | wc -l | bc)" -eq "0" ]; then
echo -e "\033[31m✘\033[0m Aborting commit! \"package.json\" was not updated with a new version."
fi
fi
@flesch
flesch / pkg.sh
Created July 13, 2018 01:43
Read or create a package.json file
# Add this function to .bashrc or .bash_profile
# $ pkg
# $ pkg dependencies # (to show only the dpendencies)
# Requires `jq`
pkg() {
if [ -f package.json ]; then
cat package.json | jq .$1
else
read -p "package.json doesn't exist. Create one? [Y/n] " -n 1 -r
if [[ $REPLY =~ ^(Y|y| ) ]] || [[ -z $REPLY ]]; then
@flesch
flesch / starredRepositories.graphql
Created May 3, 2018 04:01
starredRepositories.graphql
query starredRepositories($repositories: Int = 10, $after: String, $releases: Int = 1) {
viewer {
starredRepositories(first: $repositories, after: $after, ownedByViewer: false, orderBy: {field: STARRED_AT, direction: DESC}) {
pageInfo {
hasNextPage
endCursor
}
edges {
cursor
starredAt
@flesch
flesch / README.md
Last active January 28, 2018 04:05

@flesch/env-json

Inject env.json into process.env.

Install

$ npm install --save gist:333c4fac79f302d411365927ca06d328
const { buildSchema } = require('graphql');
const glob = require('glob-promise');
const { readFile } = require('fs-extra');
const { join } = require('path');
async function stitchSchema(dir) {
const files = await glob(dir);
const contents = await Promise.all(files.map(file => readFile(file, 'utf8')));
return buildSchema(contents.join('\n\n'));
}
@flesch
flesch / scoreboard.js
Created May 29, 2017 03:12
⚾️ MLB Master Scoreboard
const fetch = require('node-fetch');
const format = require('date-fns/format');
const [ year, month, day ] = format(new Date(), 'YYYY-MM-DD').split('-');
const scoreboard = `http://mlb.mlb.com/gdcross/components/game/mlb/year_${year}/month_${month}/day_${day}/master_scoreboard.json`;
fetch(scoreboard).then(res => res.json()).then(json => {
console.log(json);
});
'use strict';
const { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
const Query = new GraphQLObjectType({
name: 'Query',
description: 'The root type defines how GraphQL operations begin. It is the entry point to constructing GraphQL queries.',
fields: () => ({
hello: {
type: GraphQLString,