Skip to content

Instantly share code, notes, and snippets.

View codeyourwayup's full-sized avatar

FRANK GO codeyourwayup

View GitHub Profile
@codeyourwayup
codeyourwayup / gist:7a270b47a2dff6abac6a88d5e24b8cbb
Created December 25, 2023 12:45
Nature's Particle Manager
Nature's Particle Manager
@codeyourwayup
codeyourwayup / README.md
Created March 4, 2023 10:59 — forked from Dosant/README.md
AWS S3 to OpenAI Whisper via Node.js stream

Current (2023-03-01) OpenAI Whisper API expects a file uploaded as part of multipart/form-data in POST request. I initially struggled to use this API inside Node.js with an audio file stored inside an AWS s3 bucket, so I decided to share this snippet:

The API usage example from the OpenAI docs:

curl --request POST \
  --url https://api.openai.com/v1/audio/transcriptions \
  --header 'Authorization: Bearer TOKEN' \
 --header 'Content-Type: multipart/form-data' \
@codeyourwayup
codeyourwayup / recorder.html
Created March 4, 2023 10:14 — forked from liketaurus/recorder.html
How to record audio in client code and upload recording to AWS S3 bucket
<!-- https://medium.com/@bryanjenningz/how-to-record-and-play-audio-in-javascript-faa1b2b3e49b -->
<!-- https://docs.aws.amazon.com/en_us/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html -->
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.585.0.min.js"></script>
<script>
function uploadAWS(blob) {
var vaultBucketName = "[YOUR-BUCKET-NAME]";
var bucketRegion = "[YOUR-AWS-REGION]";
var IdentityPoolId = "[YOUR-IDENTITY-POOL-ID]";
@codeyourwayup
codeyourwayup / simulate_keypress.js
Created February 8, 2023 01:49 — forked from ejoubaud/simulate_keypress.js
Simulate keypress that works in Google nav in Chrome
// Based on http://stackoverflow.com/a/10520017/1307721 and http://stackoverflow.com/a/16022728/1307721
Podium = {};
Podium.keydown = function(k) {
var oEvent = document.createEvent('KeyboardEvent');
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get : function() {
@codeyourwayup
codeyourwayup / git-rebase-todo
Created June 18, 2022 06:52 — forked from juniorbird/git-rebase-todo
Sample git rebase todo
pick 019325e 0.1.0
pick a4b689d Fetch all dependencies
squash 714a49d Matches keywords to Docker repos
pick d2d1ca3 parseDependencies returns an object of dependencies.
squash e3b6cd9 Clean up packageParser
squash 57acd67 Initial commit
squash 3f3e05e Rough out how we'll make Dockerfiles
squash 9e10b94 Can check for, make Docker files
squash a27b0ee Write docker files
pick a0980b8 Build Dockerfiles
@codeyourwayup
codeyourwayup / mask-array.js
Created June 30, 2021 09:58
Mask an array to calculate sub-array average
function ave(arr) {
if (arr && arr.length) {
//easy way to get array total is using reduce; c is current
const total = arr.reduce((a, c) => {
return a + c;
});
return total / arr.length;
}
throw new Error('wrong arr');
};
(function () {
var ROOT_URL = "https://canopy.co";
var PRICE_SELECTORS = [
".priceLarge",
".a-color-price.a-size-large",
".a-color-price.a-size-medium",
"#priceblock_ourprice"
];
var IMAGE_SELECTORS = [
This means that 1rem equals the font size
of the html element (which for most browsers has a default value of 16px).
function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
// if the item doesn't exist, return null
if (!itemStr) {
return null
}
const item = JSON.parse(itemStr)
const now = new Date()
// compare the expiry time of the item with the current time
if (now.getTime() > item.expiry) {
function setWithExpiry(key, value, ttl) {
const now = new Date()
// `item` is an object which contains the original value
// as well as the time when it's supposed to expire
const item = {
value: value,
expiry: now.getTime() + ttl,
}
localStorage.setItem(key, JSON.stringify(item))