Wednesday, June 16, 2010

How to get the IP address of local area connection in C#

NetworkInterface[] NInterfaces = null;
NInterfaces = NetworkInterface.GetAllNetworkInterfaces;

foreach(NetworkInterface NInterface in NInterfaces) {
if(NInterface.Name == "Local Area Connection") {
foreach(IPAddressInformation Info in NInterface.GetIPProperties().UnicastAddresses) {
if(Info.Address.AddressFamily.ToString == "InterNetwork") {
MessageBox.Show("IP Address: " + Info.Address.ToString());

You can also use this function to get the local IPv4 IP when you have IPv6 enabled:

private IPAddress GetIPAddress() {

System.Net.IPAddress IP = null;

foreach (IPAddress localIP in System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList) {
if (localIP.AddressFamily == AddressFamily.InterNetwork & IP == null) {
IP = localIP;

return IP;


Monday, May 3, 2010

You know you have been programming too much when...

You know you have been programming too much when you start ending your sentences with a semicolon instead of a period;

Friday, April 16, 2010

Rename a VPN Connection in Windows 7

Question: How do I rename a VPN connection in Windows 7? There’s no option to rename it in the Network and Sharing Center or on the taskbar.

This question is asked a lot because there is currently no intuitive way to quickly change the name of a VPN connection in Windows 7.

Answer: Click (left mouse button) the connection icon on the task tray then click "Open Network and Sharing Center" then click "Change adapter settings" on the left of that window then right click the connection and click "Rename".

To recap:
"Network and Sharing Center" -> "Change adapter settings" -> "Rename"

And that is how you rename your VPN connection in Windows 7.

Tuesday, April 6, 2010

jQuery Plug-in I Wrote For Doing Web Form Textfield Placeholders

Here is a very useful jQuery plug-in I wrote to show placeholders in input text fields and input password fields. Great for a Facebook style log-in form.

Download it here: Password Compatible jQuery Placeholder

Apache HTTPD Virtual Hosting Setup in Step By Step Instructions

A buddy of mine is new to server administration and one of the first things I am going to show him since he is a web developer is how to setup a virtual host in Apache on CentOS 5 allowing you to run multiple web sites on a single IP address. Read the steps carefully and take your time if this is your first time doing this, it is a simple task that can easily go wrong if you rush it.

  1. Add your server IP to GoDaddy or other domain registrar's DNS settings.
    For GoDaddy this is located by navigating to Domain Manager -> Your domain -> Total DNS Control then editing the "A (Host)" record.
  2. Login to your server using putty.exe or some other SSH client.

  3. Type:
    ls /var/www
    Then look to see if there is currently a folder named "vhosts", if there isn't then type:
    mkdir /var/www/vhosts
    Next add a domain by typing:
    mkdir /var/www/vhosts/
    Then to add a logging directory type:
    mkdir /var/www/vhosts/
    Then to add an error log file type:
    touch /var/www/vhosts/
    Then to give apache permissions to the logging folder type:
    chown -R apache:apache /var/www/vhosts/

  4. Type:
    vi /etc/httpd/conf/httpd.conf
    Then hold the "Page Down" key to scroll to the very bottom of the file and then type:
    Then press the enter key and enter the following lines:

    <VirtualHost *:80>
    DocumentRoot /var/www/vhosts/
    ErrorLog /var/www/vhosts/
    <Directory /var/www/vhosts/>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    And then navigate around using the arrow keys and replace all instances of "yournewdomain" with your new domain name. When "-- INSERT --" shows in the lower left corner of the screen you are in edit mode, to enter edit mode you hit "i" or "a", to exit edit mode hit ESC. When in edit mode keystrokes are inserted into the document, when not in edit mode keystrokes are interpreted as commands. Always be aware if you are in edit mode or not.

    You are done editing so hit ESC to exit edit mode.
    When everything looks right then type the following to save and exit (when out of INSERT mode)
    If you made a mistake then type:
    This series of keystrokes will undo all changes in vi so you can start your edits over.

  5. Restart apache by typing:
    /sbin/service httpd restart

  6. To setup vsftpd (FTP server) to go to the vhosts folder on login then create a ftp user by typing the following command:

    adduser wwwftp -d /var/www/vhosts -M -p PASSWORD_FOR_USER_HERE -s /sbin/nologin

    And you are done. Use FTP with the user "wwwftp" and the password you set to upload your website files to /var/www/vhosts/

Wednesday, March 31, 2010

Use mysqldump to copy tables from one schema to another

The following command is great for copying tables from one schema to another within the same MySQL database:
Be aware that this will overwrite existing tables and data which is usually exactly what you want.
To copy to a schema on a different system:

Find all files with a specific extension and delete them under Linux or Unix

This will search the current directory and recursively look through every folder under the current directory for files with the extension .gz and delete them.

find . -type f -name "*.gz" -exec rm -f {} \;

Monday, March 29, 2010

Upgrading CentOS 5.4 to PHP 5.2.11

rpm --import
vi /etc/yum.repos.d/utterramblings.repo

Paste into file:
name=Jason's Utter Ramblings Repo

yum install php

Wednesday, March 3, 2010

Converting military 24 hour time to 12 hour time in PHP

Here is a function I use with array_walk to convert all of the values in the array to 12 hour time from military time.

function convert_to_twelve_hour(&$i) {
if($i >= 1 && $i <= 12) {
$hour = $i;
$ampm = ($i < 12) ? 'am' : 'pm';
} elseif($i < 1) {
$hour = $i + 12;
$ampm = 'am';
} elseif($i > 12) {
$hour = $i - 12;
$ampm = ($i < 12) ? 'am' : 'pm';
$i = $hour.$ampm;

This of course is an alternative to:

date("g:i a", strtotime("14:30"));

Tuesday, March 2, 2010

Controlling a Servo attached to an Arduino via Visual Basic.NET or C#.NET

Here is an example of using VB.NET to control a servo via serial port that is attached to an Arduino board.

Attach the servo to ground, 5v and digital pin 9.

My Arduino code is also outputting to a parallel LCD. If you do not have an LCD attached you can remove those lines.

As you can see in the picture I also have the WiiChuck adapter attached. I will demonstrate the use of this adapter in a future post.

Visual Basic.NET Code:

Public Class Form1

Private serialPort As New IO.Ports.SerialPort

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

With serialPort
.PortName = "COM3"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With


Catch ex As Exception
End Try

End Sub

Private Sub TrackBar1_Scroll(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TrackBar1.Scroll
serialPort.Write(TrackBar1.Value & "s")
End Sub

End Class

C#.NET Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
public partial class Form1 : Form
public Form1()

private void trackBar1_Scroll(object sender, EventArgs e)
serialPort1.Write(trackBar1.Value + "s");

private void Form1_Load(object sender, EventArgs e)

Arduino C/C++ Code:

#include <servo.h>
#include <liquidcrystal.h>

Servo myservo;

int servoPosition = 1;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
lcd.print("Position Data:");

void loop() {

static int val = 0;
lcd.setCursor(0, 1);

if(Serial.available()) {

char ch =;

switch(ch) {
case '0'...'9':
val = val * 10 + ch - '0';
case 's':
val = 0;


Snowboarding at Mt. Hood Meadows