Importance of installing your own development machine

If you are a software developer like me, every once in awhile comes the opportunity to install your new development machine. Some of the causes can be a new job, new computer or just reinstalling your current computer.

I am trying to emphasize the importance of installing your own machine, just like Jedi knights have to build their own lightsabers, you should be competent enough to install the required software on your development machine.

I will try not to go into platform specific rants or anything, just a guideline on how to do it.

1. Know your OS – be it windows, linux or osx, please be familiar with the os you are planning to develop on, if you get stuck, search for some tutorials on the web. You should be very friendly with the command line, if you are planning to use linux, and even in some cases osx.

2. Know your platform – be it ruby, java, python, .net or anything else, learn how to install the basic tools to get you running, you have great video tutorials for just about anything, so go ahead and watch them.

3. Don’t be afraid to ask someone – take this one with caution, it is ok to ask for an advice, or if you get stuck, but never ask another developer to install some of the tools for you, as you then seem incompetent in their eyes.

And do try to follow some of the people creating the technology you are using on social networks, you can see some tips and tricks, update and version release announcements and everything else. Looking at a few cat pictures is sure worth it considering the knowledge you are getting from these people.

 

 

Deploying Rails applications on Windows

Due to some legacy issues, and HP workstations being shit that you can’t turn the hardware virtualization on, i had an issue with one client regarding speed and loading time of an application. My common deployment server is running Ubuntu on VMWare or Oracle VBox, passenger + nginx, or apache even. But, this “server” is just a regular machine(people here don’t want to invest in real hardware, or just don’t have the money).

So i had to deploy the app on windows 7, and i will show you how.

First, there are few steps you have to take care of:

1. Install Ruby with the ruby installer http://rubyinstaller.org/downloads/

2. Install Ruby DevKit from the same source(this will be needed for you to compile some native binaries)

3. Install Thin server(gem install thin)

4. Set up dropbox deployment for your application(i know this is monkeypatching as hell, but if it works…) as described on Rob Conery’s blog

5. Test the app and make sure everything is working ok, (run rails server), then thin start -e production, just to make sure everything is ok, and all of your gems work on windows(fix or replace the ones that don’t)

6. Set up the task scheduler(this is a fine piece of software on Win 7 and up) as described  here, to run rails application almost as a windows service( you start with ‘thin start -e production -p 80 -c “path_to_your_app” ‘)

7. Write a nifty batch script that will restart the server, run migrations, compile the assets and whatnot.


cd "path_to_your_app"

bundle exec rake db:migrate RAILS_ENV=production

bundle exec rake assets:precompile

schtasks /End /TN "name_of_your_task_in_scheduler"

schtasks /Run /TN "name_of_your_task_in_scheduler"

8. After you pull to your dropbox synced repository, login to the server and execute the batch file from there to almost automate the deployment process.

I know this is not capistrano, and cap deploy, and it is hacked as it can be, and also, it works, it’s a small client so i don’t expect much trouble with this.

Lesson here: Try as much as you can to deploy your rails server on a linux server, best in a virtual machine. But if HP messes with you and you have some shitty hardware running windows, this is the best way i have found. If anyone has anything better, put it into comments, i’m happy to make my life easier.

References:

1. http://wekeroad.com/danger-danger/git-and-dropbox-sitting-in-a-tree

2. http://unicornless.com/systems-administration/run-thin-as-windows-service

Allow only one instance of MDI child in your VB.NET MDI application

I have encountered a problem in class today, we needed our Contact Manager application only to run one instance of every MDI child form, so the user will not be able to start unlimited(more than 1) number of Contacts form, or any of the settings forms. I have binged the solution and found a piece of code that allows something like that, but as i am teaching VB.NET here, i had to rewrite it from C# to VB.NET. The original C# Code provided by Roy Osherove is HERE
Here is the VB.NET code i have rewritten from Roy’s version:

Imports System
Imports System.Windows.Forms
Imports System.Collections.Specialized
Public Class MdiFormLoader
    Private m_InitializedForms As HybridDictionary = New HybridDictionary()
    Public Sub LoadFormType(ByVal formType As Type, ByVal mdiParentForm As Form)
        If (IsAlreadyLoaded(formType)) Then
            Return
        End If
        FlagAsLoaded(formType)
        Dim frm As Form = Activator.CreateInstance(formType)
        frm.MdiParent = mdiParentForm
        AddHandler frm.Closed, New EventHandler(AddressOf FormClosed)
        frm.Show()
    End Sub
    Private Sub FlagAsLoaded(ByVal formType As Type)
        m_InitializedForms(formType.Name) = True
    End Sub
    Private Sub FlagAsNotLoaded(ByVal formType As Type)
        m_InitializedForms(formType.Name) = False
    End Sub
    Private Function IsAlreadyLoaded(ByVal formType As Type) As Boolean
        Return If(m_InitializedForms(formType.Name), m_InitializedForms(formType.Name) = True)
    End Function
    Private Sub FormClosed(ByVal sender As Object, ByVal e As EventArgs)
        Dim closingForm As Form = sender
        RemoveHandler closingForm.Closed, New EventHandler(AddressOf FormClosed)
        FlagAsNotLoaded(sender.GetType())
    End Sub
End Class

You can call your form by using these 2 lines:

Dim _formLoader As New MdiFormLoader()
_formLoader.LoadFormType(GetType(ContactsMain), Me)