javascript
Table of Contents
- 1. javascript
- 1.1. Dino (remplazo de Node.js)
- 1.2. Javascript from an outsider’s perspective
- 1.3. Javascript is a Mess
- 1.3.1. https://www.reddit.com/r/webdev/comments/dbmxso/why_is_the_javascript_environment_such_a_hot_mess/
- 1.3.2. https://dev.to/sotiriskourouklis/why-javascript-is-a-mess-25j2
- 1.3.3. 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU
- 1.3.4. Is JavaScript A Hot Mess?
- 1.3.5. https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how-to-program/
- 1.4. Javascript Notebook
- 1.5. Web Assembly wasm
- 1.5.1. The Birth & Death of JavaScript
- 1.5.2. The best WebAssembly runtime may be no runtime at all
- 1.5.3. appcypher/awesome-wasm-langs: 😎 A curated list of languages that compile directly to or have their VMs in WebAssembly
- 1.5.4. WASM Playground / Chaos Alchemist | Observable
- 1.5.5. WASMtoy
- 1.5.6. Don’t Trust Anything! Real-world Uses For WebAssembly • Katie Bell • YOW! 2023 - YouTube
- 1.5.7. Python wasm
- 1.6. npm
- 1.7. JSON
- 1.8. Recursos
- 1.9. Aprender JS learn
- 1.9.1. Libros
- 1.9.2. Trucos
- 1.9.3. groupBy y demás métodos para listas
- 1.9.4. Reemplazar página web
- 1.9.5. Javascript Without Frameworks
- 1.9.6. Ejercicios
- 1.9.7. Typescript
- 1.9.8. Node
- 1.9.9. Katas y demás
- 1.9.10. “7 Must-Use Developer Tools for Increased Efficiency”
- 1.9.11. React
- 1.9.12. Lista de tecnologías
- 1.10. Dokuwiki
1. javascript
1.1. Dino (remplazo de Node.js)
1.2. Javascript from an outsider’s perspective
1.3. Javascript is a Mess
1.3.1. https://www.reddit.com/r/webdev/comments/dbmxso/why_is_the_javascript_environment_such_a_hot_mess/
- Organic grow ⇒ inconsistencies and redundant code
JavaScript has grown organically with the web and as such is full of inconsistencies and redundant code. That’s makes it interesting but such a pain in the ass sometimes. PHP has evolved the same way and has the same qualities. Dynamic and vibrant but oh-so-infuriating. I go play with a python or rust project when I need a sanity check.
- Need to keep backwards compatiblity with 10 years old browsers, each one with its own twists → Babel
Most other languages operate in a more controlled ecosystem and don’t have to worry about being compatible with 10 year old browsers on every platform.
1.3.2. https://dev.to/sotiriskourouklis/why-javascript-is-a-mess-25j2
- Lack of consistency. There are many ways to do the same thing, many folder structures, code style, …
- For example
- For example
1.3.4. Is JavaScript A Hot Mess?
1.3.4.1. 1:33
Small dependencies added to a lot of projects when copy-paste would have been better:
https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code/
1.3.4.2. 2:02
Created in 10 days(!), browser fragmentation
1.3.4.3. 3:38
node_modules is huge and has a lot of packages seem overcomplicated
1.3.4.4. 5:27
Complicated builds
- Babel
- Webpack
1.3.4.5. 6:02
CSS preprocessors (also complex builds)
1.3.4.6. 6:17
A lot of loaders with different configuration each
1.3.4.7. 6:33
You could probably get rid of half of the tools
1.3.4.8. 7:23
Fast pace of changes means if you’re out of javascript for 4 years ⇒ outdated
1.3.4.9. 8:18
Starter code packs are HUGE because there is a lot of different tooling/build/code formater and they just bundle it with the start code so that everything works
This leads to huge Hello World examples, and only when you start to understand all of this you actually make smaller apps
1.3.4.10. 9:56
Dynamic typing with automatic conversion ⇒ weird rules that you don’t expect
1.4. Javascript Notebook
1.5. Web Assembly wasm
1.5.1. The Birth & Death of JavaScript
Treat Javascript as another platform (like x86, ARM), by using transpilers
https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript
1.5.2. The best WebAssembly runtime may be no runtime at all
Compile WebAssembly to C
1.5.5. WASMtoy
1.5.7. Python wasm
- https://wasmer.io/posts/py2wasm-a-python-to-wasm-compiler
https://news.ycombinator.com/item?id=40115099
WebGL, WebGPU, WebNN
Which have better process isolation; containers or Chrome’s app sandbox at pwn2own how do I know what is running in a WASM browser tab?
JupyterLite, datasette-lite, and the Pyodide plugin for vscode.dev ship with Pyodide’s WASM compilation of CPython and SciPy Stack / PyData tools.
`%pip install -q mendeley` in a notebook opened with the Pyodide Jupyter kernel works by calling `await micropip.install([“mendeley”])` IIRC.
picomamba installs conda packages from emscripten-forge, which is like conda-forge: https://news.ycombinator.com/item?id=33892076#33916270 :
> FWIU Service Workers and Task Workers and Web Locks are the browser APIs available for concurrency in browsers
sqlite-wasm, sqlite-wasm-http, duckdb-wasm, (edit) postgresql WASM / pglite ; WhatTheDuck, pretzelai ; lancedb/lance is faster than pandas with dtype_backend=“arrow” and has a vector index
“SQLite Wasm in the browser backed by the Origin Private File System” (2023) https://news.ycombinator.com/item?id=34352935#34366429
“WebGPU is now available on Android” (2024) https://news.ycombinator.com/item?id=39046787
“WebNN: Web Neural Network API” https://www.w3.org/TR/webnn/ : https://news.ycombinator.com/item?id=36159049
“The best WebAssembly runtime may be no runtime” (2024) https://news.ycombinator.com/item?id=38609105
(Edit) emscripten-forge packages are built for the wasm32-unknown-emscripten build target, but wasm32-wasi is what is now supported by cpython (and pypi?) https://www.google.com/search?q=wasm32-wasi+conda-forge
- Accessing postgres database from python kernel · Issue #1083 · jupyterlite/jupyterlite
JupyterLite (Pyodide) ↔ GraphQL ↔ PostgresQL
- oscar6echo/ph-local
- Si no otra que se me ocurre es utilizar una sqlite https://github.com/sql-js/sql.js/ y sincronizar con postgres https://github.com/zknill/sqledge https://github.com/powersync-ja https://www.tcl.tk/community/tcl2017/assets/talk95/Slides.pdf
- oscar6echo/ph-local
pip install nuitka # necesita patchelf y ccache opcionalmente para que vaya más rápido time CC=clang MAKEFLAGS="-j8" python -m nuitka --follow-imports script.py -o script.elf pip install py2wasm # Hay que instalar wasmer luego para hacerlo funcionar # MAKEFLAGS no hace que wasm-ld utilize todos los núcleos MAKEFLAGS="-j8" py2wasm script.py -o script.wasm
1.6. npm
https://registry.npmjs.org/<name of package> → search tarball:
https://registry.npmjs.org/@hokyjack/jupyterlab-monokai-plus/-/jupyterlab-monokai-plus-0.1.4.tgz
- https://deb.nodesource.com/setup_16.x Para instalar node
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
. Qué podría salir mal?¯\_(ツ)_/¯
- Luego he tenido que instalar nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
1.6.1. https://github.com/Schniz/fnm try
🚀 Fast and simple Node.js version manager, built in Rust
1.7. JSON
- JSON Crack - Crack your data into pieces JSON Visualization
- JSONB
- JSONL
- JSONC (JSON with Comments)
1.9. Aprender JS learn
https://javascript.info/
https://hackr.io/blog/best-javascript-courses Avanzado
“A Study Plan To Cure JavaScript Fatigue” por Sacha Greif
https://link.medium.com/9lipfoF0W8
1.9.1. Libros
- Javascript for Impatient Programmers
- Eloquent Javascript
1.9.2. Trucos
- Object.keys(objeto) ,Object.values(objeto) y Object.entries(objeto) para sacar las claves, valores y entradas (items en Python) de un objeto
- Array.from(objeto) para convertir lo que sea en array y poder utilizar .map
Quitar clave de un diccionario
delete thisIsObject['Cow'];
If you are using Underscore.js or Lodash, there is a function ’omit’ that will do it.
http://underscorejs.org/#omit
Create an object within a map function
const keys = ['key1', 'key2']; const result = keys.map(key => { let obj = {}; obj[key] = (Math.random() * 2) - 1; return obj; }); return result;
[ { key1: 0.45488502758210236 }, { key2: 0.4172403939051943 } ]
-
const arrayOfLetters = ['a', 'b', 'c', 'd', 'e', 'f']; var n = 3 console.log( arrayOfLetters.slice(0, n).concat(arrayOfLetters.slice(n+1)) ) n = -1 console.log( arrayOfLetters.slice(0, n) ) console.log( arrayOfLetters.slice(1) )
[ ’a’, ’b’, ’c’, ’e’, ’f’ ]
[ ’a’, ’b’, ’c’, ’d’, ’e’ ]
[ ’b’, ’c’, ’d’, ’e’, ’f’ ]
undefined
- Object.getPrototypeOf para obtener la clase de un objeto (typeof no vale)
Para comprobar si está una string en un array
Object.keys(data).includes("next")
-
var defaultDict = new Proxy({}, { get: (target, name) => name in target ? target[name] : 0 })
pivot_table
conteo_resultados = resultados .map((x) => { let obj = {}; // Convertir de {"estado": "Activo", "estado__count": 1} a {"Activo": 1} obj[x["estado"]] = x["estado__count"]; return obj; }) .reduce((acc, obj) => { // Juntar todos {"Activo": 1, "Inactivo": 2} Object.keys(obj).forEach((key) => ((acc[key] || 0) + obj[key]); return acc; });
- range() function
[…Array(5).keys()]; - JavaScript Date Reference
No tiene un strftime/strptime sin librerías - urlencode
encodeURIComponent
1.9.3. groupBy y demás métodos para listas
1.9.4. Reemplazar página web
Con JQuery
$(document).ready(function() { // Replace the current window with the contents from a new URL function replaceWindowWithContent(url) { $.get(url, function(data) { $('body').html(data); window.history.replaceState(null, '', url); }); } // Example usage: Replace the window with contents from a new URL on button click $('#replaceButton').on('click', function() { var newURL = 'https://example.com'; // Replace with your desired URL replaceWindowWithContent(newURL); }); });
1.9.5. Javascript Without Frameworks
1.9.5.2. https://jstherightway.org/
1.9.6. Ejercicios
1.9.7. Typescript
1.9.7.1. Typescript typing limitations
1.9.8. Node
1.9.9. Katas y demás
1.9.10. “7 Must-Use Developer Tools for Increased Efficiency”
“7 Must-Use Developer Tools for Increased Efficiency” por Mahdhi Rezvi
https://link.medium.com/RfwZLBnh88 Bit.dev interesante para ver ejemplos de código
1.9.11. React
1.9.11.1. The React Productivity Revolution - Forte Labs
1.9.12. Lista de tecnologías
https://guillaumechereau.github.io/js-is-a-mess/
- angular
- babel
- backbone
- bootstrap
- bower
- browserify
- closure compiler
- ember
- grunt
- gulp
- handlebars
- jquery
- jquery ui
- jsx
- less
- materializecss
- meteor
- modernizr
- mustache
- nodejs
- npm
- polymer
- react
- sass
- stylus
- underscore
- vuejs
- webpack
- yeoman
1.10. Dokuwiki
- flatted -> Si un JSON tiene una estructura circular, esto sirve como remplazo a
JSON.stringify, JSON.parse
permitiendo referencias circulares - minanim.js animaciones declarativas
- crossfilter Fast n-dimensional filtering and grouping of records
- https://bocoup.com/blog/smoothly-animate-thousands-of-points-with-html5-canvas-and-d3
- Bootstrap CSS Lo bueno y lo malo
- Purescript → functional Javascript transpiler
1.10.1. </> htmx - high power tools for html → HTML as complete hypertext
- Why should only
<a>
and<form>
be able to make HTTP requests? - Why should only
click
&submit
events trigger them? - Why should only
GET
&POST
methods be available? - Why should you only be able to replace the entire screen?
By removing these arbitrary constraints, htmx completes HTML as a hypertext - </> htmx ~ When Should You Use Hypermedia?
- Hypermedia: A Good Fit If…
- …If your UI is mostly text & images
- …If your UI is CRUD-y
- …If your UI is “nested”, with updates mostly taking place within well-defined blocks
- …If you need “deep links” & good first-render performance
- …If your UI is mostly text & images
- Hypermedia: Not A Good Fit If…
- #…If your UI has many, dynamic interdependencies
- …If you require offline functionality
- …If your UI state is updated extremely frequently
- …If your team is not on board
- #…If your UI has many, dynamic interdependencies
- Hypermedia: A Good Fit If…
- Django, HTMX and Alpine.JS: A Match Made In Heaven - DEV Community