Friday, June 29, 2007

Get file extension using javascript

Get file extension using javascript:
=============================


//way to call
GetExtension(form1.attach1.value);


function GetExtension(filename) {
var ext;
//get last 3 letters i.e. extension
ext=filename.substring(filename.length-3,filename.length);
return ext;
}

Tuesday, June 26, 2007

play with ms sql server sysobjects

play with ms sql server sysobjects
===========================


Sometimes you may want to see the list of all the objects within a database. This can be easily achieved.

SELECT * FROM master..sysobjects


This below query list out all the store procedure within a database :

SELECT * FROM master..sysobjects WHERE TYPE='P'

You may try out the other options:

SELECT * FROM master..sysobjects WHERE TYPE='U'

SELECT * FROM master..sysobjects WHERE TYPE='X'

You may list out some system functions:


SELECT LEFT(name, 30) FROM master..sysobjects WHERE LEFT(name, 3) = 'fn_'

How to view structure of a table using Ms Sql Server

How to view structure of a table using Ms Sql Server
=========================================


You must be aware of describe table / desc table statement in oracle. By using this statement you can view the structure of a oracle table.

Same way in Ms Sql Server you can do the same by using
sp_columns store procedure.

Eg: sp_columns myTable

Generate insert statement from sql query

Generate insert statement from sql query
=================================


In some case you might have a requirement where you might want to generate insert statments directly by firing a sql query. I am sure you might need to use this especially for those who are into maintainance related work.

Anyway here is the process:

You might want to create a table : (I am assuming that you are already having a table)

create table myTable (
Id int,
name nvarchar(200))

select * from myTable


Insert some data into the table : (I am assuming that you are already having data into table)

insert into myTable values(1,'kingkong')
insert into myTable values(2,'godzilla')


