Skip to content

Instantly share code, notes, and snippets.

View creuserr's full-sized avatar

si delv creuserr

  • andromeda
View GitHub Profile
@creuserr
creuserr / README.md
Last active June 1, 2024 05:32
cloudcre: audio api template

Usage

https://your-deployment.vercel.app/<YT-ID>/<Filename>.mp3

Where <YT-ID> is the youtube video ID, and <Filename> is the default name of the file.

<Filename> can be anything because the purpose of this is to customize the audio's default filename when downloading.

Note that .mp3 is required.

@creuserr
creuserr / index.js
Created June 1, 2024 05:19
cloudcre: index.js template
async function getAudio(name, artist) {
// Place your audio API deployment here
const domain = "your-deployment.vercel.app";
// If you want to change the piped instance,
// go to https://github.com/TeamPiped/Piped/wiki/Instances
// and find a domain
const pipe = "ngn.tf";
const f = await fetch(`https://pipedapi.${pipe}/search?q=${encodeURIComponent(`${name} ${artist}`)}&filter=music_songs`);
const res = await f.json();
const id = res.items[0].url.substr(9, res.items[0].url.length);
@creuserr
creuserr / is-following.js
Last active May 25, 2024 05:53
check if a github user follows a specific user by its personal access token
async function isFollowing(token, username) {
const req = await fetch(`https://api.github.com/user/following/${username}`, {
headers: {
authorization: `Bearer ${token}`
}
});
return req.status == 204;
}
@creuserr
creuserr / index.js
Last active March 1, 2024 10:05
📨 Building your Email API with Fastmail for free! (https://dev.to/creuserr/building-your-email-api-with-fastmail-for-free-h91)
const { createTransport } = require("nodemailer")
require("dotenv").config()
module.exports = (req, res) => {
// if the client is within the server,
// you can remove this header to
// prevent outside access.
res.setHeader("Access-Control-Allow-Origin", "*")
res.setHeader("Content-Type", "text/plain")
if(req.method != "POST") {
async function pocketdb(token) {
if (token != null) {
// use existing database
try {
var req = await fetch(`https://api.telegra.ph/getPageList?access_token=${token}&limit=200`);
req = await req.json();
} catch(e) {
throw `Failed to connect (${e})`;
}
if (req.ok != true) throw `Failed to connect (${req.error})`;
@creuserr
creuserr / DIY_GitHub_CDN.md
Last active January 24, 2024 07:58
🗃️ Effortless GitHub CDN Setup with Vercel and NodeJS

Effortless GitHub CDN Setup with Vercel and NodeJS

Certain CDNs rely on extended caching, expiring after up to 7 days. Consider crafting your own CDN for GitHub repositories. This gist provides a simplified setup and boilerplate for creating your personal GitHub CDN exclusively using Vercel and NodeJS.

Setup

  1. Begin by creating a new repository.
  2. Add the essential files: vercel.json and index.js.
  3. Deploy your repository effortlessly to Vercel.

Usage

@creuserr
creuserr / cantor-compress.js
Last active January 22, 2024 16:14
🗜️ Employing Cantor-Pairing for efficient compression and decompression, reducing the size of a string by half.
// Try it online:
// https://bit.ly/48ZZbOE
function compress(t) {
function pair(a, b) {
return 0.5 * (a + b) * (a + b + 1) + b;
}
return new Array(Math.ceil(t.length / 2)).fill(0).map((_, i) => String.fromCharCode(pair(t.charCodeAt(i * 2) + 1, t.charCodeAt(i * 2 + 1) + 1 || 0))).join("");
}