Monkey Patching: Find all files in a folder with Ruby 0

Here is an extension to Ruby’s File class to allow you to search for all files below a specific folder.

  class File 
    begin
      def self.find(dir, filename="*.*", subdirs=true) 
        Dir[ subdirs ? File.join(dir.split(/\\/), "**", filename) : File.join(dir.split(/\\/), filename)  ].select { |x| File.file?(x) } 
      end
    end
  end

Ruby is amazing that you can Monkey Patch code. Having just started with Ruby yesterday, and I’m sure I’ll find a better to do this in the future, but for now, this is the best I have. This started from a simple script. Notice the little juice at the end that only returns “real files” according to the File API, now it behaves nicely.

sqlfiles = File.find(Dir.pwd, "*.sql")

Bootstrapping Goodness 0

Here’s some code from the BootStrapper that I’ve been rather happy with building WinForms apps lately:

public ApplicationContext Initialize() {

        this.container.Configure(c => c.AddRegistry<SomeStructureMapRegistry>());
        this.container.Inject(this.container);

        ApplicationSettings settings = new AppSettingsParser().Parse(this.appSettings);
        this.container.Inject(settings);

        this.attachErrorHandling();

        var context = this.container.GetInstance<AppContext>();
        return context;
    }

Of course, you use it something like this:

private static void Main() {

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Application.Run(new BootStrapper(ConfigurationManager.AppSettings, new Container()).Initialize());
    }

Running KeePass 2.x on OSX using macpack 7

Last year, I finally declared password bankruptcy and found a password manager that:

  • would integrate with FireFox, or at least import existing passwords
  • is open source (security programs that cannot demonstrate how they are safeguarding your info should not be trusted)
  • is cross-platform capable (WinXP, Win7, OSX, Linux)

Fortunately, I found KeePass. It can run using Mono under OSX, but it can be a hassle to run. The default way of doing that is:

  • Open Terminal and navigate to KeePass directory
  • Typing: mono KeePass.exe

We can do this:

  • Install Mono Framework
  • Download latest version of KeePass 2.x and unpack it
  • Open Terminal and navigate to unpacked KeePass folder
  • Run the following command:

    macpack -o:. -m:winforms -r:/Library/Frameworks/Mono.framework/Versions/Current/lib/ libCocoaSharpGlue.dylib -r:KeePass.chm -r:KeePass.XmlSerializers.dll -r:KeePassLibC32.dll -r:KeePassLibC64.dll -r:License.txt -r:ShinstUtil.exe -r:./XSL -n:KeePass -a:KeePass.exe

This will create a KeePass.app file that you can drag into your \Applications folder, and you should be all set.

Next Page »