Skip to content

Instantly share code, notes, and snippets.

View ctrlaltdylan's full-sized avatar

Dylan Pierce ctrlaltdylan

View GitHub Profile
@ctrlaltdylan
ctrlaltdylan / area_code_states.json
Created December 6, 2018 16:24
Each U.S. state area code and their corresponding state
{
"512": "TX",
"513": "OH",
"515": "IA",
"516": "NY",
"517": "MI",
"518": "NY",
"520": "AZ",
"530": "CA",
"531": "NE",
@ctrlaltdylan
ctrlaltdylan / state_area_codes.json
Created December 6, 2018 16:04
Phone area codes belonging to each US State
{
"AL": [205, 251, 256, 334, 938],
"AK": 907,
"AZ": [480, 520, 602, 623, 928],
"AR": [479, 501, 870],
"CA": [209, 213, 310, 323, 408, 415, 424, 442, 510, 530, 559, 562, 619, 626, 628, 650, 657, 661, 669, 707, 714, 747, 760, 805, 818, 831, 858, 909, 916, 925, 949, 951],
"CO": [303, 719, 720, 970],
"CT": [203, 475, 860, 959],
"DE": 302,
"FL": [239, 305, 321, 352, 386, 407, 561, 727, 754, 772, 786, 813, 850, 863, 904, 941, 954],
@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
@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 / sendgrid_inbound_parse_webhook_example.json
Created July 6, 2018 20:31
SendGrid Inbound Parse Webhook Example
{
"headers": "Received: by mx0047p1mdw1.sendgrid.net with SMTP id 6WCVv7KAWn Wed, 27 Jul 2016 20:53:06 +0000 (UTC)
Received: from mail-io0-f169.google.com (mail-io0-f169.google.com [209.85.223.169]) by mx0047p1mdw1.sendgrid.net (Postfix) with ESMTPS id AA9FFA817F2 for <example@example.comom>; Wed, 27 Jul 2016 20:53:06 +0000 (UTC)
Received: by mail-io0-f169.google.com with SMTP id b62so81593819iod.3 for <example@example.comom>; Wed, 27 Jul 2016 13:53:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.com; s=ga1; h=mime-version:from:date:message-id:subject:to; bh=DpB1CYYeumytcPF3q0Upvx3Sq/oF4ZblEwnuVzFwqGI=; b=GH5YTxjt6r4HoTa+94w6ZGQszFQSgegF+Jlv69YV76OLycJI4Gxdwfh6Wlqfez5yID 5dsWuqaVJZQyMq/Dy/c2gHSqVo60BKG56YrynYeSrMPy8abE/6/muPilYxDoPoEyIr/c UXH5rhOKjmJ7nICKu1o99Tfl0cXyCskE7ERW0=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:sub
@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 / 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 / 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 / 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 / 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,
{