sort

Sorting ‘ls’ command output by filesize alvin July 17, 2016 - 1:01pm

I just noticed that some of the MySQL files on this website had grown very large, so I wanted to be able to list all of the files in the MySQL data directory and sort them by filesize, with the largest files shown at the end of the listing. This ls command did the trick, resulting in the output shown in the image:

ls -Slhr

The -S option is the key, telling the ls command to sort the file listing by size. The -h option tells ls to make the output human readable, and -r tells it to reverse the output, so in this case the largest files are shown at the end of the output.

How to show the largest files under a directory on Mac OS X (Unix) alvin November 9, 2015 - 4:22pm

I haven’t solved my overall problem yet — which is how to fit 64 GB of music onto a tablet with 24GB free space — but I did solve another problem today: How to show the largest files under a directory on Mac OS X (and Unix systems). In this short tutorial I’ll demonstrate what I learned.

A command to show the largest files under a directory on Mac OS X

The Unix command that worked for me on my Mac OS X system is this:

Scala Quicksort algorithms: FP/recursive, imperative (and performance) alvin November 2, 2015 - 4:13pm

As a short “note to self,” the quickSort function in the following code is from the “Scala By Example” PDF, and it shows a Scala version of a Quicksort algorithm:

How to use sortable Sets in Scala (SortedSet, TreeSet, LinkedHashSet) alvin June 6, 2015 - 3:49pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.28, “How to Use Sortable Sets in Scala”

Problem

You want to be able to store and retrieve items from a set in a sorted order.

Solution

To retrieve values from a set in sorted order, use a SortedSet. To retrieve elements from a set in the order in which elements were inserted, use a LinkedHashSet.

A SortedSet returns elements in a sorted order:

How to sort a Scala Map by key or value (sortBy, sortWith) alvin June 6, 2015 - 3:33pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.23, “How to Sort an Existing Map by Key or Value”

Problem

You have an unsorted map and want to sort the elements in the map by the key or value.

Solution

Given a basic, immutable Map:

How to sort Arrays in Scala alvin June 6, 2015 - 12:59pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is one of the shortest recipes in the book, Recipe 11.10, “How to Sort Arrays in Scala”

Problem

You want to sort the elements in an Array (or ArrayBuffer).

How to sort Scala collections classes (sortWith, sorted, Ordered, Ordering) alvin June 6, 2015 - 12:05pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.28, “How to Sort a Scala Collection”

Problem

You want to sort a sequential collection. Or, you want to implement the Ordered trait in a custom class so you can use the sorted method, or operators like <, <=, >, and >= to compare instances of your class.

A Casbah (MongoDB) ORDER BY 'find' query example alvin September 2, 2013 - 10:10pm

To create an order by query using the find method of the MongoDB Casbah driver (Scala), use the sort method, as shown in this example:

Show unique list elements with the Linux sort -u command alvin December 20, 2011 - 6:27am

If you're ever working on a Unix or Linux system, and have a list with duplicated items in it, and want a smaller list of only the unique items in the list, the sort command is your friend.

I just ran into a situation where I generated a list of fonts on a Mac OS X (Unix) system, and my list ended up with a bunch of duplicated names, like this:

A Drupal 7 table with sortable headers and pager alvin August 7, 2011 - 9:58pm

In my previous blog post I wrote about how to create an HTML table in a Drupal 7 module form. As promised in that tutorial, once I figured out how to make the table columns sortable, I'd share that secret recipe as well. Here then is how to make an HTML table in a Drupal 7 module/form: