Skip to content

Instantly share code, notes, and snippets.

View stemmlerjs's full-sized avatar

Khalil Stemmler stemmlerjs

View GitHub Profile
@stemmlerjs
stemmlerjs / strip-annotations.js
Created October 1, 2020 08:22
Strip annotations from a YouTube transcript
function hasAnnotations (text) {
return getNextAnnotationStartIndex(text) !== -1 ||
getNextAnnotationEndIndex(text) !== -1;
}
function getNextAnnotationStartIndex (text) {
return text.indexOf(`\n\n**`)
}
function getNextAnnotationEndIndex (text) {
import React from "react";
import { useMutation, gql } from "@apollo/client";
const SINGLE_UPLOAD = gql`
mutation($file: Upload!) {
singleUpload(file: $file) {
filename
mimetype
encoding
url
import { useMutation, gql } from "@apollo/client";
const SINGLE_UPLOAD = gql`
mutation($file: Upload!) {
singleUpload(file: $file) {
filename
mimetype
encoding
url
}
const UploadFile = () => {
const [mutate, { loading, error }] = useMutation(SINGLE_UPLOAD);
const onChange = ({
target: {
validity,
files: [file]
}
}: any) => validity.valid && mutate({ variables: { file } });
if (loading) return <div>Loading...</div>;
import React from "react";
const App: React.FC = () => {
return (
<UploadFile />
);
};
export default App;
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./index.css"
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
HttpLink
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./index.css"
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
HttpLink
async singleFileUploadResolver(
parent,
{ file }: { file: Promise<File> }
): Promise<ApolloServerFileUploads.UploadedFileResponse> {
const { stream, filename, mimetype, encoding } = await file;
// Create the destination file path
const filePath = this.createDestinationFilePath(
filename,
mimetype,
async singleFileUploadResolver(
parent,
{ file }: { file: Promise<ApolloServerFileUploads.File> }
): Promise<ApolloServerFileUploads.UploadedFileResponse> {
const { stream, filename, mimetype, encoding } = await file;
// Create the destination file path
const filePath = this.createDestinationFilePath(
filename,
mimetype,
import stream from "stream";
type S3UploadStream = {
writeStream: stream.PassThrough;
promise: Promise<AWS.S3.ManagedUpload.SendData>;
};
export class AWSS3Uploader implements ApolloServerFileUploads.IUploader {
private s3: AWS.S3;
public config: S3UploadConfig;