Skip to content

Instantly share code, notes, and snippets.

View ctrlaltdylan's full-sized avatar

Dylan Pierce ctrlaltdylan

View GitHub Profile
@ctrlaltdylan
ctrlaltdylan / [[...slug.js]].js
Created February 25, 2021 13:44
Bullboard with Next JS
import nc from "next-connect";
const { setQueues, BullAdapter, router } = require("bull-board");
import emailQueue from 'queues/emailQueue'; // or wherever your queues lie
setQueues([
new BullAdapter(emailQueue),
]);
const handler = nc().use(
@ctrlaltdylan
ctrlaltdylan / next.config.js
Created December 10, 2020 18:43
Next config for Heroku to expose public frontend variables at build time
module.exports = {
env: {
NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
NEXT_PUBLIC_SHOPIFY_API_PUBLIC_KEY: process.env.NEXT_PUBLIC_SHOPIFY_API_PUBLIC_KEY,
},
};
@ctrlaltdylan
ctrlaltdylan / upload.js
Created November 14, 2020 01:38
Browser Axios Cloudinary Upload
let formData = new FormData();
formData.append("upload_preset", "<your preset from Cloudinary Dashboard here> * Required");
formData.append("file", <instance of a File here>);
axios
.post(
"https://api.cloudinary.com/v1_1/<your Cloudinary cloud name here>/image/upload",
formData,
{
@ctrlaltdylan
ctrlaltdylan / default.conf
Last active January 19, 2024 02:05
Reverse proxy for Radarr, Sonarr, Deluge && Jackett for pretty URLs instead of ports (store in /etc/nginx/default.conf)
server {
location /sonarr {
proxy_pass http://localhost:8989/sonarr;
}
location /radarr {
proxy_pass http://localhost:7878/radarr;
}
location /jackett {
@ctrlaltdylan
ctrlaltdylan / compound_search_with_query.js
Created September 11, 2020 00:24
Mongod Text query with compound index
// Create the searchable checks index
db.collection("checks")
.createIndex({ shopName: 1, firstName: "text", lastName: "text" })
.then((res) => {
console.log("checks text index created");
})
.catch((err) => console.log("checks text index creation failed", err));
const checks = await db
@ctrlaltdylan
ctrlaltdylan / mongodb-s3-backup.sh
Created September 1, 2020 13:39 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@ctrlaltdylan
ctrlaltdylan / change_collation_db_wide.rb
Created July 21, 2020 15:37
Change whole MySQL database collation to utf8mb4 with LHM
class ChangeCollationDbWide < ActiveRecord::Migration[5.2]
def change
db = ActiveRecord::Base.connection
tables = ActiveRecord::Base.connection.tables.map { |t| t.to_sym }
tables.each do |t|
Lhm.change_table(t) do |table|
table.ddl "ALTER TABLE `#{table.name}` DEFAULT CHARACTER SET utf8mb4, DEFAULT COLLATE utf8mb4_unicode_ci"
end
end
@ctrlaltdylan
ctrlaltdylan / Dockerfile
Created July 20, 2020 13:52
Ruby image with node & yarn
FROM ruby:2.6-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
gnupg \
git \
# substitute 12.x with whichever Node version you require:
&& curl -sL https://deb.nodesource.com/setup_12.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
@ctrlaltdylan
ctrlaltdylan / app.js
Created April 7, 2020 17:22
Mongo DB Connection
// require('koa') or require('express') whatever fits your fancy
const { Connection } = require('./db');
Connection.connectToMongo().then(() => {
// initialize your app and register routes
router.get('whatever', async(ctx) => {
const result = await Connection.db.collectionName.find({ id: ctx.params.id });
ctx.res.body = result;
@ctrlaltdylan
ctrlaltdylan / Dockerfile
Created February 24, 2020 15:37
Angular Docker example
FROM node
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm i
RUN npm i -g @angular/cli --unsafe