Skip to content

Instantly share code, notes, and snippets.

@thawkin3
thawkin3 / app.py
Last active October 1, 2023 20:13
Plagiarism checker built using Python, Flask, and the Pinecone SDK
from dotenv import load_dotenv
from flask import Flask
from flask import render_template
from flask import request
from flask import url_for
import json
import os
import pandas as pd
import pinecone
import re
@thawkin3
thawkin3 / app.py
Created July 10, 2021 20:16
Pinecone customer support chatbot demo app (Python backend)
from dotenv import load_dotenv
from flask import Flask
from flask import render_template
from flask import request
from flask import url_for
import json
import os
import pandas as pd
import pinecone
import requests
@thawkin3
thawkin3 / player-history.ts
Created September 22, 2023 21:16
Ping Pong Ranking App - Player History
type Inputs = {
playerID: string;
};
type Match = {
matchID: string;
winnerID: string;
loserID: string;
};
@thawkin3
thawkin3 / leaderboard.ts
Created September 22, 2023 21:15
Ping Pong Ranking App - Leaderboard
type PlayerRecord = {
playerID: string;
losses: number;
wins: number;
};
type PlayerRecords = {
[key: string]: PlayerRecord;
};
@thawkin3
thawkin3 / main.ts
Created September 22, 2023 21:14
Ping Pong Ranking App - Record a New Match
type Inputs = {
playerOneID: string;
playerTwoID: string;
winnerID: string;
};
export async function handler(inputs: Inputs) {
const { playerOneID, playerTwoID, winnerID } = inputs;
if (!playerOneID || !playerTwoID || !winnerID) {
@thawkin3
thawkin3 / downloadPDFWithPDFMake.js
Created November 5, 2020 02:16
downloadPDFWithPDFMake
function downloadPDFWithPDFMake() {
var tableHeaderText = [...document.querySelectorAll('#styledTable thead tr th')].map(thElement => ({ text: thElement.textContent, style: 'tableHeader' }));
var tableRowCells = [...document.querySelectorAll('#styledTable tbody tr td')].map(tdElement => ({ text: tdElement.textContent, style: 'tableData' }));
var tableDataAsRows = tableRowCells.reduce((rows, cellData, index) => {
if (index % 4 === 0) {
rows.push([]);
}
rows[rows.length - 1].push(cellData);
export const findKeyInBox = (box) => {
console.log(`Looking in Box ${box.id}`);
for (let i = 0; i < box.contents.length; i++) {
if (box.contents[i].type === 'key') {
console.log(`Found the key in Box ${box.id}!`);
return box.id;
}
if (box.contents[i].type === 'box') {
export const findKeyInBox = (box) => {
const pile = [];
pile.push(box);
while (pile.length > 0) {
const currentBox = pile.pop();
console.log(`Looking in Box ${currentBox.id}`);
for (let i = 0; i < currentBox.contents.length; i++) {
if (currentBox.contents[i].type === 'key') {
export const maxNumberArray = (numbers) => {
if (numbers.length <= 1) {
return numbers[0];
}
const numberA = numbers[0];
const numberB = maxNumberArray(numbers.slice(1));
return numberA > numberB ? numberA : numberB;
};
export const maxNumberArray = (numbers) => {
let max = numbers[0];
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}
return max;