Skip to content

Instantly share code, notes, and snippets.

@thurt
thurt / ExampleQueryParameters.js
Last active April 2, 2020 21:31
Manually get or set more than one query parameter
import React, { useEffect, useState } from "react";
import { useLocation, useHistory } from "react-router";
const ExampleQueryParameters = () => {
const history = useHistory();
const [state, setState] = useState(
Object.fromEntries(new URLSearchParams(useLocation().search))
);
useEffect(() => {
@thurt
thurt / ExampleQueryParam.js
Created April 2, 2020 18:36
Manually getting and setting query parameter in a component
import React, { useEffect, useState } from "react";
import { useHistory, useLocation } from "react-router";
const ExampleQueryParam = () => {
const history = useHistory();
const location = useLocation();
const [q, setQ] = useState(new URLSearchParams(location.search).get("q"));
useEffect(() => {
history.replace("?" + new URLSearchParams([["q", q]]).toString());
@thurt
thurt / specification.yaml
Created January 16, 2020 19:54
photo sharing specification file
openapi: 3.0.1
info:
title: Photo Sharing Service
version: "1.0.0"
servers:
- url: http://localhost:3000/api
description: localhost
- url: https://{domain}/api
description: Production Server
variables:
@thurt
thurt / Include-in-Sequelize.md
Created May 15, 2019 20:49 — forked from zcaceres/Include-in-Sequelize.md
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

#!/bin/bash
# Verify Ruby is installed (Installed by default in MacOS)
if [ -x !"$(command -v ruby)" ]; then
echo 'Ruby is not installed. See instructor.'
exit 1
fi
# Install Homebrew
if [ ! -x "$(command -v brew)" ]; then
import React, { Component } from "react";
import "./index.css";
import todosList from "./todos.json";
class App extends Component {
state = {
todos: todosList
};
handleCreateTodo = event => {
@thurt
thurt / gitlab-ci.yml
Created February 20, 2019 04:46
Publish your create-react-app website via Gitlab CI. tags: #gitlab #git #deploy #ci
image: node:6.5.0 # can be upgraded, depending on your node version used
pages:
stage: deploy
script:
- npm install
- npm run build
- rm -rf public
- mv build public
artifacts:
function zipObject(keys, values) {
// often simple edge cases are taken care of at the top so they aren't hidden inside the middle of the function
if (keys === undefined && values === undefined) {
return {}; // for test 3
}
// category of problem: convert [] -> {}
// simple strategy for conversion problems is to create a blank object at the beginning, build it up in the middle, return it at the end
// create blank starter obj

Enable Docker Remote API with TLS client verification

Docker's Remote API can be secured via TLS and client certificate verification.
First of all you need a few certificates and keys:

  • CA certificate
  • Server certificate
  • Server key
  • Client certificate
  • Client key

Create certificate files

@thurt
thurt / build.sh
Created May 6, 2018 23:43 — forked from bobbytables/build.sh
Protocol Buffer build script for multiple folders
#!/usr/bin/env bash
# This script is meant to build and compile every protocolbuffer for each
# service declared in this repository (as defined by sub-directories).
# It compiles using docker containers based on Namely's protoc image
# seen here: https://github.com/namely/docker-protoc
set -e
REPOPATH=${REPOPATH-/opt/protolangs}
CURRENT_BRANCH=${CIRCLE_BRANCH-"branch-not-available"}