Spires in Flight

posted in ireland with 0 comments

When I first met Eadaoin at the Dublin picnic, I speculated about what would happen if the Spire of Dublin were to be dropped from space. Imagine the carnage! Imagine the fire! Without further ado:

The volume of a cone is one-third of the area of the base multiplied by the height:

0.3 * π * r2 * h

The Spire is 121.2 metres in height and 3 metres in diametre at the base:

0.3 * 3.141 * 1.5 * 1.5 * 121.2 ≈ 257 m3

The spire is mostly hollow inside:

It is constructed from eight hollow tubes of stainless steel and features a tuned mass damper[...]

The Spire’s declared mass is 126 metric tonnes. The kinetic energy delivered by an impact is:

0.5 * m * v2

Energy is measured in Joules released.

That’s simple. The more mass or velocity, the more kinetic energy is released on impact. There’s more of increase in kinetic energy from an increase in velocity than an increase in mass. I said “dropped from space”, but dropped from space can mean a great many things.

I have read the fantastic Space Weapons Earth Wars by the RAND Corporation more than once, and I am aware of considerations that will affect the impact:

  • Angle.
  • The Earth’s gravity.
  • The Spire’s initial orbit inclination, altitude, and velocity.
  • Ablation as the Spire travels through the atmosphere.

For sake of this post ending before my beer does, the Spire is dropped perfectly straight through a vacuum-that is to say it travels directly perpendicular to the ground through a perfect vacuum.

The ISS
The International Space Station has an average orbital velocity of 7.66 km/s.

0.5 * 126 * 7660 * 7660 ≈ 3696562800 J

Round it to 3.696 x 1010 Joules. A quick look at this chart finds that it is a little under four-fifths the energy of America’s air-dropped GBU-43/B Massive Ordnance Air Blast bomb. Here is an explosion for reference.

If the Spire impacted at 8910 m/s then it would release an amount comparable to a MOAB blast.

0.5 * 126 * 8910 * 8910 ≈ 5001450300 J

I do not have a single source to site, but several websites anecdotally relate that the blast radius of the MOAB is ~150 metres. Secondary effects like broken windows and launched shrapnel would project far beyond this. To reiterate: Everything within 150 metres of the bomb would be obliterated. There would still be lethal effects out to as far as 1.5 kilometres.

MOAB Dublin blast radius

I measured distances of 150 m and 1500 m in Google Maps, and filled in the circles in the Gimp. Everyone in the red circle would die, everyone in the yellow circle would be decreasingly affected by a MOAB explosion as you moved out from ground zero. Most of the energy of a kinetic impactor is directed straight into the ground (see pages 139-141 of Space Weapons Earth Wars).

Hilariously-speaking, everyone in central would die horribly.
Realistically-speaking, most of the energy goes into the ground, and only a fraction of the painted radius is actually affected. I’m out of beer, however, so the math ends here.

by Mark -

Find duplicate files in a directory

posted in code with 0 comments

When I photographed heavily/professionally, I was rigorous in how I handled my imported raw files, and master processed (PSD/XCF) files. I was much less rigorous in how I sorted and stored my processed JPG files, to the point that I’ve found several directories with anywhere between hundreds and thousand of images, some or many of them straight duplicates.

For the hell of it, and also because I haven’t touched C# since early 2013, I drew up a simple console application in C# to search for duplicate file in a given directory. I made a good start on it in Bash, but…fuck. Bash is slow and interacting with arrays in Bash leaves me wanting to murder somebody.

Order of the program:

  1. Check directory was provided. Check directory exists. Check it has more than one file.
  2. Get list of files in directory.
  3. Generate MD5 checksums for each given file.
  4. For each checksum:
    i. Check each file after this in the list to see if it has the same sum.
    ii. If a duplicate is found, check if it is on the recorded dupe list.
    iii. If it isn’t on the dupe list, add it.
  5. Run through the file list once for each dupe checksum. Print all file names with the same checksum.

I need to find more little projects like this in C#; it was fun to dust off what I knew.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Security.Cryptography;

public class findDupes {
    static void Main(string[] args) {
        CheckBeforeProceeding(args);

        string[] files = Directory.GetFiles(args[0]);
        List<string> filesums = new List<string>();

        foreach (string file in files)
            filesums.Add(GetFileSum(file));

        List<string> dupes = SearchForDupes(filesums);
        PrintDupes(filesums, dupes, files);
    }

