Skip to content

Instantly share code, notes, and snippets.

View elliott-king's full-sized avatar

Elliott King elliott-king

View GitHub Profile
@elliott-king
elliott-king / sampleREADME.md
Created November 12, 2020 22:24 — forked from FrancesCoronel/sampleREADME.md
A sample README for all your GitHub projects.

FVCproductions

INSERT GRAPHIC HERE (include hyperlink in image)

Repository Title Goes Here

Subtitle or Short Description Goes Here

$ flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: While importing "app", an ImportError was raised:
Traceback (most recent call last):
# for sending the request
require "uri"
require "net/http"
require "json"
# for loading our environment variables
require "dotenv/load"
# for scraping our blog
require "open-uri"
@elliott-king
elliott-king / s3_heroku_rails_04_requests.js
Created August 30, 2020 15:12
The three requests needed to upload a file to S3 using a Rails API backend
import { fileChecksum } from 'utils/checksum'
const createPresignedUrl = async(file, byte_size, checksum) => {
let options = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
@elliott-king
elliott-king / s3_heroku_rails_03_checksum.js
Last active September 14, 2020 15:39
Given a file, return the MD5 hash of it encoded in base64.
import CryptoJS from 'crypto-js'
// Note that for larger files, you may want to hash them incrementally.
// Taken from https://stackoverflow.com/questions/768268/
const md5FromFile = (file) => {
// FileReader is event driven, does not return promise
// Wrap with promise api so we can call w/ async await
// https://stackoverflow.com/questions/34495796
return new Promise((resolve, reject) => {
const reader = new FileReader()
@elliott-king
elliott-king / s3_heroku_rails_02_users_controller.rb
Created August 30, 2020 15:00
Controller to create new user and attach Active Storage file ID
class UsersController < ApplicationController
def create
resume = params[:pdf]
params = user_params.except(:pdf)
user = User.create!(params)
user.resume.attach(resume) if resume.present? && !!user
render json: user.as_json(root: false, methods: :resume_url).except('updated_at')
end
private
@elliott-king
elliott-king / s3_heroku_rails_01_direct_upload_controller.rb
Created August 30, 2020 14:46
Creates a URL for an Active Storage direct upload
class DirectUploadController < ApplicationController
def create
response = generate_direct_upload(blob_params)
render json: response
end
private
def blob_params
params.require(:file).permit(:filename, :byte_size, :checksum, :content_type, metadata: {})
@elliott-king
elliott-king / what.js
Last active May 14, 2020 20:23
what.
const url = 'http://localhost:3000/toys';
document.addEventListener("DOMContentLoaded", () => {
const toyCollection = document.querySelector('#toy-collection')
fetch(url)
.then(resp => resp.json())
.then(toys => {
for(const toy of toys) {
const toyDiv = document.createElement('div')
@elliott-king
elliott-king / firefox-curl.txt
Created October 30, 2019 16:03
Usage when selecting 'copy as cURL' in various browsers.
curl 'https://q0tmlopf1j-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%20(lite)%203.27.0%3BJS%20Helper%202.25.1&x-algolia-application-id=Q0TMLOPF1J&x-algolia-api-key=30a0c84a152d179ea8aa1a7a59374d08' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0' -H 'Accept: application/json' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'content-type: application/x-www-form-urlencoded' -H 'Origin: https://www.carnegiehall.org' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Cache-Control: max-age=0, no-cache' -H 'Pragma: no-cache' --data '{"requests":[{"indexName":"sitecore-events","params":"query=&hitsPerPage=10&page=0&facets=%5B%22eventtype%22%2C%22seasonnumber%22%2C%22facilityfacet%22%2C%22genre%22%2C%22instrument%22%5D&tagFilters=&facetFilters=%5B%22eventtype%3ACarnegie%20Hall%20Presents%22%2C%22eventtype%3AFree%20Events%22%2C%22facilityfacet%3AOffsite%22%2C%5B%22facilityfacet%3AOffsite%22%5D%5D&numericFilters=%5B%22startdate%3E15724417131
@elliott-king
elliott-king / base16-new-england.minttyrc
Created October 1, 2019 18:53
A port of the New England theme
ForegroundColour=62,69,78
BackgroundColour=253,241,212
CursorColour=62,69,78
Black=62,69,78
BoldBlack=58,72,91
Red=102,0,0
BoldRed=128,0,0
Green=133,153,0
BoldGreen=133,153,0
Yellow=102,68,0