Skip to content

Instantly share code, notes, and snippets.

View darrylmorley's full-sized avatar

Darryl Morley darrylmorley

View GitHub Profile
@darrylmorley
darrylmorley / create-docker-image.md
Last active November 5, 2024 11:49
Create Docker Image - Bash Alias

Bash Alias to Create a Docker Image

alias docker-build='function \_docker_deploy() { \
 image_name=$(basename "$PWD"); \
 short_hash=$(git rev-parse --short HEAD); \
  full_tag="registry.digitalocean.com/shootingsupplies/${image_name}:${short_hash}"; \
  docker compose build --no-cache; \
  docker tag "${image_name}" "$full_tag"; \
 docker push "$full_tag"; \
@darrylmorley
darrylmorley / next-robots-txt
Last active June 21, 2024 09:49
NextJS Robots.txt
User-agent: *
# Next.JS Crawl Budget Performance Updates
# Block files ending in .json, _buildManifest.js, _middlewareManifest.js, _ssgManifest.js, and any other JS files
Disallow: /*.json$
Disallow: /*_buildManifest.js$
Disallow: /*_middlewareManifest.js$
Disallow: /*_ssgManifest.js$
Disallow: /*.js$
Disallow: /api/
Disallow: /_next/

import { PrismaClient } from '@prisma/client'

const prismaClientSingleton = () => { return new PrismaClient() }

declare const globalThis: { prismaGlobal: ReturnType; } & typeof global;

@darrylmorley
darrylmorley / ssl
Last active December 22, 2023 14:27
Generate private SSL key
# Generat Openssl key and cert.
openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365

Set a default Layout - Inertia / Vue

createInertiaApp({
  resolve: (name) => {
    let page = resolvePageComponent(
			`./Pages/${name}.vue`,
			import.meta.glob('./Pages/**/*.vue')
    );
 page.then((module) => {

docker history --human --format "{{.CreatedBy}}: {{.Size}}" docker-image

@darrylmorley
darrylmorley / js-dynamic-form
Created October 20, 2021 09:44
Create form dynamically
// Create a form synamically
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "submit.php");
// Create an input element for Full Name
var FN = document.createElement("input");
FN.setAttribute("type", "text");
FN.setAttribute("name", "FullName");
FN.setAttribute("placeholder", "Full Name");
@darrylmorley
darrylmorley / gist:a013734967a0fa6cb46e7c9674016c29
Created October 1, 2021 06:46
Portainer Traefik Labels Example
"traefik.enable=true"
"traefik.docker.network=proxy"
"traefik.http.routers.app-secure.entrypoints=websecure"
"traefik.http.routers.app-secure.rule=Host(`domain.name`)"
Dockerfile changes:
# Install dependencies only when needed
FROM node:14-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
**COPY ./prisma/schema.prisma ./prisma/schema.prisma**
RUN yarn install --frozen-lockfile
@darrylmorley
darrylmorley / 401Interceptor.js
Last active August 1, 2020 22:41
Axios response interceptor for handling http 401 errors & dealing with token refresh. #javascript
axios.interceptors.response.use(function(response) {
return response;
}, async function(error) {
await new Promise(function(res) {
setTimeout(function() {res()}, 10000);
});
const originalRequest = error.config;
if (error.response.status===401 && !originalRequest._retry) {