Wake up on LAN on Windows XP, Windows 7 and Linux

To set up the wake on LAN feature, it requires a little bit of patience and testing.

If you're looking to wake up your Linux machine, see the link in the "sources" below.

The Windows 7 sleeper

*updated 23/07/14

This one caught me off-guard. I thought this tutorial would be enough but alas, it isn't.

  • Hit up Device Manager
  • Your network adapter > Properties
  • Power Management
  • Tick "Allow the computer to turn off this device to save power" (you have to, otherwise the other two will be disabled)
  • Tick "Allow this device to wake the computer"
  • And also tick "Only allow a magic packet to wake the computer" (otherwise your computer will wake up randomly)
  • Go to the "Advanced" tab
  • Enable "Shutdown Wake-On-Lan" and "Wake on Magic Packet"
  • Disable "Wake on pattern match"
  • Click "OK" to save your settings
  • Open up "Windows Firewall with Advanced Security"
  • Click on "Inbound rules"
  • Click on "New Rule" on the top right
  • Select Port > UDP > Specific local port = 9 > Allow the connection
  • Profile will depend on your network setup
  • And name it "Wake on Lan"

That should now be enough for you to skip to the "Network and computer settings" section.

image image


The Windows XP sleeper

Assuming that your machine is running Windows, you'll need to set some stuff on your network interface card (NIC).

Configure NIC

  • Open up the settings dialog for your network card
  • Click on "Advanced"
  • Scroll down to "Wake from shutdown"
  • Set it to "On"
  • Click the next one, "Wake-up Capabilities"
  • Set it to "Magic packet & Pattern match"
  • Go to "Power Management" tab
  • Make sure "Allow this device to bring the computer out of standby" is UNTICKED (I know it sounds weird, but you will get random startups after shutdown if it is ticked)
  • Click OK to save

image imageimage 

Network and computer settings

Mac Address

Open up command prompt

  • Type in "ipconfig /all"
  • Look for your NIC (it should resemble something like "Ethernet adapter Local Area Connection")
  • Write down the MAC address (labelled "Physical address")

Motherboard config

Now you'll need to set up your BIOS, so this will vary depending on your motherboard.

The following instructions are for the Asus P5K-E WiFi motherboard which I use. I take no responsibility if you mess up settings on your motherboard if it is not the same.

Enable Boot ROM

  • Advanced
  • Onboard Devices Configuration
  • Set "Marvell GigaBit LAN" to "Enabled"
  • Set "LAN Boot ROM" to "Enabled"
Configure Automated Power Management Settings
  • Power
  • APM Configuration
  • Set "Power On By PCI Devices" to "Enabled"
  • Set "Power On By PCIE Devices" to "Enabled"

Save and exit, then shutdown after the next boot completes. While you wait, begin setting up the next part.

*Issue 10/7/2011*

I can't seem to figure this one out, but my machine restarts itself after a shutdown about 80% of the time.

Usually it happens after I've had the machine on for a few hours and shutdown. It boots up again, but if I shutdown the second time it stays off. Very, very annoying.

If anyone knows how to fix this, let me know!

*Update 20/7/2011*

So I'm getting sick of the automatic restarts after shutdown due to wake on LAN.

Managed to find a long thread with plenty of potential fixes. The major offenders are:

  • "Magic packet and matching pattern" selected - change it to "Magic packet" only. This did the trick for me!
  • Mouse/keyboard or even another wireless card with power management options, which should have "Allow this device to bring the computer out of standby" unticked.
  • Other devices to check can be found by running the command prompt and typing "powercfg /DEVICEQUERY wake_armed" followed by "powercfg /DEVICEQUERY wake_programmable"
  • Scheduled tasks able to wake the computer up.

Someone had faulty hardware such as power supply units with bulging capacitors while another had a faulty graphics card which triggered the reboots.

A fairly odd one was that a fridge was jumpstarting the PC due to dodgy electrical circuits in the house.

The Linux "alarm clock" machine

I'm using my "always on" Linux box to wake up the Windows machine.

