Archive for May, 2008

Programming with colors

May 30, 08 by the programmer

Are you boring with programming on the old fashion way, by using characters, signs, numbers, symbols. If so then you might consider changing your programming style, or programming language.

I just found a programming language that you can make programs in using colors or by making abstract pictures.

What would you say if I told you that the above picture is a “Hello World” programm, would you believe it. You better believe it.

The programming language is called PIET.

Piet is an esoteric programming language designed by David Morgan-Mar, whose programs are bitmaps that look like abstract art. Piet was named after the Dutch painter Piet Mondrian.

“Hello World” in 10 programming languages

May 28, 08 by the programmer

This is how the popular “Hello World” looks like in 10 programming languages

JAVA

// Hello World in Java

class HelloWorld {
static public void main( String args[] ) {
System.out.println( “Hello World!” );
}
}

PHP

<?php
// Hello World in PHP
echo ‘Hello World!’;

?>

SQL

# Hello World in SQL

SELECT ‘Hello World’;

C#

// Hello World in Microsoft C# (”C-Sharp”).

using System;

class HelloWorld
{
public static int Main(String[] args)
{
Console.WriteLine(”Hello, World!”);
return 0;
}
}

C++

// Hello World in C++ (pre-ISO)

#include <iostream.h>

main()
{
cout << “Hello World!” << endl;
return 0;

}

Cobol

* Hello World in Cobol

*****************************
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
MAIN SECTION.
DISPLAY “Hello World!”
STOP RUN.
****************************

ColdFusion

<!—Hello world in ColdFusion—>

<cfset message = “Hello World”>
<cfoutput> #message#</cfoutput>

Delphi

// Hello World in Delphi
Program Hello_World;

{$APPTYPE CONSOLE}

Begin
WriteLn(’Hello World’);

End.

Fortran

C Hello World in Fortran

PROGRAM HELLO
WRITE (*,100)
STOP
100 FORMAT (’ Hello World! ‘ /)
END

VisualBasic6

‘ Hello World in Visual Basic 6

Private Sub Form_Load()
Print “Hello World”
End Sub

Display a calendar in UNIX

May 28, 08 by the programmer

If you want to see a calendar in UNIX all you have to do is write the cal command in the terminal.

This is how it’s used:

cal [-options] [[month] year]

DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows:

-1 Display single month output. (This is the default.)
-3 Display prev/current/next month output.
-s Display Sunday as the first day of the week. (This is the default.)
-m Display Monday as the first day of the week.
-j Display Julian dates (days one-based, numbered from January 1).
-y Display a calendar for the current year.

A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified

Two parameters denote the month (1 - 12) and year. If no parameters are specified, the current month is calendar is displayed.
A year starts on Jan 1.
The cal command first appeared in Version 6 AT&T UNIX.

How can I disable / enable the internal PC speaker in Windows?

May 25, 08 by the programmer

If you’re running Microsoft Windows you can enable the Internal Speaker or PC speaker by following the below steps.

  1. Open Device Manager
  2. In Device Manager click View and click “Show hidden devices”
  3. This should make “Non-Plug and Play Drivers” visible in Device Manager.
  4. Expand Non-Plug and Play Drivers by clicking the plus and double-click Beep.
  5. Within the “Beep properties” window click the Driver tab.
  6. Under the driver tab if you wish to temporarily enable this device click the Start button. If you wish to permanently enable this device under the Startup Type select System.

What is a Cookie?

May 25, 08 by the programmer

A cookie is a text-only string that websites stores in your browser.

This information is used by the website that stored it for later reference.

For example if a web site wants to store a information for a user that browsing it from that computer it can store that information in a cookie, so the next time this user comes to the web site the website can access the cookie and read the information.

Example:

If a website wants to know how many times a user has visited it can store an information of the number of times the user has been on the site in a cookie and each time the user comes back it can increment the cookie value.

Checking if cookies are enabled with JavaScript

May 25, 08 by the programmer

If you want to check if cookies are enabled or disabled on a browser you can do this with this very simple javascript.

It returns a boolean variable set to true if cookies are enabled or set to false if they are disabled.

What it does is very simple, it tries to set a cookie and checks if the cookie is accepted or not.

function check_cookies() {

var c=”test_cookie=valid”;

document.cookie=c;

if(document.cookie.indexOf(c)==-1){

cookies_are_disabled = true;

}else {

cookies_are_disabled = false;

}

return cookies_are_disabled;

}

Generate a unique id in PHP using uniqid()

May 25, 08 by the programmer

This is how you can generate a unique id in php using the uniqid() php function.

string uniqid ([ string $prefix [, bool $more_entropy ]] )

This function takes two parameters

- prefix (this string will be appended in front of each generated unique number ).

  • This parameter was made optional in PHP v5.0
  • The limit of 114 characters long for prefix was raised in PHP v4.3.1

- boolean more_entropy - If you set this to true the generated number will be longer (23 characters) if it is false it will be 13 characters

//This syntax without prefix can be used after PHP v5.0

$unique_id = uniqid();

// better, difficult to guess if you use the random number generator function for the prefix
$better_unique_id = uniqid(rand(), true);

Map of Mars by Google

May 25, 08 by the programmer

Google always surprises us.

This is very interesting, a map of Mars. It was made In collaboration with NASA researchers at Arizona State University, and Google. It is most detailed scientific maps of Mars ever made.

Check it out

http://www.google.com/mars/

Track your visitors with Google Analytics

May 25, 08 by the programmer

Ok, you have a website, but you have no idea how many visitors have visited your site.

Maybe you want to know how they found your site, from search engines or from referring links from other websites or by typing the domain name of your site in the browser.

There is a great free tool just for you. This tool is called Google Analytics.

There is no way you can run a website without this tool, it’s awseome, it has every possible report that you will ever need.

It can help you find out a lot about your site and the visitors that came on you site.

Check it out

http://www.google.com/analytics/

Execute server side file without using AJAX

May 22, 08 by the programmer

There are situations when you have to execute a php, asp or any other file that is on the server side from a javascript.

You can do that using AJAX, but there is a much more simpler way of doing that.

It is very simple all you have to do is create a new Image object and set the source of the image object with the url that you want to execute. You don’t have to import AJAX JavaScript files or use anything else, just three simple lines of code.

Nice a :)

var unique_number = new Date().getTime();
var i=new Image();
i.src=”server_file_that_you_want_to_call.php?parameter_1=”+parametar_1_value+ “&un=”+unique_number;

The unique number is for insuring the it is not going to be cached and it is going to execute every time you call it.

So you can use this when you want to execute server side files without a need for a result.

Cool