Skip to content

Instantly share code, notes, and snippets.

View nitobuendia's full-sized avatar

Nito Buendia nitobuendia

View GitHub Profile
@nitobuendia
nitobuendia / index.html
Created November 28, 2020 11:09
Emoji Classifier
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Getting Started with ml5.js</title>
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- ml5 -->
@nitobuendia
nitobuendia / import_ssl_certificates.sh
Created January 3, 2021 11:50
Import letsecrypt certificates to UniFi Controller
#!/usr/bin/env bash
# Modified from:
# https://github.com/jacobalberty/unifi-docker/blob/master/import_cert
echo "Loading constants"
DATADIR="/usr/lib/unifi/data"
CERTDIR="/ssl"
CERTNAME="fullchain.pem"
@nitobuendia
nitobuendia / main.js
Created May 14, 2021 11:22
Prime Factorization
/**
* Gets all the prime factors of a given number.
* @param {number} number for which to get all prime factors.
* @param {!Array<number>=} allDivisors List of all prime factors.
* This parameter is not meant to be sent when called by a user, but
* it is used for the recursive nature of the implementation.
*/
const getPrimeFactors = (number, allDivisors = []) => {
if (number < 2) throw new Error('getPrimeFactors only accepts numbers greater than 1.');
const maxDivisor = Math.ceil(Math.sqrt(number));
@nitobuendia
nitobuendia / hex.js
Last active February 26, 2022 10:43
A gradient calculator in pure vanilla JavaScript
/**
* @typdef {{
* r: number,
* g: number,
* b: number
* }}
*/
let Color;
/**
@nitobuendia
nitobuendia / shuffle_youtube_playlist.js
Last active April 13, 2022 13:52
Shuffle YouTube Playlist (via Apps Script)
/**
* @fileoverview Shuffles a YouTube playlist on every run.
*
* Note: currently this only supports up to 50 videos, but you can extend it to
* support more by combining the pages into one.
*
* This code is meant to be run on Google Apps Script. To get started with
* YouTube API on Apps Script and add the YouTube service, read this article:
* https://developers.google.com/apps-script/guides/services/advanced
*/
@nitobuendia
nitobuendia / random_number_statistics.js
Last active July 9, 2022 07:59
Basic statistics on a random number generator
const MIN_INT = 1;
const MAX_INT = 5;
const ROUNDS = 1000;
const FLOATING_ACCURACY = 2;
function getRandomInt(min = MIN_INT, max = MAX_INT){
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@nitobuendia
nitobuendia / Code.js
Last active January 20, 2024 09:43
Apps Script to import Facebook Messages (JSON format) into a spreadsheet
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and