Python “time” Module

October 28, 2009
>>> import time
>>> now = time.strftime("%Y-%m-%d %H:%M:%S")
>>> now
'2009-10-28 14:10:52'
>>> tup = time.strptime(now, "%Y-%m-%d %H:%M:%S")
>>> tup
(2009, 10, 28, 14, 10, 52, 2, 301, -1)
>>> unix = time.mktime(tup)
>>> unix
1256710252.0
>>> tup2 = time.gmtime(unix)
>>> tup2 == tup
False
>>> tup
(2009, 10, 28, 14, 10, 52, 2, 301, -1)
>>> tup2
(2009, 10, 28, 6, 10, 52, 2, 301, 0)
>>> time.strftime("%Y-%m-%d %H:%M:%S", tup)
'2009-10-28 06:10:52'
>>> time.strftime("%Y-%m-%d %H:%M:%S", tup2)
'2009-10-28 06:10:52'

UZZAP CHATROOMS

November 27, 2008

I am quite amazed by the COMMUNITY BUILDING activities the Uzzap Chatters have been conducting. It is evident with the UZZAP Clans that have been established by these people. Most clans make themselves known by flooding. (X_+) and apparently, since they would mostly abide when a moderator tells them so, they have earned the UZZAP Showdown Rooms where they can exhibit their flood art. The most popular clans are:

  • Shadows
  • - I think they specialize in dancing text art.

  • R.!.P
  • - They invented SYNCHRONIZED flooding with color schemes. (Link to R.!.P Friendster Account)

  • [BOMB]/Bombards
  • - The first UZZAP Clan ever. Their flood is systematic as well and I guess they specialize in firepower related text arts. :D (Link to BOMBS Friendster Account)

  • KFU
  • - Bunch of nice people. Their flood look like some tribal patterns. (Link to their KFU Multipy account)

  • H20
  • - They kinda do some synchronized flooding (not so original) but what I like about them is that their names are always Clan-name related (Ex: Drift, Drip, Aqua, Hydrone, Ice, Flow, Rain, Splash). Apparently they don’t shut up in the presence of moderators and sadly, they get banned often.

  • CFA
  • - Most people describe them as “magulo” which means “sloppy”. I kinda agree. But most of them are nice and welcoming and they also produce some good stuff. (Link to CFA Friendster Account)

  • 4th Bat
  • - These people are the best-mannered. :D They have a thing for text LINE ART. (Link to 4th Bat Friendster Account)

And of course, we have the….

HERE ARE SAMPLE TEXT ARTS:


Dates in PHP (Tomorrow, Yesterday, Today of a Given Date)

August 1, 2008

<?php
echo “<h4>Date Yesterday</h4>”;
$yesterday = date(“Y-m-d”, time()-86400);
echo $yesterday;

echo “<h4>Date Today</h4>”;
echo date(“Y-m-d”);

echo “<h4>Date Tomorrow</h4>”;
$tomorrow = date(“Y-m-d”, time()+86400);
echo $tomorrow;

echo “<hr>”;
echo “<h4>Previous Date from User-defined Date</h4>”;

$gdate = “2008-07-11″;
echo “(” . $gdate . ” supplied.) <br>”;
$dt = strtotime($gdate);
echo date(“Y-m-d”, $dt-86400);

echo “<h4>Next Date from User-defined Date</h4>”;
echo “(” . $gdate . ” supplied.) <br>”;
$dt = strtotime($gdate);
echo date(“Y-m-d”, $dt+86400);

// DAYS IN BETWEEN TWO DATES

function days_in_between($s, $e){
$d = array();
$s = strtotime($s);
$e = strtotime($e);
for($n=$s; $n<=$e; $n=$n+86400){
array_push($d, strftime(“%Y-%m-%d”, $n));
}
return $d;

}

?>


UZZAP

July 14, 2008

This is the very thing that keeps me busy!

Checkout Uzzap’s official website now!


Let’s Uzzap about Sports

July 7, 2008

I am posting this as a bridge to my past and present entries.

So yes, Boston became NBA Champs as Predicted and my Paul Pierce became MVP as expected except that the Celtics actually made garbage time on the Lakers and made Special Attendance at the Pacman-Diaz Match last week wherein Pacman practically killed his opponent early in round 2 and finished though in the 8th.

Aside from that, UEFA EURO 2008 finals champion Spain finally does it after 24 years, now on the account of loser Germany who had an early land on the top. 1-nil just proves a tough match though, similar to this 5-set heart-pounding victory by new king Rafael Nadal over the 5-time-reigning ex-champ Roger Federer in this years Wimbledon Men’s Final

In local Sports, well, NCAA kicks off. :D

See one of its official journalists’ blog

Now….. What is Uzzap!?

It’s the most amazing messenger in the world for extended messaging that also includes:

- IM to Yahoo and MSN
- What they call E-SMS
- Email!
- Unique Chatrooms
- Auto-Buddy-Matching (Common contacts on mobile phones who become Uzzap users automatically become buddies).
- Themes
- and More!

Visit the Official Website at uzzap.com.
Text “uzzap” to 7272 for Smart subscribers
Or download directly on uzzap.com/download on your mobile and PC. :D


Javascript: DOM, Window Object, Page Load and URL Encoding/Decoding Examples

May 26, 2008

This software (wordpress.com) is so good at omitting scripts from your post and it’s true that if you wanna benefit from the glory of it all use the actual product (wordpress.org). I do not have my own domain for that though, so in spite of the absence of an actual demonstration, here are some useful javascript source codes!

window element

This code shows how to display a popup window.