Here is the main sql statement which generates the sql. The logic is straigh forward. Just to insert single quotes you might need to add '''' .. just change the query as per your own requirement



select convert(varchar(1000),'insert into myTable values(' + convert(varchar(10),Id) + ',' + '''' + convert(varchar(100),Name) + '''' + ')') from myTable

Result: (listing all the insert statement for a given table)

insert into myTable values(1,'kingkong')
insert into myTable values(2,'godzilla')


Same way like above you might want to generate custom update statement as well. You can also try it out by yourself

Wednesday, June 13, 2007

Sql Connection in Ruby

sql connection in Ruby
=================


Define a sql connectivity function:

def connection
#connection details like dsn, uid and password
$dsn = "POS"
$uid = ""
$pwd = ""
$c = ODBC.connect($dsn, $uid, $pwd)
end


def callConnection()
#opening database connection
connection()
end


#Typical login script
def onLoginClick(event)
$username="myUserName"
$password="myPassword"
$sql="select * from loginmaster where username='" + $username + "' and password='" + $password + "'"
#creating a connection object
$dsn = "POS"
$uid = ""
$pwd = ""
$c = ODBC.connect($dsn, $uid, $pwd)

$q=$c.prepare($sql)
$q.execute

if $q.fetch == nil then
#message will only show if you use wxpos - uncomment below if you are using wxwidget
# message_box("Incorrect Login", "Login",OK ICON_INFORMATION, self)

else
close()
end

end





Introduction to Ruby language

Introduction to Ruby language

About Ruby Language

Ruby is a powerful and dynamic open source, object-oriented language, cross-platform language and interpreted language developed by Yukihiro Matsumoto(Matz) around 1994. Matz is a professional programmer who has worked for the Japanese open source company, netlab. jp. Ruby is developed under Linux, and is written in fairly straightforward C. It runs under UNIX, DOS, Windows 95/98/NT/2000, Mac OSX, BeOS, Amiga, Acorn Risc OS, and OS/2.


Features of Ruby include :

• Simple Syntax
• Normal Object-Oriented features(ex. class, method calls)
• Advanced Object-Oriented features(ex. Mix-in, Singleton-method)
• Operator Overloading
• Exception Handling
• Iterators and Closures
• Garbage Collection
• Dynamic Loading of Object files(on some architecture)
• Highly Portable(works on many UNIX machines, and on DOS, Windows, Mac, BeOS etc.)


Reasons To Learn Ruby :

Ruby's primary focus is productivity of program development, and users will find that programming in Ruby is productive and even fun. Ruby is well suited for the problem domains such as these:

Text processing—Ruby's File, String, and Regexp classes help you process text data quickly and cleanly.

CGI programming—Ruby has everything you need to do CGI programming, including text-handling classes, a CGI library, database interface, and even eRuby (embedded Ruby) and mod_ruby for Apache.

Network programming—Network programming can be fun with Ruby's well-designed socket classes.

GUI programming—GUI tool kit interfaces such as Ruby/Tk, Ruby/Gtk, Ruby/WxRuby etc are available.

XML programming—Text-handling features and the UTF-8-aware regular expression engine make XML programming handy in Ruby. The interface to the expat XML parser library is also available.

Prototyping—With its high productivity, Ruby is often used to make prototypes. Prototypes sometimes become production systems by replacing the bottlenecks with C written extensions.

Programming education—You can teach students that programming is fun


Why should you switch to Ruby?

If you are happy with Perl or Python, you don’t have to. But if you do feel there must be a better language, Ruby may be your language of choice. Learning a new language is harmless. It gives you new ideas and insights. You don’t have to switch, just learn and try it. You may find yourself comfortable enough with Ruby to decide to switch to it."

. Yukihiro Matsumoto (Matz)

Ruby Home-page : http://www.ruby-lang.org/

wxRUBY (wxWidget/wxWindows) - Widgets

wxRuby is a library to allow Ruby programs to use wxWindows 2.4.x (wxWidgets) which is a mature cross platform, GUI toolkit that uses native widgets where possible.

With the help of wxRUBY nice GUI objects can be used with your program. wxRUBY supports a huge library of widgets.

It uses NativeWidgets where possible, but draws its own complex widgets when the native platform doesn't have them. On Win32 it uses all (or almost all) native widgets, but on GTK+ it draws a tree control and a list control that are like the Win32 versions. This makes cross-platform portability easier without having to just use "lowest common denominator" widgets.

There is a wrapper for the Scintilla (www.scintilla.org) syntax-highlighting text editor. Scintilla supports Ruby syntax. There were recent discussions on the mailing list about a Ruby IDE. The Scintilla support makes wxWindows an interesting possibility for writing such an IDE.

In addition to Win32 and GTK+, it also runs on the Mac, and a port to embedded systems is almost ready. wxWindows has been around for 10 years, and has a wide selection of widgets available.

wxRuby is actively being developed at: http://rubyforge.org/projects/wxruby/

Basic Screen Save in C language (begineers)

Basic Screen Save in C language (begineers)

/* very basic screen saver in C language */
/* Screen saver - random circles, lines and rectangle and other shapes
COMPILER: Turbo C 2.01
*/


#include
#include
#include
#include


char ch;
/****************************************/
/* for line */
int lrandx, lrandy, lrandxx, lrandyy;
/* for rectangle */
int rrandx, rrandy, rrandxx, rrandyy;
/* for circle*/
int crandx, crandy, cradius;
/* random colour and shape generation */

int shape;
int col;

int gdriver,gmode,errorcode;
/*****************************************/
void main(){
gdriver=EGA;
gmode=EGAHI;
/*initialize the graphics driver*/
initgraph(&gdriver,&gmode,"");
/* error handling for graphics driver */
errorcode = graphresult();
if (errorcode != grOk ) {
printf("Graphics Error \n %s",grapherrormsg(errorcode));
printf("\n Press any key to halt:");
getch();
exit(1);
}
/* setting initiation of text and background color */
initialscreen();
while (!kbhit()) /* do nothing */ {
sleep(0.5);
mainscreen();
/*
outtextxy(133,44,"Sss");
*/

}
/*closing or deallocating graphic driver*/
closegraph();
}


/*main background screen*/
mainscreen() {
shape=rand()%3;
col=rand() % 14;
if (shape==0) {
rrandx=rand() % 600;
rrandy=rand() % 600;
rrandxx=rand() % 800;
rrandyy=rand() % 800;
setcolor(col);
rectangle(rrandx, rrandy, rrandxx, rrandyy);
}
else if (shape==1) {
lrandx=rand() % 200;
lrandy=rand() % 200;
lrandxx=rand() % 200;
lrandyy=rand() % 200;
setcolor(col);
line(lrandx, lrandy, lrandxx, lrandyy);
}
else {
crandx=rand() % 600;
crandy=rand() % 600;
cradius=rand() % 100;
setcolor(col);
circle(crandx, crandy, cradius);
}
return 0;
}

initialscreen() {
setbkcolor(4);
setcolor(1);
settextstyle(0,0,2);
outtextxy(40,40,"SCREEN SAVER...");
setcolor(11);
outtextxy(150,120,"---- computer bapu");
sleep(2);
cleardevice();
return 0;
}