• WordPress Quick Install and Setup On Ubuntu

    Here’s some quick notes for installing WordPress on Ubuntu 10.

    Official install doc: http://codex.wordpress.org/Installing_WordPress

    I choose hosting on Linode, which has been an awesome experience so far, they have really good help guides too.

    Server

    You’ll need MySql, PHP, Apache installed.

    apt-get install apache2 apache2-doc apache2-utils

    apt-get install libapache2-mod-php5 php5 php-pear php5-xcache php5-suhosin php5-mysql

    apt-get install mysql-server

    Run MySql Secure Installation

    mysql_secure_installation

    Enable Rewriting

    a2enmod rewrite

    Enable image support for php.

    sudo apt-get install php5-gd

    /etc/init.d/apache2 restart

    Get It

    wget http://wordpress.org/latest.tar.gz > tar -xzvf latest.tar.gz

    Database

    mysql -u adminusername -p
    
    CREATE DATABASE databasename;
     
    GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"localhost"
    IDENTIFIED BY "password";
      
    FLUSH PRIVILEGES;
    

    Setup Apache

    Create the web root directories

    mkdir /var/www/red27.net/public_html -p <br />mkdir /var/www/red27.net/logs

    Create an apache virtual host config

    See what’s there in the sites-available

    ls /etc/apache2/sites-available/

    Copy an existing config

    cp /etc/apache2/sites-available/candland.net /etc/apache2/sites-available/red27.net

    Edit to match the correct location.

    vim /etc/apache2/sites-available/red27.net

    Copy the WP files to the site root

    cp downloads/wordpress/* /var/www/red27.net/public_html/ -r

    Change owner

    chown -R www-data /var/www/red27.net/public_html/

    Config WordPress

    Rename the wp-config.php file

    mv /var/www/red27.net/public_html/wp-config-sample.php /var/www/red27.net/public_html/wp-config.php

    Edit the wp-config.php, set the correct db connection values, and replace the security lines from here

    vim /var/www/red27.net/public_html/wp-config.php

    Enable the site

    a2ensite red27.net

    Restart apache

    /etc/init.d/apache2 restart

    Visit the site and configure WordPress!

  • AutoTest Powershell Script

    This script will watch a source directory for changes, just *.cs files in this case and then execute a script when a change is detected. This handles the issue of the change event being triggered twice for one change. I’m just calling my default Psake script, but you can put any build/test script call in place of it.

    function watch-folder {
        param([string]$path, [string]$filter = "*.*", $command)
        get-eventsubscriber -force | unregister-event -force
        $global:lastGen = [datetime]::Now
        $expandedPath = convert-path $path
        write-host "Watching" $expandedPath\$filter
        $fileSystemWatcher = new-object System.IO.FileSystemWatcher
        $fileSystemWatcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite
        $fileSystemWatcher.Path = $expandedPath
        $fileSystemWatcher.Filter = $filter
        $fileSystemWatcher.IncludeSubdirectories = $true
        $action = {
            $timeGenerated = $event.TimeGenerated
    
            if ($timeGenerated - $global:lastGen -gt (new-timespan -sec 1)) {
                write-host ***************************************** -foreground Green
                write-host $eventArgs.FullPath -foreground Green
                write-host $eventArgs.ChangeType at $event.TimeGenerated -foreground Green
                write-host TESTING $event.MessageData -foreground Green
                $result = &amp; $event.MessageData | out-string -stream
                if ($LastExitCode -gt 0) {
                    $result | select-object -last 70 | out-host
                    write-host FAILED -foreground Red
                    write-host ***************************************** -foreground Red
                }
                else {
                    write-host SUCCESS -foreground Green
                    write-host ***************************************** -foreground Green
                }
            }
    
            $global:lastGen = $timeGenerated
        }
        [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Created -SourceIdentifier ThisFileWatcher -Action $action -MessageData $command)
        [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Changed -SourceIdentifier ThisFileWatcherA -Action $action -MessageData $command)
        [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Deleted -SourceIdentifier ThisFileWatcherB -Action $action -MessageData $command)
    }
    
    watch-folder ".\src" "*.cs" {
      psake
    }
    
    wait-event "ctrl-c"
    

    Thanks to this post PowerShell, events and file watcher.

  • ViEmu + ReSharper + VS2010 Review

    I’ve been using the ViEmu plugin with ReSharper in VS2010 for a couple of weeks now. Overall, I really like combo. However there are a few things that annoy me with ViEmu. The selections modes are not the same between ViEmu and selecting text with the mouse, looks like a licensed copy might fix that. The replace function is missing the ‘c’ confirm option. The other things are mostly key bindings that ViEmu overrides, this can be changed with the _viemurc file. You need to create that file in the c:\users[username] directory, then add the bindings you’d like. I’ve added some for ReSharpers goto type command, and changed Ctrl+V back to paste.

    map <C-n> gS:vsc ReSharper.ReSharper_GotoType<CR>
    imap <C-n> gS:vsc ReSharper.ReSharper_GotoType<CR>
    map <C-v> gS:vsc Edit.Paste<CR>
    

    BYW, You can find the commands you’re looking for from the VS toos:options:keyboard menu.

    I’m think I’m going to get a license for ViEmu, anyone else have any tips for it?

  • Nhibernate Many-to-many mapping with an Enumeration on One Side

    I’m posting this because I was trying to do this in an intuitive way and was thinking about it in the wrong way. A post on StackOverflow,  Map to a list of enums, got me pointed in the right direction.

    I prefer using Enum’s in code, in place of database lookup tables, doing this for single properties, it makes sense to just map the Enum value into the database column of the owning entity. However when thinking about mapping many-to-many, for example, the US States a person has visited, and you fall into DB thinking mode. Many-to-many is the solution, unless States is an Enum and that’s all you need. In that case you should think about the problem for the domain side, a person as a list of visited States. In this way, you only need to have a one-to-many relationship, where the many side is the Enum value.

    Adding something like the mapping code below to you Person mapping will get a VisitedStates table with a PersonId column and StateId column. No lookup tables needed, of course one could be added to help the DBAs. In the code you have a States list on the Person class.

    <bag name="States" cascade="all" table="VisitedStates">
      <key column="PersonId"/>
      <element type="States" column="StateId" />
    </bag>
    

    Advantages

    • No mapping table.
    • Lookup data defined in code, as an Enumeration.
    • Less classes and mapping files.
    • Don’t have to worry about updating a lookup table with new values.
    • Don’t have to worry about making a State class with a immutable mapping.

    Disadvantages

    • DBAs won’t know the values without maintaining a lookup table (even if it doesn’t get used by code).
    • Can not reorder the Enumeration values without updating the DB.

    Other advantages/disadvantages?

  • PowerVim, setup VIM to use Powershell

    [https://candland.net/assets/binary/PowerVimsetupVIMtousePowershell_DAD5/vim_logo_2.png]

    I’m using VIM more and more and have come to the point where issuing commands to the shell would be useful, the problem is I use PowerShell. This is fairly easy to setup in VIM, but I did hit two things that needed to be worked around. Script execution issues and my ps profile script changing directories.

    First script execution, by default, does not allow custom scripts, like your modified ps profile. This was easy to take care of in the _vimrc file. Here’s what I added to setup PowerShell:

     # change to powershell       
     set shell=powershell.exe\ -ExecutionPolicy\ Unrestricted
     set shellcmdflag=-Command
     set shellpipe=>       
     set shellredir=>
    

    You should also make sure to set your VIM encoding=utf-8. With that in place, PowerShell can be invoked and it will load your profile. However…

    My profile always sets the current directory to my projects folder, which is good except when it’s being opened by VIM. Here’s my fix.

    if ($HOME -eq $pwd.path) { 
       cd $projects 
    }
    

    With those changes in place I can now issue PowerShell commands from within VIM.

  • Psake Tab Expansion!

    After installing the awesome posh-git stuff, I thought “it would be cool to have tab expansion for my psake tasks”. So, I read the posh-git stuff and decided it would be easy to follow the pattern they’ve used and adopt it for psake. That a complement on the job the posh-git guys have done and with only about 23 lines, a complement to the power of Powershell.

    Anyway, below is how I integrated both posh-git and psake tab expansion into my powershell profile after including the PsakeTabExpansion.ps1 file.

    After installing the awesome posh-git stuff, I thought “it would be cool to have tab expansion for my psake tasks”. So, I read the posh-git stuff and decided it would be easy to follow the pattern they’ve used and adopt it for psake. That a complement on the job the posh-git guys have done and with only about 23 lines, a complement to the power of Powershell.

    Anyway, below is how I integrated both posh-git and psake tab expansion into my powershell profile after including the PsakeTabExpansion.ps1 file.

    # Set up tab expansion and include git expansion
    function TabExpansion($line, $lastWord) {
      $lastBlock = [regex]::Split($line, '[|;]')[-1]
    
      switch -regex ($lastBlock) {
          # Execute git tab completion for all git-related commands
          'git (.*)' { GitTabExpansion $lastBlock }
          '(Invoke-psake|psake) (.*)' { PsakeTabExpansion $lastBlock }
          # Fall back on existing tab expansion
          default { DefaultTabExpansion $line $lastWord }
      }
    }
    

    The zip file has a readme w/ some sample code to drop in your profile. And the PsakeTabExpansion.ps1 flie, which I have in the same directory as my profile. I’m going to send the psake team, hopefully they will add it to the psake codebase.

    PsakeTabExpansion.zip

  • Ensure Spark Views Are Marked As Content With Powershell

    I kept publishing a website project only to find each time a couple of spark files didn’t make it because they were not set as content in the cs project file. In order to limit the wasted time, I added the code below to the build script.

    Below I’m using the following to grab the project file as xml. Then foreach (|%) None element in Item group elements. Where (|?) the Include attribute is a spark file, add to the $notset collection. If any, then list and throw to stop the build. This was just added as a psake task. BTW, I’m really loving psake, you should really check it out if you need a build script on windows, for anything.

    $basedir = Resolve-Path .
    $proj = [xml] (get-content "$basedir\src\website\website.csproj")
    $notset = $proj.Project.ItemGroup |% {$.None} |? {$.Include -like "*.spark"}
    
    if ($notset.Count -gt 0) {
      $notset; throw &quot;The above Spark files not set to content.&quot;
    }