onclick="window.open('test.html', 'windowname1', 'width=200, height=77'); return false;"
Full window properties
function popup(url)
{
 var width  = 500;
 var height = 500;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

The DOM

This code shows how to change the innerHTML value of a tag, change the color of a text, change the options of a select, make some page contents disappear, disable radio buttons, mark radio buttons as checked by default and basically how to user a switch function in JS and use the function getElementByID().


<script language="javascript">
function act(n){
	switch(n){
		default: break;
		case 1:{
			document.getElementById("targetObj").innerHTML =
"<p id='helloworld'>hello world</p>";
			replaceSelectOpt("change color of 'hello world'", 2);
			break;
		}
		case 2:{
			document.getElementById("helloworld").style.color = "red";
			replaceSelectOpt("change me into useless radio buttons", 3);
			break;
		}
		case 3:{
			r = "<input type='radio' name='rad' checked='true'>huhuhuh";
			r = r + "<input type='radio' name='rad' disabled='true'>nahnah";
			document.getElementById("thejester").innerHTML = r;
			s = "<a href='javascript:void(0)' onClick='act(4)'>
I am tired. Make me vanish.</a>";
			document.getElementById("helloworld").innerHTML = s;
			break;
		}
		case 4:{
			document.getElementById('thejester').innerHTML = "";
			document.getElementById('targetObj').innerHTML = "";
		}
	}
}

function replaceSelectOpt(txt, nxt){
	full = "<option>Choose!</option><option onClick=
'act(" + nxt + ")'>" + txt + "</option>";
	document.getElementById("you_have_no_choice_but_to_follow").innerHTML = full;
}

</script>

<div id="thejester">
	<select id="you_have_no_choice_but_to_follow">
	<option>Choose!</option>
	<option onClick="act(1)">show me a paragraph</option>
	</select>
</div>

<br>
<div id="targetObj"></div>

history.go() function

Go to previous page

For whatever purpose it may serve, you may use the history() function to navigate towards a specific page in your history.

history.go(-1);
Reload Page
history.go(0);

escape() and unescape() functions //url encode and decode

These are the javascript counterparts for PHP’s rawurldecode and rawurlencode.

<input type="text" size="100" onKeyPress=
"document.getElementById('s').innerHTML=escape(this.value)">
<div id="s"></div>

Jeassshhh… There’s too much code here….(X_+)


Useful PHP Functions

May 5, 2008

These are three of my favorite PHP functions. :D

string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] )Get the contents of a url.

Example:

// following code will display the contents of the web page www.example.com
$url = “http://www.example.com”;
$contents = file_get_contents($url);
echo $contents;

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )Requires an email server. This functions programatically sends an email based on the given parameters.
Example:

// send an email to someone@somedomain.com
$to=”someone@somedomain.com
$subj = “example”;
$message=”this is an email”;
if(mail($to, $subj, $message)) echo “Email was sent”;
else echo “Email sending failed.”;

int fwrite ( resource $handle , string $string [, int $length ] ) - Write something to a file. Note that the file and it’s parent directory should have permissions granted to a user such as “apache” or “www-data”.

Example:

// open a file called test.txt and if it does not exist, attempt to create it; place the pointer at the begining of the file
$handle = fopen(“test.txt”, “a+”);
$data = “I am programatically written.\n”;
fwrite($handle, $data);
fclose($handle);

I’ll stick with these 3 functions for the meantime. With this though, you can make programs such as:

  • A simple email interface. :D
  • A logging system using just the last function
  • A proxy browser or something.

PHP SESSION

May 5, 2008

This post was originally titled "PHP Developer Essentials" which was what I really wanted to post instead of "PHP Essentials". But as I was at it, I got really bored and I realize, I really just wanted to list all my favorite or let me just say "mostly used" php functions.

But to preserve the efforts, let me just leave what I have already typed here—Creating a session with PHP.

Creating a Session

login.php

<?php
$login_name = $_POST['username'];
$login_password = $_POST['password'];
if($login_name==’admin’ && $login_password==’@dm!n’){
   session_start();
   session_cache_expire(15);
   $_SESSION['user'] = $_POST['username'];
   header("Location: ‘home.html’");
}
else{
   die("Authentication Failed");
}
?>

What this simple program does, is get post data from a form that uses the POST method and defined the URL of this code as the form target. The form will look like:

<form action=’login.php’ method=’post’>
Username: <input type=’text’ name=’username’>
Password: <input type=’password’ name=’password’>
<input type=’submit’ value=’Login’>

After retrieving post data, it will validate the user inputs then start a session and store the login data (username) in a session variable called (user). It will then set the window location to the home page using the header() function.



PHP Essentials

May 5, 2008

Learn PHP quick! Here are the php elements and functions which I find essential in developing applications with PHP.

Basic Syntax

<?php
echo “hello world”;
?>

The output would be:

hello world

Variables

Variables are represented by a dollar sign ($) and does not require type declaration.

<?php
$a = “this is a string”;
$b = 1;
$c = 2;
$d = $b + $c;
echo $d . ” is an integer” . “<br>”;
echo $a;
?>

The output would be:

3 is an integer

this is a string

Basic Conditions

Here are some of the most basic conditions:

<?php
$a = 1;
$b = 2;
if($a==$b){
echo “a is equal to b” . “<br>”;
}
else if($a!=$b){
echo “a is not equal to b” . “<br>”;
}
if($a>=$b) or $a==1){
echo “a is greater than or equal to b or a is equal to 1″;
}
?>

The output would be:

a is not equal to be
a is greater than or equal to b or a is equal to 1

….Anyway, this is supposed to be a reference, not a tutorial. To really learn php, go to this site!


IT / Computer

April 28, 2008

Since I’m at this profession, I included this category to be able to share with aspiring programmers/ it developers, some knowledge they might need (a little open source isn’t so hard to give).