Install wakeonlan using "sudo apt-get install wakeonlan"

Now when you're ready to wake up the windows machine, type in "wakeonlan -i mac_address"

The "192.168.1" bit will depend on your network. Just keep the 255 bit because that is to broadcast the MAC address to the whole subnet.

BAM! Wake up!

*Updates 29/6/2011*

  • Disable allow device to power up computer
  • Broadcast IP

Testing your setup

*added 23/7/2014

I wish I knew this earlier, but it's always nice to be able to test your config. It saves you a LOT of time rebooting!

Download the "Wake-on-LAN packet sniffer v1.1 (freeware)" and run it. Attempt to send a test packet from your phone using an app (I used "Wake on Lan" by mafro for Android). If nothing comes through, check your firewall or network settings.



Linux: Editing Gnome panels causes system to lock up and freeze before the desktop is visible

I'm not sure what sort of Linux gods I have angered but it seems they have it in for me.


I was editing a secondary panel and moving the applets around when suddenly the system crashed.

Fair enough, I'll just restart the thing and just try again. However, I wasn't lucky enough to get back into the system...

The desktop froze at a black screen, showing only the faulty secondary panel. No icons, no desktop, no menus, no responses to keyboard, nothing.

So, lucky I had a second computer to look up the fix. Seriously, Linux is not ready for mainstream use if you can't even fiddle with the user interface.

  • Load up your system and get into restore mode via GRUB
  • Select "Drop to root shell prompt"


  • Type "rm -rf /home/your_username/.gconf/apps/panel"
  • Exit and restart your system
  • Unfortunately you'll have to set up your panels again
  • Fortunately, you don't have to format and reinstall Linux (starting to sound like Windows)

Alternate solution

I tried this first and it did not work. It involved deleting "/home/your_username/.recently-used.xbel" instead.


Firefox 4: Disable auto update of addons

This was completely unknown to me until a certain much-used Firebug feature was removed.

HTML preview feature available again in Firebug 1.8

They had pushed out a security update but removed the HTML preview feature which I use quite often due to my work with AJAX/JSON.

Fuck, what was I to do?

First, prevention is always better than a cure. Stop the automatic updates!

  • Open up your addons manager (Firefox > Add-ons)
  • In the top right, click on the cog icon
  • Untick "Update Add-ons Automatically"
  • For safe measures, also click on "Reset All Add-ons to Update Manually"

imageDon't worry. Firefox still looks for updates and tells you when they're available. This way, you can read the change log before it's applied.

The second thing to do is Firebug specific. Go to the site and download 1.8beta4. It works fine so install it.

django: Date time picker on a custom form without undocumented hacks or importing admin files

The problem

I tried using the forms.DateTimeField and forms.DateField in my form and it kept coming up with "Enter a valid date/time.", despite the fact I given the custom "input_formats" in the constructor.

Most of the search results bring you back to a post on StackOverflow called "Using Django time/date widgets in custom form". It's basically reusing the JS widget that you can access in the admin and it works really well.

But personally I'm not a fan of this method. You'll have to use some undocumented features and import a whole stack of Django admin CSS/JS files on every page you need the date picker.

For security sake, I tend to keep public and admin CSS/JS files separate.

We'll fix this chump up!

The Theory

The way which I implemented this involves use of a 3rd party Javascript date picker of your choice. This way you get to fully customise the selection.

I prefer to eyecon's datepicker, which allows for some pretty neat customisation. I especially like how they made it incredibly easy to pick the month/year. It is much smaller compared to jQueryUI datepicker.

In Practice

The main thing is to change the form field to a CharField.

class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ('title', 'details', 'when')

