Archive

Archive for the ‘Info.Tech’ Category

Visual C#: Detect Conflict Schedule

January 18th, 2010
Screenshot

Screenshot

It seems a lot of people are searching about solving conflict schedule. So I decided to create a sample. Below is the core code of checking conflict schedule…

// sample conflict detection (defined) [start]
DateTime d = new DateTime(2010, 1, 13);
richTextBox1.Text = DateTime.Now.ToLongDateString() + ” = ” + d.ToLongDateString() + “\n”;
if (DateTime.Now.CompareTo(d) > 0)
{
richTextBox1.Text += “true\n” + DateTime.Now.CompareTo(d).ToString();
}
else
{
richTextBox1.Text += “false\n” + DateTime.Now.CompareTo(d).ToString();
}
richTextBox1.Text += “\n\n”;
DateTime dx = DateTime.Now;
//MessageBox.Show(dx.Hour.ToString());
DateTime[] dt = new DateTime[4];
// enrolled schedule
dt[0] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 8, 0, 0);
dt[1] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
// adding new schedule
dt[2] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
dt[3] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 10, 0, 0);
// checking schedule conflict
if (((dt[0].CompareTo(dt[2]) < 0) && (dt[1].CompareTo(dt[2]) > 0)) || (dt[0].ToShortTimeString() == dt[2].ToShortTimeString()))
{
richTextBox1.Text += dt[0].ToShortTimeString() + ” – ” + dt[1].ToShortTimeString() + ” against ” + dt[2].ToShortTimeString() + ” – ” + dt[3].ToShortTimeString() + “\nResult: CONFLICT”;
}
else
{
richTextBox1.Text += dt[0].ToShortTimeString() + ” – ” + dt[1].ToShortTimeString() + ” against ” + dt[2].ToShortTimeString() + ” – ” + dt[3].ToShortTimeString() + “\nResult: NO CONFLICT”;
}
// sample conflict detection (defined) [end]

If you want to download the whole code, link below and enjoy… Do not practice the copy and paste! :)

Download: Detect Conflict Schedule (5)

Camilo III Info.Tech, Software Development, Visual C#

Ubuntu Professional Certification

December 18th, 2009
Ubuntu Girl

Ubuntu Girl

Today, I tried to answer the pre-test of UPC or the Ubuntu Professional Certification… and the result was…

Dear Camilo III,

Thank you very much for taking part in the pre-training assessment.

Your score is 9, which means that you are probably over-qualified for this course.

As a next step we suggest that you read through the Deploying Ubuntu Server Edition course overview found here: http://www.ubuntu.com/training/certificationcourses/server and then complete the corresponding online assessment.

Ubuntu Training courses are taught by Canonical-trained Ubuntu Certified Instructors. The Deploying Ubuntu Server Edition course is available through online training and classroom training, so you can can learn in the environment that suits you best.

Visit: www.ubuntu.com/training for more information.

Best regards and good luck
The Ubuntu Training Team

How flattering!! I admit it, I’m not that good… but anyway, the test is so easy.. hahahaha.. :) And one thing, I don’t have a dollars to pay the $1,600 for the Deploying Ubuntu Server Edition Certification. Its like PhP 76,800.00 in my country, that is 9 months to save my whole salary. hahahaha.. Damn! I will starved to death if I will take the exam… :P

Camilo III Administration, Info.Tech, Operating Systems

Visual C#: Retrieving Image (BLOB) from MySQL database

December 14th, 2009

I’ve been searching an article about storing and retrieving an image (BLOB data type) from MySQL database. Somehow, I only found the retrieving process but I created the storing process using PHP… :)

You may download my works, link provided below…

  • idsystem_database.sql.zip – the dump file of MySQL database; import this SQL file before running the project
  • the rest of the files are the project sample files

-> retrieveImg_public.zip (12) or http://camilord.kagayan.com/my.files/retrieveImg_public.zip

For the credits, Thanks to Markusek Peter…

MySqlConnection myConnection = new MySqlConnection(myConnString);

string testQuery = “SELECT sp.studePhoto, s.firstName, s.lastName

FROM students AS s, student_photos AS sp WHERE s.id = sp.studentID”;
MySqlCommand myCommand = new MySqlCommand(testQuery, myConnection);

