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)


	return 0;

It uses the camera of the computer.


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.

A Simple Random String Generator Implemented in Python

The general idea of this program is that given a grammar, construct any random string that follows the grammar rules. It is guaranteed that all the strings produced will be valid.

For the grammar, all the non-terminals are positioned on the left side while the equivalent values are positioned on the right side.

This is the grammar provided to us by our professor. This is a grammar for a simple calculator. The assumption here is that the grammar is Context Free and that the string has a finite length. Continue reading

String Rewriting Parser Implemented in Python

The program assumes that you will be providing Context-Free Grammar, otherwise it will not work properly. The idea of the program is to break a sentence down to its atomic elements. It follows the concept of String Rewriting System.

Given a sentence: abbabab

and grammar rules:

  1. ab -> S
  2. aS -> S
  3. Sb -> S
  4. SS -> S

The program determines whether the sentence can be parsed or not. It can be parsed if the sentence follows the grammar rules. Continue reading

Simple Finite State Parser Implemented in Python

This is a Simple Finite State Parser that checks whether is an English sentence is syntactically correct or not based on the grammar provided by my teacher.

The following is the Finite State Diagram of the grammar:

The program reads from a file a dictionary of valid words which also contains the type of the word. See sample below: Continue reading

Windows 8.1 Managing Network Profiles

Open the Registry Editor (regedit via Run command) and go to this directory:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles

Each network location is represented by a folder entry under this directory.

If you want to set up again the network locations when the network adapter connects to the network, delete all the subfolders of Profiles folder.

If you want to rename the network location, click on the right subfolder and edit the key named ProfileName and input the name you desire for the network location.

Script File to Backup SimStudent Logs

My group and I are performing an experiment in one of our subjects. We are using the SimStudent program which is locally installed in approximately 80 machines. We needed a way to copy all the logs of all the program instances and store them in a network storage.

This is the script I made. This will only work in Windows.

@echo off

REM	Written by: Yancy Vance M. Paredes, March 18, 2014

REM 	Go to the directory where the log folder is located
cd simstudent\SimStAlgebraV8

REM 	Prompt the user to enter the correct student number
SET /p STUDENT_ID="Enter student ID (ex: 02 [with leading zero]): "

REM	Prompt the user to enter the session number
SET /p SESSION_ID="Session No. (1, 2 or 3): "

REM	Prepare the target path based on the user's input

REM	Make sure to update this one to point to the UITO network storage

REM	Copy the file to the network storage, prompt for overwriting
REM	and copy everything inside the log folder to the new directory
xcopy log "%TARGET_PATH%" /s /-y

The assumption here is that the script is located just outside the SimStudent directory.

How to Calibrate Samsung Devices’ Magnetic Sensor

If your Samsung device comes with a magnetic sensor, you can calibrate it.

The first thing that you have to do is go to the Diagnostic Menu by issuing the code *#0*# . Afterwards, go to Sensor. You will know if the magnetic sensor is calibrated or not. See the picture below.

2014-02-11 23.11.56

The value should be 3 and not 1. By the way, this screenshot was taken from my Note 10.1. To calibrate it, just shake your device until it becomes 3. Just wait for a few minutes before the value changes. See the picture below. Continue reading