This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Video < ApplicationRecord | |
UPLOAD_BUCKET = "medium-article-#{Rails.env}-videos" | |
belongs_to :user, optional: true | |
before_save :assign_random_key | |
def original_url | |
"https://#{ENV['CLOUDFRONT_DOMAIN']}/#{key}" | |
end | |
def low_res_url | |
return unless low_res_key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::VideosController < Api::ApplicationController | |
skip_before_action :authenticate_user, only: %i[derivative] | |
# POST /api/videos | |
def create | |
@video = current_user.videos.new | |
if @video.save | |
render json: VideoSerializer.render(@video, view: :with_upload_details), status: :ok | |
else | |
render json: @video.errors, status: :bad_request | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Transform: AWS::Serverless-2016-10-31 | |
Description: > | |
SAM project for Medium article about uploading and processing videos | |
Parameters: | |
EnvironmentValue: | |
AllowedValues: | |
- "staging" | |
- "production" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const s3Util = require("./s3-util"); | |
const childProcessPromise = require("./child-process-promise"); | |
const path = require("path"); | |
const os = require("os"); | |
const fs = require("fs"); | |
const https = require("https"); | |
const OUTPUT_BUCKET = process.env.OUTPUT_BUCKET; | |
const VIDEO_MIME_TYPE = process.env.VIDEO_MIME_TYPE; | |
const LAMBDA_SHARED_SECRET = process.env.LAMBDA_SHARED_SECRET; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global module, require, Promise, console */ | |
const aws = require("aws-sdk"); | |
const fs = require("fs"); | |
const s3 = new aws.S3(); | |
const downloadFileFromS3 = function (bucket, fileKey, filePath) { | |
"use strict"; | |
console.log("Downloading", bucket, fileKey, filePath); | |
return new Promise(function (resolve, reject) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const childProcess = require('child_process'), | |
spawnPromise = function (command, argsarray, envOptions) { | |
return new Promise((resolve, reject) => { | |
console.log('executing', command, argsarray.join(' ')); | |
const childProc = childProcess.spawn(command, argsarray, envOptions || {env: process.env, cwd: process.cwd()}) | |
const resultBuffers = []; | |
childProc.stdout.on('data', buffer => { | |
console.log(buffer.toString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(...) | |
print('Making predictions for an unseen user...') | |
items_to_rate = [trainset.to_raw_iid(i) for i in trainset.all_items()] | |
# We will consider this user to be ID 0 since that is not a valid ID for our real users | |
user_id = 0 | |
# Make predictions | |
predictions = [] | |
for iid in items_to_rate: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Transform: AWS::Serverless-2016-10-31 | |
Description: > | |
collaborative-filtering | |
SAM project for collaborative-filtering | |
Imports data from SQL and exports results to S3 | |
Parameters: | |
RdsPassword: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Library used for training of the model | |
# NOTE: We require the environment variable SURPRISE_DATA_FOLDER to designate the | |
# the directory used by Surprise. Else it will err due to the default Lambda home | |
# directory being read only. | |
from surprise import SVD | |
from surprise import Dataset | |
from surprise import Reader | |
import os # Get environment variables | |
import psycopg2 # PSQL connector library | |
import csv # Format we will export ratings as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SLURM Enqueue Workflow | |
on: | |
push: | |
branches: | |
- 'master' | |
jobs: | |
enqueue: | |
runs-on: ubuntu-latest |