Create a Waveform Image with ffmpeg

Waveform images have a variety of uses and I’ve started seeing waveform images overlaying at the bottom of videos.  That type of feature seems useful if you want to see identify music in a video or specific spaces in a video which feature action.  If you’re creating an audio-centric app, you may have a dozen […]
The post Create a Waveform Image with ffmpeg appeared first on David Walsh Blog.

Link: https://davidwalsh.name/waveform

Shell: Create a Comma Separated String

I recently needed to generate a string with comma separated values, based on iterating a range of numbers (e.g. we should get the following output where n = 3).
foo-0,foo-1,foo-2
I only had Shell available to me so I couldn’t shell out into Python or Ruby, for example. That means it’s Bash scripting time!

Link: https://dzone.com/articles/shell-create-a-comma-separated-string?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

Create Aliases in Bash

Every developer likes a shortcut — they’re what make us more efficient in our work.  Of course there are good shortcuts and bad shortcuts (lazy coding, lack of security review, etc.), but let’s stick with the positive and talk about a good shortcut:  bash aliases. We all have commands that we execute regularly but aren’t able to remember […]
The post Create Aliases in Bash appeared first on David Walsh Blog.

Link: https://davidwalsh.name/alias-bash

Address Validation API with streetlayer

There is so much of our web and eCommerce that consumers take for granted: payment types and validation, exchange rates, etc.  One of the aspects of eCommerce that should be a given, from both a developer and consumer perspective, is address handling.  We’d like to think the consumer enters their address correctly but the risk is if the don’t […]
The post Address Validation API with streetlayer appeared first on David Walsh Blog.

Link: https://davidwalsh.name/streetlayer-address-api

Track Empty Directories with git

There are times when you’d like to track an empty directory within git but there’s a problem: git wont allow you to add a directory that doesn’t have a file in it.  The easy solution is putting an empty stub file within the directory, and the industry standard for that stub file name is .gitkeep. You […]
The post Track Empty Directories with git appeared first on David Walsh Blog.

Link: https://davidwalsh.name/git-empty-directory

Get Keychain Passwords from Command Line

One of my favorite command line utilities is Guillermo Rauch’s wifi-password, a utility that allows you to get a saved password for the wifi network you’re presently connected to (to share with colleagues or creeper in the cafe you’re in).  The idea of being able to get a password from command line is super useful, especially […]
The post Get Keychain Passwords from Command Line appeared first on David Walsh Blog.

Link: https://davidwalsh.name/keychain-command-line

Get Python Requirements Package Hashes

Python’s (pip’s) requirements.txt file is the equivalent to package.json in the JavaScript / Node.js world.  This requirements.txt file isn’t as pretty as package.json but it not only defines a version but goes a step further, providing a sha hash to compare against to ensure package integrity: Flask==0.12.1 \ –hash=sha256:6c3130c8927109a08225993e4e503de4ac4f2678678ae211b33b519c622a7242 Jinja2==2.9.6 \ –hash=sha256:2231bace0dfd8d2bf1e5d7e41239c06c9e0ded46e70cc1094a0aa64b0afeb054 MarkupSafe==1.0 \ –hash=sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665 …. Coming from the JavaScript / package.json world, you […]
The post Get Python Requirements Package Hashes appeared first on David Walsh Blog.

Link: https://davidwalsh.name/hashin

currencylayer: Simple, Effective Currency Conversion

Every developer that’s maintained an eCommerce site will tell you that being responsible for properly handling currency will tell you it can be a very stressful task.  If you write buggy or insecure code, you’re going to cost either your employer or the user money.  An added complication for developers can be currency conversion if the app caters to an international […]
The post currencylayer: Simple, Effective Currency Conversion appeared first on David Walsh Blog.

Link: https://davidwalsh.name/currencylayer

Continue Download with cURL

One of the most useful but least talked about utilities a developer has at their disposal is cURL.  The cURL command line utility has been so amazing that Chrome lets you copy requests as cURL from the developer tools Requests panel.  cURL lets you post form data, follow redirects, get response headers, determine redirect URL, check gzip encoding, and much more. […]
The post Continue Download with cURL appeared first on David Walsh Blog.

Link: https://davidwalsh.name/continue-download-curl

How to Write Shell Scripts with JavaScript

This week I had to upgrade a client’s website to use SSL. This wasn’t a difficult task in itself — installing the certificate was just the click of a button — yet once I had made the switch, I was left with a lot of mixed content warnings. Part of fixing these meant that I had to go through the theme directory (it was a WordPress site) and identify all of the files in which assets were being included via HTTP.
Previously, I would have used a small Ruby script to automate this. Ruby was the first programming language I learned and is ideally suited to such tasks. However, we recently published an article on using Node to create a command-line interface. This article served to remind me that JavaScript has long since grown beyond the browser and can (amongst many other things) be used to great effect for desktop scripting.
In the rest of this post, I’ll explain how to use JavaScript to recursively iterate over the files in a directory and to identify any occurrences of a specified string. I’ll also offer a gentle introduction to writing shell scripts in JavaScript and put you on the road to writing your own.
Set Up
The only prerequisite here is Node.js. If you don’t have this installed already, you can head over to their website and download one of the binaries. Alternatively, you can use a version manager such as nvm. We’ve got a tutorial on that here.
Getting Started
So where to begin? The first thing we need to do is iterate over all of the files in the theme directory. Luckily Node’s native File System module comes with a readdir method we can use for that. It takes the directory path and a callback function as parameters. The callback gets two arguments (err and entries) where entries is an array of the names of the entries in the directory excluding . and .. — the current directory and the parent directory, respectively.
const fs = require(‘fs’);

function buildTree(startPath) {
fs.readdir(startPath, (err, entries) => {
console.log(entries);
});
}

buildTree(‘/home/jim/Desktop/theme’);

If you’re following along with this, save the above in a file named search_and_replace.js and run it from the command line using node search_and_replace.js. You’ll also need to adjust the path to whichever directory you are using.
Adding Recursion
So far so good! The above script logs the directory’s top level entries to the console, but my theme folder contained subdirectories which also had files that needed processing. That means that we need to iterate over the array of entries and have the function call itself for any directories it encounters.
To do this, we first need to work out if we are dealing with a directory. Luckily the File System module has a method for that, too: lstatSync. This returns an fs.Stats object, which itself has an isDirectory method. This method returns true or false accordingly.
Continue reading %How to Write Shell Scripts with JavaScript%

Link: https://www.sitepoint.com/shell-scripts-javascript/