myConnection.Open();
MySqlDataReader myReader = myCommand.ExecuteReader();

FileStream fs; // Writes the BLOB to a file (*.jpg).

BinaryWriter bw; // Streams the BLOB to the FileStream object.

int bufferSize = 100; // Size of the BLOB buffer.

// The BLOB byte[] buffer to be filled by GetBytes.

byte[] outbyte = new byte[bufferSize];
long retval; // The bytes returned from GetBytes.
long startIndex = 0; // The starting position in the BLOB output.

while (myReader.Read())
{
DateTime tmp = new DateTime();
tmp = DateTime.Now;
// Create a file to hold the output.
string filename = camilordMD5(tmp.ToLongDateString().ToString() + tmp.ToLongTimeString().ToString()) + “.jpg”;

string dest = Directory.GetCurrentDirectory() + “/” + filename;
fs = new FileStream(dest, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);

// Reset the starting byte for the new BLOB.
startIndex = 0;
// Read the bytes into outbyte[] and retain the number of bytes returned.

//myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
retval =(long) myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
lblName.Text = myReader.GetString(1) + ” ” + myReader.GetString(2);

// Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();

// Reposition the start index to the end of the last buffer and fill thebuffer.
startIndex += bufferSize;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);

}

pictureBox1.ImageLocation = Directory.GetCurrentDirectory() + “/test.jpg”;
//pictureBox1.Image = retval;

// Write the remaining buffer.

bw.Write(outbyte, 0, (int)retval – 1);
bw.Flush();

// Close the output file.
bw.Close();
fs.Close();
}

Camilo III Info.Tech, Software Development, Visual C#

Visual C#: Handling X button (top-right)

December 7th, 2009

xbuttonDisabling the X button

private const int CP_NOCLOSE_BUTTON = 0x200;

protected override CreateParams CreateParams
{
     get
     {
        CreateParams myCp = base.CreateParams;
        myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
        return myCp;
     }
}

Add confirmation if window closing or closed…

Insert this code to Main form or the Form1.cs