title = forms.CharField(required = False)
details = forms.CharField(widget = forms.Textarea()
when = forms.CharField(min_length = 10, widget = DateInput(format="%d-%m-%Y"))

def clean_when(self):
when = self.cleaned_data.get('when')

if when:
when = datetime.datetime.strptime(when, '%d-%m-%Y')
except ValueError:
when = None
self._errors['when'] = ['Invalid date selected.']

return when

That's the form done.

Now to set up the date picker widget.

Import the CSS and JS files.

<link rel="stylesheet" media="screen" type="text/css" href="{{ MEDIA_URL }}datepicker.css" />
<script type="text/javascript" src="{{ MEDIA_URL }}datepicker.js"></script>

To set up the date picker:

var date_element = $('#id_when');

date: date_str,
onBeforeShow: function(){
date_element.DatePickerSetDate(date_element.val(), true);

That's it! See the date picker documentation for more options, but that's more than enough to get you up and running.

Magneto Kid
Now you're badass!

Custom initial date format

*update 23/6/2011*

Oops, forgot something. If your Django system time format differs to the format you want to use on your Javascript date picker, you'll have to tweak the CharField() a little to include the DateInput() widget.



Git: Cherry-picking and removing git commits

So I dun goofed one of my workmate's git branches and had to remove one commit from the history.


You may have noticed that this was buried under a whole stack of other commits...

Normally, if you've made an accidental commit and realised straight away, you can just do:

git reset HEAD^

This will pop off the latest commit but leave all of your changes to the files intact.

Because this commit is buried under a whole plethora of changes from other people, we need to do something else.

Using "git rebase", we can shift things around and keep the other unrelated changes in the history.

(From the git rebase help)

      A---B---C topic
D---E---F---G master


              A´--B´--C´ topic 
D---E---F---G master

It's a bit hairy, but here's how you can pull it off:

  • Checkout "master" branch for the project
  • Pull everything in line with:

git submodule update --init

  • Create a clean branch using:

git checkout -b 0000_fixed

  • Checkout your broken branch

git checkout 0000_broken

  • Update init to pull everything in line

git submodule update --init

  • Create a copy of the broken branch

git checkout -b 0000_temp

  • Rebase towards the clean target branch

git rebase -i 0000_fixed

  • Now you get a chance to cherry-pick the commits. Remove any commits you don't want. This step should be easy, assuming you've entered in good commit messages.
  • Save and exit.
  • git rebase will now attempt to automatically shift your commits.
  • If it worked, you'll see this:

Successfully rebased and updated refs/heads/0000_temp

  • If not, you'll have some fun conflicts to deal with

Automatic cherry-pick failed.  After resolving the conflicts,
mark the corrected paths with 'git add <paths>', and
run 'git rebase --continue'
Could not apply xxxxxxx... progress commit

  • Treat this like a normal merge/conflict scenario.
  • Do "git submodule update --init" again
  • Go into each conflicted file and resolve the conflicts
  • Go into each conflicted submodule and checkout your working branch
  • Merge in the previous head so you get the incoming changes
  • Go back to the project
  • Re-commit the conflict resolutions (with the previous commit comment if possible)
  • Type:

git rebase --continue

  • Rinse and repeat until successful.
Let's just hope you never have to do this again.


Windows: Create a boot USB from Windows setup CD/DVD

I had to format a HP Mini and an EEE PC (both have no DVD drive) so the only option was to boot the little sorry excuse for a computer by USB.
I stumbled upon this blog as one of the first hits, and amazingly it was very easy to get Windows booting up on USB. It supports Windows XP/2003/Vista/2008/7 and even Windows 8 beta!
For best results, it's a good idea to use the target OS to create the bootable image.
For example, if you're setting up a bootable Windows 7 image, install WinToFlash on a Windows 7 computer and set it up from there.
  • Download WinToFlash and extract it.
  • Insert or load the Windows setup disc into a drive
  • Open up "WinToFlash.exe"
  • Run through the first start wizard
  • When it's done, click on the "Advanced mode" tab
  • Select "Transfer <Source Windows> setup to USB drive"
  • Click "Run"
  • Make sure the drive settings are correct and skim the formatting settings (default settings work fine)
  • Click "Run" and wait
That's it. You now have yourself a bootable USB drive with the Windows setup.
Just make sure the BIOS settings are correct (they're different for each brand of motherboard so look it up for what you have)
Celebrate with some carrot facial!


Invention: Rear View Mirror Partial Night Mode

The rear view mirror should have something that limits the amount of light reflected to dim bright lights.

That way we don't have to flip the rear view because of some knob with super high beams or one wonky misaligned light bulb that shines right into your eyes.

Invention: Balloon clips for ribbons

Somebody should invent balloon ribbon clips. This way we don't have to tie the damn things anymore.

All you have to do is feed the ribbon through the clip, clamp it.

Then create a loop and clip it again.

The clamp should be reusable and require no tying.

django: Fix for HttpResponse.set_cookie() TypeError: translate() takes exactly one argument (2 given)

What the hell is this!? It's the first strange quirk I've noticed in Django, that's what!

Time to freak out!

I'm still not sure exactly why this happens but it's the first time I've encountered it, even though I've been using the set_cookie() method for a while now.

So in testing, this was the sample code I had:

response = HttpResponse('')
response.set_cookie('cookie_name', 1)
return response

In theory, that would normally work. For some strange reason, it threw an exception at the 2nd line.

Apparently it doesn't like unicode for the cookie key. To fix it, wrap the key with str().

So now the code looks like this:

response.set_cookie(str('cookie_name'), 1)

[ Source ]

Linux: Installing ipblock/iplist and configuring autostart

*Update 5/1/2014* This post has been superceeded by
"Linux: Installing Peer Guardian 2; an IP blocker like PeerBlock for Windows".


iplist/ipblock is a great little tool for Linux which protects you from "bad connections", pretty much what PeerGuardian/PeerBlock does for Windows.

I had a bit of trouble getting it to run properly, and considering how many posts there were about it I figured I'd write a post to help out some people.

Depending on your base version of Linux, add the sources.list in the repository list given here. (It's kept more up to date than this blog post)

Remember to import the signed keys too!

Note: If you're not comfortable with using "vim", feel free to replace any following commands with "gksu gedit" instead.

Once you've done that, put yourself on superuser mode and prepare to get down and dirty with the terminal.

apt-get update
apt-get install iplist

Once it's done installing, copy the default setting files over:

cp /usr/share/doc/iplist/examples/ipblock.lists /etc
cp /usr/share/doc/iplist/examples/ipblock.conf /etc

Now to edit the configuration files:

vim /etc/ipblock.conf
  • Change AUTOSTART to "Yes".
  • Remove any lists you don't want from BLOCK_LIST (at minimum keep "level1" and "bogon")
  • Any event information is logged in "/tmp/ipblock.log"
  • Your downloaded list files are stored in "/var/cache/ipblock"

Now edit the list files:

vim /etc/ipblock.lists

Replace the "bluetack.co.uk" entries for the lists you want to keep (in BLOCK_LIST) with the corresponding URL from iblocklists. From my experience, iblocklists.com is updated more often and more reliable than bluetack.

Now to download the lists. You can either use the terminal or the GUI ("Menu" > "Internet" > "IP Block" > click "Update" at the top)

ipblock -u

Then remember to get out of superuser mode.


Restart your computer to check if the AUTOSTART is running properly!



If ipblock is preventing your computer from accessing the internet after a reboot (preventing outbound connections, connection into your computer, not pinging correctly, etc) then I'm assuming that you're using wireless/WiFi.

This took a few days for me to figure out but the reason why this is happening is because the wireless takes a moment to connect.

This "moment" is long enough for ipblock to start via the init.d daemon script. It loads up ip_tables, then realises there are no active connections to filter and exits.

This issue will also cause the download of your list files to fail.

ipblock[####]: error: update of level1.gz failed

ipblock[####]: error: update of bogon.gz failed

ipblock[####]: error: update of edu.gz failed

Even though checking the status of ipblock will say it's not running:

sudo ipblock -l
ipblock[####]: error: IPblock is not running

Starting it manually after the WiFi has connected will fix everything, whoever this is not ideal.

To fix this, you'll have to add a short delay before ipblock starts.

sudo vim /etc/init.d/ipblock

Now add in "sleep 30" after "start)":

case "$1" in
    sleep 30
    log_daemon_msg "Starting $DESC" "ipblock"

Save, reboot and test.

All is well. Time to embrace your victory ...



Office: Dear Microsoft, Your Ribbons Suck!

MS: Love the Office Ribbon?
Twig: NO.

Please don't ruin Windows 8 with ribbons. As soon as I heard that they were going to be scattered all over the place I was immediately put off by the decision and will chose to stick with Windows 7.

I don't care how much faster you make it. I don't care what sort of neat tools add or fancy animations you slather on.

The ribbons suck. Please understand this.

Oh but the ribbons make everything easy to access!

Please refer to the Search Commands plugin from OfficeLabs.

You know there’s a button for it, but you don’t know or remember where it is. If this ever happens to you, check out Search Commands.

Wait a second, wasn't this the problem that the ribbons were DESIGNED to solve?

The ribbons will improve efficiency

According to the results of this survey from ExcelUser.com, no they don't.

People who have used it for a while love the Ribbon

A teaser link to a blogpost by Jensen Harris, Office User Experience Manager, called "The Story of the Ribbon" brings a whole heap of comments from frustrated users.

Many of which have tried Office 2007 and either reverted back to Office 2003 or gone to an Office alternative such as Google Docs or Open Office.

Also, companies are opting NOT to use Office 2007. With big companies with as many staff as 150,000 worldwide, this is a huge mistake on behalf of Microsoft. Think of all the rupees they're losing out on!

There are more arguments here, it's pretty entertaining.

Python: Calculate the first/last Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday of the Month

Date calculation is pretty easy in Python, but to find the first/last specific day of the month may be a bit harder.
import calendar

# Get the first "day" of the month and the number of days in the month
month_range = calendar.monthrange(your_date.year, your_date.month)

if offset_position == 'first': # First Monday of the month
date_corrected = datetime.date(your_date.year, your_date.month, 1)
delta = (calendar.MONDAY - month_range[0]) % 7
return your_date_corrected + datetime.timedelta(days = delta)

else: # Last Monday of the month
date_corrected = datetime.date(your_date.year, your_date.month, month_range[1])
delta = (your_date.weekday() - calendar.MONDAY) % 7
return your_date_corrected - datetime.timedelta(days = delta)

The snippet above will find the first or last Monday in the year/month given in "your_date". Throw it into a reusable function and you won't have to look at this problem again.
Now for more important things in life.


django: Create your own documentation for offline use

Assuming that you're running Linux,

  • Download the Django package
  • Extract the "docs" folder
  • In a terminal console, start typing these commands
  • sudo apt-get install python-setuptools
  • sudo easy_install simplejson
  • sudo easy_install Sphinx
  • Finally, get into the docs folder and type "make html" to start compiling it to the HTML format.
  • Your docs will be in built in the folder "_build/html"
  • Now you're ready to fight!

Opera: Disable context menu on double click

I like Opera. It's fast, slick and clean but some of it's default behaviour really puts me off making it my default browser.
One of which is the double clicking of text brings up the context menu. The way I like to read is to highlight as I go, and often I do so by double or triple clicking text.
To stop this from happening:
  • Click on the Opera button
  • Go to "Settings"
  • Select "Preferences"
  • Click on "Advanced"
  • "Toolbars"
  • Untick "Double-click to display context menu"
  • OK to save and exit
Voila! No more stupid context menu unless you right click.
[ Source ]

Asus EEE PC: Replacing the 1005HA keyboard

I got a 2nd hand EEE PC cheap because the keyboard was defective. Either buttons wouldn't work or it'd repeat itself and flood the screen with crap.

Hoping that it was simply a software issue, I loaded up Linux via live boot and it was still stuffed. Unplugged and checking the wiring on the keyboard didn't fix it either =\

But alas, I ordered a replacement keyboard from battery-adapter.com. At the time of purchase it was the cheapest one I could find at only $32.99 with free shipping!

The brand spankin' new keyboard arrived nicely packaged and quickly. Then I got to it!
I soon discovered that the keyboard didn't fit properly! FUUUUU!

Note: Don't force it in coz it's a bitch to get out!
What you'll need
  • A replacement keyboard
  • Something sharp, like a pin


Guess it's an issue with using the 1008HA compatible keyboards because it had an extra 2 black plastic clips at the bottom near the space bar.


To fix this, get a pair of nail clippers or something small and just snap them off. It should just crack off, but if it doesn't then twist a little.

Now the keyboard should be able to sit comfortably in your netbook.

Out with the old

  • First, remove your battery by unlocking the right clip.
  • Then hold the left clip to the left while pulling the battery out. It should slide out easily.
  • Now looking at the back of the laptop, there are 4 metal clips you have to pry open. Click on the picture to see where they are.
clips - all
  • Close up pictures
clips - left clips - middle clips - right
  • Note: the first 2 clips face left, and the other two face to the right.
  • Grab your pointy sharp object and start prying. I used my old maths compass. You don't have to bend them much.
compass clips - pry left clips - pry right
  • Once you've opened up the 4 clips, flip the EEE PC around in your hands and look at the keyboard.
  • The highlighted areas have double-sided tape on the back of the keyboard to keep it in place. This may make you worry a little when removing the keyboard.
keyboard in
  • Now place your fingernail under the ESC key.
  • Gently pull the key up and it should lift the corner of the keyboard up with it.
keyboard - pry
  • While you lift, try to run a finger from your other hand from the left along to the right side of the keyboard.
  • When you start feeling like it's stuck, don't worry its just the sticky tape. Just keep going and it'll pop off by itself.
  • When the top half of the keyboard is free, gently pull it towards yourself. The sticky tape on the bottom left corner should come off easily.
keyboard - residue
Keyboard residue 
  • Be careful not to damage the keyboard ribbon.
This ribbon came from the old keyboard (has a fold on it)
  • Now hold the keyboard in one hand as you use the pin to push the little black clips up (away from you, towards the screen) with the other, freeing the ribbon and removing the old keyboard.
ribbon - clipped

In with the new

  • Now curve the new keyboard ribbon around so it points towards you.
  • Holding it like this makes it a lot easier to put it into the keyboard slot.
ribbon - hold ribbon - hold behind
  • Slot the keyboard ribbon into the slot and use the pin to close the clips.
  • Slip the bottom of the keyboard back into the laptop and lay it down so the top fits in, carefully folding the ribbon.
  • Press on the keyboard so it sticks to the double sided tape.
  • Hold the keyboard against the laptop as you turn it around to bend the 4 metal clips back into place.
  • Once that's done, close the lid and put the battery back in.
  • Remember to lock the battery!
  • Fire it up and test out your new keyboard!
It should be an absolute delight to use!

Update 16/10/2012: Thanks to Anonymous for that little clarification =)

Firebug: Image corrupt or truncated: <unknown>

I saw this strange error flooding my Firebug console today when I left my dev page open for a while.

Strangely enough, it's because the favicon image was incorrectly linked.

Once the favicon is fixed, it shouldn't happen anymore.


[ Source ]

Excel: Easily convert hyperlinks to text showing the URL address

So there were about 5000 rows in the spreadsheet I was working with and each row had a hyperlink labelled "Website".
This made life a little difficult when I converted the file to CSV for processing because the hyperlink was removed...
So before converting to CSV, I converted it into the actual URL location/address/href/source using a neat little macro.
  • In your spreadsheet, select the cells that you want to convert
  • Press ALT+F8 to bring up the Macro dialog below
  • Type in "RemoveHyperlinks" and click "Create"
  • It should open up in a new window
  • Between "Sub" and "End Sub", paste the following code
Dim Cell As Range
For Each Cell In Intersect(Selection, ActiveSheet.UsedRange)
    If Cell.Hyperlinks.Count > 0 Then
        Cell.Value = Cell.Hyperlinks.Item(1).Address
    End If
  • It should now look like this:
  • Press F5 (or click the "Play" button)
  • The hyperlinks should now display the actual URL


A few scrambled pieces of this and this.
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog