Educational Revolution Must Start from the Top and Go All the Way to the Bottom

11.30.2013, No Comments, Education, by .

If you stop for a second and watch the TED talks about education, you will witness professionals talking about the issues we have in education and ideas on how to solve them. All of them provide a wonderful argument and their ideas are marvellous; however, they all fail to point an important piece for this educational revolution to succeeded which is asking where to start doing these changes. Most speakers in TED talk about changes from kindergarten up to High School; however, they do skip the level of education at university level. From these levels of education is were we must start the educational revolution, not the other way around. Here are the two main reason why we should start from there:

1. Lets assume you have an student who had grow up in this new educational system. What would happen to that student when he goes to the university and encounter that they teaching using the old methods of education? Is he going to be able to adapt?
2. Most of the educators that are teaching in schools today, they learned how to teach when they were students at the universities. If the classes at the universities do not use these new methods of education then how do you expect to see them applied at the schools?

The universities are the parents of the educational system. They must provide the correct example if we wish for the children, the schools, to follow. If we keep this current old system running in our universities then any hopes for an educational revolution is wasted. The educational revolution must start in our universities now if we wish to see any changes at our schools in the near future.

Example of Knapsack Algorithm

Example of Knapsack algorithm.

NOTIFICATION: These examples are provided for educational purposes. Using this code is under your own responsibility and risk. The code is given ‘as is’. I do not take responsibilities of how they are used.

knapsack.c:

/**
* Knapsack Algorithm
* @author: Alejandro G. Carlstein R. M.
* @description: Simple Knapsack algorithm
*/
#include <stdio.h>

/* Macros Functions */
#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })

/* Debugging flags */
#define DBG_LV1 0
#define DBG_LV2 0

/* Constants */
#define MAX_STRING_LEN 80
#define MAX_ITEMS 100
#define MAX_WEIGHT 1000

/* This is an item we can put into the knapsack. */
typedef struct{
char name[MAX_STRING_LEN];
int weight;
int value;
} item;

/* Our dynamic programming table element.  We have the value
* that we can store, and also a way to remember what we selected.
*/
typedef struct{
int value;
int prev_row;
int prev_column;
} prog;

void print_table(int num_items, int max_weight);
void print_table_prev_xy(int num_items, int max_weight);

/* The actual DP table, and the items.  Note that we have an extra
* row and column in the table for the "zero elements" and "no weight"
* situation.
*/
prog table[MAX_ITEMS + 1][MAX_WEIGHT + 1];

item items[MAX_ITEMS];

