Skip to content

Instantly share code, notes, and snippets.

View jaronwanderley's full-sized avatar

Jaron Wanderley jaronwanderley

View GitHub Profile
@prb28
prb28 / mathcalc.js
Last active April 15, 2021 00:15 — forked from paiv/mathcalc.js
Expression parser in JavaScript
//
// MathCalc: a parser for basic mathematical expressions
// From here: https://paiv.github.io/blog/2016/03/23/js-calc.html
//
//
// Copyright (c) 2016, Pavel Ivashkov, github.com/paiv
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
@jeffposnick
jeffposnick / service-worker.js
Created September 20, 2019 00:56
Example of InjectManifest in Workbox v5
// Add any other logic here as needed.
import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin';
import { CacheFirst } from 'workbox-strategies/CacheFirst';
import { createHandlerForURL } from 'workbox-precaching/createHandlerForURL';
import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin';
import { NavigationRoute } from 'workbox-routing/NavigationRoute';
import { precacheAndRoute } from 'workbox-precaching/precacheAndRoute';
import { registerRoute } from 'workbox-routing/registerRoute';
@richardblondet
richardblondet / README.md
Last active February 13, 2025 05:58
Create a simple API backend with Google App Script and a Spreadsheet

Google App Script CRUD

Inspired by this gist.

Getting Started

  1. Create a new App Script project.
  2. Paste the content of the file google-app-script-crud.gs in the default Code.gs file.
  3. Create a new Spreadsheet.
  4. Copy the Spreadsheet ID found in the URL into the variable SHEET_ID located in line 1 of your file.
@manuelbl
manuelbl / README.md
Created August 3, 2019 09:12
ESP32 as Bluetooth Keyboard

ESP32 as Bluetooth Keyboard

With its built-in Bluetooth capabilities, the ESP32 can act as a Bluetooth keyboard. The below code is a minimal example of how to achieve it. It will generate the key strokes for a message whenever a button attached to the ESP32 is pressed.

For the example setup, a momentary button should be connected to pin 2 and to ground. Pin 2 will be configured as an input with pull-up.

In order to receive the message, add the ESP32 as a Bluetooth keyboard of your computer or mobile phone:

  1. Go to your computers/phones settings
  2. Ensure Bluetooth is turned on
@bcnzer
bcnzer / worker.js
Last active September 28, 2022 22:26
Example of a Cloudflare Worker and Worker KV storage used to transfer/migrate traffic to alternatively infrastructure
addEventListener('fetch', event => {
event.passThroughOnException()
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const maxBizId = await MIGRATION_SETTINGS.get('maxbizid')
const currentBusinessId = getBusinessIdFromCookie(request)
if (!maxBizId || maxBizId == 0 || !currentBusinessId) {
@mattdesl
mattdesl / offset-path.js
Created December 19, 2018 14:44
MIT – 2D vector path offsetting algorithm (work in progress)
/*
Copyright 2018 Matt DesLauriers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@mattdesl
mattdesl / motion-blur.js
Last active January 2, 2022 12:05
canvas-sketch + motion blur + canvas2D (NOTE: Only blurs on sequence export) adapted from @delucis
// Adapted from @delucis
// https://github.com/delucis/pellicola/blob/735bd7487bdc597ac7272e4ddce9473c15f68d09/lib/frame-maker.js#L99-L134
const canvasSketch = require('canvas-sketch');
const settings = {
dimensions: [ 512, 512 ],
duration: 3,
animate: true,
fps: 24
@bcnzer
bcnzer / workerPart4.js
Last active September 28, 2022 22:26
Example of a Cloudflare Worker handling Google reCAPTCHA in an "edged out" POST request
// NOTE: all auth code has been removed for the sake of brevity. Please see part 2 of blog series
// for more info: https://liftcodeplay.com/2018/10/16/pushing-my-api-to-the-edge-part-2-authentication-and-authorization/
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
const genderFemale = 'Female'
const genderMale = 'Male'
/**
@bcnzer
bcnzer / worker.js
Created October 15, 2018 09:31
Cloudflare Worker that uses Workers KV to get Authorization data. All authentication and authorization is done on the edge
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
/**
* Entry point of the worker
*/
async function handleRequest(event) {
try {
// Get the JWT
@alenaksu
alenaksu / centroid.js
Created August 29, 2018 14:31
Centroid of a polygon
export function default (polygon) {
let cx = 0, cy = 0, a = 0;
for (let i = 0, l = polygon.length; i < l; i++) {
let x0 = polygon[i].x,
x1 = polygon[(i + 1) % l].x,
y0 = polygon[i].y,
y1 = polygon[(i + 1) % l].y;
let m = (x0 * y1 - x1 * y0);