惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
博客园_首页
Vercel News
Vercel News
WordPress大学
WordPress大学
美团技术团队
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Y
Y Combinator Blog
博客园 - 【当耐特】
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
腾讯CDC
M
MIT News - Artificial intelligence
爱范儿
爱范儿
Recent Announcements
Recent Announcements
雷峰网
雷峰网
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
Jina AI
Jina AI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
Help Net Security
Help Net Security
N
News and Events Feed by Topic
博客园 - Franky
P
Proofpoint News Feed
L
LINUX DO - 热门话题
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
D
Docker
Google DeepMind News
Google DeepMind News
有赞技术团队
有赞技术团队
IT之家
IT之家
Security Latest
Security Latest
L
LangChain Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
J
Java Code Geeks

StackBlitz Blog

Cloudflare is now backing pkg.pr.new’s data infrastructure! Bolt 100K Open Source Fund ViteConf 2024 was a blast Unbundling the JavaScript ecosystem StackBlitz is joining the Open Source Pledge Announcing TutorialKit: Interactive tutorials in the browser Get ready for ViteConf 2024 Announcing pkg.pr.new StackBlitz welcomes Ari Perkkiö, core team member of Vitest Catch us at Figma Config WebContainers and the future of web dev (interview with Jòan Varvenne) Open Source at StackBlitz Avoiding CORS issues with this one simple trick How to document design system components What is Vite (and why is it so popular)? Improving the developer experience of enterprise design systems Flow state: Why fragmented thinking is worse than any interruption What is Storybook? An Overview for Developers Starters Upgrade: WebContainers and Vite Putting the Dev in Figma’s Dev Mode Announcing StackBlitz Self-hosted Building Together in Illinois 5 lessons design systems teams can learn from open-source maintainers Announcing Native Language Support in WebContainers Introducing StackBlitz Teams ViteConf is back! Bringing Sharp to WebAssembly and WebContainers npm, yarn and pnpm are now supported natively in WebContainers The Atomic Waltz: Unraveling WebAssembly Issues in V8 and SpiderMonkey WebContainers now run on Safari, iOS, and iPadOS Now I am become the Destroyer of Threads WebContainer API is here. StackBlitz September 2022 Update StackBlitz August 2022 Update StackBlitz July 2022 Update Introducing: Collections and Social Previews! Down the caching-hole: adventures in Announcing ViteConf StackBlitz June 2022 Update The Fox and the Bolt: Bringing WebContainers to Firefox WebContainers are now supported in Firefox on desktop and Android StackBlitz May 2022 Update StackBlitz April 2022 Update Cloudflare and StackBlitz partner to bring Cloudflare Workers to your browser Powering over 2M developers a month, StackBlitz has raised $7.9M StackBlitz March 2022 Update Announcement: WebContainers are out of beta in Chromium StackBlitz has joined the Bytecode Alliance StackBlitz February 2022 Update Bringing WebContainers to all Browsers: a call to action for COEP Credentialless Cross-Browser support with Cross-Origin isolation StackBlitz welcomes Patak, core maintainer of Vite Chasing Memory Bugs through V8 and WebAssembly Remix v1 has landed, and it runs on WebContainers SvelteKit is now fully supported in WebContainers We Shopify partners with StackBlitz to bring Hydrogen development in-browser StackBlitz September 2021 Update Introducing Vite.new Templates! Announcing WebContainers Astro support! 🛰 Introducing: SQLite3 support in WebContainers! 🧪 StackBlitz July 2021 Update StackBlitz June 2021 Update Introducing WebContainers: Run Node.js natively in your browser Interactive Docs: The new norm for Remote Work
The Self-Rendering Eval Shirt
Eric Simons CEO at StackBlitz making web development fast & secu · 2024-02-20 · via StackBlitz Blog

A few months ago I was looking for a way to say “thanks” to our users who came to our meetups, tried out our new products, or took a demo from our team.

A free t-shirt fit the bill, but free t-shirts are everywhere. With a few exceptions, most are pretty boring: usually just a logo on a t-shirt.

Its a logo… on a t-shirt. Its a logo… on a t-shirt.

Instead, I wanted to challenge ourselves to create a design our community would be genuinely excited to wear.

I also wanted our shirt to capture the spirit of what we do at StackBlitz—providing a web-based IDE that lets developers build for the web, anywhere.

The idea hit me as I was waiting to board a flight to Hawaii with my in-laws: a t-shirt design that incorporated the StackBlitz lightning bolt constructed with actually valid JavaScript code. And not only would the code be valid, it would be the source code of the image itself.

With 5 hours of uninterrupted plane time ahead of me, I pulled out my laptop and popped open a vite.new project. By the time the wheels touched the ground, I had a working design.

And a few months later, here’s the final result:

Demo video of the Eval Shirt

Getting this ready for prime time included a number of wild challenges: technically, how can you even make this type of program/design? And once we had it, how can you get it printed (without paying an arm and a leg) in full fidelity with such small font sizes?

In the rest of this post I’m going to go into detail how we pulled it off, but first…

How can you get one?!

Of course, the question you’re almost certainly asking 😃 Here are the three ways you can currently get your own StackBlitz Eval t-shirt:

  1. Join the meetup we’re hosting this Thursday, Feb 22nd at Figma HQ (space limited)!
  2. If you work at a company with more than a few hundred employees or a design system team, we’d love to chat! Just fill out this form and take a demo call with our team and we’ll send you a free t-shirt 👕
  3. If you don’t already have one, sign up for a StackBlitz Teams plan (starting at $29/month)!

So how did we make it? That’s one heck of a story…

Here’s where things get inception-y

First of all, for (perhaps obvious) recursive reasons, it’s not possible for a statically rendered image to display the exact source code of that image itself.

If you did try such a thing, you’d end up with an infinite loop that slugged through every bit of memory and storage your device has until it crashes completely. Every time you embed the source code, it would change the image code, which then would trigger a re-render, which would then change the image’s code…

But what about SVGs? Those things can accept plaintext as a subset of HTML. But we still run into the same problem. Each code addition changes the resulting image, leaving us with another infinite loop but this time with SVG markup.

How do you solve an impossible problem? Change the requirements to be possible.

So image binaries/markup alone cannot defeat the infinite loop problem. What if instead, we wrote a program that when evaluated, generates the image dynamically? The code displayed within the image is the source code of that program.

This means that the program’s code would have to be identical to the outputted code of the image. Or, in programming terms: what if we wrote a new type of quine?

Theoretically, that could work. But first, I needed a design as that will set the requirements of the program’s size and shape. StackBlitz’s logo is a lightning bolt. This is great, because it’s one contiguous object which means it should be easier to draw ASCII-art style.

I started by putting the StackBlitz bolt on the webpage, and then zero-filling by hand all the values to get a sense of how the image should look. This was a process of a lot of tweaking, figuring out how many lines of code top to bottom, how many characters for each line, and getting the spacing just right so it mapped perfectly onto the real lightning bolt.

Zero-filling the lightning bolt

Note: I’m sure there’s a pro way of doing this part, but I was on a timeboxed flight to Hawaii, so I was just brute forcing it!

After all my tweaks, I ended up with a very obvious lightning bolt. However, from a design/UX point of view, I didn’t think that it would be clear this is real, runnable code. To try and emphasize this, I add the big eval() statement around it — a function every JavaScript dev is familiar with. This was purely a design choice and isn’t technically needed as the code will be an IIFE.

Lightning bolt with the eval statement

Looks amazing! So I now have the ASCII-ified logo design. But, it’s not actually showing real code in the bolt. Now I need to make the program that’s actually going to output and render the program itself. Easy enough, right? Just call .toString() on the function?

And this is where things got really hard… and tedious! 🥵

To start, I wrote an IIFE that simply took the SVG layout, called .toString on itself, and inserted every character into the bolt. There were two problems with this:

  1. This was way too many characters, I’d need to minify the code.
  2. For someone to be able to copy and paste this code, every single line has to be valid JavaScript. And nearly everly line of code in the lightning bolt was not a valid statement after it got rendered.

I’ll spare you the tedious details of my 5 hours of trial and error. But let’s just say, it was like playing a murderous game of Jenga. You get one line to be valid, only to mess up the one 4 lines down, rinse and repeat…

One nice trick for solving multi-line was using modern ES6 template literals, which is how I was able to load the correct Google Font in there (technically you could do this for every line of code which would’ve made it far easier, but what’s the fun in that?!)

Finally… voilà!

An SVG composed of actual code that you can copy and paste directly into any Javascript console and it outputs itself. Need convincing? Try it for yourself over at stackblitz.com/eval or in the embedded editor below:

Several weeks later, wearing the design on an actual t-shirt, I like to think the code is actually rendering itself onto the fabric. It’s a piece of digital graffiti that can be copied infinitely in both the physical and digital mediums.

StackBlitz quine tshirt

Getting the small font size of the code printed in full fidelity was a challenge most vendors couldn’t achieve. Fortunately, our merchandising partners at Canary were able to work some magic and brought my idea to life, and we’re excited to share this with all of you! Developer cred aside, these are the softest shirts I’ve ever worn and arrive in packaging (created by Corey Thomas) that explain the story behind the design.

Again… how can you get one?!

It’s pretty cool, right! Here are the ways you can currently get your own StackBlitz Eval t-shirt:

  1. If you work at a company with more than a few hundred employees or a design system team, we’d love to chat! Just fill out this form and take a demo call with our team and we’ll send you a free t-shirt 👕
  2. If you don’t already have one, sign up for a StackBlitz Teams plan (starting at $29/month)!

I hope you’re as excited to share this with your friends and coworkers as I am. I can’t wait to for the selfies to start popping up on my timeline 🤳