.Net - Casting Using a Type variable

Type type = typeof(MyEnum);
var stringList = new List<string> { "First", "Second" };
var typeArray = Array.CreateInstance(type, stringList.Count);
var objectArray = stringList
    .Select(val => Enum.Parse(type, val))
objectArray.CopyTo(typeArray, 0);

This is the cleanest way I've found to cast a Type variable. I'm using an Array (since that is what I needed for my case) but you can call Array.CreateInstance(type, 1) if you just have one variable.

Using FFMPEG to watermark your videos (on Mac OS X)

Installing ffmpeg

  1. Install Homebrew
  2. In Terminal type
    $ brew install ffmpeg

watermarkos.sh - Script to add watermark to video

Download from gist 

Setup - folder structure

The script and watermark image should be in the root folder. The videos are in sub-folders (only one level deep) under the root folder. The script converts videos one folder at a time. Then folders get renamed with a tilde "~" prepended to each folder name.

How to Run

  • Grant executable permissions on the script
    $ chmod 700 watermarkos.sh
  • Run like so
    $ ./watermarkos.sh


  • ffmpeg maxes out the CPU which is why it sleeps after each run
  • The variable dbox is where the watermarked videos go. They go to a Dropbox folder in my example.