Posts Tagged ‘Code’

How can you fight spam on your blog?

Saturday, November 15th, 2008

MT 3.3 offers a built-in spam protection plugin called SpamLookup. In addition to this plugin, there are several other options you can implement to help stem the tide of spam. Note that the spammers are constantly improving their methods to game the system, requiring constant vigilance on the part of the MT community to keep coming up with new ways to block them.

* SpamLookup
SpamLookup is a Movable Type plugin, developed by Brad Choate, that uses several techniques to identify spam, and then uses user-supplied choices to either moderate or block it. SpamLookup is an integrated part of MT 3.3, so if you have installed the latest version of MT, there is nothing more you need to install. SpamLookup utilizes several blacklist services to check incoming comments and trackbacks against known spammers. It allows you to either “junk” or moderate comments and trackbacks based on different settings for links and keywords. You can even “white list” domains or IP addresses. To adjust the settings on SpamLookup, simply open up your Plugins menu from the System Overview of your Movable Type editing window. Scroll to the bottom and select “Show Settings” from any of the SpamLookup modules. See Neil Turner’s suggestions on Making the Most of SpamLookup and David Philip’s SpamLookup’s Keyword Filter Explained for more information on how to best use this plugin.

* Akismet
Akismet is a distributed spam filtering service developed by the Wordpress community. According to the Akismet FAQ, the way it works is “When a new comment, trackback, or pingback comes to your blog it is submitted to the Akismet web service which runs hundreds of tests on the comment and returns a thumbs up or thumbs down.” MT developer Tim Appnel has created an MT plugin for Akismet (MT-Akismet) which can be downloaded from the Akismet website. Many have found Akismet to be more effective at catching spam than SpamLookup.

* Comment Challenge
Jay Allen’s Comment Challenge plugin requires a commenter to type a keyword into a separate field from the comment field in order for the comment cgi script to run. This plugin effectively halts automatic computer generated spam comments.

* Use a “Captcha”
A captcha is a security code that a commenter must enter in order for her comment to load. The benefit is that it screens out automated comment spam bots. The downside is that it keeps visually disabled people from easily contributing a comment. Arvind has released an SCode plugin to work with MT 3.2 - MT-SCode 1.0.

* Require approval before a comment posts
One way to ensure that your readers never have to see a spam message is that you personally approve comments before they are posted. MT3 has the comment moderation features built-in. (See Settings > Feedback > check “Immediate publish comments from No one”.)

Close old comments.
One way to cut down on blog spam is to reduce the opportunities by closing the ability to comment on blog posts older than X number of days. Mark Carey’s BlogJanitor plugin lets you do just that, and all automatically.

Display an Alert Message on Web Page Load

Monday, July 14th, 2008

If you would like an alert box to display when your page loads, place the following code within the HTML of your web page between your <HEAD> and </HEAD> tags.

<script language=”Javascript”>
<!–
alert (”Alert Message”)
//–>
</script>

Change the text indicated in red to the message you would like to display.

Although you can use the above HTML code to display an alert box when your web page loads, please use it cautiously, as you don’t want to irritate your visitors.

Creating a Stationary HTML Web Page Background

Monday, July 14th, 2008

You can create a stationary HTML web page background within your web page.

Stationary background images remain in one place even when scrolling through the page. Only the text will move. To create this effect, place the following code within your <BODY> tag.

<body background =”yourimage.gif” bgproperties=”fixed”>

When selecting your background image, keep in mind that your text will be moving over your image, so try to select an image that won’t make your text difficult to read.

To prevent your background image from tiling (repeating), place the following code between your <HEAD> and </HEAD> tags.

<STYLE TYPE=”text/css”>
<!–
BODY { background-image: url(yourimage.jpg) }
BODY { background-repeat: no-repeat }
BODY { background-position: center }
–>
</STYLE>

Replace the text indicated in red with your image file.

Enlarging Text Size within a Web Page

Sunday, July 13th, 2008

Although you can enlarge web page  text with the FONT tag, you also use the BIG tag.

The BIG tag is used to increase the size of your font. You can add additional BIG tags, side by side, to increase your font size even further. For each additional BIG tag you use, your font size will increase.

HTML Code:

<BIG>Your Text</BIG>

