How to Get a Base64 Version of a File From Command Line

A while back I wrote an article on how to Convert Image to Data URI with JavaScript. It’s a neat trick developers can use for any number of reasons. Instead of abusing canvas, however, why not simply get the base64 data from command line? You can use base64 and pbcopy to convert a file to base64 and copy it to the clipboard: # base64 gets data, pbcopy copies to clipboard base64 -i logo.jpeg | pbcopy Once you have the file data copied in base64 format, the URL format to use the data is: # data:{mime-type};base64,{data} data:image/jpeg;base64,/9j/4AAQSkZJRgAB...... While base64 data and data URIs do look cryptic, they’re useful to avoid making requests to other files. I use them... more →
Posted in: JavaScript

Download Data as a File with Alpine.js

As my readers know, I’ve been updating some of my earlier Vue.js examples to demonstrate how they would work with Alpine.js. Normally I post these "conversions" when I see one of the Vue posts pop up in my stats. Today I noticed this entry was "trending" – Vue Quick Shot – Downloading Data as a File. I thought it would be a great candidate for showing an Alpine version. Let’s take a look. While I won’t repeat everything from the previous post, I’ll quickly cover how it worked. First, it makes use of the download attribute of the anchor tag. This will take a normal link operation and instead ask the browser to download the resource at the... more →
Posted in: JavaScript

Determine Default App for File Type from Command Line

One quality of life improvement any developer can make for themselves is ensuring different file types open in the app they’re most proficient in. If you know me, you know I prefer accomplishing as much as possible from the command line. The duti utility allows users to determine default file type from command line. The duti utility allows developers to query which app is the default for different file types. You can install duti with brew: brew install duti Once you have duti available, you can check on the default app for file type with the following command: ~ duti -x md Xcode.app /Applications/Xcode.app com.apple.dt.Xcode You can set the default app by using its package: duti... more →
Posted in: JavaScript

Simplify Your File Handling With Filestack Workflows (Sponsored)

Automation is a really important skill for engineers, especially when it comes to working with various file types. The more you accept for input, and the more you automate, the better end output you can offer. Filestack’s workflows allow developers to define automated tasks using a their specialized UI. With no coding required, it’s easy to create a document workflow and scan every assignment for viruses, quarantine it until it can be reviewed, and alert the sender of the issue so that no work is late.  After signing up for a free Filestack account, you can shift to creating your own workflows. When creating your workflow, you can choose from dozens of UI items that represent... more →
Posted in: JavaScript