Blog

Here I post interesting news, code snippets and other fun stuff. To keep up to date with my blog you can also subscribe to the RSS feed.


Block empty User Agents and Referers

Blocking requests without a user agent header and referer is a simple step to reduce web abuse.

RewriteCond %{HTTP_REFERER} ^$ [NC]
This line matches a blank REFERER field. It is ANDed with the following rule, which detects a blank USER AGENT:
RewriteCond %{HTTP_USER_AGENT} ^$ [NC]

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^$ [NC]
RewriteCond %{HTTP_USER_AGENT} ^$ [NC]
RewriteRule .* - [F]

Source: Block empty User Agent headers

CSS Naming Convention

#container{...}
/*---- Top section ----*/
#header{...}
#navbar{...}

/*---- Main ----*/
#menu{...}
#main{...}
#sidebar{...}

/*---- Footer ----*/
#footer{...}

1. Container
#container” is the section which “wrap” all elements of your page in a specific position within the browser’s window. For this section you can also use these names: “wrapper“, “wrap“, “page“.

2. Header
“#header” is the website’s top section. In general, it includes site’s logo and other elements. For this section you can also use these names: “top“, “logo“, “page-header” (or pageHeader).

3. Navbar
#navbar” identifies the horizontal navigation bar, a classic elements for every web site. For this section you can also use these names: “nav”, “navigation”, “nav-wrapper”.

4. Menu
#menu” section contains general links and menu. For this section you can also use this names: “sub-nav “, “links“.

5. Main
#main” is the site’s main section; if you have a blog it’s the section which contains your posts. For this section you can also use these names: “content“, “main-content” (or “mainContent”),

6. Sidebar
“#sidebar” section can contain secondary content, for example recent entries, some info about the site, ads elements… For this section you can also use these names: “sub-nav“, “side-panel“, “secondary-content“.

7. Footer
“#footer” contains additional information about the website. For this section you can also use the name: “copyright“.

Source: http://woork.blogspot.com/2008/11/css-coding-semantic-approach-in-naming.html

Password Protect Folder / Directory with htaccess and htpasswd on Apache and Linux / Unix

Step 1 – Create .htaccess file in folder you want to protect, copy the code and paste the code below, and then set server path to the file.

AuthUserFile /path/to/.htpasswd
AuthName "Restricted Area"
AuthType Basic
Require valid-user

Step 2 – Open Terminal, go to the directory you want to protect, and enter the following (changing the username to whatever you want). Enter the password upon prompting.

htpasswd -c .htpasswd username

Source: http://snipplr.com/view/3791/

Control access using htaccess file

# NO ENTRY outside of the LAN! No nasty crackers in here!
order deny,allow
deny from all
allow from 192.168.0.0/24
# this would do the same thing..
#allow from 192.168.0
192.168.10.

Source: http://parmendra.wordpress.com/2009/07/10/control-access-through-htaccess/

Clickability Developer updated for Firefox 4

Today, I finally made the leap of upgrading my browser to Firefox 4.0 and got busy updating my Clickability Developer add-on. The only other change I made is the Support Tickets link, it now links to Clickability’s new support portal. Once again my add-on has to make it through Mozilla’s review process before it is released. It shouldn’t be too long before it’s available for download.

Remove Unwanted Style Propeties

function cleantxt($string){
    // remove unwanted style propeties
    $except = array('color','text-align','font-size','height','width'); // declare your exceptions
    $allow = implode($except, '|');
    $regexp = '@([^;"]+)?(?<!--'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';
    //$string = preg_replace($regexp, '', $string);
    //$string = preg_replace('@[a-z]*=""@is', '', $string); // remove any unwanted style attributes
    $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';//this line should be replaced with other gibberish that excludes certain strings of 4 characters...
    $string = preg_replace($regexp, '', $string);
    // remove unwanted style propeties end
    $string = str_replace ( ' style=""', '', $string );
    return $string;
}

Blood Alcohol Concentration

Clickability Developer updated for Firefox 3.6

I’ve finally got around to updating my Clickability Developer add-on to be compatible with Firefox version 3.6. This will definitely be good news to the many people who emailed me requesting this. Currently, the updated version is sitting in a queue at Mozilla waiting to be approved by an editor. It should be available for download in 1-2 weeks.

Michelle Obama’s Dress is Famous

I heard this news on the radio driving into work this morning. Michelle Obama’s inauguration dress (Designed by Jason Wu), was donated to the Smithsonian National Museum of American History.

The Bloom Box Fuel Cell

eBay, Google, Staples, FedEx and Walmart have already started using these ultra-secretive boxes.