Python Network Sub-Netting Calculator

I had an assignment in my Computer Networks class. It involves sub-netting. Instead of solving everything manually, I opted to write a Python script to automate the process for me.

The idea here is just to take a network address and the prefix of the network. It will check first if the network address is valid. If it is not, it identifies the correct network address and begins the operation there.

I implemented my Network class using Python. It encapsulates all the needed methods.  Continue reading

Converting String to Integer in C++

If you want to convert a string data to an int in C++, you can use the atoi() function. This function is defined under the cstdlib library for C++.

#include <iostream>
#include <cstdlib>

using namespace std;

int main(void) {
	string data;
	int year;

	cout << "Enter birth year: ";
	cin >> data;

	year = atoi(data.c_str());

	cout << "Age is: " << (2014-year) << endl;

	return 0;
}

The assumption is that, of course, data can be converted into an integer. The c_str() method of the string object converts the string into an array of characters.

There are other functions that you can use to convert from string to float or long. Read more here.

I read something about the stoi() function but when I tried it, it did not work. According to forums, it has something to do with the MinGW compiler wherein you have to patch it.

Automatically Formatting Reference to ACM Style in Microsoft Word

If you don’t want to do the bibliography of your paper manually, you can let Microsoft Word do the formatting for you. The assumption here is that you have the BibTeX source of the citation of a reference material.

Installing Reference Manager

What I use to manage all my references is JabRef. It is a free reference manager that you can use. Download it here. Install it on your system afterwards.

Adding Reference to Database

Google Scholar and other online digital libraries have the feature that allows you to copy the BibTeX source in citing the document. For example, in Google Scholar:

search

Click on the Cite link below the search result. Continue reading

Samsung Galaxy Note 10.1 (2012 Edition) — N8000 4.4.2 KitKat Upgrade

I own a Samsung Galaxy  Note 10.1 (2012 edition) which is 3G and WiFi enabled. I was able to update it to KitKat. I live in the Phlippines and my device is not locked to any mobile networks.

Here are some screenshots:

2014-06-16 19.37.08

It was a really big update file. It was around 800 MB and it took me around 3 hours to finish downloading. Or maybe my Internet speed was just crappy?

2014-06-16 23.07.06

After downloading the file, I was prompted if I wanted to install the update. Continue reading

Measurement of Effectiveness of a Queuing System

We discussed this in our Computer Modelling and Simulations class.

Assuming we have a Burger restaurant and we want to identify how many servers will be needed to accommodate all the customers.

This Measurement of Effectiveness (MOE) provides a detailed information about the probability of having a queue, the probability of how many customers will have to wait and the utilization factor.

The following code seeks to identify the most optimal (cheapest) number of servers for a system that has a queue.

To be able to compute for the total cost for a particular number of server, the waiting cost and the service cost should be identified. The waiting cost is the opportunity cost of losing a customer per time period per unit. The service cost is the cost per time period for each server. Continue reading

Yan-C Programming Language: A Simple Lexer and Parser

One of my final project for my Programming Language class was to make my own programming language. Aside from that, I was tasked to develop a lexical analyzer (lexer) as well a parser for my language.

I managed to create the two programs. However, because of time constraints, I was not able to optimize my codes. Also, I found out that my grammar was (slightly) ambiguous. The parser follows the Recursive Descent Algorithm.

Here is the link to the documentation of my language.

The lexer and the parser were both written from scratch using Java. The file extension of the language is .y (of course).

I uploaded my project in BitBucket. If you want to improve it, you are free to do so. If you also want to suggest any improvements, you can just leave a comment below or send me an e-mail.

If you are familiar with Mercurial, you can fork my project or issue a pull request.

https://bitbucket.org/yancyvance/yan-c-programming-language

I am still working on the grammar. Hopefully somebody can collaborate with me.

Accessing Computer’s Camera using OpenCV

The assumption here is that the necessary dependencies are all set up.

I used Visual Studio as my editor for a C++ project.

#include <opencv\cv.h>
#include <opencv\highgui.h>

char key;

int main(void) {
	cvNamedWindow("Camera_Output", 1);
	CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);

	while( true ) {
		IplImage* frame = cvQueryFrame(capture);
		cvShowImage("Camera_Output", frame);
		key = cvWaitKey(10);

		// stop if the ESC button is pressed.
		if(char(key) == 27)
			break;
	}

	cvReleaseCapture(&capture);
	cvDestroyWindow("Camera_Output");

	return 0;
}

It uses the camera of the computer.

Reference:

http://opencvlover.blogspot.com/2011/07/accesing-camera-using-opencv.html

Creating a File with Arbitrary Size on Ubuntu

If you want to create a file with arbitrary size on Ubuntu, you can issue the following command:

dd if=/dev/zero of=dummy.dat bs=1 count=0 seek=1G

The program reads from an input file, in this case, it uses 0 as an input. The output file is written with file name “dummy.dat”. The bs stands for byte size. The count specifies the number of blocks to copy. The seek skips this space before writing.

The sample code above generates a file with size 1 GB. In my case, it was created in less than a second. Remember that 1 KB = 1024 bytes.

Here are some values that you can use for the seek flag: T (TeraByte), G (GigaByte), M (MegaByte), K (KiloByte), and many more. For more information, you can see the manual of the dd program.