    static void PrintDupes(List<string> sums, List<string> dupes, string[] files) {
        // Print output.
        foreach (string dupe in dupes) {
            Console.WriteLine("{0}\n----------", dupe);

            for (int i = 0; i <= (files.Length - 1); i++)
                if (sums[i] == dupe)
                    Console.WriteLine(files[i]);

            Console.WriteLine();
        }
    }

    static List<string> SearchForDupes(List<string> sums) {
        // Search for duplicate files within the given list of sums.
        List<string> dupes = new List<string>();

        for (int i = 0; i <= (sums.Count - 2); i++)
            for (int j = (i + 1); j <= (sums.Count - 2); j++)
                if (sums[i] == sums[j])
                    if (!dupes.Contains(sums[i]))
                        dupes.Add(sums[i]);

        return dupes;
    }

    static void CheckBeforeProceeding(string[] args) {
        // Check things are good with the target dir before proceeding.
        if (args.Length == 0) {
            Console.WriteLine("Error: No directory provided");
            Environment.Exit(1);
        }

        if (!Directory.Exists(args[0])) {
            Console.WriteLine("Error: '{0}' is not a valid directory", args[0]);
            Environment.Exit(2);
        } 

        if (Directory.GetFiles(args[0]).Length == 0) {
            Console.WriteLine("Error: '{0}' does not contain any files", args[0]);
            Environment.Exit(3);
        }

        if (Directory.GetFiles(args[0]).Length == 1) {
            Console.WriteLine("Error: '{0}' only contains 1 file", args[0]);
            Environment.Exit(3);
        }
    }

    static string GetFileSum(string file) {
        // Function scalped from http://stackoverflow.com/a/10520086/1433400
        using (var sum = MD5.Create())
            using (var stream = File.OpenRead(file))
                return BitConverter.ToString(sum.ComputeHash(stream)).Replace("-","").ToLower();
    }
}

Here is some example output:

[mark][new_instagram] $ ~/dupe_find.exe .
d89b812d61bb41d037b1e6704d146d11
----------
./1.jpg
./17.jpg

4c6cc2794010fe3b018038b0e1162744
----------
./132.jpg
./312.jpg

...

Neater output from the program is left as an exercise to the reader.

by Mark -

Sass is fucking awesome

posted in the website with 0 comments

I rewrote most of the site’s stylesheet today, and I’ve barely even started begun! I reduced a dozen scattered rules down to:

input[type=submit] {
    background: $color_bright_blue url('img/looking_glass.png') no-repeat center center;
    background-size: 65% auto;
    display: block;
    float: right;
    height: 100%;
    margin-top: -35px;
    position: relative;
    width: 35px;

    &:hover {
        background-color: $color_dark_red;
    }

    &:active {
        border: 1px solid $color_dark_grey;
    } 
}

by Mark -

Two thousand Instagram snapshots!

posted in code with 0 comments

Gallery of Instagram images

Holy small landmark. I had a great suggestion for what photograph to upload:

A snapshot of a a [sic] large multi-monitor display showcasing your previous 1,999 snapshots. Moffy

I keep a copy of each Instagram snapshot in my Dropbox. There is a mix of photographs from my old Wildfire S and newer iPhone; some were added by hand, and a few by script, but most come from Dropbox upload. It’s a great workflow: Snap, process, upload, share, and forget while it is backed up automatically.

The first step for a photowall/montage is to select random photographs out of the directory:

#!/bin/bash

photoDir="$HOME/Dropbox/Photos/Instagram"
destinationDir="$HOME/instagram_montage"
photoCount=$(ls -1 $photoDir | wc -l)
imgNum=1

if [[ ! -d $destinationDir ]]; then
    mkdir $destinationDir
fi

cd $photoDir
echo $photoList

while [[ $imgNum -le $photoCount ]]; do
    rand=$(($RANDOM % $photoCount))
    selectedImage=$(ls -1 . | sed -n "$rand"p)
    cp -v "$selectedImage" "$destinationDir/$imgNum.jpg"
    let imgNum++
done

exit 0

The second step is to shrink them:

