Get a Random Array Item with JavaScript / / No Comments JavaScript Arrays are probably my favorite primitive in JavaScript. You can do all sorts of awesome things with arrays: get unique values, clone them, empty them, etc. What about getting a random value from an array? To get a random item from an array, you can employ Math.random: const arr = [ "one", "two", "three", "four", "tell", "me", "that", "you", "love", "me", "more" ]; const random1 = arr[(Math.floor(Math.random() * (arr.length)))] const random2 = arr[(Math.floor(Math.random() * (arr.length)))] const random3 = arr[(Math.floor(Math.random() * (arr.length)))] const random4 = arr[(Math.floor(Math.random() * (arr.length)))] console.log(random1,... more → Posted in: JavaScript Tagged with: Array, Item, JavaScript, Random
Building Table Sorting and Pagination in Alpine.js / / No Comments A few months back, I realized that one of my most popular blog posts (Building Table Sorting and Pagination in Vue.js) would be an excellent opportunity to update for a more plain (or vanilla if you will) JavaScript version. That post (Building Table Sorting and Pagination in JavaScript) was pretty fun to write. As much as I enjoyed using Vue over the past few years, I find myself more and more trying to rely less on external frameworks and sticking to simpler methods of getting things done. That being said… I am also really intrigued by Alpine.js. Raymond Camden… more → Posted in: JavaScript Tagged with: Alpine.js, building, Pagination, Sorting, table
Interview with an Intiface Haptics Engineer / / No Comments I was recently re-reading my Interview with a PornHub Web Developer and one bit I started thinking about was the VR question and the idea of making users not just see but feel` something. The haptic feedback of VR games is what really sets them apart from your standard PC or console game. So when it comes to sex tech, what’s it like to create experiences you feel instead of see? I had the opportunity to interview Kyle Machulis, aka qDot, about coding haptic experiences that give people good vibes. Enjoy! Warning: This blog post details coding for sex toys and other adult conversation. Please discontinue reading if these topics could offend you. What was the original... more → Posted in: JavaScript Tagged with: Engineer, Haptics, interview, Intiface
Legacy String Methods for Generating HTML / / No Comments I’m always really excited to see new methods on JavaScript primitives. These additions are acknowledgement that the language needs to evolve and that we’re doing exciting new things. That being said, I somehow just discovered some legacy String methods that you probably shouldn’t use but have existed forever. Let’s take a look! These legacy string methods take a basic string of text and wrap it in a HTML tag of the same name: "Hello".big() // "<big>Hello</big>" "Hello".blink() // "<blink>Hello</blink>" "Hello".bold() // "<b>Hello</b>" "Hello".italics() // "<i>Hello</i>" "Hello".link("https://davidwalsh.name") // "<a... more → Posted in: JavaScript Tagged with: Generating, HTML, Legacy, methods, String
Store Nintendo Switch Screenshots in the Cloud using Pipedream / / No Comments I’ve been a gamer for my entire life, starting with the venerable Atari 2600 back when I was almost late for grade school because I was having a really good game of Space Invaders. Raymond Camden… more → Posted in: JavaScript Tagged with: cloud, Nintendo, Pipedream, Screenshots, Store, Switch, using
Watching RSS Feeds for Keywords in Pipedream / / No Comments Back in the day, I used to run a website called rssWatcher. (If you want, you can read the original launch announcement from 2004.) The idea was simple. You would sign up, then create a list of RSS feeds and corresponding keywords. The service would check this on a schedule and let you know when a match was found. I built this in ColdFusion and I honestly don’t remember when I shut it down, but it was in my mind recently and thought I’d take a stab at building a simple version of this on my favorite service, Pipedream. Here’s how I did it. Raymond Camden… more → Posted in: JavaScript Tagged with: Feeds, Keywords, Pipedream, Watching
Input valueAsNumber / / No Comments Every once in a while I learn about a JavaScript property that I wish I had known about years earlier — valueAsNumber is one of them. The valueAsNumber provides the value of an input[type=number] as a Number type, instead of the traditional string representation when you get the value: /* Assuming an <input type="number" value="1.234" /> */ // BAD: Get the value and convert the number input.value // "1.234" const numberValue = parseFloat(input.value, 10); // GOOD: Use valueAsNumber input.valueAsNumber // 1.234 This property allows us to avoid parseInt/parseFloat, but one gotcha with valueAsNumber is that it will return NaN if the input is empty. Thank you to Steve Sewell for... more → Posted in: JavaScript Tagged with: input, valueAsNumber
Use Your Saffron Recipes in the Jamstack / / No Comments Like a lot of people, I took up baking during the pandemic. This was particularly difficult for me as I have a lot of anxiety when it comes to new things. I tend to stress over ensuring I get everything perfect and my worry about cooking is that if I do one thing wrong, I’ll ruin it. While I’m not over that particular anxiety, I have had the chance to try making many things and while I’m not that good at it, I enjoy it, and can make some delicious items at times. Raymond Camden… more → Posted in: JavaScript Tagged with: Jamstack, Recipes, Saffron