Skip to content

Instantly share code, notes, and snippets.

View adamAfro's full-sized avatar
🎭

Adam adamAfro

🎭
View GitHub Profile
@adamAfro
adamAfro / profile.dict.py
Last active November 18, 2024 13:24
converts XML and JSON data to tables with respect to the repeating names as separate entities, relations 'r kept as order of the closest ancestor
from pandas import DataFrame
import json, xmltodict
from tqdm import tqdm as progress
class Profile:
def __init__(self, raw:dict|None=None):
self.Q = raw if raw is not None else {}
self.Y = []
@adamAfro
adamAfro / grab.js
Created September 25, 2024 08:10
moving elements around a circle in a browser using HTML Drag and Drop API, applies little tilt based on x position
/** @param {DragEvent} e */
function grab(e, D=256) {
let n = /** @type {HTMLElement} */ (e.target)
if (!n.hasAttribute) return
if (!n.hasAttribute('draggable')) return
let M = { x: e.clientX, y: e.clientY }
let P = n.getBoundingClientRect()
let Tx = 0, Ty = 0
let T = n.style.transform
@adamAfro
adamAfro / fetch.py
Created June 28, 2024 09:05
Python function for parallel web requesting with progress bar
async def parallel(data: list, callback:callable, delay=.1, timeout=10., limit=5, desc=''):
import aiohttp, asyncio
from tqdm.asyncio import tqdm
timeout = aiohttp.ClientTimeout(total=timeout)
limit = asyncio.Semaphore(limit)
async def task_wrapper(x):
async with limit:
@adamAfro
adamAfro / Insider.ts
Created January 7, 2024 12:30
pobiera najnowszą strone biznes insider i jej artykuły - zapisuje je do epub na czytniki
import { JSDOM } from 'jsdom'
function parseHTML(html: string) {
const browser = false
if (browser) {
const domParser = new DOMParser()
return domParser.parseFromString(html, "text/html")
}
@adamAfro
adamAfro / mediaexpert2df.deno.ts
Created May 1, 2023 18:50
Skrapuje strony z produktami w domenie mediaexpert.pl na ramkę danych
/**
* Skrapuje strony z produktami w domenie mediaexpert.pl na ramkę danych:
* * nazwa (name)
* * cena (price)
* * kategoria (category)
* * ...atrybuty (tak jak zostały zapisane na stronie)
*
* Konsola:
* deno run mediaexpert2df.ts
* y ... y y y
@adamAfro
adamAfro / HTMLinlineCSS.ts
Created March 25, 2023 20:44
allows to write CSS inside HTML like <img padding="2em" .../>
import { DOMParser, Element, Document } from "https://deno.land/x/deno_dom@v0.1.35-alpha/deno-dom-wasm.ts"
export default function html(strings: TemplateStringsArray, ...values: any[]) {
const html = String.raw({ raw: strings }, ...values)
const document = new DOMParser().parseFromString(html, "text/html")
if (!document)
return ""
applyInlineCSS(document)
@adamAfro
adamAfro / mochideck.ts
Last active March 22, 2023 07:33
Do some stuff over mochi API, I, for once, add here emojis, CHAT itself had soo many buuuugs so i did this
// turns out I could just use
///// <ai>Generate an emoji for italian word <<Back>>, respond only with that emoji and insert it inside \{\{\}\}</ai>
// so the script for givent purpose is worthless
/** Script for using mochi.cards/api written for use in deno.js
*
* Motivation
* * I wanted to add emoji genereted by Chat GPT to each card
*
* and this is what it is doing
@adamAfro
adamAfro / example.route.tsx
Created March 16, 2023 22:23
Pozwala na używanie stylów CSS jako atrubutów HTML, dla czytelności i wygody
import { Head } from "$fresh/runtime.ts"
import { options, VNode } from 'preact'
import inlineCSS from "../components/inline.tsx"
options.vnode = (vnode: VNode) => inlineCSS(vnode)
export default () => <>
<Head>
<title>Fresh App</title>
@adamAfro
adamAfro / emoji.hpp
Last active February 19, 2023 16:49
Przykładowe sturktury danych napisane z użyciem c++ z emotkami
// klasy
#define 🗂️ class
#define 🔓 public
#define 🔐 protected
#define 🔒 private
#define 🚫 ~
#define 💚 friend
#define 🏗️ new
@adamAfro
adamAfro / deno2browser.js
Last active February 22, 2023 09:18
Konwertuje kod z deno ale usuwa includowanie DOMParsera, później mieli kod do 4 plików do imporotwania czy inaczej
import * as esbuild from "https://deno.land/x/esbuild@v0.15.10/mod.js";
const plugins = [{
name: "remove-non-browser-imports",
setup(build) { build.onLoad({ filter: /\.ts$/ }, (args) => ({
loader: "ts",
contents: Deno.readTextFileSync(args.path)
.replaceAll(/(import).*("https:\/\/).*(")/gm, "")
// remove all https:// imports, including async :(, may do BUGsss