Aug. 21, 2022, 12:17 p.m.

PinkLetter - Shamelessly sharing my hacks

PinkLetter (odone.io)

Pink circle

Welcome to my PinkLetter. A short, weekly, technology-agnostic, and pink newsletter where we cultivate timeless skills in web development.

My Ramblings This Week

Tiny code experiments are the best way to learn.

Here’s what I discovered building code2html in a couple of days:

Demo of code2html

code2html transforms a JavaScript code snippet into html with inlined styles. It features:

  • An advanced code editor
  • Multiple themes
  • A cute wrapper around the code

I tried with a textarea, but the text inside cannot be styled.

Then, I tried to overlay a textarea on top of a div styled with highlightjs, but it was a mess to coordinate.

So I stole as Picasso would.

I found out that http://carbon.now.sh and http://ray.so delegate it all to http://codemirror.net, so I did the same.

But what about inlining css styles?

I tried to use node.getComputedStyle() and inline all the css but:

  • It’s slow
  • It’s inconsistent across browsers

So I did something else.

When you click on “Copy html”:

  • Extract all cssRules from document.stylesheets
  • Traverse all the nodes
  • If node.matches(cssRule.selectorText)
  • Then, inline css
  • Finally, copy innerHTML to clipboard

But how to switch themes?

All the inactive themes are wrapped in <style class="theme" media="not all">

The only active theme is wrapped in <style class="theme" media="all">

You still can’t believe all these hacks work? (No worries, I’m there with you.)

Github

Page

Elsewhere on the Web

GENERALISTS VS SPECIALISTS: MUSIC EDITION by Jonathan Stark

You might be tempted to think that an orchestra conductor is a generalist and a lead violinist is a specialist.

Riccardo: I cannot stop but thinking that a full-stack engineer is a generalist and a product engineer is a specialist


Brag Doc: Why and How? by Janahan Sivaraman

You’re already doing awesome work, therefore, you should get recognized for it.

Riccardo: This is an excellent way to stop thinking about your input (I write ruby) and start thinking about your output (I increased traffic 2x).


HAVING, a less understood SQL clause

Understanding how the group by and having clauses work can help us write more efficient sql. I want to demonstrate this with an example based on a real situation.

Riccardo: Declarative code FTW (sometimes)

You just read issue #111 of PinkLetter (odone.io). You can also browse the full archives of this newsletter.

This email brought to you by Buttondown, the easiest way to start and grow your newsletter.