Browser View:

Your Text

HTML Code:

<BIG><BIG>Your Text</BIG></BIG>

Browser View:

Your Text

The BIG tag can be used in place of the FONT tag, as they both perform the same task.

Example Font Tag:

<FONT size=”3″>

PHP:Arrange an array by the first letter

Monday, June 30th, 2008

Here is a small PHP tips&tricks post : we have an array full of values, let’s say a country list (in this example the list is limited, we don’t want to see 190+ values).
PHP  CODE:

Array
(
[0] => Array
(
[0] => Afghanistan
[name] => Afghanistan
[1] => AF
[code] => AF
)

[1] => Array
(
[0] => Albania
[name] => Albania
[1] => AL
[code] => AL
)

[2] => Array
(
[0] => Algeria
[name] => Algeria
[1] => DZ
[code] => DZ
)

[3] => Array
(
[0] => Bangladesh
[name] => Bangladesh
[1] => BD
[code] => BD
)

[4] => Array
(
[0] => Barbados
[name] => Barbados
[1] => BB
[code] => BB
)

[5] => Array
(
[0] => Belgium
[name] => Belgium
[1] => BE
[code] => BE
)

[6] => Array
(
[0] => Brazil
[name] => Brazil
[1] => BR
[code] => BR
)

[7] => Array
(
[0] => Cape Verde
[name] => Cape Verde
[1] => CV
[code] => CV
)

[8] => Array
(
[0] => Cayman Islands
[name] => Cayman Islands
[1] => KY
[code] => KY
)
)

PHP CODE:

Array

(

[0] => Array

(

[0] => Afghanistan

[name] => Afghanistan

[1] => AF

[code] => AF

)

[1] => Array

(

[0] => Albania
[name] => Albania

[1] => AL

[code] => AL

)

[2] => Array

(

[0] => Algeria

[name] => Algeria

[1] => DZ

[code] => DZ

)

[3] => Array

(

[0] => Bangladesh

[name] => Bangladesh

[1] => BD

[code] => BD

)

[4] => Array

(

[0] => Barbados

[name] => Barbados

[1] => BB
[code] => BB

)

[5] => Array

(

[0] => Belgium

[name] => Belgium

[1] => BE

[code] => BE

)

[6] => Array

(

[0] => Brazil

[name] => Brazil

[1] => BR

[code] => BR

)

[7] => Array

(

[0] => Cape Verde

[name] => Cape Verde

[1] => CV

[code] => CV

)

[8] => Array

(

[0] => Cayman Islands

[name] => Cayman Islands

[1] => KY

[code] => KY

)

)

and we want to display like this
-A-

* Afghanistan
* Albania
* Algeria

-B-

* Bangladesh
* Barbados
* Belgium
* Brazil

-C-

* Cape Verde
* Cayman Islands

, the right and easy way to do this would be to retain in a variable the first letter of the last country and in another variable the first letter of the current country. We compare them and if they are different we just output the first letter and then the name of the current country. All this in just few and simple to understand lines, right? :P
PHP  CODE:

//try to do the A-Z list
$v = function to get your country list from a DB sorted by country name!;
$last_letter = ”;
$current_letter = ”;
for ($i=0;$i
” . $current_letter . ”

“;
}
print $v[$i]["name"] . “”;
$last_letter = $current_letter;
}

PHP CODE:

//try to do the A-Z list

$v = function to get your country list from a DB sorted by country name!;

$last_letter = ”;

$current_letter = ”;

for ($i=0;$i<count($v);$i++)

{

$current_letter = substr($v[$i]["name"],0,1);

if ($last_letter != $current_letter)

{

print “<div align=center>” . $current_letter . “</div>”;

}

print $v[$i]["name"] . “<br />”;

$last_letter = $current_letter;

}

Source code highlight plugin/modifier for PHP template engine Smarty

Monday, June 30th, 2008

<?php

function smarty_modifier_highlight_code($text)
{
$text = highlight_string($text, 1);
return $text;
}
?>

PHP:This tip/code snippet describes a simple php session example

Monday, June 30th, 2008

<?php
// Start the session
session_start();

// Init the counter
if( !isset( $_SESSION[ 'counter' ] ) )
{
$_SESSION[ 'counter' ] = 0;
}

