Quick guide to installing Django framework on Windows

djangoDjango is a dev framework for building web apps that uses Python. It has many great features (db api, auto admin interface, templates, cache framework, etc.). Installing the framework on Windows take a few steps to get going and has a few prerequisites. The below steps assume you don’t have Python or Django currently installed. This guide was created on Windows 7 (64 bit). Now let’s get to it:

  1. Download Python: http://www.python.org/download/releases/3.3.3/
  2. Install Python (to c:\python)
  3. Go to the pip download area: http://www.pip-installer.org/en/latest/installing.html#using-the-installer
  4. Right click, download / save ez_setup.py to c:\python
  5. In cmd prompt: cd\python
  6. Run: python.exe ez_setup.py
  7. From the same link, download get-pip.py
  8. In the cmd prompt, run python.exe get-pip.py
  9. When finished, in cmd, navigate to: \python\scripts  (where pip lives now)
  10. Now run pip install Django
  11. To see if Django was installed correctly, at a cmd prompt run:
    python -c “import django; print(django.get_version())”
    This should return 1.6.1 (or similar).
  12. Add c:\python\scripts to your windows environment path
  13. Close / reopen a cmd prompt (to reflect the addition to your PATH variable)
  14. Now you can navigate to any folder (ie: c:\projects) and run:
    django-admin.py startproject thenextbigidea
  15. Your project was created! To test:
  16. Navigate to c:\projects\thenextbigidea and run:
    python manage.py runserver
  17. In your browser, visit: http://localhost:8000/

So that’s just the start. Visit https://docs.djangoproject.com to continue your journey!

Quick guide to installing Django framework on Windows

Enabling SMB / Samba Write on Xbian (XBMC for Raspberry Pi)

Raspi_Colour_RIf you’ve got a Raspberry Pi (if you don’t, please go order one right now), and use Xbian (a great version of XBMC for Pi) you may have connected to your Pi via SMB but noticed it’s read only. Fixing this (to read / write) only takes a few seconds.

Provided you already have Xbian installed and your Pi is connected to your network and you know the address (something like 192.168.x.x – or you should be able to simple use “Xbian”), you can:

  1. On a PC, download and run Putty. Putty is a great – free – ssh terminal app.
  2. Enter your Pi’s ip (or “Xbian”) in the host name textbox.
  3. Click Open to connect to the Pi.
  4. Enter the default username: xbian and password: raspberry
  5. At the prompt, enter: sudo nano /etc/usbmount/usbmount.conf
  6. In Nano (a text editor) find the line: SMBSHARE=no
  7. Change SMBSHARE=no to SMBSHARE=yes
  8. Exit Nano and save (Control+X, Y).
  9. Reboot.
  10. You should now be able to connect to you Pi in Windows using SMB with \\XBIAN\ or find your Pi in your Network and have write permission.

Happy downloading AND uploading.

Enabling SMB / Samba Write on Xbian (XBMC for Raspberry Pi)

Checking if a file is locked in C# using Win32

Below is a simple, fast way you can check if a file is locked, using Interop to use a win32 function. I’ve found this method to be pretty fast, but I would caution, you should still have some error logic in your code in case in the window of time between you checking your file for availability and using your file, it should become locked. Below is the c# code:


using System;
using System.IO;
using System.Runtime.InteropServices;

And in your class:

        private static extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(string lpFileName, System.UInt32 dwDesiredAccess, System.UInt32 dwShareMode, IntPtr pSecurityAttributes, System.UInt32 dwCreationDisposition, System.UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);

        private static readonly uint GENERIC_WRITE = 0x40000000;
        private static readonly uint OPEN_EXISTING = 3;

        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool CloseHandle(SafeHandle hObject);

        public static bool boolFileLocked(string fPath)
            if (!File.Exists(fPath))
                return false;

            SafeHandle sHandle = null;

                sHandle = CreateFile(fPath, GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);

                bool inUse = sHandle.IsInvalid;

                return inUse;
                if (sHandle != null)

To test, toss this into your Main:

long tStart = DateTime.Now.Ticks;
Console.WriteLine(string.Format("{0:n0}", DateTime.Now.Ticks - tStart));
tStart = DateTime.Now.Ticks;
Console.WriteLine(string.Format("{0:n0}", DateTime.Now.Ticks - tStart));
tStart = DateTime.Now.Ticks;
Console.WriteLine(string.Format("{0:n0}", DateTime.Now.Ticks - tStart));
Checking if a file is locked in C# using Win32

RavenDB Document Database – Super Quickstart Guide

Raven-info0RavenDB is among the many available document databases on the market today (mongo, redis, etc.). If you’re looking to try this db and see if it’s right for your project, below is a super quick guide to start using using RavenDB on Windows with asp.net. Below are my 10 simple steps to start using. You can skip to the bottom for entire “source” code.  Continue reading “RavenDB Document Database – Super Quickstart Guide”

RavenDB Document Database – Super Quickstart Guide