Skip to content

Instantly share code, notes, and snippets.

View zavan's full-sized avatar
🏠
Working from home

Felipe Zavan zavan

🏠
Working from home
View GitHub Profile
@zavan
zavan / readline-pipeline.md
Created February 9, 2024 12:54
Using node Readline.createInterface in a pipeline

pipeline [accepts a function][1] which receives the source as an argument and expects it to return a promise or async iterator, and the Interface object returned by Readline.createInterface [can be used as an async iterator][2], so you can do this:

import { pipeline } from "node:stream";
import { createInterface } from "node:readline";

pipeline(
  process.stdin,
  (input) => createInterface({ input }),
  process.stdout,
@zavan
zavan / index.html
Last active February 27, 2023 10:17
Simple NPM + Vite + PostCSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Dummy eSite</title>
<!-- CSS Assets -->
<link rel="stylesheet" href="/src/styles.css">
@zavan
zavan / getGlobalLib.js
Last active November 19, 2022 17:13
Inject and use global script libs dynamically and idempotently (bonus: react custom hook)
const scripts = {};
const defaultOptions = {
async: true,
defer: true,
};
function getGlobalLib(name, url, options = defaultOptions) {
if (scripts[name]) return scripts[name];
@zavan
zavan / setup_mysql.yml
Last active February 3, 2022 14:06
Installing MySQL v5.7 on Ubuntu 20.04 with Ansible
- name: Setup MySQL v5.7
become: yes
block:
- name: Add MySQL apt key
apt_key:
keyserver: pgp.mit.edu
id: 3A79BD29
state: present
- name: Add MySQL apt repo
@zavan
zavan / yt.js
Last active February 20, 2024 00:26
Listening to the YouTube Embed Iframe time change events without polling player.getCurrentTime()
// Load the IFrame Player API code asynchronously.
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Instantiate the Player.
function onYouTubeIframeAPIReady() {
var player = new YT.Player("player", {
@zavan
zavan / mmdd_mask.html
Last active October 7, 2020 16:35
Pure JS MM/DD input masking
<input id="input-id" placeholder="MM/DD" maxlength="5">
<script src="./mmdd_mask.js"></script>
<script>
var el = document.getElementById('#input-id');
var mmddMask = new MMDDMask(el);
</script>
@zavan
zavan / check_spell.rb
Last active September 4, 2020 11:48
Parsing aspell CLI output with Ruby for TinyMCE
# See https://stackoverflow.com/a/63740582/1415262
class TinymceController < ApplicationController
skip_forgery_protection
respond_to :json
def spellcheck
suggestions = check_spelling_new(
spellcheck_params[:text],
@zavan
zavan / mysql2-monterey.md
Last active May 5, 2022 10:18 — forked from fernandoaleman/mysql2-mojave.md
Install mysql2 gem on MacOS Monterey

For MacOS Catalina, visit Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Monterey.

Solution

Make sure openssl is installed on Mac via Homebrew.

@zavan
zavan / typingtest_pwn.js
Created June 6, 2020 23:36
Fooling typingtest.com and breaking records
let time = 10; // Increase this if you're getting typing errors
function pressKey(key, code, eventType = 'keypress') {
console.log(`Typing "${key}" (${code}) with event ${eventType}`);
let event = new KeyboardEvent(eventType, {
key: key,
keyCode: code,
which: code,
charCode: code
@zavan
zavan / typing_pwn.js
Created June 2, 2020 22:20
Fooling typing.com and breaking records
// Just open a test page on typing.com and run this on the browser console:
// Tested on Safari.
// If you get errors, increase the setTimeout time.
$('.letter').each(function(i) {
setTimeout(() => {
const text = $(this).text();
let char = text;
let charCode = char.charCodeAt(0);