Partitioning a large directory into subdirectories by size

Since I’m not fond of carrying around all my photos on a cell phone where they’re perpetually at list of loss, I peridiocally dump the image and video files to a drive on my desktop for later burning to optical disc.1 Saving these images in archival form is a hedge against the bet that my existing backup system won’t fail someday.

I’m using Blue-Ray optical discs to archive these image and video files; and each stores 25 GB of data. So my plan was to split the iPhone image dump into 24 GB partitions. H

#!/bin/bash      
                                                               
directory=${1:-testdir}                                                         
sizelimit=${2:-1000} # in MB                                                    
sizesofar=0                                                                     
dircount=1                                                                      
du -s -m "$directory"/* | while read -r size file                  
do                                                                              
	if ((sizesofar + size > sizelimit))                                           
	then                                                                          
		(( dircount++ ))                                                            
		sizesofar=0                                                                 
	fi                                                                            
	(( sizesofar += size ))                                                       
	mkdir -p -- "$directory/sub_$dircount"                                           
	mv -- "$file" "$directory/sub_$dircount"                                           
done

We call the script with ./dump-split.sh dir_to_split your_size_limit. In my case, the size limit (in MB) was 2400. This script is modified slightly from a version for Unix.2 The du tool differs between these two platforms. This script doesn’t optimize the packing of the discs, but over the many files being archived, it all evens out.

See also


  1. Yes, I could probably go through many if not most of them and delete nearly the entire lot since the best of them have already been moved over to my Lightroom catalogue. ↩︎

  2. How to split a large folder into smaller folders of equal size - Note that –block-size parameter isn’t available on macOS. Intead, the -m flag serves the same purpose as --block-size=1M ↩︎

More chorus repetition macros for Audacity

In a previous post I described macros to support certain tasks in generating source material for L2 chorus repetition practice. Today, I’ll describe two other macros that automate this practice by slowing the playback speed of the repetition.

Background

I’ve described the rationale for chorus repetition practice in previous posts. The technique I describe here is to slow the sentence playback speed to give the learner time to build speed by practicing slower repetitions. By applying the Change Tempo... effect^[Change tempo effect in the Audacity manual] in Audacity. In my own practice, I will often begin complex Russian sentences at -50% speed and progress to -25% speed before practicing the pronunciation at native-level speed. By practicing at slow speeds, it gives the learner time to appreciate how syllables are connected to each other. The prosody is more apparent.

Technique

Num Command Explanation
01 SelectAll: Select the entire source sentence
02 ChangeTempo:Percentage="-50" SBSMS=“1” Change the tempo (without altering pitch) by -50%
03 Select:End="-0.65" Mode=“Set” RelativeTo=“SelectionEnd” Start=“0” Create an empty 0.65 second region
04 Silence:Use_Preset=“User Preset:650ms” Add 0.65 seconds of silence
05 SelectAll: Select the original clip + the silence
06 CursSelEnd: Move the cursor to the end of the new selection
07 Repeat:Count=“5” Repeat 5 times for a total of six iterations on the track.

You can see that we’ve just add a single additional step (02) to the previous iteration generator macro - in this case, reducing the tempo by 50%.

If you want to reduce the speed by only 25%, then you just need to alter the corresponding command 02:

Num Command Explanation
02 ChangeTempo:Percentage="-25" SBSMS=“1” Change the tempo (without altering pitch) by -25%

Download the files [Kjellin sentences 50.txt](/attachments/2020/07/16/Kjellin\ sentences\ 50.txt) and [Kjellin sentences 25.txt](/attachments/2020/07/16/Kjellin\ sentences\ 25.txt) and on macOS install them at ~/Library/Application Support/Audacity/Macros.

Audacity macros to support chorus repetition practice

Achieving fluid, native-quality speech in a second language is difficult task for adult learners. For several years, I’ve used Dr. Olle Kjellin’s method of “chorus repetition” for my Russian language study. In this post, I’m presenting a method for scripting Audacity to facilitate the development of audio source material to support his methodology.

Background

For detailed background on the methodology, I refer you to Kjellin’s seminal paper “Quality Practise Pronunciation with Audacity - The Best Method!” on the subject of chorus repetition practice. The first half of the paper outlines the neurophysiologic rational for the method and the second half describes the practical use of the cross-platform tool Audacity to generate source material for this practice.

Scripting Apple Music on macOS for chorus repetition practice

This is an update to my previous post on automating iTunes on macOS to support chorus repetition practice. You can read the original post for the theory behind the idea; but in short, one way of developing prosody and quality pronunciation in a foreign language is to do mass repetitions in chorus with a recording of a native speaker.

Because in macOS 10.15, iTunes is no more, I’ve updated the script to work with the new Music app. It turns out that it’s a lot simpler. No need to dive into the application classes.

A meritocracy reading list

Meritocracy has been on everyone’s minds lately, it seems. Reading Daniel Markovits’ “The Meritocracy Trap,” I was fully ready to condemn the concept completely. I may be still; but I need to take a moment to think about it more fully.

Here’s the problem with condemning meritocracy outright: if we look at ability on a case-by-case basis, would you rather a well-trained, accomplished pilot or a mediocre one? Would you rather go to a concert performed by a scratchy third-rate violinist or someone whose pedigree includes Juilliard, Curtis, or the like? Maybe the problem with meritocracy is simply that it doesn’t scale well in capitalist markets. (Don’t hold me to that idea; I’m not quite ready to embrace it fully.) In the process of scaling to the level of a large society, does any inherent rightness of merit confer a right to so distort the economic life of a country that only narrower and narrower slices of it garner larger and larger portions of the economic output?

A folder-based image gallery for Hugo

Hugo is the platform I use to publish this weblog. Occasionally I have the need to include a collection of images in a post. Mostly this comes up on other sites that I publish. Fancybox can do this; but it wasn’t immediately clear how to direct Fancybox to create a gallery of images in a page based on images in a directory. Previously, I’ve solved this in different ways, but I was anxious to find a simple shortcode-based method.

An alternative method for keyboard input switching on macOS

macOS offers a variety of virtual keyboard layouts which are accessible through System Preferences > Keyboard > Input Sources. Because I spend about half of my time writing in Russian and half in English, rapid switching between keyboard layouts is important. Optionally in the Input Sources preference pane, you can choose to use the Caps lock key to toggle between sources. This almost always works well with the exception of Anki. Presumably Anki’s non-standard text management system thwarts the built-in Caps Lock/toggle mechanism for reasons that are not clear to me. Equally unclear is why this worked previously but now does not. I’ve not updated either Anki or the system software. It’s a mystery. Nonetheless, began to search for an alternative method for switching between keyboard layout switching. What I developed relies on several tools: