IPv4 netmask conversions (Bits / Decimal / Hexadecimal / Binary)

Bitmask (Bits) Dotted Decimal Hexadecimal Binary
/0 0.0.0.0 0x00000000 00000000 00000000 00000000 00000000
/1 128.0.0.0 0x80000000 10000000 00000000 00000000 00000000
/2 192.0.0.0 0xc0000000 11000000 00000000 00000000 00000000
/3 224.0.0.0 0xe0000000 11100000 00000000 00000000 00000000
/4 240.0.0.0 0xf0000000 11110000 00000000 00000000 00000000
/5 248.0.0.0 0xf8000000 11111000 00000000 00000000 00000000
/6 252.0.0.0 0xfc000000 11111100 00000000 00000000 00000000
/7 254.0.0.0 0xfe000000 11111110 00000000 00000000 00000000
/8 255.0.0.0 0xff000000 11111111 00000000 00000000 00000000
/9 255.128.0.0 0xff800000 11111111 10000000 00000000 00000000
/10 255.192.0.0 0xffc00000 11111111 11000000 00000000 00000000
/11 255.224.0.0 0xffe00000 11111111 11100000 00000000 00000000
/12 255.240.0.0 0xfff00000 11111111 11110000 00000000 00000000
/13 255.248.0.0 0xfff80000 11111111 11111000 00000000 00000000
/14 255.252.0.0 0xfffc0000 11111111 11111100 00000000 00000000
/15 255.254.0.0 0xfffe0000 11111111 11111110 00000000 00000000
/16 255.255.0.0 0xffff0000 11111111 11111111 00000000 00000000
/17 255.255.128.0 0xffff8000 11111111 11111111 10000000 00000000
/18 255.255.192.0 0xffffc000 11111111 11111111 11000000 00000000
/19 255.255.224.0 0xffffe000 11111111 11111111 11100000 00000000
/20 255.255.240.0 0xfffff000 11111111 11111111 11110000 00000000
/21 255.255.248.0 0xfffff800 11111111 11111111 11111000 00000000
/22 255.255.252.0 0xfffffc00 11111111 11111111 11111100 00000000
/23 255.255.254.0 0xfffffe00 11111111 11111111 11111110 00000000
/24 255.255.255.0 0xffffff00 11111111 11111111 11111111 00000000
/25 255.255.255.128 0xffffff80 11111111 11111111 11111111 10000000
/26 255.255.255.192 0xffffffc0 11111111 11111111 11111111 11000000
/27 255.255.255.224 0xffffffe0 11111111 11111111 11111111 11100000
/28 255.255.255.240 0xfffffff0 11111111 11111111 11111111 11110000
/29 255.255.255.248 0xfffffff8 11111111 11111111 11111111 11111000
/30 255.255.255.252 0xfffffffc 11111111 11111111 11111111 11111100
/31 255.255.255.254 0xfffffffe 11111111 11111111 11111111 11111110
/32 255.255.255.255 0xffffffff 11111111 11111111 11111111 11111111

How to delete all lines of a file in Vim

Sometimes you might want to erase all lines from a file in Vim. You don’t want to spend much time on doing that.

For example, holding ‘d’ is not quite fast if you have over a thousand lines.

And doing ‘d1000d’ (delete exact 1000 lines) will only work if you know how much lines to delete.

The fastest way is to goto the first line of the file with ‘gg’ if you aren’t already there.

Then do ‘dG’, this will tell Vim to first go into delete mode and then goto the last line.

However you might not use this very often, it is handy to know in case you do need it.

Mostly I use ‘dd’ to delete one line, ‘gg’ / ‘:0′ to navigate to the first line and ‘G’ to navigate to the last line.

So now you have it, some nice shortcuts to remember.

VNC Secure Remote Desktop connection over SSH

The following script will make an SSH connection to the remote location and then tunnel the VNC port.

On your machine you can connect to that port on localhost with the VNC client.

Temporarily offline message with PHP headers

Lets say, you have a website where you want to edit some things that might cause errors to your visitor…

You want the best for your visitors right? So it is better to show a temporarily offline message than errors or a blank page… Or worse, 404 errors or internal server errors ;-)

Here you show everyone a maintainance message except the IP ‘12.34.56.78’, this might be your office IP.

It is a simple message without an design but at least it won’t show anything bad to the visitor.

When you are done, simply remove this piece of code and everything goes back to normal.
If you done your changes correctly of course ;)

Maximum upload file size possible in PHP

Lets say you build websites for different servers the chance that the maximum upload size differs on these servers might be big. So, you want to automatically handle this.

In the following example we simply get the sizes who have influence on the maximum upload possible. Note that you can set the upload_max_filesize to a really big value but you still need memory to handle the file in most cases!

With the following example you can get the lowest possible value and use that in your script to handle as upload maximum.

This example gets the value in MegaBytes.

How to optional include config files in Apache

If you want to easy manage sites in separate configurations it might become handy to simply include them in the httpd.conf instead of defining the VirtualHosts in your httpd-vhosts.conf every time.

The following will include all files not starting with a hash character in the sites directory.

Of course you still need to check for configuration errors using apachectl -t

My advice for naming the config files is as follows:

  • com_mariusvw.conf
  • com_mariusvw_subdomain.conf
  • com_mariusvw_sub-domain.conf

You might notice that I write the names in reverse, I do this so all the configs of one domain are sorted next to each other.

Of course you can make your own way of writing it down :-)

How to reset a Fritz!Box DSL router to factory settings?

You have two options here.
The first is use an analog phone and dial the reset code.
The second is using the web interface within a certain time on the 169.254.1.x range.

Reset by phone

  • Connect an analog phone to port FON1.
  • Pick up the phone and wait for the dial tone.
  • Dial #991*15901590*

Reset by Web Interface

  • Set your IP manually to something in the 169.254.1.x range (169.254.1.3)
  • Unplug the router and wait 10 seconds Plug it back in
  • Windows: Open a command window (cmd) and run: ping 169.254.1.1 -t
  • Unix: Open a shell and run: ping 169.254.1.1
  • As soon as you get reply’s go to the webinterface at http://169.254.1.1
  • You have a option ‘click here if you forgot your password’ (click on here)
  • Then click ‘Restore factory settings’ (This option disappears after about 10 minutes)

Crackling (bad) sound from Bluetooth A2DP headsets or speakers on Mac OS X

If you found this post you probably ran into the same issue as I had, low volume on your headset or speakers or crackling sound.

The solution for this might sound more complex than it is, the Bitpool for the Bluetooth Audio Agent by default is 35, this seems to be too low if you also use a mouse and keyboard at the same time. In my case only a mouse. Raising it to a higher value solved this problem for me.

I raised it to 50 and it worked perfectly!

You can edit the preference file with a plist editor in this file: ~/Library/Preferences/com.apple.BluetoothAudioAgent

Or, more simple, you can run the following in the program Terminal located at /Applications/Utilities/Terminal.app

At the command line enter the following command:

After doing this you might need to reconnect your device or reboot your Mac to apply the change. In my case turning off the bluetooth adapter and enabling it again was enough.

I tested this with a Sennheiser PX 210 BT and it works perfectly!

In case you want to revert to the default settintgs, simply trash:
~/Library/Preferences/com.apple.BluetoothAudioAgent.plist

Updated @ 03-01-2013
It seems that a Macbook Air has a default value of 2. So far, I haven’t noticed bad sound with this system.

Here the default settings:

Updated @ 06-02-2013
After some testing for my Sennheiser PX210 BT it seems that the settings below seem to do the perfect job.

You might want to play around with the Bitpool settings in case these don’t work perfectly for you.

I noticed some difference when locking the Bitpool to a more strict range, these are the values that I tested:

30 – Low audio quality
40 – Medium audio quality
48 – High audio quality
58 – Excellent audio quality

I found these numbers on the Apple discussion forum, seems that still a lot of people seem to have problems with their audio quality.

How to secure wipe a disk

If you need to trash disk its always smart to first erase all your data on a way others cannot recover it easily.

This script is a nice way to wipe it on a DoD 5220.22-M compatible way.

Keep in mind that you WILL lose all data on the target disk!