<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dmitry Borody</title>
    <description>The latest articles on DEV Community by Dmitry Borody (@dmitru).</description>
    <link>https://dev.to/dmitru</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F318989%2F190a6389-d814-48fa-991c-fe214d66655e.jpg</url>
      <title>DEV Community: Dmitry Borody</title>
      <link>https://dev.to/dmitru</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmitru"/>
    <language>en</language>
    <item>
      <title>Console.log for Images and Canvases</title>
      <dc:creator>Dmitry Borody</dc:creator>
      <pubDate>Mon, 21 Sep 2020 16:01:39 +0000</pubDate>
      <link>https://dev.to/dmitru/displaying-images-in-browser-console-58mm</link>
      <guid>https://dev.to/dmitru/displaying-images-in-browser-console-58mm</guid>
      <description>&lt;p&gt;🎉 Just published a &lt;a href="https://www.npmjs.com/package/console-log-img" rel="noopener noreferrer"&gt;tiny NPM library&lt;/a&gt; to print images in the browser console!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foayk29b29vjudw9h3ygx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foayk29b29vjudw9h3ygx.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's like &lt;code&gt;console.log&lt;/code&gt;, but for images: you can print an image from a URL, a Canvas or Image element, or an ImageBitmap.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to use it
&lt;/h1&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initConsoleLogImg&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;console-log-img&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;// Run this once to initialize the library&lt;/span&gt;
&lt;span class="nf"&gt;initConsoleLogImg&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// Optionally, disable image dimensions logging (enabled by default)&lt;/span&gt;
  &lt;span class="na"&gt;printDimensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// ... later in the code ...&lt;/span&gt;

&lt;span class="c1"&gt;// Print an image from a URI, at original size&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;img&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://openclipart.org/image/800px/5661&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Print a Canvas at 30% zoom, also log canvas dimensions&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;img&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Print a CanvasRenderingContext2D&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;img&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Print an ImageBitmap at 100% zoom&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bitmap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createImageBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;img&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Print an Image DOM element&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imgEl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-img&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;img&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;imgEl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/console-log-img-test-bti64" rel="noopener noreferrer"&gt;DEMO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code was adapted from various sources and wrapped up in a neat TypeScript library.&lt;/p&gt;

&lt;p&gt;Under the hood, it uses some hacks with styled console.log to set the background to the passed image. Check out the &lt;a href="https://github.com/dmitru/console-log-img" rel="noopener noreferrer"&gt;source code&lt;/a&gt; if you want more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why would you want to print images to console?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Easier Debugging
&lt;/h3&gt;

&lt;p&gt;I used it extensively when working on Canvas-heavy apps (e.g. &lt;a href="https://inkarnate.com" rel="noopener noreferrer"&gt;Inkarnate&lt;/a&gt; – online fantasy maps editor) to make debugging of Canvas rendering easier.&lt;/p&gt;

&lt;p&gt;I think it'll be especially helpful for those working on Canvas visualizations (e.g. generative artists) or other graphical apps like editors or generators.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Uses
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hiring banners&lt;/strong&gt;. You can use it to show some fancy-pants hiring console banners to invite web devs to join your team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fraud prevention.&lt;/strong&gt; Ever seen anti-fraud console banner on Facebook? That's to prevent bad guys from manipulating users into pasting bad things to their browser console.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it! Hope you'll find it helpful. 😃&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Faster TypeScript compilation in VSCode</title>
      <dc:creator>Dmitry Borody</dc:creator>
      <pubDate>Tue, 08 Sep 2020 17:55:28 +0000</pubDate>
      <link>https://dev.to/dmitru/faster-typescript-compilation-in-vscode-13c3</link>
      <guid>https://dev.to/dmitru/faster-typescript-compilation-in-vscode-13c3</guid>
      <description>&lt;h2&gt;
  
  
  TypeScript is slow in VSCode?
&lt;/h2&gt;

&lt;p&gt;We all know how &lt;strong&gt;TypeScript can get slow in VSCode&lt;/strong&gt; 🐌 . Ever found yourself waiting for the compiler to catch up with you as you type new code or fix errors?&lt;/p&gt;

&lt;p&gt;This quickly gets frustrating, slowing down your feedback loops (and fast feedback loops are great to keep you happy and motivated!).&lt;/p&gt;

&lt;p&gt;Here I'm &lt;strong&gt;sharing a simple tip that saved me hours&lt;/strong&gt; of my life over the last 3 years working with TypeScript codebases (especially large ones!).&lt;/p&gt;

&lt;p&gt;I wish I knew it earlier when I was just getting started with TypeScript…&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix slow TypeScript compilation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Here’s the trick:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Run a separate TypeScript process in watch mode in a terminal tab.&lt;/li&gt;
&lt;li&gt;Keep it running as you write code — it’ll respond to changes and highlight errors a lot faster compared to VSCode.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iWKKJQQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yf3b6ozxl1mw426w50w5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iWKKJQQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yf3b6ozxl1mw426w50w5.png" alt="How to make TypeScript compile faster in VSCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my experience, the difference can be striking (see the screenshot). It seems to depend on the project and npm libs it’s using, but the general pattern is pretty consistent across different projects and TS versions I worked with.&lt;/p&gt;

&lt;p&gt;Now I don't know exactly how and why this hack works. What's important is that it makes my work life better! 😃 &lt;/p&gt;

&lt;p&gt;And hopefully yours too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrate with your TypeScript project
&lt;/h2&gt;

&lt;p&gt;Here’s how to make it more convenient to use this trick in your TypeScript projects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add these 2 NPM scripts to your package.json:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  ...
  "typecheck": "tsc",
  "typecheck:watch": "tsc -w"
  ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now run npm run &lt;code&gt;typecheck:watch&lt;/code&gt; in a terminal tab (I like to do it in VSCode’s Terminal panel to keep things in the same window).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This starts a separate TypeScript process in the watch mode. It’ll take some time to start, but it’ll be much faster to re-compile your code incrementally as you change your code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use npm run typechek if only need to do the check once. It’ll run faster than the watch mode.
I find it handy e.g. before deploying to make sure the build will be succesful.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  🙌 That’s it!
&lt;/h2&gt;

&lt;p&gt;I hope this tip helps you to have a faster TypeScript workflow and to be more efficient and happier when coding (it certainly helped me).&lt;/p&gt;

&lt;p&gt;Please share your own experiences — did it help you to speed up your workflow?&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vscode</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
