Skip to content

Instantly share code, notes, and snippets.

@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

@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:

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"}
@thurt
thurt / gist:88df0e404b38b8923355ad0b9a700cff
Created April 5, 2018 15:16 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@thurt
thurt / smtp-gmail-send.go
Created March 3, 2018 16:33 — forked from jpillora/smtp-gmail-send.go
Send email using Go (Golang) via GMail with net/smtp
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
@thurt
thurt / docker-compose.yml
Created February 7, 2018 21:44 — forked from ahromis/docker-compose.yml
Gogs docker-compose.yml
version: '3'
services:
postgres:
image: postgres:9.5
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER-root}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD-root}
- POSTGRES_DB=gogs
volumes:
@thurt
thurt / swagger.sh
Created January 28, 2018 23:38 — forked from jimschubert/swagger.sh
Quick script for running swagger codegen cli directly
#!/bin/bash
ver=2.2.0
jar=swagger-codegen-cli-$ver.jar
md5=57e673eb334364ab614cc6083b0f4b27
repo="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/$ver/$jar"
if [ ! -f $jar ]; then
echo "[info] downloading $PWD/$jar from $repo" 1>&2
if ! curl --location --silent --fail --remote-name $repo -o $jar; then
@thurt
thurt / revprox.go
Last active March 31, 2024 05:14 — forked from JalfResi/revprox.go
Simple reverse proxy in Go (forked from original to use a struct instead of a closure)
package main
import(
"log"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {
# Here's how to back up a named volume
# 1. Using a `ubuntu` image, we mount the named volume (`myproj_dbdata`) to a `/dbdata` folder inside the `ubuntu` container.
# 2. Then, we create a new folder inside the `ubuntu` container named `/backup`.
# 3. We then create an archive containing the contents of the `/dbdata` folder and we store it inside the `/backup` folder (inside the container).
# 4. We also mount the `/backup` folder from the container to the docker host (your local machine) in a folder named `/backups` inside the current directory.
docker run --rm -v myproj_dbdata:/dbdata -v $(pwd)/backups:/backup ubuntu tar cvf /backup/db_data_"$(date '+%y-%m-%d')".tar /dbdata