private void Form1_Closing(object sender,
                   System.ComponentModel.CancelEventArgs e)
{
     if (MessageBox.Show("Are you sure you want to exit?", "Confirm exit",
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
     {
        e.Cancel = true;
     }
}

Insert this to Form1.Designer.cs…

this.Closing += new System.ComponentModel.CancelEventHandler(
                             this.frmCCS_Closing);

Camilo III Info.Tech, Software Development, Visual C#

[PHP] Converting a value to MAC address format

October 20th, 2009

php_codeI just want to post this since someone ask about it. It might help if someone in this world is searching for an answer with the same problem my friend does. This is about converting a value of 0014:f8c4:9e32 or 0014f8c49e32 to 00:14:f8:c4:9e:32

Now here’s some answers for that…

function convertMACAddress($input)
{
    // clean up unwanted characters
    $input = preg_replace( '/[^a-zA-Z0-9]/', '', $input);

    // initiate character positioning
    $pos = 0;

    // declare output container
    $output = '';

     // if given MAC is invalid, terminate process and return an error
     if (strlen($input) < 12)
     {
           return '[Unrecognized MAC address]';
     }

    // initiate convertion...
    for ($i = 0; $i < 6; $i++)
    {
           if ($i == 0)
           {
                  $output .= substr($input, $pos, 2);
           }
           else
           {
                   $output .= ':'.substr($input, $pos, 2);
            }
            $pos += 2;
     }

      return $output;
}

That’s it… Problem solved. :) If need a sample code, please download the source -> Mac Convert (8) — Have fun coding..

Camilo III Info.Tech, PHP, Web Development

Gmail v.s. Ymail

July 13th, 2009

yahoo-vs-google-300x289Since my first plug into the internet, I use yahoo. When I search, I also use Yahoo search and that was year 1998. But now, Yahoo change a lot with sophisticated functionality. For google, I only use for search as alternative for Yahoo. But now, Google has the best functionalities and all.

Gmail and Google Search

  • Simple
  • User-friendly
  • Less Ads (if there’s an ads, it’s just a line)
  • Powerful spam filter
  • Lots of labs modules

Ymail and Yahoo Search

  • Sophisticated Functionalities
  • Lots of spam
  • Copied the chat functionality of Google
  • Lots of Ads (like really big ads)
  • Stupid Seals

As a conclusion, Yahoo sucks! Google Rocks!!!

Camilo III Info.Tech

Freelance Freedom by NC Winters

May 20th, 2009

These comic trips by N.C. Winters relates my work pretty much…

Camilo III Administration, Personal, Web Development, Wooow! , , , ,

Oracle Database 10g Express Edition

May 20th, 2009

Oracle Database 10g Express Edition
Free to develop, deploy, and distribute

Oracle XEOracle Database 10g Express Edition (Oracle Database XE) is an entry-level, small-footprint database based on the Oracle Database 10g Release 2 code base that’s free to develop, deploy, and distribute; fast to download; and simple to administer. Oracle Database XE is a great starter database for:

* Developers working on PHP, Java, .NET, XML, and Open Source applications
* DBAs who need a free, starter database for training and deployment
* Independent Software Vendors (ISVs) and hardware vendors who want a starter database to distribute free of charge
* Educational institutions and students who need a free database for their curriculum

With Oracle Database XE, you can now develop and deploy applications with a powerful, proven, industry-leading infrastructure, and then upgrade when necessary without costly and complex migrations. Read what users say about Oracle Database XE.

Oracle Database XE can be installed on any size host machine with any number of CPUs (one database per machine), but XE will store up to 4GB of user data, use up to 1GB of memory, and use one CPU on the host machine.

After installation, be sure to register for an exclusive Oracle Database 10g Express Edition Discussion Forum hosted by Oracle expert Tom Kyte—click on the “Registration” link on XE’s Database homepage.

Camilo III Info.Tech, Software Development, Web Development , , ,

HowTo: Install CentOS Web Server + cPanel

April 30th, 2009
cPanel

cPanel

This is a basic installation tutorial for the CentOS operating system for dedicated server duties.
CentOS is a free white label distro of RedHat Enterprise with all the bells and whistles, and is the OS of choice for many web hosting companies

Installing the OS using ‘Text Mode’ :

1 – Insert the first Linux installation CD-ROM (disc 1) in the CD-ROM drive of your server and restart the server.
2 – At the boot: prompt, type text and press the Enter key. This starts the installation process.
3 – On the Language Selection screen, select English as the language that you want to run the installation program in, then click OK.
4 – On the Keyboard Selection screen, select the keyboard attached to your server, then click OK.
5 – On the Mouse Selection screen, select the mouse attached to your server, then click OK.
6 – On the Welcome screen, review the installation information, then click OK.
7 – On the Installation Type screen, select Custom, then click OK.
8 – On the Disk Partitioning Setup screen, select Disk Druid. Quote:
- If your disk has existing partitions, select each partition and click Delete.
9 – Create the following disk partitions:

The following partitions are recommended prior to installing cPanel:

**1 GB /
*50 MB /boot (No seperate /boot for FreeBSD)
**1 GB /tmp
*10 GB /usr
**7 GB /var
**1 GB swap (swap should be 2x RAM)
Remaining space to /home

Note: The above partitioning scheme is assuming a 40 GB hard drive. If you have a larger hard drive, you should increment /usr & /var accordingly. To create the / partition ‘root’:

* On the Partitioning screen (see step 8 ) , click New.
* In the Mount Point field, type / .
* For the Filesystem type select ext3.
* In the Size (MB) field, type 1024, then click OK. To create the /boot partition: Quote:
* On the Partitioning screen (see step 8 ) , click New.
* In the Mount Point field, type /boot.
* For the Filesystem type select ext3.
* In the Size (MB) field, type 50, then click OK. To create the /tmp partition : Quote:
* On the Partitioning screen (see step 8 ) , click New.
* In the Mount Point field, type /tmp .
* For the Filesystem type select ext3.
* In the Size (MB) field, type 1024, then click OK. To create the /usr partition : Quote:
* On the Partitioning screen (see step 8 ) , click New.
* In the Mount Point field, type /usr .
* For the Filesystem type select ext3.
* In the Size (MB) field, type 10240, then click OK. To create the /var partition : Quote:
* On the Partitioning screen (see step 8 ) , click New.
* In the Mount Point field, type /var .
* For the Filesystem type select ext3.
* In the Size (MB) field, type 7168, then click OK. To create the swap partition: Quote:
* On the Partitioning screen (see step , click New.
* For the Filesystem type field, select swap.
* In the Size (MB) field, enter a number that is twice the current RAM (1024 If you are using 512 MB Ram), then click OK. To create the /home partition: Quote:
* On the Partitioning screen (see step , click New.
* In the Mount Point field, type /home.
* For the Filesystem type select ext3.
* In the Size (MB) field, select Fill all available space, then click OK.

10 – When finished, Click OK.
11 – On the Boot Loader Configuration screen, select LILO Boot Loader, then click OK.
12 – On each of the following three screens, click OK.
13 – On the Network Configuration screen, clear Use bootp/dhcp, enter your server network configuration, then click OK.
14 – On the Hostname Configuration screen, enter the fully qualified host name of your server, then click OK.
15 – On the Firewall Configuration screen, select No firewall, then click OK.
16 – On the Language Support screen, select English (USA), then click OK.
17 – On the Time Zone Selection screen, select the location, then click OK.
18 – On the Root Password screen, enter in the root password for your server, re-enter the password to confirm it, then click OK.
19 – If you want to create an account that you can use to remotely log on to your server using SSH or FTP, click Add.
*** Provide the login name and password, then click OK.
20 – Review the information on the User Account Setup screen, then click OK.
21 – Review the information on the Authentication Configuration screen, then click OK.
22 – On the Package Group Selection screen, verify that only the following packages are selected. Clear all other check boxes.

. Network Support
. Messaging and Web Tools
. DNS Name Server
. Network Managed Workstation
. Software Development

23 – Click OK.
24 – Review the Installation to begin screen, then click OK.
25 – Insert the second/third installation CD-ROM when notified to, then click OK.
26 – To create a boot disk, click Yes. Otherwise, click No.
27 – When done, the installation complete screen displays.
28 – Click OK, then press Enter to restart.

[2] Checking the host name and network settings :
After your first boot, you must check your system’s host name and network configuration to ensure that they are correct. To check your system’s host name and network configuration:
- Log on to the system as the root user.
- Type vi /etc/hosts to open the host file and modify the contents.
- Verify that the file is in the following format:
- Verify that the loopback entry (127.0.0.1) appears in the file. A correctly configured file should look like this: Note : The IP addresses used here are for illustration purposes only; they are not valid values.

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
10.1.1.1 myhost.mydomain.com myhost – Modify the file as needed.
- Type :wq to close the file.
- Type vi /etc/sysconfig/network to open the network sysconfig file and modify the contents.
- Verify the host name. A correctly configured file should look like this: Note : The IP addresses used here are for illustration purposes only; they are not valid values.

NETWORKING=yes
HOSTNAME=myserver.mydomain.com
GATEWAY=10.100.0.1 – Modify the file as needed.
- Type :wq to close the file.
- Type vi /etc/sysconfig/network-scripts/ifcfg-eth0 to open the network scripts file and modify the contents.
- Verify that network information. A correctly configured file should look like this: Note : The IP addresses used here are for illustration purposes only; they are not valid values.

DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.1.1.1
IPADDR=10.1.1.1
NETMASK=255.255.0.0
NETWORK=10.1.0.0
ONBOOT=yes – Modify the file as needed.
- To make these changes active, restart the system by typing:

shutdown -r now

[3]cPanel Installation Instructions:

Important : You must have a valid cPanel license. If you do not have a valid cPanel license, please contact one of cPanel distributors listed at http://www.cpanel.net/dist.htm or buy a license directly from cPanel at http://www.cpanel.net/store/. cPanel now uses a universal install script which can be found at http://layer1.cpanel.net/. You can use the following commands in the root shell to download and start the installation script:

mkdir /home/cpins
cd /home/cpins
wget http://layer1.cpanel.net/latest
sh latest

At this point the installation has started and may take anywhere from 30 – 60 minutes to complete. At no point during the installation should you be prompted for user input. You will know the cPanel installation has been completed by the screen output coming to a stop & the statement “Done.” is printed on your screen. You should then hit “ctrl c”† to continue. Note: You must be on a stable connection to install cPanel. If your shell session disconnects during a cPanel install the cPanel installation will be aborted. You can restart the cPanel installation by completing “sh cpanel-*”† again, however it is recommended that you reformat your machine & start over to ensure a clean slate before placing the machine into production.

[4]cPanel/WHM Configuration: Following a successful install you should setup cPanel/WHM as soon as possible. In order to complete this process you will need to log into your machine using its main (eth0/fxp0) IP address; you should input something similar to this into your browser:

https://xxx.xxx.xxx.xxx:2087

Note: you should replace xxx.xxx.xxx.xxx with your actual IP address. Further to that, you will be prompted about a self signed SSL certificate; ignore this by clicking on “Yes”. A self signed certificate is generated by cPanel/WHM to ensure a secure/encrypted communication with your server. You will now be prompted with a few questions related to how you would like your installation of cPanel/WHM customized. You can walk through the wizard by clicking on “Next Step” or if you are an experienced user feel free to click on “Finish” to skip to the end. For a complete user guide on how to access cPanel/WHM and/or use any of the functions within cPanel/WHM, please visit cPanel do*****ents section at http://www.cpanel.net/docs.htm That’s all for now .. Just keep in mind, this is not the all-in-one package for server installaion, you’ll have to secure the server, update your kernel, install a firewall, configure SSH, apply patches …. etc.

 

Reference:

Camilo III Administration, Info.Tech, Operating Systems , , ,

Visual C#: Connecting to MySQL remotely

April 13th, 2009

I have a current project that connects to a remote database server using Visual C# as client window application. So before I started my project, I tested it if it is possible to connect and the result, it does connect. For those does who failed to solve this problem, here’s my tutorial/guide.

Test Project Requirements:

  • VMware Workstation 5.5
  • CentOS 4.4
  • Visual C# Express Edition
  • MySQL Data Connector .Net v1.0.7

Scenario:

The client’s OS is MS Windows XP and the server is CentOS Linux. The client will connect to the Linux server to query and process some transaction. But in the sample code, it demonstrate only how to connect remotely in the server. My server’s IP address is 192.168.10.117 and a MySQL port of 3306 (default port).

Screenshots:

mysqlRemote1.jpg

Step 1:

Setup the Linux server, be sure you already installed MySQL server. In our case, we use VMware and a CentOS 4.4 is installed. For installation help, google it! :P The first thing to do is configure your IP tables by using iptables command. see illustration below;

iptables1.jpg

If your configuration does not allow foreign connection to your MySQL, then change that and allow it. In real scenario if your server is public, I recommend that you must have a new server which can only be access through local network. Or if cannot afford, just setup well the IP tables that only local connections are allowed. Anyway, here’s my new IP tables setup in my server;

iptables2.jpg

In MySQL CLI, create a user that can access everywhere. To do this, see sample below;

mysql> GRANT ALL PRIVILEGES ON *.* to ‘beasaw’@'%’ IDENTIFIED BY ‘qwerty’;

Explained: the command shown above is to allow user, beasaw, to access anywhere using a password qwerty.

That’s it… server setup completed. :D

Step 2:

Before you create a new project in VCS, test first the connection using the command;

C:\> mysql\bin\mysql --host=192.168.10.117 --port=3306 --user=beasaw --password=qwerty

See image below;

cmd_mysql.jpg

Step 3:

  1. Open your Visual C# and create a new project, name it to remoteMySQL.
  2. In Form1.cs, layout just like the screenshot above.
  3. Add a reference, MySql.Data.dll (assumed that you already installed the MySQL data connector .Net v1.0.7)
  4. Add mysql to the project: using MySql.Data.MySqlClient;
  5. Begin your codes, see sample code (download link below)… :P

mysqlRemote2.jpg

That’s it… You can create as many applications you want with this method. Like Ticketing System, connecting 10 terminals to the servers simultaneously and etc. And of course, connection varies also to your MySQL server setup. :D

Download:

» VCS Remote Connect to MySQL Server (61)

Camilo III Info.Tech, Software Development, Visual C# , , , , , ,