Skip to content

Instantly share code, notes, and snippets.

@David256
David256 / ui.js
Created November 21, 2024 06:12
This script does not help with skipping YouTube ads manually for PC browser
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.code === 'Space') {
document.querySelector('video').currentTime = document.querySelector('video').duration;
event.preventDefault();
}
});
@David256
David256 / ai.sh
Created November 21, 2024 02:11
ChatGPT for Terminal - bash script that consumes the OpenAI API
#!/bin/bash
if [ -z $OPENAI_API_KEY ];
then
echo "Missing define OPENAI_API_KEY"
exit 1
fi
function chat() {
@David256
David256 / translate-tweets.js
Created October 25, 2024 14:14
Javascript to automatically translate tweets
window.translator = setInterval(() => {
document.querySelectorAll('[data-testid="tweetText"][lang="en"]').forEach(tweetText => {
const parent = tweetText.parentNode;
const translateButton = parent.querySelector('button span');
if (translateButton && translateButton.textContent.includes("Traducir post")) {
translateButton.closest('button').click();
console.log(translateButton)
tweetText.style.color = "#555";
}
@David256
David256 / short_polling_server.ts
Last active August 16, 2024 18:35
short_polling_server.ts
let powerstatus = "0";
let lastPowerstatus = "0";
const waitForChange = (timeout: number) => {
return new Promise<string>((resolve) => {
const start = Date.now();
const interval = 100;
const check = () => {
if (powerstatus !== lastPowerstatus) {
@David256
David256 / update-discord.sh
Created July 31, 2024 20:46
This Bash script updates Discord on a Linux system. It downloads the latest version, verifies the download, extracts the files, replaces the old version, and restores the launcher.
#!/bin/bash
echo "Vamos a actualizar Discord"
if [ "$1" != "-y" ];
then
read -n 1 -s -r -p "Presiona cualquier tecla para continuar..."
echo
fi
@David256
David256 / self_improving_script_with_openai.py
Created April 9, 2023 22:28
This code is a proof of context for a Python script that self-improves using the OpenAI API.
#!/usr/bin/env python
"""
Run this code under the Python interpreter.
"""
import os
import random
import re
import openai
@David256
David256 / express-server.js
Created August 17, 2022 21:23
express.js launches stuffs and responses if the process is still running
const express = require('express');
const {
exec,
} = require('child_process');
const app = express();
const port = 7000;
let isRunning = false;
@David256
David256 / dynamic-hexagon-component-styles.sass
Created May 19, 2022 20:37
React.js component to create a hexagon with CSS (or SASS): So... pure CSS hexagons with box-shadow, border, and background image.
// This
// Use this for math.div(number, divider) function
@use "sass:math"
// The sqrt function, just to calc sqrt(3) ._.
// Source: https://www.antimath.info/css/sass-sqrt-function/
@function sqrt($r)
$x0: 1
$x1: $x0
@David256
David256 / colores.py
Created May 25, 2021 17:45
Script to create a GIF with colors
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from numpy import pi, array, full, uint8
import imageio
import matplotlib.pyplot as plt
theta = 0.5 # valor entre [0,1)
light = 1 # valor entre [0,1)
@David256
David256 / script.js
Created April 17, 2021 17:49
I don't know why
const L = 37, R = 39, U = 38, D = 40;
let a = [
[L, U, R, D], [L, D, R, U],
[R, U, L, D], [R, D, L, U],
[U, L, D, R], [U, R, D, L],
[D, L, U, R], [D, R, U, L]
];
let d = document;
let c = d.getElementsByTagName("canvas")[0];
let gdir = () => { return a[Math.floor(Math.random() * a.length)]; }