Code Snippets Javascript

Short texts Javascript 🧑‍💻 Code snippets Javascript ✍️ Reading lists Javascript 👀

static.block.2.js

let peekMySecret; class C { #secret; constructor(mySecret) { this.#secret = mySecret; } static { peekMySecret = (obj) => console.log(obj.#secret); } } peekMySecret(new C(‘created with my secret’));

Memolock JS

import Redis from ‘ioredis’ const { HOST: host, PORT: port, } = process.env const redis = new Redis({ host, port }) const subscribe = async (key, notifKey) => { const subclient = new Redis({ host, port }) await subclient.subscribe(notifKey) // re-get in case we missed notifKey by a hair after lock attempt let value = […]

GENERATE PDF

const express = require(“express”); const PDF = require(“pdfkit-construct”); const fs = require(“fs”); const cors = require(“cors”); const app = express(); app.use(cors()); app.get(“/json”, (req, res) => { res.status(200).json({ message: “Este es un mensaje”, code: 3000 }); }); app.get(“/pdf”, (req, res) => { const doc = new PDF({ size: “letter”, margins: { top: 20, left: 10, right: […]

Rotating Elements with Mouse and Touch

Rotating Elements with Mouse and Touch ————————————– Working prototype to rotate an element to the current position of the mouse or touch location. Discussed in depth [on my blog](http://thenewcode.com/1124/Rotating-Elements-To-Mouse-and-Touch-Locations-Using-JavaScript). A [Pen](https://codepen.io/dudleystorey/pen/jARmWV) by [Dudley Storey](https://codepen.io/dudleystorey) on [CodePen](https://codepen.io). [License](https://codepen.io/dudleystorey/pen/jARmWV/license). document.addEventListener(“DOMContentLoaded”, function() { var pointer = document.getElementById(“pointer”), pointerBox = pointer.getBoundingClientRect(), centerPoint = window.getComputedStyle(pointer).transformOrigin, centers = centerPoint.split(” “); function […]