int main(int argc, char *argv[]){

int num_items; // Number of items
int w; // Weight
int max_weight;
int n; // Item number;
int i, j;
int diff_weight;

/* Read in the maximum weight and number of items. */
scanf("%d %d", &max_weight, &num_items);

if (DBG_LV2){
printf("\nMax Weight: %d, Number of Items: %d \n\n", max_weight, num_items);
}//end if

/* Read in the items */
for (n = 0; n < num_items; ++n){
scanf("%d %d %s",
&items[n].weight,
&items[n].value,
items[n].name);

if (DBG_LV1)
printf("%d %d %s\n",
items[n].weight,
items[n].value,
items[n].name);
}//end for

if(DBG_LV2)
printf("\n");

/* Initialize the first row of the table. */
for (w = 0; w <= max_weight; ++w){
table[0][w].value = 0;
table[0][w].prev_row = table[0][w].prev_column = -1;
}//end for

// Fill in the table
// Should be a for loop for the items, a for loop for the weight,
// and inside all of that, a few if statements to determine if you
// can take an item -- and if so, do you want to?
//
// I strongly recommend printing out EVERY DECISION your program
// makes while debugging things -- and feed your program very small
// problems until it's running.
//
// Debugging code is an important skill.  If you can work through a
// problem by hand, you should be able to get your code to solve the
// same thing.

/* Initialize the first column of the table */
for (i= 0; i <= num_items; ++i){
table[i][0].value = 0;
}

if (DBG_LV2){
printf("TABLE VALUES\n");
print_table(num_items, max_weight);
}//end if

if (DBG_LV2){
printf("TABLE PREVIOUS COORDINATES\n");
print_table_prev_xy(num_items, max_weight);
}//end if

// Perform knapsack and find maximun value
for (i = 1; i <= num_items; ++i){

for (w = 0; w <= max_weight; ++w){

table[i][w].prev_row = i - 1;
table[i][w].prev_column = w;

// Check if item fit inside the knapsack

if(items[i - 1].weight <= w) {

int diff_weight = w - items[i - 1].weight;

// Check which value is higher
table[i][w].value = max((items[i - 1].value +
table[i - 1][diff_weight].value),
table[i - 1][w].value);

// Keep track of the previous column
if(table[i][w].value > table[i - 1][w].value)

table[i][w].prev_column = diff_weight;

}else{

table[i][w].value = table[i - 1][w].value;

}//end if

}//end for

}//end for

if (DBG_LV2){
printf("************\n\n");
}//end if

if (DBG_LV2){
printf("TABLE VALUES\n");
print_table(num_items, max_weight);
}//end if

if (DBG_LV2){
printf("TABLE PREVIOUS COORDINATES\n");
print_table_prev_xy(num_items, max_weight);
}//end if

// In my code, the maximum value is here.
// I can use the prev_row and prev_column to trace back the solution.
if (DBG_LV1)
printf("Maximum value is %d\n", table[num_items][max_weight].value);

if (DBG_LV2){
printf("************\n\n");
}//end if

// Print results:

w = max_weight;

int count = -1;

int t;

int total_weight = 0;

item *p_items[MAX_ITEMS];

for(i = num_items;
i > 0;
t = w,
w = table[i][w].prev_column,
i = table[i][t].prev_row){

if(table[i][w].value != table[i - 1][w].value){

total_weight += items[i - 1].weight;

p_items[++count] = &items[i - 1];

}//end if

}//end for

printf("%d\n", table[num_items][max_weight].value);

printf("%d\n", total_weight);

for (i = 0; i <= count; ++i){

printf("%d %d %s \n",
p_items[i]->weight,
p_items[i]->value,
p_items[i]->name);

}//end for

}

/*
*
*/
void print_table(int num_items, int max_weight){

int w,i;

for (i = 0; i <= num_items; ++i){
for (w = 0; w <= max_weight; ++w){
printf("%d ", table[i][w].value);
}//end for
printf("\n");
}//end for
printf("\n");

}

/*
*
*/
void print_table_prev_xy(int num_items, int max_weight){

int w,i;

for (i = 0; i <= num_items; ++i){
for (w = 0; w <= max_weight; ++w){
printf("[%d,%d] ", table[i][w].prev_row, table[i][w].prev_column);
}//end for
printf("\n");
}//end for
printf("\n");

}

input.txt:

5
4
2 3 item_A
3 4 item_B
4 5 item_C
5 6 item_D

Working with SQLite Cursors

A common mistake is the improper way to use cursors. It is very common to use a cursor and forget to close it. This produce an IllegalStateException.

A code similar to the following code example will produce an error the moment you leave the activity:

dbContact.open();
Cursor cursor = dbContact.getContact(contactDataId);
if (cursor.moveToFirst()) {
...
} else {
...
}
dbContact.close();
...
}

The problem is that you are not closing the cursor properly.
You could try the following variable of the previous code:

dbContact.open();
Cursor cursor = dbContact.getContact(contactDataId);
if (cursor.moveToFirst()) {
...
} else {
...
}
cursor.close();
dbContact.close();
...
}

However, there are cases that this code produce a warning when cursor calls the method finalizer(). This seems to be a problem with Droid 2.

This method seems to work better:

Cursor cursor = null;
try{
dbContact.open();
cursor = dbContact.getContact(contactDataId);
if (cursor.moveToFirst()) {
...
} else {
...
}
dbContact.close();
}finally{
if (cursor != null){
cursor.deactivate();
cursor.close();
}
}
}

Finally, there is always the option of using startManagingCursor(); however, this will be deprecated and replaced with CursorLoader class when using API 11.

Art – Sculpture – Paranoia

06.15.2010, No Comments, Art, Sculpture, by .

