Wednesday, January 20, 2010
My toolbox for web development using .net
GhostDoc: This free extension automatically generates your documentation comments for your code. A must. [link]
Clone Detective: This add-in tells you where you are repeating code. Very helpful but sometimes does not play well with others add-ins. [link]
Dundas: Best graphing framework on .NET period. Only negative is that it is not cheap but you can accomplish most stuff with ASP.NET Charting Controls. [link]
Virtual Earth: Fun control to use Virtual Earth. [link]
Telerik Controls: Great controls and is a must but like Dundas is not cheap. [link]
ASP.Net Ajax Framework: A must if you are still doing web forms page. [link]
ASP.Net Ajax Toolkit: The bells and whistles for the framework. [link]
Monday, December 28, 2009
Most Common Sorting algorithms in C# class
using System;
using System.Collections.Generic;
using System.Web;
namespace ats.SortAlgo
{
public class Sorters
{
}
public class QuickSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Quick Sort Algorithm
public void sortArray()
{
q_sort(0, x - 1);
}
public void q_sort(int left, int right)
{
int pivot, l_hold, r_hold;
l_hold = left;
r_hold = right;
pivot = a[left];
while (left < right)
{
while ((a[right] >= pivot) && (left < right))
{
right--;
}
if (left != right)
{
a[left] = a[right];
left++;
}
while ((a[left] <= pivot) && (left < right))
{
left++;
}
if (left != right)
{
a[right] = a[left];
right--;
}
}
a[left] = pivot;
pivot = left;
left = l_hold;
right = r_hold;
if (left < pivot)
{
q_sort(left, pivot - 1);
}
if (right > pivot)
{
q_sort(pivot + 1, right);
}
}
}
public class BubbleSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Bubble Sort Algorithm
public void sortArray()
{
int i;
int j;
int temp;
for (i = (x - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (a[j - 1] > a[j])
{
temp = a[j - 1];
a[j - 1] = a[j];
a[j] = temp;
}
}
}
}
}
public class HeapSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Heap Sort Algorithm
public void sortArray()
{
int i;
int temp;
for (i = (x / 2) - 1; i >= 0; i--)
{
siftDown(i, x);
}
for (i = x - 1; i >= 1; i--)
{
temp = a[0];
a[0] = a[i];
a[i] = temp;
siftDown(0, i - 1);
}
}
public void siftDown(int root, int bottom)
{
bool done = false;
int maxChild;
int temp;
while ((root * 2 <= bottom) && (!done))
{
if (root * 2 == bottom)
maxChild = root * 2;
else if (a[root * 2] > a[root * 2 + 1])
maxChild = root * 2;
else
maxChild = root * 2 + 1;
if (a[root] < a[maxChild])
{
temp = a[root];
a[root] = a[maxChild];
a[maxChild] = temp;
root = maxChild;
}
else
{
done = true;
}
}
}
}
public class InsertionSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Insertion Sort Algorithm
public void sortArray()
{
int i;
int j;
int index;
for (i = 1; i < x; i++)
{
index = a[i];
j = i;
while ((j > 0) && (a[j - 1] > index))
{
a[j] = a[j - 1];
j = j - 1;
}
a[j] = index;
}
}
}
public class MergeSort
{
// array of integers to hold values
private int[] a = new int[100];
private int[] b = new int[100];
// number of elements in array
private int x;
// Merge Sort Algorithm
public void sortArray()
{
m_sort(0, x - 1);
}
public void m_sort(int left, int right)
{
int mid;
if (right > left)
{
mid = (right + left) / 2;
m_sort(left, mid);
m_sort(mid + 1, right);
merge(left, mid + 1, right);
}
}
public void merge(int left, int mid, int right)
{
int i, left_end, num_elements, tmp_pos;
left_end = mid - 1;
tmp_pos = left;
num_elements = right - left + 1;
while ((left <= left_end) && (mid <= right))
{
if (a[left] <= a[mid])
{
b[tmp_pos] = a[left];
tmp_pos = tmp_pos + 1;
left = left + 1;
}
else
{
b[tmp_pos] = a[mid];
tmp_pos = tmp_pos + 1;
mid = mid + 1;
}
}
while (left <= left_end)
{
b[tmp_pos] = a[left];
left = left + 1;
tmp_pos = tmp_pos + 1;
}
while (mid <= right)
{
b[tmp_pos] = a[mid];
mid = mid + 1;
tmp_pos = tmp_pos + 1;
}
for (i = 0; i < num_elements; i++)
{
a[right] = b[right];
right = right - 1;
}
}
}
public class SelectionSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Selection Sort Algorithm
public void sortArray()
{
int i, j;
int min, temp;
for (i = 0; i < x - 1; i++)
{
min = i;
for (j = i + 1; j < x; j++)
{
if (a[j] < a[min])
{
min = j;
}
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
public class ShellSort
{
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Shell Sort Algorithm
public void sortArray()
{
int i, j, increment, temp;
increment = 3;
while (increment > 0)
{
for (i = 0; i < x; i++)
{
j = i;
temp = a[i];
while ((j >= increment) && (a[j - increment] > temp))
{
a[j] = a[j - increment];
j = j - increment;
}
a[j] = temp;
}
if (increment / 2 != 0)
{
increment = increment / 2;
}
else if (increment == 1)
{
increment = 0;
}
else
{
increment = 1;
}
}
}
}
}
Saturday, October 3, 2009
Basic of Electronics to build robots
a transistor is a semiconductor device commonly used to amplify or switch electronic signals.

One of the Symbols used for transistors in schematic diagrams
a common transistor that i use is the C945 transistor.
Examples of Transistors
Resistor
A resistor is a block of material that limits the flow of current. The greater the resistance, the lower the current will be. on other words Resistors restrict the flow of electric current, for example a resistor is placed in series with a light-emitting diode (LED) to limit the current passing through the LED.

Resistor values are normally shown using coloured bands.
Each colour represents a number as shown in the table.
Most resistors have 4 bands:
- The first band gives the first digit.
- The second band gives the second digit.
- The third band indicates the number of zeros.
- The fourth band is used to shows the tolerance (precision) of the resistor, this may be ignored for almost all circuits

Colour Code | |
| Colour | Number |
| Black | |
| Brown | |
| Red | |
| Orange | |
| Yellow | |
| Green | |
| Blue | |
| Violet | |
| Grey | |
| White | |


Capacitors
A capacitor (historically known as a "condenser") is a device that stores energy in an electric field, by accumulating an internal imbalance of electric charge.
A capacitor functions much like a battery, but charges and discharges much more efficiently (batteries, though, can store much more charge).

Capacitor Symbol

Capacitors are labeled differently for a list please see http://www.twysted-pair.com/capidcds.htm
Relay
A relay is an electrically operated switch.
Relays are used to and for:
* Control a high-voltage circuit with a low-voltage signal, as in some types of modems or audio amplifiers.

Relay Symbols

a typical 5 pin relay (different with 6 pin replay)

Other Examples
Thursday, August 20, 2009
10 CSS Hacks
If you are front end coder you must know how important is to make cross browses, valid CSS and xHTML code. And also you must know how much time we are spending in all those hacks and fixes for various browsers. I've written about some of them earlier on PNG transparency issues, Yellow fields in web form, Vertical align div etc..
Here is the list of 10 hand picked CSS hacks and tricks which can help you in your CSS code and also save some time.1. Vertical align div
One of current CSS left outs is vertical align div. And before CSS 3 comes we have to use some tricks to solve this problem. I looked over for some solutions and it all comes up to defining it as table and using vertical align. The second one appears a lot and it’s a nice solution, but it has two faults, I’ll tell you later about them, here’s the code first.
Idea is to place absolute div 50% left and top and then to move margin left and top half if it’s size.
Vector people
.wrapper {
width: 100px;
height: 100px;position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-top: -50px;
}
Problem?
This works only with defined height and when div height is less then browser height so you can’t have scroll. Now you’ll ask why do anyone want vertical align when there’s a vertical scroll? Well for example you have container height 820px and you have it vertically centered in all larger resolutions, simple.
Solution
In this problem (when browser height is less than div height) at smaller resolutions 1/3 of div is not visible, it’s in negative top margin. So idea is to place some relative div that will prevent div to go into negative margin. Here is the code.
<div id="shim"/></div>
<div id="wrapper">
Content
</div>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
* {
margin:0px auto;
padding:0;
}
div#shim {
visibility: hidden;
width: 100%;
height: 50%;
margin-top: -200px;
float: left;
}
div#wrapper {
width: 1000px;
height: 400px;
clear: both;
background:red;
position: relative;
top: -200px;
/* IE4ever Hack: Hide from IE4 **/
position: static;
/** end hack */
}
/* Hide from IE5mac \*//*/
div#shim {
display: none;
}
html, body {
height: auto;}/* end hack */
/* ]]> */
2. Min-Height
selector {
min-height:500px;
height:auto; !important
height:500px;
}
3. PNG transparency
First one is if you need just simple transparent image, without some special needs for example backgrounds etc. The solution would be png fix. I've used it many times but it has lots of faults, for example with padding, margins and absolute positioning. Sometimes i can mess up the rest of your JavaScript files, but anyway very useful script. You can download it here http://homepage.ntlworld.com/bobosola/pngfix.js and just include it in your <head> tag
PNG<!--[if lt IE 7.]>
<script defer type="text/javascript" src="pngfix.js"></script><![endif]-->
The second one can partly handle issues from first and it's pure CSS solution. I mostly use this for backgrounds, because if your path for a background is from CSS file then png fix can't handle it.
PNG
.someelement {
background-image: url(images/image.png);
}
* html .someelemen {
background-color: #333;
back\ground-color: transparent;
background-image: url(images/blank.gif);
filter: progid:DXImageTransform.Microsoft.
AlphaImageLoader(src="images/image.png", sizingMethod="scale");
}
I found this very useful, and also when you add some hover effects for example some color or other image. You can see live example here
NOTE: This simple hover is just example and it doesn't work in IE6
.someelement:hover {
background: #333;
}
.someelement:hover {
background-image: url(images/image2.gif);
}
Only problem I had with this was with <a> tag, link just don't work (when it's in div with this kind of background) and i don't know why (talking again for IE6). And only solution i could think of was to place another absolute div over it for the links, content etc... Yes i know it's not elegant but it works if content is not dynamic.
4. Autoclear
.container:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.container {display: inline-table;}
/* Hides from IE-mac \*/
* html .container {height: 1%;}
.container {display: block;}
/* End hide from IE-mac */
5. Reset CSS
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
border:0pt none;
font-family:inherit;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0pt;
outline-color:invert;
outline-style:none;
outline-width:0pt;
padding:0pt;
vertical-align:baseline;
}
table {
border-collapse:separate;
border-spacing:0pt;
}
caption, th, td {
font-weight:normal;
text-align:left;
}
blockquote:before, blockquote:after, q:before, q:after {
content:"";
}
blockquote, q {
quotes:"" "";
}
strong {
font-weight:bold;
}
em {
font-style:italic;
}
* {
margin:0pt;
padding:0pt;
}
6. Scrolling Render IE
html {
background : url(null) fixed no-repeat;
}
7. Opacity
#transdiv {
filter:alpha(opacity=75);
-moz-opacity:.75;
opacity:.75;
}
8. PRE Tag
pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
9. Li Background Repeat IE
<!--[if lt IE 7]>
<style>
#leftnav li { zoom: 1;} /* haslayout=true */
</style>
<![endif]-->
10. Good to know
@charset "UTF-8";
/* ----------------------------------------------------------------------
WinIE7
---------------------------------------------------------------------- */
*:first-child+html selector{property:value;}
/* ----------------------------------------------------------------------
WinIE6 & Mac IE
---------------------------------------------------------------------- */
* html selector{property:value;}
/* ----------------------------------------------------------------------
WinIE6
---------------------------------------------------------------------- */
/*\*/
* html selector{property:value;}
/**/
/* ----------------------------------------------------------------------
MacIE
---------------------------------------------------------------------- */
/*\*//*/
selector{property:value;}
/**/
Monday, August 10, 2009
Weka Using Command Prompt
Using the WEKA GUI is fun and easy, but there are more options when using the command line. also the command line allows you to incorporate any programming language by simply calling the function from the command prompt. Here is what you need to do to get things going.
Download and install WINRAR (you will need to extract the classes)
Download and install WEKA. go to the directory and create a new folder "EXEC"
Notice the default directory. and notice the WEKA.JAR file. aswell as the new folder that we created.
Extract the contents of WEKA.JAR to EXEC folder
going to the EXEC folder, you will notice 3 folders that were extracted. your all set to use the command line.
Try the following code
C:/> java weka.classifiers.functions.multilayerperceptron
you will see a list of commands you can use.
if your just starting and dont know what each command or keyword means. you can copy the exact from the GUI.
but you can start with the GUI. multilayerperceptron is located under weka > Classifiers > functions
once you click you will see a set of commands you can edit via GUI but there are more from the command line. lastly -T tells java what file to look for
the following is an example of running a neural network from the command line
the following is the result of the command.
Saturday, August 8, 2009
Introduction to WEKA (GUI)
Collection of machine learning algorithms for solving data mining problems implemented in Java and open sourced under the GPL.
you can download it from
http://www.cs.waikato.ac.nz/ml/weka/
data files have an extension of ARFF
when creating a file which holds all your data, use the following in sequence:
- @relation -> holds the name of the data and how its related to your research
- @attribute -> informs you of what attribute each of your data is about(ex. its a real number)
- @data -> your main data which should be the same length as the number of attributes separated by a comma.
example:
@relation MusicGenre
@attribute BitRate real
@attribute Music {Jazz, Rock, Country, Classical}
@data
12.51,Jazz
45.23,Pop
the weka version im using is 3.6.1. lets start off with opening weka, you will see the following once the program starts running
The explorer window will open, select choose a file for your data input
select choose for the type of classifier
once the type of classifier appeas, right click on it and an option list will appear for settings
adjust the settings to your desired needs. as you can see all settings are default. click OK when done
Press Start to run the classifier. we are using a back-propagation with sigmoid function
The GUI option ON will give you the following output, allowing you to train your neural network per build since we are running at 10 folds. you can edit and move your neurons (see weka documentation) once your done with your training, accept and continue
the following shows the output either using the GUI ON/OFF feature. as you can see our classifier was able to classify 90% of the time.
Friday, July 24, 2009
Lecture 1: Programming paradigms (notes)
C
Assembly
C++ / Java
Concurrent programming ( not a language)
Lisp
Python
i want to give u all some mileage and some very relevant knowledge and languages that you can use for research and the industry however the real intellectual value in learning all these languages is to study the paradigms they represent.
to program in C or C++/Java is following a totally different thought process than in Lisp or Python. Im sure many of you already know C and C++, all you have to do is remove the Object oriented way of programming and you will be left with C. When u program in C and pure C with no classes and ur very procedure oriented you think of a main function as being a high level outline of sub functions and sub sub function. your oriented around procedures and you program with side effects, you pass around pointers and references with the idea of updating shared data. you do that in both C and C++. but as far as C is concerned you call it the procedural or sometimes the imperative paradigm. its verb oriented. the first thing you see is the function call. and the function call is so strong that it will let you know what the function will accomplish.
but in C++ all of a sudden rather than calling "Do this and Pass the address with some object". you do my object arrow do this. in java its my object dot do this. so the first thing you see is the data or the object thats being manipulated. and thats why its object oriented.
in between i have assembly here. now i have yet to decide on the direction to go however there is an assembly language called "MIPS" its very easy as far as assembly language goes. however im not really interested in teaching you assembly but im going to use it as a tool to show you how C and C++ files compile and eventually become binaries. im interesting in teaching u how a line like a=0 or a++ will translate to binary (one and zero). ill give u some insight on how C is translated in to assembly and how your variables functions all boil down to a collection of zeros and ones and a little for C++ aswell. while it turns out that C and C++ represent different paradigms; that they really also compile to 0 and 1. and after u get a hand at the manual computation and find out of a C or C++ code will look like in assembly; your really going to see almost look like the same language as far as the zeros and ones are concerned.
so by the end of this ill be able to do something like
****&*P arrow ***** = 7
and you will know exactly what it means.
it will take a little work but when it compiles it means something and when it runs it actually does something. and you will know why it crashes rather it is crashing.
now ill spend some time talking about concurrent programing. we actually do that in C however in concurrent programming we will get two functions to run seemingly simultaneously. please note the "seamless". because if we have a single CPU the process goes back and forth on the two functions. since its so fast u wont be able to say they dont run concurrently. Also there are some problems you will encounter that u might not think about for example the atm machine with data integrity issues.
Lisp Represents the functional paradigms. its very interesting because when you program you rely on a return value of a function to move forward. now whats nice about it is that there are no side effects. when you code in C or C++ u always have side effects. the return value doesnt tell you very much because it might be a number of a boolean but when you pass in a data structure by reference to a function and you update it so the original data structure has been changed, thats programing by side effects. while in Lisp you dont have that at all. you always synthesize the result or partial result that become larger results. and only then you see the answer on the screen. but we will get there. its a fun language and the easiest of all others.
python has been around for 17 or 18 years. it has a good library for dealing with web programming. and python being a scripting language is interpreted. so your going to write a small dynamic web server in python for the final project, it wont be that hard. you wont write all of Apache but you will write something that u have a web server making decisions on how to construct an HTML page and serve it to a client. you can program procedurally, OOP, functionally.
now there are some other paradigms that i will not cover but these are most likely what you will see for the next 10 to 15 years.