cd [mark][~] $ cd instagram_montage/
[mark][instagram_montage] $ for img in *.jpg; do mogrify -resize 400x+0+0 -quality 80 -verbose $img; done 

The third step is to assemble the gallery. I already wrote a simple gallery which utilizes a row of images. Copy the gallery code, removed the lightbox parts, and create a page-wide gallery. Furthermore, I reduced the padding between images, and row sizes too.

The fourth step was to add a small function to insert a given number of the images from the pool:

function addImagesToGallery(imageCount, imageFolder, modifier) {
    for (var i = 1; i <= imageCount; i++) {
        $(galleryClass).first().append('<img src="' + imageFolder + '/' + i + modifier + '.jpg" />');
    }
}

Two thousand shots on screen wasn’t practical if I wanted you to be able to see the images. About 50×50 pixels, and between 25 and 35 images per row is a good balance. Small, but viewable.

var customClass = '.instagram';
var galleryClass = customClass + '-gallery';
var rowClass = customClass + '-row';
// Row lengths will inclusively range between min and max.
var rowSizeMin = 25;
var rowSizeMax = 35;
// For mobile views. Fixed width.
var rowSizeTiny = 20;
// Break point before switching to mobile view.
var mobileSize = 800;
// Include image alt text as anchor title?
var altAsTitle = false;
// Debug. Replace anchor hyperlinks with "javascript:void(0)".
var voidHref = true;
// Two-dimensional array of all gallery images on this page.
var galleryImages = [];
// Total images.
var totalImages = 700;
var imageSourceFolder = 'img';
var imageModifier = 0;

by Mark -

Learning Sass and re-designing the site

posted in the website with 0 comments

I’m moving to Sass for my CSS. I tried, but didn’t enjoy, DRY. The principles of DRY are sounds, and there are countless use cases and successful stories, but the philosophy doesn’t fit my needs. Plus, honestly, if I have to refactor my CSS and learn a new skill, I would rather learn Sass first. I can learn the philosophy as I learn the tool.

I’ve been prompted in this by the appearance of the website. I don’t feel comfortable with it anymore. I like clean and white typography, but that doesn’t reflect what I want… Last week I added the <pre> style I created for Alanna (example block here) to the site. I found that the colours were a better reflection of what I wanted than coal grey, blood red, and white.

So redesign and Sass.

by Mark -

x to y of z search results

posted in code with 0 comments

I’m the dozen hundredth person to code this solution. I am always rebuilding my site on an ongoing basis-see a better way, code a better way. Today I’ve worked on the search results template. I want to be able to sort results, and have a counter for the results in the manner of “results x to y of z”:

It is pretty easy. Three numbers are needed:

  1. Current page number.
  2. Number of posts displayed per page.
  3. Total count of search results.

Calculate the top count-range number first (y in ‘x to y of z’):

$page_number * $posts_per_page;

Then the bottom count-range number:

$count_low  = ($count_high - $posts_per_page) + 1;

And finally round the top count-range if it is over the total:

$count_high = ($count_high > $total_results) ? $total_results : $count_high;

Here is the completed function. You can just drop this into your functions.php as-is.

function search_results_count($page_num, $total_results) {
    $page_num = ($page_num == 0) ? 1 : $page_num;
    $posts_per_page = get_option('posts_per_page');
    $count_high = $page_num * $posts_per_page;
    $count_low  = ($count_high - $posts_per_page) + 1;
    $count_high = ($count_high > $total_results) ? $total_results : $count_high;
    echo 'Results ' . $count_low . ' to ' . $count_high . ' of ' . $total_results;
}

Execute it with this line in search.php:

<?php global $wp_query; search_results_count(get_query_var('paged'), $wp_query->found_posts); ?>

It will output this string (for example):

Results 1 to 10 of 158

by Mark -

Went to Guardians of the Galaxy with friends

posted in friends with 0 comments

Galway geeks :)

Guardians of the Galaxy was brilliant and funny. I organized the group for Mike, who has been ill lately, but he bowed out at the last moment. At that point everyone has made their bookings so it was too late to completely cancel.

Clockwise from bottom left: Mary, Derek, not sure, Katie, not sure, Duncan, Ciaran, Oisin, Alanna, Patrick, Linda, Kieran.

by Mark -