Skip to content

Instantly share code, notes, and snippets.

View Weiyuan-Lane's full-sized avatar
🐈
Code. Code! CODE! CODE!!!!!!

Weiyuan Liu Weiyuan-Lane

🐈
Code. Code! CODE! CODE!!!!!!
View GitHub Profile

Intro

Sequelize is a promise-based Node.js ORM for Postgres, and I totally didn't copy this from the documentation XD

Here's some common usages to get you started

Code Generator, using the terminal

With sequelize, what we want to do is utilise the principle of "migrations" to create and update your content at different points of development (as and when tables are updated). Simply put it's files with timestamps, and when applying new migration files, previously applied migration files will not be applied again.

@Weiyuan-Lane
Weiyuan-Lane / wait-and-go
Created November 20, 2019 10:28
Watcher for go using inotify-tools
#!/bin/sh
# This shell script accepts two parameters
# $1 - to compile and run the main service code. e.g. `go run main.go`
# $2 - files/dir to watch from local dir context
#
# Note that a inotify-tools dependency is required here.
# apt-get install inotify-tools
# OR
# apk --no-cache add inotify-tools
@Weiyuan-Lane
Weiyuan-Lane / speedrun_script
Last active December 4, 2019 07:08
No more GUI for GCP speedrun! CLI is enough!
#!/bin/sh
project=$1
billingId=$2
# Create Project
gcloud projects create $project
# Variables to be used later on
projectId=`gcloud projects list --format="get(projectNumber)" --limit=1 --filter="projectId=$project"`
@Weiyuan-Lane
Weiyuan-Lane / cloudbuild.yaml
Created January 12, 2020 10:55
Cloud Build configuration for deploying App Engine and Cloud Run with a node application
timeout: '600s'
steps:
- id: init
waitFor: ['-']
name: 'gcr.io/cloud-builders/npm'
args: ['install']
- id: frontendTest
waitFor: ['init']
name: 'gcr.io/cloud-builders/npm'
@Weiyuan-Lane
Weiyuan-Lane / app.yaml
Created January 12, 2020 11:12
app.yaml sample for deploying to app engine
runtime: nodejs10
instance_class: B1
manual_scaling:
instances: 1
handlers:
- url: /static
static_dir: static
- url: /public
static_dir: public
export AWS_ACCESS_KEY_ID="access-key-id"
export AWS_SECRET_ACCESS_KEY="secret-access-key"
export AWS_SESSION_TOKEN="session-token"
[default]
aws_access_key_id = "user-access-key-id"
aws_secret_access_key = "user-secret-access-key"
[mfa-user]
aws_access_key_id = "temp-access-key-id"
aws_secret_access_key = "temp-secret-access-key"
aws_session_token = "temp-session-token"
@Weiyuan-Lane
Weiyuan-Lane / init-mfa.sh
Last active March 23, 2023 04:55
Initialisation script for MFA with awscli
#!/bin/sh
# Default filename values - change this or add as environment values, depending on your own needs
MFA_SERIAL_FILE=".mfaserial"
# For variable value of $TMP_DIR, you can either set this as a path that is .gitignored in this project, for saving this developer's context for this project, or a absolute path from root as a system configuration. wrap this script with some other environment variable injected for this value
mkdir -p $TMP_DIR
# A loop to continue prompting the user for the device serial code until a non-empty string is returned
echo "Tip - You can get your ARN for MFA device here: https://console.aws.amazon.com/iam/home#/security_credentials"
@Weiyuan-Lane
Weiyuan-Lane / mfa-auth.sh
Last active March 23, 2023 04:54
Authentication steps for MFA using AWS Cli
#!/bin/bash
# Copyright (c) 2020 by Liu Weiyuan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@Weiyuan-Lane
Weiyuan-Lane / nullish-coalescing-example.js
Last active January 28, 2020 15:49
Showcase nullish coalescing in JavaScript
const strVar = '';
const numVar = 0;
const boolVar = false;
const nullVar = null;
const undefinedVar = undefined;
// Example for OR operator ||
console.log("strVar || 'default string' = ");
console.log(`'${strVar || 'default string'}'`); // Output will be 'default string'