$_SESSION[ 'counter' ]++;
// if the counter exceeds 50 reset it
if ( $_SESSION[ 'counter' ] > 50 )
{
$_SESSION[ 'counter' ] = 0;
}

// Output session ID and counter
printf(”Our session ID is: %s<br>”, session_id());
print(”The counter value is: ” . $_SESSION[ 'counter' ] );

?>

Tips for optimizing your php code

Saturday, June 28th, 2008

# If a method can be static, declare it static. Speed improvement is by a factor of 4.

# echo is faster than print.

# Use echo’s multiple parameters instead of string concatenation.

# Set the maxvalue for your for-loops before and not in the loop.

# Unset your variables to free memory, especially large arrays.

# Avoid magic like __get, __set, __autoload

# require_once() is expensive

# Use full paths in includes and requires, less time spent on resolving the OS paths.

# If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()

# See if you can use strncasecmp, strpbrk and stripos instead of regex

# str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4

# If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.

# It’s better to use select statements than multi if, else if, statements.

# Error suppression with @ is very slow.

# Turn on apache’s mod_deflate

# Close your database connections when you’re done with them

# $row[’id’] is 7 times faster than $row[id]

# Error messages are expensive

# Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

# Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.

How To Set Up Proxies In Your Browser

Wednesday, June 18th, 2008

This is a small Tutor - try it out!

===================================
How to set up proxies in your browser, (!!!!be anonymous and make the passes last longer…!!!!!!
===================================
In Internet Explorer
===================================
Click “Tools”, then “Internet Options”, the in the “connections” Tab, click the “LAN Setup” Button in the bottom. There is a “Proxy Servers”, tick the “Use a proxy…..” and then enter the proxy in the bigger textbox and the port (the part that comes after the “:”) in the smaller textbox. Hit okay, and then go to
CODE
www.whatismyip.com
to see if the proxy is now your IP.
===================================
In OPERA
===================================
Click “Files”, then “Preferences”, then “Network”, then click the button “Proxy Servers”, tick “HTTP”, fill in with the proxy:port, click okay and that’s it! Don’t forget to check with
CODE
www.whatismyip.com

===================================
In Firefox
===================================
Tools -> Options
Then click the General Icon
Then the “Connection Settings…” button
Then click the “manually configure proxies” radio button, and enter the proxy address and port in the HTTP Proxy area.
Don’t forget to check with
CODE
www.whatismyip.com

CODE
www.proxy4free.com
www.safeproxy.org
www.megaproxy.com
www.guardster.com
www.silenter.com
www.anonymizer.com

Happy Anonymous surfing!

To be clear: if I give you 255.255.255.255:8080, that means 255.255.255.255 is the proxy and 8080 is the port
To Optain Fresh and new proxies,u can alvays check Google…

Firefox Speed Tweaks

Wednesday, June 18th, 2008

Yes, firefox is already pretty damn fast but did you know that you can tweak it and improve the speed even more?

That’s the beauty of this program being open source.
Here’s what you do:
In the URL bar, type “about:config” and press enter. This will bring up the configuration “menu” where you can change the parameters of Firefox.

Note that these are what I’ve found to REALLY speed up my Firefox significantly - and these settings seem to be common among everybody else as well. But these settings are optimized for broadband connections - I mean with as much concurrent requests we’re going to open up with pipelining… lol… you’d better have a big connection.

Double Click on the following settins and put in the numbers below - for the true / false booleans - they’ll change when you double click.

Code:
browser.tabs.showSingleWindowModePrefs – true
network.http.max-connections – 48
network.http.max-connections-per-server – 16
network.http.max-persistent-connections-per-proxy – 8
network.http.max-persistent-connections-per-server – 4
network.http.pipelining – true
network.http.pipelining.maxrequests – 100
network.http.proxy.pipelining – true
network.http.request.timeout – 300

One more thing… Right-click somewhere on that screen and add a NEW -> Integer. Name it “nglayout.initialpaint.delay” and set its value to “0”. This value is the amount of time the browser waits before it acts on information it receives. Since you’re broadband - it shouldn’t have to wait.

Now you should notice you’re loading pages MUCH faster now!