David Walsh Blog https://davidwalsh.name A blog featuring tutorials about JavaScript, HTML5, AJAX, PHP, CSS, WordPress, and everything else development. Wed, 04 Sep 2024 04:42:37 +0000 en-US hourly 1 https://wordpress.org/?v=5.0.2 How to Download a YouTube Video or Channel https://davidwalsh.name/download-youtube-mp3 https://davidwalsh.name/download-youtube-mp3#respond Wed, 04 Sep 2024 04:42:36 +0000 <![CDATA[David Walsh]]> <![CDATA[Quick Tips]]> <![CDATA[Shell]]> https://davidwalsh.name/?p=27867 <![CDATA[

The ability to download media on the internet almost feels like a lost art. When I was in my teens, piracy of mp3s, movies, and just about everything else via torrents and apps like Kazaa, LimeWire, Napster, etc. was in full swing. These days sites use blob URLs and other means to prevent downloads. Luckily […]

The post How to Download a YouTube Video or Channel appeared first on David Walsh Blog.

]]>
<![CDATA[

The ability to download media on the internet almost feels like a lost art. When I was in my teens, piracy of mp3s, movies, and just about everything else via torrents and apps like Kazaa, LimeWire, Napster, etc. was in full swing. These days sites use blob URLs and other means to prevent downloads. Luckily we have tools like yt-dlp to download individual YouTube videos or entire channels of content.

To download an entire channel, you can use yt-dlp:

yt-dlp https://www.youtube.com/@beetlejuicearchives3490

If you’re like me and only care for the audio, you can use a few more arguments:

yt-dlp -x --audio-format mp3 https://www.youtube.com/@beetlejuicearchives3490

youtube-dl used to be the standard for downloading YouTube videos but yt-dlp seems to have taken the throne. YouTube has such a wealth of information on just about anything, be sure to download content for travel, long walks, or any other reason!

The post How to Download a YouTube Video or Channel appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/download-youtube-mp3/feed 0
How to Add a Header to a curl Request https://davidwalsh.name/curl-add-header https://davidwalsh.name/curl-add-header#respond Sat, 03 Aug 2024 16:51:46 +0000 <![CDATA[David Walsh]]> <![CDATA[Quick Tips]]> <![CDATA[Shell]]> https://davidwalsh.name/?p=27866 <![CDATA[

curl is one of those great utilities that’s been around seemingly forever and has endless use cases. These days I find myself using curl to batch download files and test APIs. Sometimes my testing leads me to using different HTTP headers in my requests. To add a header to a curl request, use the -H […]

The post How to Add a Header to a curl Request appeared first on David Walsh Blog.

]]>
<![CDATA[

curl is one of those great utilities that’s been around seemingly forever and has endless use cases. These days I find myself using curl to batch download files and test APIs. Sometimes my testing leads me to using different HTTP headers in my requests.

To add a header to a curl request, use the -H flag:

curl -X 'GET' \
 'https://nft.api.cx.metamask.io/collections?chainId=1' \
 -H 'accept: application/json' \
 -H 'Version: 1'

You can add multiple headers with multiple -H uses. Header format is usually [key]: [value].

The post How to Add a Header to a curl Request appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/curl-add-header/feed 0
Case Insensitive CSS Attribute Selector https://davidwalsh.name/css-attribute-case https://davidwalsh.name/css-attribute-case#respond Wed, 19 Jun 2024 11:31:27 +0000 <![CDATA[David Walsh]]> <![CDATA[CSS]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27859 <![CDATA[

CSS selectors never cease to amaze me in how powerful they can be in matching complex patterns. Most of that flexibility is in parent/child/sibling relationships, very seldomly in value matching. Consider my surprise when I learned that CSS allows matching attribute values regardless off case! Adding a {space}i to the attribute selector brackets will make […]

The post Case Insensitive CSS Attribute Selector appeared first on David Walsh Blog.

]]>
<![CDATA[

CSS selectors never cease to amaze me in how powerful they can be in matching complex patterns. Most of that flexibility is in parent/child/sibling relationships, very seldomly in value matching. Consider my surprise when I learned that CSS allows matching attribute values regardless off case!

Adding a {space}i to the attribute selector brackets will make the attribute value search case insensitive:

/* case sensitive, only matches "example" */
[class=example] {
  background: pink;
}

/* case insensitive, matches "example", "eXampLe", etc. */
[class=example i] {
  background: lightblue;
}

The use cases for this i flag are likely very limited, especially if this flag is knew knowledge for you and you’re used to a standard lower-case standard. A loose CSS classname standard will have and would continue to lead to problems, so use this case insensitivity flag sparingly!

The post Case Insensitive CSS Attribute Selector appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/css-attribute-case/feed 0
How to Set Date Time from Mac Command Line https://davidwalsh.name/mac-set-date https://davidwalsh.name/mac-set-date#comments Mon, 17 Jun 2024 12:01:38 +0000 <![CDATA[David Walsh]]> <![CDATA[Quick Tips]]> <![CDATA[Shell]]> https://davidwalsh.name/?p=27858 <![CDATA[

Working on a web extension that ships to an app store and isn’t immediately modifiable, like a website, can be difficult. Since you cannot immediately deploy updates, you sometimes need to bake in hardcoded date-based logic. Testing future dates can be difficult if you don’t know how to quickly change the date on your local […]

The post How to Set Date Time from Mac Command Line appeared first on David Walsh Blog.

]]>
<![CDATA[

Working on a web extension that ships to an app store and isn’t immediately modifiable, like a website, can be difficult. Since you cannot immediately deploy updates, you sometimes need to bake in hardcoded date-based logic. Testing future dates can be difficult if you don’t know how to quickly change the date on your local machine.

To change the current date on your Mac, execute the following from command line:

# Date Format:  MMDDYYYY
sudo date -I 06142024

This command does not modify time, only the current date. Using the same command to reset to current date is easy as well!

The post How to Set Date Time from Mac Command Line appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/mac-set-date/feed 1
How to Retrieve WiFi Password on Windows https://davidwalsh.name/retrieve-wifi-password-windows https://davidwalsh.name/retrieve-wifi-password-windows#respond Mon, 13 May 2024 10:45:29 +0000 <![CDATA[David Walsh]]> <![CDATA[Microsoft]]> <![CDATA[Shell]]> https://davidwalsh.name/?p=27852 <![CDATA[

Remembering the WiFi password when on a guest network is never easy. Even worse is when it’s no longer posted and someone else is asking you for it. Luckily there’s a built in Windows command to recover the password of a given WiFi network. The Shell Code Open cmd and execute the following command: netsh […]

The post How to Retrieve WiFi Password on Windows appeared first on David Walsh Blog.

]]>
<![CDATA[

Remembering the WiFi password when on a guest network is never easy. Even worse is when it’s no longer posted and someone else is asking you for it. Luckily there’s a built in Windows command to recover the password of a given WiFi network.

The Shell Code

Open cmd and execute the following command:

netsh wlan show profile name="David Walsh's Network" key=clear

The result of the command, assuming the network is found, is a long text output with a variety of information about the network. To get the see the password for the network, look under the “Security settings” heading which will look like this:

Security settings
-----------------
    Authentication         : WPA2-Personal
    Cipher                 : CCMP
    Authentication         : WPA2-Personal
    Cipher                 : GCMP
    Security key           : Present
    Key Content            : **THE_PLAIN_TEXT_PASSWORD**

As with any complicated command line format, it’s best to create an alias so that you don’t need to remember the full string!

The post How to Retrieve WiFi Password on Windows appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/retrieve-wifi-password-windows/feed 0
How to Fix: Windows WASD Keys Reversed with Arrow Keys https://davidwalsh.name/fix-wasd-keys https://davidwalsh.name/fix-wasd-keys#comments Thu, 02 May 2024 01:55:27 +0000 <![CDATA[David Walsh]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27850 <![CDATA[

This past weekend I had the opportunity to be what every father wants, if only for a moment: the “cool dad”. My wife was out of town and my youngest son wanted to play PUBG. I caved in, taught him the basic FPS key binds, and he was having a great time. While he was […]

The post How to Fix: Windows WASD Keys Reversed with Arrow Keys appeared first on David Walsh Blog.

]]>
<![CDATA[

This past weekend I had the opportunity to be what every father wants, if only for a moment: the “cool dad”. My wife was out of town and my youngest son wanted to play PUBG. I caved in, taught him the basic FPS key binds, and he was having a great time. While he was fragging out, he pressed a bunch of random keys and ended up changing movement buttons. Suddenly the traditional WASD movement keys were useless and the arrow keys triggered movement.

Of course, this was a degradation of player experience. After struggling to figure out what my son did, I found the solution.

To restore the WASD keys as movement keys, press the FN+W key combination. You’ll switch back to WASD keys for movement and be back on top of your game!

The post How to Fix: Windows WASD Keys Reversed with Arrow Keys appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/fix-wasd-keys/feed 1
HTML popover Attribute https://davidwalsh.name/html-popover-attribute https://davidwalsh.name/html-popover-attribute#comments Mon, 15 Apr 2024 11:19:02 +0000 <![CDATA[David Walsh]]> <![CDATA[CSS]]> <![CDATA[HTML5]]> https://davidwalsh.name/?p=27845 <![CDATA[

Modals have been an important part of websites for two decades. Stacking contents and using fetch to accomplish tasks are a great way to improve UX on both desktop and mobile. Unfortunately most developers don’t know that the HTML and JavaScript specs have implemented a native modal system via the popover attribute — let’s check […]

The post HTML popover Attribute appeared first on David Walsh Blog.

]]>
<![CDATA[

Modals have been an important part of websites for two decades. Stacking contents and using fetch to accomplish tasks are a great way to improve UX on both desktop and mobile. Unfortunately most developers don’t know that the HTML and JavaScript specs have implemented a native modal system via the popover attribute — let’s check it out!

The HTML

Creating a native HTML modal consists of using the popovertarget attribute as the trigger and the popover attribute, paired with an id, to identify the content element:

<!-- 
  "popovertarget" attribute will map to "id" of popover contents
-->
<button popovertarget="popover-contents">Open popover</button>
<div id="popover-contents" popover>This is the contents of the popover</div>

Upon clicking the button, the popover will open. The popover, however, will not have a traditional background layer color so we’ll need to implement that on our own with some CSS magic.

The CSS

Styling the contents of the popover content is pretty standard but we can use the browser stylesheet selector’s pseudo-selector to style the “background” of the modal:

/* contents of the popover */
[popover] {
  background: lightblue;
  padding: 20px;
}

/* the dialog's "modal" background */
[popover]:-internal-popover-in-top-layer::backdrop {
  background: rgba(0, 0, 0, .5);  
}

:-internal-popover-in-top-layer::backdrop represents the “background” of the modal. Traditionally that UI has been an element with opacity such to show the stacking relationship.

The post HTML popover Attribute appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/html-popover-attribute/feed 6
Get Started in AI and NFTs with the Limewire API (Sponsored) https://davidwalsh.name/get-started-in-ai-and-nfts-with-the-limewire-api https://davidwalsh.name/get-started-in-ai-and-nfts-with-the-limewire-api#respond Mon, 25 Mar 2024 21:50:46 +0000 <![CDATA[David Walsh]]> <![CDATA[Sponsored]]> https://davidwalsh.name/?p=27840 <![CDATA[

AI media creation has expanded to incredible video art and a host of other important improvements, and LimeWire is leading the way in creating an awesome interface for the average user to become an AI artist. Limewire has just released its Developer API, a method for engineers like us to create dynamic AI art on […]

The post Get Started in AI and NFTs with the Limewire API (Sponsored) appeared first on David Walsh Blog.

]]>
<![CDATA[
LimeWire

AI media creation has expanded to incredible video art and a host of other important improvements, and LimeWire is leading the way in creating an awesome interface for the average user to become an AI artist. Limewire has just released its Developer API, a method for engineers like us to create dynamic AI art on the fly!

Quick Hits

  • Free to sign up!
  • Provides methods to create a variety of quality images from any number of AI services and algorithms
  • Create images based on text and other images
  • Modify existing images to scale them, remove backgrounds, and more
  • Use JavaScript, PHP, Python, or any of your favorite languages
  • Documentation is clean and easy to understand
  • Very easy to get started

A simple API call is as easy as:

curl -i -X POST \
  https://api.limewire.com/api/image/generation \
  -H 'Authorization: Bearer MY_API_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'X-Api-Version: v1' \
  -d '{
    "prompt": "A beautiful princess in front of her kingdom",
    "aspect_ratio": "1:1"
  }'

You can also upscale an existing, uploaded image:

curl -i -X POST \
  https://api.limewire.com/api/image/upscaling \
  -H 'Authorization: Bearer MY_API_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'X-Api-Version: v1' \
  -d '{
    "image_asset_id": "116a972f-666a-44a1-a3df-c9c28a1f56c0",
    "upscale_factor": 4
  }'

The value in creating AI art dynamically is hard to stress the enormity of for engineers and authors alike. Rather than scouring Google Images for image to match my blog post, I can use LimeWire’s API to send keywords from the article to create a representative image. Likewise, authors can feed their story to LimeWire to generate illustrations! You can even integrate the developer API into your platform for your users to employ!

Give LimeWire’s new developer API a try! LimeWire lets you create AI images where you are!

The post Get Started in AI and NFTs with the Limewire API (Sponsored) appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/get-started-in-ai-and-nfts-with-the-limewire-api/feed 0
I’m So Old: Web Edition https://davidwalsh.name/im-so-old-1 https://davidwalsh.name/im-so-old-1#comments Mon, 18 Mar 2024 13:00:20 +0000 <![CDATA[David Walsh]]> <![CDATA[Theory / Ideas]]> https://davidwalsh.name/?p=27834 <![CDATA[

Time can be a funny thing. I still remember discovering HTML, CSS, and JavaScript coding. I still remember my first college programming course. I still remember my first day at my first coding job, then my first day at my second coding job, and then my first day at Mozilla. I still remember my first […]

The post I’m So Old: Web Edition appeared first on David Walsh Blog.

]]>
<![CDATA[

Time can be a funny thing. I still remember discovering HTML, CSS, and JavaScript coding. I still remember my first college programming course. I still remember my first day at my first coding job, then my first day at my second coding job, and then my first day at Mozilla. I still remember my first day coding for MetaMask. This year marks my 20th year as a professional software engineer and it’s happened in the blink of an eye.

Every once in a while I will make an old programming reference to a much younger engineer and then realize they have no idea what I’m talking about.

I’m so old…

  • Webpage layouts were being done with <table>s and this new “CSS float” property was becoming the new standard
  • Rounded corners were achieved via images and VML hacks for Internet Explorer
  • FTP was the best way to upload websites changes
  • SVN and copying its trunk was the best versioning tool
  • alert and confirm were the standard for “modals”
  • Firebug was the best debugging tool available
  • The “standard” for getting videos to play properly was finding the right codec to install
  • ActionScript knowledge was as valuable as JavaScript knowledge
  • Dreamweaver was best in class text editor and design tool
  • XML was the future of data structures
  • Mobile-first? Mobile didn’t exist
  • Reactive navigation? How about Java Applets…
  • …or even different <img src=""> upon mouseover and mouseleave!
  • Want to code a desktop app with web tech? Try Adobe Air!
  • NPM stood for “not performant, man”
  • Voting on a poll meant the page would refresh
  • “Social media” meant HotOrNot.com
  • The love sound of the web was a 56k modem connection purrrrr
  • Disabling right-click enforced image security
  • Bitmap (.bmp) was a viable image format
  • JavaScript had a competitor called JScript
  • SpyJax’ing let you detect where your user had been
  • Cookies were the pinnacle of user tracking
  • Social media wall? It’s called a “guestbook”…
  • …and a friends list? It’s called a “web ring’
  • Search engine optimization was spamming the <title> with keywords=

Whew, those where the days. How old are you in web?

The post I’m So Old: Web Edition appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/im-so-old-1/feed 40
Detect Caps Lock with JavaScript https://davidwalsh.name/detect-caps-lock https://davidwalsh.name/detect-caps-lock#comments Tue, 06 Feb 2024 10:33:10 +0000 <![CDATA[David Walsh]]> <![CDATA[JavaScript]]> https://davidwalsh.name/?p=27828 <![CDATA[

Anyone is capable of having their caps lock key on at any given time without realizing so. Users can easily spot unwanted caps lock when typing in most inputs, but when using a password input, the problem isn’t so obvious. That leads to the user’s password being incorrect, which is an annoyance. Ideally developers could […]

The post Detect Caps Lock with JavaScript appeared first on David Walsh Blog.

]]>
<![CDATA[

Anyone is capable of having their caps lock key on at any given time without realizing so. Users can easily spot unwanted caps lock when typing in most inputs, but when using a password input, the problem isn’t so obvious. That leads to the user’s password being incorrect, which is an annoyance. Ideally developers could let the user know their caps lock key is activated.

To detect if a user has their keyboard’s caps lock turn on, we’ll employ KeyboardEvent‘s getModifierState method:

document.querySelector('input[type=password]').addEventListener('keyup', function (keyboardEvent) {
    const capsLockOn = keyboardEvent.getModifierState('CapsLock');
    if (capsLockOn) {
        // Warn the user that their caps lock is on?
    }
});

I’d never seen getModifierState used before, so I explored the W3C documentation to discover other useful values:

dictionary EventModifierInit : UIEventInit {
  boolean ctrlKey = false;
  boolean shiftKey = false;
  boolean altKey = false;
  boolean metaKey = false;

  boolean modifierAltGraph = false;
  boolean modifierCapsLock = false;
  boolean modifierFn = false;
  boolean modifierFnLock = false;
  boolean modifierHyper = false;
  boolean modifierNumLock = false;
  boolean modifierScrollLock = false;
  boolean modifierSuper = false;
  boolean modifierSymbol = false;
  boolean modifierSymbolLock = false;
};

getModifierState provides a wealth of insight as to the user’s keyboard during key-centric events. I wish I had known about getModifier earlier in my career!

The post Detect Caps Lock with JavaScript appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/detect-caps-lock/feed 2
How to Override width and height HTML attributes with CSS https://davidwalsh.name/css-override-width-height https://davidwalsh.name/css-override-width-height#respond Mon, 05 Feb 2024 11:28:01 +0000 <![CDATA[David Walsh]]> <![CDATA[CSS]]> <![CDATA[HTML5]]> https://davidwalsh.name/?p=27804 <![CDATA[

One of the HTML elements that frequently comes into collision with CSS is the img element. As we learned in Request Metrics’ Fixing Cumulative Layout Shift Problems on DavidWalshBlog article, providing image dimensions within the image tag will help to improve your website’s score. But in a world where responsive design is king, we need […]

The post How to Override width and height HTML attributes with CSS appeared first on David Walsh Blog.

]]>
<![CDATA[

One of the HTML elements that frequently comes into collision with CSS is the img element. As we learned in Request Metrics’ Fixing Cumulative Layout Shift Problems on DavidWalshBlog article, providing image dimensions within the image tag will help to improve your website’s score. But in a world where responsive design is king, we need CSS and HTML to work together.

Most responsive design style adjustments are done via max-width values, but when you provide a height value to your image, you can get a distorted image. The goal should always be a display images in relative dimensions. So how do we ensure the height attribute doesn’t conflict with max-width values?

The answer is as easy as height: auto!

/* assuming any media query */
img {
  /* Ensure the image doesn't go offscreen */
  max-width: 500px;
  /* Ensure the image height is responsive regardless of HTML attribute */
  height: auto;
}

The dance to please users and search engines is always a fun balance. CSS and HTML were never meant to conflict but in some cases they do. Use this code to optimize for both users and search engines!

The post How to Override width and height HTML attributes with CSS appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/css-override-width-height/feed 0
Fixing Cumulative Layout Shift Problems on DavidWalshBlog https://davidwalsh.name/fixing-cumulative-layout-shift-problems-on-davidwalshblog https://davidwalsh.name/fixing-cumulative-layout-shift-problems-on-davidwalshblog#respond Wed, 24 Jan 2024 11:56:41 +0000 <![CDATA[Todd Gardner]]> <![CDATA[Optimization]]> <![CDATA[Performance]]> https://davidwalsh.name/?p=27819 <![CDATA[

Over 50 thousand developers visit DavidWalshBlog every month from around the world to learn JavaScript tricks and fix problems in their code. Unfortunately, some of them have a slow experience on the site. David tracks the performance of his Core Web Vitals and overall performance with Request Metrics. Recently, we noticed that his CLS performance […]

The post Fixing Cumulative Layout Shift Problems on DavidWalshBlog appeared first on David Walsh Blog.

]]>
<![CDATA[

Over 50 thousand developers visit DavidWalshBlog every month from around the world to learn JavaScript tricks and fix problems in their code. Unfortunately, some of them have a slow experience on the site.

David tracks the performance of his Core Web Vitals and overall performance with Request Metrics. Recently, we noticed that his CLS performance score was trending pretty slow for both desktop and mobile users.

Wait, what is CLS?

Cumulative Layout Shift (CLS) is one of the Core Web Vital performance metrics. It doesn’t measure load time directly, instead it measures how much a page shifts while it is being loaded. You’ve definitely seen this and been annoyed by it. These shifts make a site feel slow to a user.

CLS and the rest of the Core Web Vitals are super important. Not only because they measure user experience, but also because they influence the pagerank of a site in search. And search traffic is life for bloggers, media sites, e-commerce stores, and pretty much everyone with a website.

If we can fix the site’s CLS problem, we’ll give readers a faster experience, and boost the search ranking so David can help even more people. Sounds like a great incentive, let’s figure it out.

Crashing with Google Lighthouse

To find a performance problem, many developers will use a tool like Google Lighthouse. I ran a Lighthouse report on David’s site, and here’s what I got.

A perfect score! Let’s pack it up and go home.

The trouble is that Google Lighthouse is a lie. Real users won’t have this performance. That score only represents a single test, from my lightning-fast computer, in the USA, on a fast broadband connection.

David’s real users come from all over the world, on varying devices and networks, and at all times of the day. Their performance experience is far from perfect. That’s why we need to get real user monitoring for the performance, otherwise we might never know that there is a problem.

Where are the CLS problems?

David has been writing for a long time and has hundreds of posts on his site. Request Metrics tracks the CLS score per page so we can zero-in on the problems.

The largest traffic page is the root page, and that has a good CLS. But many of his posts, like Play Grand Poo World and Pornhub Interview have troubling CLS scores. We can also track the elements responsible for CLS, and for most of the posts its main > article > p. That means the first paragraph of the article is the thing shifting. Why would it do that?

What is common about these posts with the worst CLS scores? Images. Images are a very common cause of CLS problems because a browser doesn’t always know how big an image is until it’s downloaded. The browser assumes it’s 0x0 until it has the image, then shifts everything around it to make room.

Posts with lots of images would shift many times as each image was downloaded and the article shifted to make room for the new content.

Using images correctly for CLS

To avoid layout shifts when using images, we need to give the browser hints about how big the images will be. The browser will use these hints to reserve space in the layout for the image when it’s finished downloading.

<img src="/path/to/image" width="300" height="100" />

Notice that the width and height are specified as their own attributes — not part of a style tag. These attributes set both a base size of the image as well as the aspect ratio to use. You can still use CSS to make the image bigger or smaller from here.

Also notice that there is no px unit specified.

Image Sizes in WordPress

DavidWalsh.name is hosted on WordPress, where there are some built-in tools to do this. We can utilize wp_image_src_get_dimensions to get the dimensions of images he’s using and add them to the markup.

Proving it works

David made the image changes a few days ago, and we’re already seeing an improvement. CLS has dropped 20% to 0.123. We’re real close to the “Good” range of CLS now.

There’s still some issues to sort out around fonts, but that will be a story for another time and another post.

If you’re looking to improve the real performance of your site, or worried about losing your SEO juice from Core Web Vital problems, have a look at Request Metrics. It’s got the tools to track your performance and actionable tips to actually fix the problems.

Plus it’s free, so it’s got that going for it.

The post Fixing Cumulative Layout Shift Problems on DavidWalshBlog appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/fixing-cumulative-layout-shift-problems-on-davidwalshblog/feed 0
Date.now() https://davidwalsh.name/date-now https://davidwalsh.name/date-now#respond Wed, 17 Jan 2024 12:06:16 +0000 <![CDATA[David Walsh]]> <![CDATA[JavaScript]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27803 <![CDATA[

Ask any software engineer and they’ll tell you that coding date logic can be a nightmare. Developers need to consider timezones, weird date defaults, and platform-specific date formats. The easiest way to work with dates is to reduce the date to the most simple format possible — usually a timestamp. To get the immediate time […]

The post Date.now() appeared first on David Walsh Blog.

]]>
<![CDATA[

Ask any software engineer and they’ll tell you that coding date logic can be a nightmare. Developers need to consider timezones, weird date defaults, and platform-specific date formats. The easiest way to work with dates is to reduce the date to the most simple format possible — usually a timestamp. To get the immediate time in integer format, you can use Date.now:

const now = Date.now(); // 1705190738870

I will oftentimes employ Date.now() in my console.log statements to differentiate likewise console.log results from each other. You could also use that date as a unique identifier for an event in a low-traffic environment.

The post Date.now() appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/date-now/feed 0
Extract a Number from a String with JavaScript https://davidwalsh.name/javascript-extract-string https://davidwalsh.name/javascript-extract-string#comments Tue, 16 Jan 2024 11:48:41 +0000 <![CDATA[David Walsh]]> <![CDATA[JavaScript]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27802 <![CDATA[

User input from HTML form fields is generally provided to JavaScript as a string. We’ve lived with that fact for decades but sometimes developers need to extract numbers from that string. There are multiple ways to get those numbers but let’s rely on regular expressions to extract those numbers! To employ a regular expression to […]

The post Extract a Number from a String with JavaScript appeared first on David Walsh Blog.

]]>
<![CDATA[

User input from HTML form fields is generally provided to JavaScript as a string. We’ve lived with that fact for decades but sometimes developers need to extract numbers from that string. There are multiple ways to get those numbers but let’s rely on regular expressions to extract those numbers!

To employ a regular expression to get a number within a string, we can use \d+:

const string = "x12345david";
const [match] = string.match(/(\d+)/);
match; // 12345

Regular expressions are capable of really powerful operations within JavaScript; this practice is one of the easier operations. Converting the number using a Number() wrapper will give you the number as a Number type.

The post Extract a Number from a String with JavaScript appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/javascript-extract-string/feed 1
Thoughts on Streaming Services: 2024 Edition https://davidwalsh.name/streaming-2024 https://davidwalsh.name/streaming-2024#comments Mon, 15 Jan 2024 11:08:32 +0000 <![CDATA[David Walsh]]> <![CDATA[Theory / Ideas]]> https://davidwalsh.name/?p=27800 <![CDATA[

Streaming services have revolutionized content delivery, sending linear media companies into a panic as they watch traditional cable services decay. “Cutting the cord” is a common practice these days, but the streaming landscape isn’t perfect. We’re a decade into streaming so I wanted to share my thoughts on the state of new media: first impressions, […]

The post Thoughts on Streaming Services: 2024 Edition appeared first on David Walsh Blog.

]]>
<![CDATA[

Streaming services have revolutionized content delivery, sending linear media companies into a panic as they watch traditional cable services decay. “Cutting the cord” is a common practice these days, but the streaming landscape isn’t perfect. We’re a decade into streaming so I wanted to share my thoughts on the state of new media: first impressions, second thoughts, and the third degree!

  • Netflix is king thanks to having first mover advantage, and making smart financial moves over the past six months, but Netflix’s content is unremarkable. Their recent wins are USA’s Suits and content licensed from Max…they need to do better
  • The biggest loser in the current streaming landscape is the sports fan. Want to watch American Football? You need YouTubeTV, Peacock, and Amazon Prime. Soccer fan? You need Peacock, ESPN Plus, Paramount Plus, and then AppleTV Plus if you care about MLS. Being a live sports fan is really, really expensive.
  • The parent companies of HBO and Showtime killed their brands with “Max” and “Paramount Plus”. HBO’s brand name and fuzzy fade in are iconic; “Max” means nothing. Part of me died with this stupid brand change.
  • Streaming services lured us in with no advertisements but they’ve learned that the ad tiers generate more revenue. Now they’re trying to price us out to get us to choose the cheaper, ad-driven tier. Smart business but I’ll pay more to avoid the ads.
  • Apple has all the resources in the world but they treat their streaming service like everything else they do: offer an unremarkable product and skate off of name. Ted Lasso was good, as was Shrinking, but everything else is filler…
  • …and charging for Killers of the Flower Moon during the holidays, then providing it for free once people are back to work, is an embarrassing money grab.
  • Amazon doesn’t offer nearly enough in exclusive content. These tech companies are half in, half out.
  • Warner Brothers Discovery licensing their content, especially the Marvel Comic Universe IP, to Netflix because they need quick cash feels like a self-own. How do you grow Max by giving your best content to a better service?
  • AppleTV’s hardware is insanely elegant to use, though I’m annoyed they didn’t commit to their gaming offering. Roku still feels like a Super Nintendo in a N64 world.
  • The free streaming options these days are awesome if you don’t want to spend money. YouTube, RokuTV, and Tubi provide loads of great content at no expense.
  • Disney Plus offer loads of great old movies but my kids rarely watch it — they’re busy watching cringe shows on Netflix…
  • One huge frustration is the lack of a “previous” button that cable remotes had. Navigating between channels in YouTubeTV is painful
  • …and to further improve the experience, it would be great if AppleTV and Roku would allow users to have two apps side by side; let us build our own multi-view.
  • Part of me wants to bin off all of my sports streaming services and simply use StreamEast…but the convenience is just too nice.

Agree or disagree? What did I miss? Let me know in the comments below!

The post Thoughts on Streaming Services: 2024 Edition appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/streaming-2024/feed 4
AutoGrow Textareas with CSS https://davidwalsh.name/autogrow-textareas https://davidwalsh.name/autogrow-textareas#comments Mon, 18 Dec 2023 11:55:51 +0000 <![CDATA[David Walsh]]> <![CDATA[CSS]]> <![CDATA[HTML5]]> https://davidwalsh.name/?p=27796 <![CDATA[

As the demands of the web change and developers experiment with different user experiences, the need for more native language improvements expands. Our presentation layer, CSS, has done incredibly well in improving capabilities, even if sometimes too slow. The need for native support for automatically expanding textarea elements has been long known…and it’s finally here! […]

The post AutoGrow Textareas with CSS appeared first on David Walsh Blog.

]]>
<![CDATA[

As the demands of the web change and developers experiment with different user experiences, the need for more native language improvements expands. Our presentation layer, CSS, has done incredibly well in improving capabilities, even if sometimes too slow. The need for native support for automatically expanding textarea elements has been long known…and it’s finally here!

To allow textarea elements to grow vertically and horizontally, add the field-sizing property with a value of content:

textarea {
  field-sizing: content; // default is `fixed`
}

The default value for field-sizing is fixed, signaling current behavior. The new behavior, content, will expand as much as possible. To constrain the size a textarea can grow, use traditional width/max-width and height/max-height properties.

The post AutoGrow Textareas with CSS appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/autogrow-textareas/feed 4
How to Play Grand Poo World 3 https://davidwalsh.name/play-grand-poo-world-3 https://davidwalsh.name/play-grand-poo-world-3#respond Tue, 28 Nov 2023 00:35:41 +0000 <![CDATA[David Walsh]]> <![CDATA[Games]]> https://davidwalsh.name/?p=27788 <![CDATA[

The underground world of creating and streaming Super Mario World-based ROM hacks continues to gain popularity. This popularity is a tribute to the creativity of gamers and the quality of the original 30 year old video game’s mechanics. Over the past decade, incredible ROM hacks like Grand Poo World 1 and 2, Invictus, and Dram […]

The post How to Play Grand Poo World 3 appeared first on David Walsh Blog.

]]>
<![CDATA[

The underground world of creating and streaming Super Mario World-based ROM hacks continues to gain popularity. This popularity is a tribute to the creativity of gamers and the quality of the original 30 year old video game’s mechanics. Over the past decade, incredible ROM hacks like Grand Poo World 1 and 2, Invictus, and Dram World have brought joy (and horror) to the Mario community. Sure, Nintendo released Mario Maker and Mario Maker 2, but I love SMW Central patches because they allow all of us to create, much like open source.

The most anticipated hack in years, Grand Poo World 3, was just released and is taking the Super Mario World community by storm. You cannot, however, just download GPW3; due to legal reasons, and the ability to modify it further, the process takes some work. Let’s learn how to build Grand Poo World 3!

What You’ll Need

You’ll need multiple apps and files to build and play Grand Poo World 3:

Patching Grand Poo World 3

With the files and utilities available, open the patching utility and provide the path, Super Mario World ROM File, and patched file path:

If the input files are successful, you’ll get a working .smc file for GPW3! The risk is usually the SMW ROM file, so be sure to validate it with JSRomClean.

With a successful Grand Poo World 3 created, it’s time to play!

The whole process of creating Grand Poo World 3 gives me joy due to two of my loves: video games and open source coding. SMWCentral has thousands of patches you can apply on top of and parellel to ROM hacks to implement features like retry system and loads more.

Enjoy (the pain of) Grand Poo World 3!

The post How to Play Grand Poo World 3 appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/play-grand-poo-world-3/feed 0
How to Get the Current Branch Name with git https://davidwalsh.name/git-current-branch https://davidwalsh.name/git-current-branch#respond Sat, 28 Oct 2023 18:54:30 +0000 <![CDATA[David Walsh]]> <![CDATA[git]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27784 <![CDATA[

Most developers spoil themselves with fun command line utilities to make their work easier and more efficient. One such command line helper allows developers to always show the git branch in the command line. How can you get the current branch? With this handy snippet: git branch --show-current It’s great to keep this snippet around […]

The post How to Get the Current Branch Name with git appeared first on David Walsh Blog.

]]>
<![CDATA[

Most developers spoil themselves with fun command line utilities to make their work easier and more efficient. One such command line helper allows developers to always show the git branch in the command line. How can you get the current branch? With this handy snippet:

git branch --show-current

It’s great to keep this snippet around for any automation you may create moving forward!

The post How to Get the Current Branch Name with git appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/git-current-branch/feed 0
AutoSave with VSCode https://davidwalsh.name/autosave-with-vscode https://davidwalsh.name/autosave-with-vscode#respond Mon, 23 Oct 2023 11:33:21 +0000 <![CDATA[David Walsh]]> <![CDATA[JavaScript]]> <![CDATA[Quick Tips]]> https://davidwalsh.name/?p=27781 <![CDATA[

Visual Studio Code has taken the crown of most used text editor, at least in JavaScript spheres. VSCode is fast, feature-filled, and supports thousands of plugins to boost productivity. Developers can also tweak hundreds of settings to enrich functionality. One such feature is the autoSave feature. To autoSave files with VS Code, you can add […]

The post AutoSave with VSCode appeared first on David Walsh Blog.

]]>
<![CDATA[

Visual Studio Code has taken the crown of most used text editor, at least in JavaScript spheres. VSCode is fast, feature-filled, and supports thousands of plugins to boost productivity. Developers can also tweak hundreds of settings to enrich functionality. One such feature is the autoSave feature.

To autoSave files with VS Code, you can add the following to your text editor config:

{
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 200
}

Just about every Operating System and web action is instant these days, so eliminating the need for manual save just makes sense. Big thanks to my old MooTools colleague Chris Nakazawa for calling this out!

The post AutoSave with VSCode appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/autosave-with-vscode/feed 0
How to Detect Failed Requests via Web Extensions https://davidwalsh.name/browser-webrequest-onerroroccurred https://davidwalsh.name/browser-webrequest-onerroroccurred#comments Mon, 02 Oct 2023 13:37:25 +0000 <![CDATA[David Walsh]]> <![CDATA[JavaScript]]> <![CDATA[Promises]]> https://davidwalsh.name/?p=27778 <![CDATA[

One of the best things that ever happened to t he user experience of the web has been web extensions. Browsers are powerful but extensions bring a new level of functionality. Whether it’s crypto wallets, media players, or other popular plugins, web extensions have become essential to every day tasks. Working on MetaMask, I am […]

The post How to Detect Failed Requests via Web Extensions appeared first on David Walsh Blog.

]]>
<![CDATA[

One of the best things that ever happened to t he user experience of the web has been web extensions. Browsers are powerful but extensions bring a new level of functionality. Whether it’s crypto wallets, media players, or other popular plugins, web extensions have become essential to every day tasks.

Working on MetaMask, I am thrust into a world of making everything Ethereum-centric work. One of those functionalities is ensuring that .eth domains resolve to ENS when input to the address bar. Requests to https://vitalik.ethnaturally fail, since .eth isn’t a natively supported top level domain, so we need to intercept this errant request.

// Add an onErrorOccurred event via the browser.webRequest extension API
browser.webRequest.onErrorOccurred.addListener((details) => {
  const { tabId, url } = details;
  const { hostname } = new URL(url);

  if(hostname.endsWith('.eth')) {
    // Redirect to wherever I want the user to go
    browser.tabs.update(tabId, { url: `https://app.ens.domains/${hostname}}` });
  }
},
{
  urls:[`*://*.eth/*`],
  types: ['main_frame'],
});

Web extensions provide a browser.webRequest.onErrorOccurred method that developers can plug into to listen for errant requests. This API does not catch 4** and 5** response errors. In the case above, we look for .eth hostnames and redirect to ENS.

You could employ onErrorOccurred for any number of reasons, but detecting custom hostnames is a great one!

The post How to Detect Failed Requests via Web Extensions appeared first on David Walsh Blog.

]]>
https://davidwalsh.name/browser-webrequest-onerroroccurred/feed 1