Tag: JavaScript
-
Detecting modifier keys being pressed with JavaScript
Been hot on a new [old] project recently and I’ve not only been coding my ass off, but delving into some territory that I haven’t delved into as of late. The latest is in terms of determining if a modifier key has been pressed in conjunction with another key press….
-
Protected routes with React Router v5
React Router makes it extremely easy to define routing in your React application, but out of the box doesn’t concern itself with which routes should require authentication and which ones should now. I’ve solved this problem in a past life, using React Router v4 and looking back at the code…
-
Converting integers to Roman numerals with TypeScript
My buddy Robert has been seeking new opportunities in the software development realm, and recently ran into a coding challenge that I haven’t thought about in a good long time: converting an integer to Roman numeral. Now, I actually hate these kinds of brain teasers in the context of interviewing…
-
Padding strings and numbers with JavaScript
Programming languages can change pretty regularly, and I try to carve out some time periodically to catch up on the latest and greatest the languages I love have to offer. With that, recently I was poking around on JavaScript’s string prototype and came to realize that there were some string…
-
How to remove an array element by index in JavaScript
Recently I was faced with the need to remove an item from an array, by index in JavaScript and I came to realize it had been quite a while since I had to do something like that. My initial, and extremely incorrect thought was that I could just use delete…
-
The most efficient way to check the last character of a string with JavaScript
Recently I was writing some code that needed to detect if a certain character was at the end of the string to determine if some additional logic should be executed. The reason for this was because the additional logic to run was pretty hefty and for pre-mature optimization’s sake, I…
-
How to check if a string contains another string with JavaScript
Checking whether or not a string contains another string, or just a single character. It’s a been a pretty unavoidable sanity check in my programming career. It’s not quite a problem for the ages, but it comes up regularly and can be approached a few different ways. ES5 and prior…
-
Chunking an array in JavaScript
Recently I was working with some data coming out of a Redis pipeline and I wanted to take the data and split it up into an array of X items per key. I was working with PHP, this wouldn’t have been a big deal, just use array_chunk and get on…
-
Days until Christmas in JavaScript
Time again for one of my holiday cop out posts 🙂 Here’s a couple of ways to calculate the number of days until Christmas: Vanilla JavaScript Math.floor((+new Date(‘2018-12-25’) – +new Date()) / 86400000) Using momentjs moment(‘2018-12-25’).diff(moment(), ‘days’) Merry Christmas!
-
Setting defaults for all your SuperAgent requests
SuperAgent is an HTTP request library for both Node.js and client-side JavaScript. It’s our current choice here at CrowdSync for making requests because it’s lightweight and easy to use. Unfortunately, out of the box, it doesn’t support setting defaults on all of your requests. The simplest approach would be to…