Category Archives: Internet

Wonderful Wonderful email things

Here are a couple of email utilities to deal with annoying websites asking for an email address for no need at all:

First is Mailinator . There is no signup, no passwords. Just give out any [email protected] and then go and check the email on mailinator. No password. Basically your email address is your password! The emails will get deleted after "some" time. Amazing piece of work! However, the spammy websites get smart and start rejecting anyone registering with mailinator.com address. But mailinator gets smarter: there are many other "mirrors" for mailinator that you can use. fastacura.com, fastnissan.com, fasttoyota.com etc. Each of the domains forwards the email to mailinator.

Second is Jetable which can act as a limited-time email forwarder. You enter your real email address and enter time limit 1-8 days and it gives you a new address (something like [email protected]) which is valid (and forwards email to your real address for the specified time).

I kind of see the value in jetable.org, but who is to guarantee that jetable.org won't start spamming your real email address ? The issue with mailinator is that of privacy (which is countered by using obscure email address). e.g. md5(string). Another issue is about the mail getting deleted. People have stepped up to solve this problem as well! There is a utility to keep scanning mailinator and forward any received email to your real email address from your desktop. Look here!

PHP Database abstraction class…

php.justinvincent.com

ezSQL Database Class - A class that makes it ridiculously easy to use mySQL, Oracle8, Inerbase/Firebase, PostgreSQL, SQLite (PHP), SQLite (C++), MS-SQL database(s) within your PHP/C++ script. Includes lots of examples making it very easy to understand how to work with databases. ezSQL has excellent debug functions making it lightning-fast to see what�s going on in your SQL code. ezSQL can dramatically decrease development time and in most cases will streamline your code and make things run faster.

EZ Results Paging Class - EZ Results is a paging class that can be formatted in any way you choose. Have a read through the documentation to see just how unlimited it is. Once you start working with it you will be amazed at how quickly you can prototype pages. Supports mySQL & Oracle.

Translate Perl code to PHP!

arrays

hashes

data structures

array split/join

case conversion

string comparisons

functions

string matching operations

basename/dirname

environment variables

POST/GET parameters

HTML elements

URL encode

MySQL database access


� Perl arrays � Php arrays
@a = (); # empty
 
@a = ( 'xx', 11, 33.5, );
 
@a = 12..33;
 
$a[2] = 'something';
 
$len = scalar(@a);
# or
$len = @a;
 
@a3 = ('xx', @a1, @a2);
 
($x, $y) = @a;
 
push
pop
shift
unshift
splice
 
foreach $i (@a) { .. }
$a = array();  # empty
 
$a = array( 'xx', 11, 33.5, );
 
$a = range(12,33);
 
$a[2] = 'something';
 
$len = count($a);
 
 
 
$a3 = array_merge('xx', $a1, $a2);
 
list($x, $y) = @a;
 
array_push
array_pop
array_shift
array_unshift
array_splice
 
foreach ($a as $i) { .. }


� Perl hashes � Php hashes
%h = ();
 
%h = ( 'x' => 'y',
       'z' => 'w',
     );
 
$h{'x'} = 7;
 
while (($key,$value) = each(%h))
{ .. }
# %h is automatically "reset"
# for another iteration
 
$a = keys(%h);
$b = values(%h);
 
delete $h{'x'};
$h = array();
 
$h = array( 'x' => 'y',
            'z' => 'w',
          );
 
$h['x'] = 7;
 
while (list($key,$value) = each($h))
{ .. }
# must reset before reusing $h
reset($h);
 
$a = array_keys($h);
$b = array_values($h);
 
unset( $h['x'] );


� Perl data structures � Php data structures
%h = ('a'=>13, 'b'=>25);
@x = ('hi', 'there', 'all',);
 
@mix = ( \%h, \@x,
         [33..39],
	 { x=>15, yy=>23, },
       );
 
$mix[0]->{'b'}  # == 25
$mix[0]{'b'}    # == 25
$mix[1]->[2]    # == 35
$mix[1][2]      # == 35
$h = array('a'=>13, 'b'=>25);
$x = array('hi', 'there', 'all',);
 
$mix = array($h, $x,
	     range(33,39),
	     array('x'=>15, 'yy'=>23),
	    );
 
$mix[0]['b']  # == 25
 
$mix[1][2]    # == 35
 


� Perl array split/join � Php array split/join
@a = split( '\|', $s );
 
@a = split( '\s+', $s );
 
 
$s = join( '|', @a );
$a = preg_split( '/\|/', $s,
            -1, PREG_SPLIT_NO_EMPTY );
$a = preg_split( '/\s+/', $s,
            -1, PREG_SPLIT_NO_EMPTY );
 
$s = join( '|', $a );


� Perl case conversion

� Php case conversion

$s = lc($s);
$s = uc($s);
 
$s =~ tr/a-z/A-Z/;
$s = strtolower($s);
$s = strtoupper($s);
 
 


� Perl string comparisons � Php string comparisons
$s1 eq $s2
 
 
 
$s1 lt $s2
strcmp($s1,$s2) == 0
# or
$s1 === $s2
 
strcmp($s1,$s2) < 0


� Perl functions � Php functions
sub foo {
 my @args = @_;
}
 
sub foo {
 $x = 5;
}
 
 
 
 
 
foo2( \@a, \%h );
function foo() {
 $args = func_get_args();
}
 
function foo() {
 global $x;
 $x = 5;
}
 
function foo2($x, $y) {
}
 
foo2( $a, $h );


� Perl string matching operations � Php string matching operations
$s =~ m/(\w+)/;
$substr = $1;
 
@all = m/(\w+)/g;
 
 
$s =~ s/\s+/X/;
$s =~ s/\s+/X/g;
 
$s =~ s/^\s+|\s+$//g;
preg_match( "/(\w+)/", $s, $match );
$substr = $match[1];
 
preg_match_all( "/(\w+)/", $s, $match );
$all = $match[0];
 
$s = preg_replace( "/\s+/", 'X', $s, 1 );
$s = preg_replace( "/\s+/", 'X', $s );
 
$s = rtrim($s);


� Perl basename/dirname

� Php basename/dirname
use File::Basename;
 
$b = basename($path);
$d = dirname($path);

 
 
$b = basename($path);
$d = dirname($path);


� Perl environment variables

� Php environment variables
%ENV
 
$ENV{REQUEST_METHOD}
 
$ARGV[$i]
 
$0

$_SERVER
 
$_SERVER[REQUEST_METHOD]
 
$argv[$i+1]
 
$argv[0]  # Php/CGI only


� Perl POST/GET parameters � Php POST/GET parameters
#form/hyperlink parameters:
# s : single-valued
# m : multi-valued
 
use CGI (:standard);
 
 
 
 
 
$s = param('s');
@m = param('m');
 
@param_names = param();
#form/hyperlink parameters:
# s   : single-valued
# m[] : multi-valued
#       (such as multi-selections
#        and checkbox groups)
 
$PARAM = array_merge(
   $HTTP_GET_VARS, $HTTP_POST_VARS
  );
 
$s = $PARAM[s];  # a scalar
$m = $PARAM[m];  # an array
 
$param_names = array_keys($PARAM);
 


� Perl HTML elements

� Php HTML elements

use CGI (:standard);
 
 
 
 
 
 
 
$ref = "x.cgi";
a({href=>$ref}, "yy")
 
textfield({name=>"yy", size=>5})
 
password({name=>"yy", size=>5})
 
textarea({name=>"yy",
	  cols=>5, rows=>2})
 
submit({value=>"yy"})
 
button( {name=>"xx",
	 value=>"yy",
         onclick=>"submit()",
        }
      )
 
%labels = (0=>'a',1=>'q',2=>'x');
popup_menu( { name=>"xx",
              values=>[0..2],
              labels=>\%labels,
              size=>4,
	    }
          )
 
 
@a = ('xx','yy','zz');
radio_group( { name=>'nn',
               values=> \@a,
               default=>'_',
               linebreak=>1,
	     }
           )
 
%labels = ('xx'=>'L1','yy'=>'L2');
@a = keys( %labels );
checkbox_group( { name=>'nn',
                  values=> \@a,
		  labels=> \%labels,
	        }
              )
 
table(
       Tr(
           [
	     td(['a','b']),
             td(['x','y']),
	   ]
         )
     )

# The Perl/CGI functions have the
# additional property of "stability"
# when used in reentrant forms.
# The values of the HTML elements are
# set according to the incoming
# parameter values for those elements.
# The versions below are not stable.
 
$ref = "x.php";
<a href="<?php echo $ref?>">yy</a>
 
<input type=text name=yy size=5>
 
<input type=password name=yy size=5>
 
<textarea name=yy cols=5 rows=2>

</textarea>
 
<input type=submit value=yy>
 
<input type=button
  name=xx value=yy
  onclick="submit()">
 
 
 
<select name=xx size=4>
<?php
$labels = array(0=>'a',1=>'q',2=>'x');
foreach (range(0,2) as $_)
  echo "<option value='$_'>",
       $labels[$_];
?>

</select>
 
$a = array('xx','yy','zz');
foreach ($a as $_)
  echo "<input type=radio
         name=nn value='$_'>$_<br>";
 
 
 
 
$labels = array('xx'=>'L1','yy'=>'L2');
foreach (array_keys($labels) as $_)
  echo "<input type=checkbox
         name=nn value='$_'>",
         $labels[$_];
 
 
 
<table>
<tr>
<td>a</td><td>b</td>

</tr>
<tr>
<td>x</td><td>y</td>
</tr>
</table>


� Perl URL encode

� Php URL encode

use URI::Escape;
 
uri_escape($val)
uri_unescape($val)
 
 
urlencode($val)
urldecode($val)


� Perl MySQL database access

� Php MySQL database access

use DBI;
$dbh = DBI->connect(
  'DBI:mysql:test:host',$usr,$pwd
);
 
 
$dbh->do( $sql_op )
 
$query = $dbh->prepare( $sql_op );
$query->execute();
 
while(@record = $query->fetchrow())
{ .. }
 
 
 
$dbh->quote($val);
 
 
 
$dbh = mysql_connect(
  'host', $usr, $pwd
);
mysql_select_db('test', $dbh)
 
mysql_query( $sql_op );
 
$results = mysql_query( $sql_op );
 
 
while($record =
        mysql_fetch_row($results))
{ .. }
 
 
mysql_quote($val)
#--------------------------- using:
function mysql_quote( $val )
{
  return
    "'" .
    preg_replace( "/'/", "'",
      preg_replace( '/\/', '',
		    $val
                  )
                )
    . "'";
}
 

Javascript: Auto Redirect to SSL page

symetrix dot net

SSL Detection

I did some searching and couldn’t turn up anything, so I decided to post this for anyone looking for something similar. Including this bit of JavaScript code into a header file of your website will cause all connections to be bounced over to an SSL secured version of your site. You can even use the same DocumentRoot for your secure and non-secure versions without problems.

<script language="javascript">
if (document.location.protocol != "https:")
{
document.location.href = "https://secure.you.tld" + document.location.pathname;
};
</script>

∞ Mon Dec 15th, 2:04pm

Comment

1. The only problem with this is that it wont work if someone doesnt have javascript. It makes security a sugestion, not a requirement. The same thing can be accomplished server side if you use apache with a mod rewrite rule.(though i imagine there must be a way to do it in IIS also).I think you would use the following(though this is off the top of my had, so it nay be wrong)*
RewriteRule http://(.*) https://$1

— jesse Wed Dec 31st, 8:14pm

Some cool tips for optimizing mozilla firebird

Some cool tips for optimizing mozilla firebird:
Geek Style: Optimizing Mozilla Firebird

Full Text:

Geek Style
Digital taste of life
� X-Pro IP SoftPhone | Main | Second hand news? Maybe worse �
December 08, 2003
Optimizing Mozilla Firebird
Posted at 09:59 PM | Permalink | Comments (4) | TrackBack (5)
It's almost 6 months now that I am stuck with Mozilla Firebird. Everyone knows that it�s a great web browser, but as always the default configuration is not the best configuration.