I created this sculpture while I was student of Ronald Gonzales at Binghamton University (﻿﻿http://ronaldgonzalez.com).
Thanks for him and his class, I discover my passion of doing sculptures as a hobby.

Paranoia

Do you feel suspicious? Or do you sense that other people want to do you harm? We are, in some degree, paranoid.

Our perception makes us change our actions in response to what surround us, to what we perceive as personally threatening. We chronically think that others are lying or cheating us in some way or another. We cannot confide ourselves to others for fear of being betrayed. Comments or events are misinterpreted as personally threatening. Insulting us, making us have long-term grudges against others. We see others actions and/or words as a direct attack in some way or another, therefore we counterattack. We think that the whole world is pitted against us. We suffer of hallucinations, fictional scenarios build inside our mind that lack of contact with reality. We take extreme actions which are completely out of proportion to what is really going on. Not only paranoia affect us, but also we make sure that it affects those who surround us.

This sculpture is made of plaster. The main colors are black and white. Inspired by the comic “Sin City” by Frank Miller, the eyes were colored. Each pair of eyes are pointing  to different directions, left, right, up and stray providing a feeling of searching for something. Black is used to provide a shadow and also to make the effect that each head goes further out.

This sculpture is a mirror. This is a reflection of that part of us that make us nuts. This is a way to say, STOP! Life is not a soup opera. Real life is not a distorted version of what is shows on TV, but TV is a distorted way to show reality. We cannot seclude ourselves to fear. We have to use fear and not being used by it. Fear is paranoid and paranoid is fear.

Notes : Computer Graphics with OpenGL – Part 5

NOTIFICATION: These notes are published for educational purposes. Using these notes is under your own responsibility and risk. These notes are given ‘as is’. I do not take responsibilities for how you use them.

PDF Content:

• Octanes
• Basic geometry mathematics
• Pythagoras
• slope base on octant
• 2D translation
• 2D rotation
• Transformation on rotation point
• Bresenham’s line draw algorithm for positive and negative slope
• Bresenham’s line draw algorithm with octanes

Programming Languages Q&A – Part 2

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

If any of these answers is incorrect or you wish a different explanation, please let me know by commenting.

1. What means to be overloaded?
When a name refer to more than one object at a given section of the program, its say that the name is overloaded.
When a given name refer to an arbitrary number of subroutines in the same scope, as long as the subroutine differ only in the number of arguments or the types of their arguments, they are said to be overloading subroutine names.
3. What is coercion?
When a compiler automatically convert a value from one type into a value of another type when the second type is required by the surrounding context, it said to be coercion.
4. What does polymorphism means?
Polymorphism means having multiple forms.
5. What does polymorphism means in programming languages?
Polymorphism means that a single subroutine can accept unconverted arguments of multiple types.
6. What is a parametric polymorphism?
Parametric polymorphism is when a code take a type or set of types as a parameter in implicity or explicitly way.
7. What is generics?
Generics is a way of explicit parametric polymorphism. The implementation is due when multiple copies of polymorphic code are created, each specialised for each need of a concrete type.
8. What is ad hoc polymorphism?
Ad hoc polymorphism is known as overloading by some authors. In the same way that generics allow to create automatically a copy of a code for every needed type, a similar way is performed with a calling syntax and a generated code.
9. What is a first-class status?
When a value can be passed as a parameter, returned from a subroutine, and/or assigned into a variable its said to be a first-class status variable.
10. What is a closure?
When a deep binding is implemented by creating an explicit representation such as a subroutine executed at present time (referencing environment) together with a reference to the subroutine its said to be a closure.

PrimeFaces: Using Included JQuery

11.12.2013, No Comments, PrimeFaces, by .

PrimeFaces is already shipped with the jQuery bundled; therefore, there is no need to include the jQuery script.

However, when in a page there are no PrimeFaces components that use jQuery then jQuery will not be automatically included.

To go around this issue, you must use the following line inside the <h:head> tag:

<hutputScript library="primefaces" name="jquery/jquery.js" />

NetBeans: PrimeFaces: Adding Theme to Project

11.12.2013, No Comments, JSP, NetBeans, PrimeFaces, by .

1. Go to the PrimeFaces theme Showcase Labs so you can pick which theme you wish to use (remember the name of the theme):
http://www.primefaces.org/showcase-labs/ui/home.jsf?theme=blitzer
2. Go to the PrimeFaces theme repository: http://repository.primefaces.org/org/primefaces/themes
3. Using the name of the theme you wish to use, go inside the theme folder and then go into the version you wish to use.