I have discovered that following configuration improves web browsing speed noticeably:

user_pref("general.smoothScroll", true);
user_pref("network.image.imageBehavior", 0);
user_pref("network.http.max-connections", 48);
user_pref("network.http.max-connections-per-server", 16);
user_pref("network.http.pipelining", true);
user_pref("network.http.pipelining.firstrequest", true);
user_pref("network.http.pipelining.maxrequests", 100);
user_pref("network.http.proxy.pipelining", true);
user_pref("nglayout.initialpaint.delay", 100);

(For those who are not familiar with above stuff, I recommend typing �about:config� in their address bar in Firebird, or searching for �prefs.js� in their profile directory. A good reference can be found here).

Well, as it is almost obvious by looking at the configuration itself, I will explain some of them:

First option turns on the �smooth scrolling� behavior in your browser, for who are switching from IE. Next option turns off auto image resizing (which is really annoying). The next options increase the number of total concurrent connections and max concurrent connections to a server at a time.

HTTP pipelining is also very useful, especially when you are behind a high delay internet link. It avoids making a separate connection for any single object, and uses a single TCP channel to transfer more than one object. This behavior makes your pages downloads faster, due to the nature of TCP three-way handshake.

The last option decreases the delay that Firebird waits before drawing pictures in a web page. Note that reducing this number to zero may cause weird behaviors by firebird, so increase it if your firebird crashes while loading images.

A good but not complete list of configuration parameters can be found at: http://www.geocities.com/pratiksolanki/
Comments

I believe that the gains from enabling HTTP pipelining are also due in part to not having to suffer the slow-start algorithm for every single file retrieved.
Posted by: Sean Neakums at February 7, 2004 06:50 PM

Sean is actually right about the pipelining thing. It is most useful for users that are behind high-delay internet links (e.g. satellite).
This way, instead of making one tcp connection per object, only one tcp connection establishes and many objects will be fetched through one connection.
Posted by: Babak Farrokhi at February 7, 2004 07:01 PM

Here are some other good ones:

// Kill window.print() which gives me an error msg since I have no printers installed.
user_pref("capability.policy.default.Window.print", "noAccess");

// Show error pages instead of popups. i.e. Unable to resolve.
// http://bugzilla.mozilla.org/show_bug.cgi?id=28586
user_pref("browser.xul.error_pages.enabled", true);

// Let remote content link to local (file://) content. This is needed for intranets.
// http://bugzilla.mozilla.org/show_bug.cgi?id=84128#c20
user_pref("security.checkloaduri", false);

// No Web page should be able to mess with my browser's UI.
// Bug 107949 - Add pref for ignoring window feature options on window.open()
// http://bugzilla.mozilla.org/show_bug.cgi?id=107949
user_pref("dom.disable_window_open_feature.close", true);
user_pref("dom.disable_window_open_feature.minimizable", true);
user_pref("dom.disable_window_open_feature.scrollbars", true);

// Bug 176304 - Option to disallow scripts from hiding toolbars
// http://bugzilla.mozilla.org/show_bug.cgi?id=176304
user_pref("dom.disable_window_open_feature.titlebar", true);
user_pref("dom.disable_window_open_feature.toolbar", true);
user_pref("dom.disable_window_open_feature.location", true);
user_pref("dom.disable_window_open_feature.directories", true);
user_pref("dom.disable_window_open_feature.personalbar", true);
user_pref("dom.disable_window_open_feature.menubar", true);
user_pref("dom.disable_window_open_feature.status", true);

// [RFE] Pref to disable resizable=no
// http://bugzilla.mozilla.org/show_bug.cgi?id=101509
user_pref("dom.disable_window_open_feature.resizable", true);

// Windows open in new window instead of tabs (target=)
// http://bugzilla.mozilla.org/show_bug.cgi?id=105547
user_pref("browser.block.target_new_window", true);

// Don't tell me I can't resize frames you stupid web author!
user_pref("layout.frames.force_resizability", true);
Posted by: Phillip at February 8, 2004 02:32 AM

Wow! What a difference. Thanks!
Posted by: Dan at February 8, 2004 08:34 PM