My Science Is Better

8Dec/110

Force IE to use the latest engine

If by some unknown reason IE8/9/10 are rendering your site in compatibility mode, ie IE7 mode or something lame like that, just force it to use the latest engine available:

<?php if (using_ie()) {header("X-UA-Compatible: IE=Edge"); ?><meta http-equiv="X-UA-Compatible" content="IE=Edge"/><?php } ?><!DOCTYPE html>

note that the code added right before the doctype declaration. the using_ie() boolean function below (credits to Simeon for this solution: http://www.php.net/manual/en/function.get-browser.php#101314)

function using_ie()
{
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = False;
    if(preg_match('/MSIE/i',$u_agent))
    {
        $ub = True;
    } 

    return $ub;
}
Tagged as: No Comments
7Oct/110

Password protect a folder in Apache using .htaccess

mkdir -p /home/secure/
htpasswd -c /home/secure/apasswords developer
chown apache:apache /home/secure/apasswords
chmod 0660 /home/secure/apasswords

then in your htaccess add these:

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/secure/apasswords
Require user developer
20Sep/110

FIX: Sites not working in IE7, IE8 CO

Recently I had to fix a site that was not being displayed correctly in IE8. Turned out that some of the DOM was written by Javascript, and IE8 on client's machine was not displaying parts of the page. At first i was not able to replicate the issue on a clean XP SP3, with IE8, but then after i disabled javascript i got the same effect as the client. Thought the solution was easy, assumed the client has JS disabled, but it turns out JS was enabled.

After closer investigation, the only difference between my IE8 and client's IE8 was a CO, installed using IEAK8 (corporate shit) and it had by default native XMLHTTP disabled. Translated: jQuery was assuming the browser is IE6.

To fix this issue, enable XMLHTTP in IE7, or IE8

1. Open IE8
2. Go to Tools -> Internet Options -> Advanced
3. make sure "Enable native XMLHTTP support" is checked
4. Save
Tagged as: No Comments
21Jul/110

Redirect entire site to another domain, excluding folder

A site i've built for a campaign needed to be redirected to another site as the campaign expired, but one folder in the domain needed still to be accessible. htaccess to the rescue:

RewriteEngine on
RewriteRule !^uploads($|/) http://example.com%{REQUEST_URI} [L,R=301]

This rule does match any URL path that does not begin with either /uploads or /uploads/ (leading / is missing in the pattern due to the path prefix removal when used in .htaccess files) and redirects the request to the corresponding path at example.com.

3May/110

Ubuntu show desktop on corner hover (mac os x style)

Open gconf-editor
ALT+F2

gconf-editor

Navigate:

apps → compiz → general→ allscreens → options → show_desktop_edge

If the show_desktop_edge key is not there, create it as string and then add the value BottomLeft and save.

19Apr/110

Add new cron job on Windows 2008 Server using Task Scheduler

I've been working recently on a windows 2008 server and i needed to setup a cron job. Well turns out that windows doesn't have a cron utility as in Linux world, but there is this Task Scheduler. When trying to find it in Control Panel and the Management Console i discovered that my user had no rights to this utility, but turns out that you can still use it if you run it in CLI (cmd.exe that is)

Open the cms by going to Start->Run and typing cmd.exe then Enter

# to find more about task scheduler:
schtasks /?

# to find more about adding new tasks
schtasks /create /?

# to actually add a new task that runs every hour
schtasks /create /tn "My Cron Job" /tr "C:\PHP\php.exe -f http://www.example.com/cron.php" /sc hourly

# create a task to run every 5 minutes
schtasks /create /tn "My Cron Job" /tr "C:\PHP\php.exe -f http://www.example.com/cron.php" /sc minute /mo 5
16Jan/110

Find string in files and show line number with grep

Handy snippet to find some string inside the files in a directory:

grep -r --line-number "string_you_search" path/where/to/look

Note the -r tells grep also to look into all subfolders recursively.

2Feb/109

Setting up Xdebug with Zend Server on Linux

Since our team work on different operating system, we switched for custom apache/php/mysql installs to Zend Server. Before everyone was using something different (the guys on windows were using XAMP, WAMP, on ubuntu i was using the packages in the repo and on the server we're using apache from cPanel) and applications were behaving a differently according to the default settings for all those platforms.

So we decided to install Zend Server CE as it has more or less the same settings over different platforms. I've had some bad experiences installing ZSCE on a system that already had apache installed via apt, but after a clear install of Karmic, ZF was running like a charm. The install process described in the online documentation works great.

After install is done, make sure to symlink php, pecl, pear and phpize so you can access them system wide:

sudo ln -s /usr/local/zend/bin/zendctl.sh /usr/sbin/zendctl
sudo ln -s /usr/local/zend/bin/pear /usr/sbin/pear
sudo ln -s /usr/local/zend/bin/pecl /usr/sbin/pecl
sudo ln -s /usr/local/zend/bin/php /usr/sbin/php
sudo ln -s /usr/local/zend/bin/phpize /usr/sbin/phpize

At this point you should be able to run php -i in terminal and the phpinfo will be displayed.

Next step is to install xdebug via pecl by running:

sudo pecl install xdebug

If all went well you should have the xdebug library located at /usr/local/zend/lib/php_extensions/xdebug.so . If you don't have it there, then something went wrong and you should NOT continue reading. This issue must be sorted first.

Next you need to comment out the 1st line of /usr/local/zend/etc/conf.d/debugger.ini so it looks like this:

#open editor
gksu gedit /usr/local/zend/etc/conf.d/debugger.ini

# this is how the 1st two lines should look afterwards
; register the extension to be loaded by Zend Extension Manager
;zend_extension_manager.dir.debugger=/usr/local/zend/lib/debugger

Xdebug needs to be loaded before Zend Extension Manager, that's why you need to add the following line just on top of the /usr/local/zend/etc/ext.d/extension_manager.ini

#open the editor
gksu gedit /usr/local/zend/etc/ext.d/extension_manager.ini

#add this line on 1st line:
zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so

#save the file

Restart zend server by running:

sudo /etc/init.d/zend-server restart

You can check if xdebug is working like so:

php -i |grep xdebug

The output should be something similar to this:

xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.idekey => mimir => no value
xdebug.manual_url => http://www.php.net => http://www.php.net
xdebug.max_nesting_level => 100 => 100
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => Off => Off
xdebug.remote_enable => Off => Off
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

Note the xdebug support => enabled on line 2.

Hope that helps :)

29Aug/090

Made the switch to wordpress

I've been using MovableType as the platform for my blog and i've been really happy with it. The reason i decided to switch to WordPress is simply because it's written using PHP and i'm able to easily extend it, unlike MT which is built in perl.
I haven't got a change to import the comments so far, but hopefully i'll get to that this week.

Let me know if you find a broken link or something unusual.

Filed under: Uncategorized No Comments
21Jan/090

So… ‘sup?

- With your linux box i mean... What's up with it?
- Not much... here goes:

  User:		mimir (uid:1000)
  Groups:	mimir adm dialout cdrom plugdev lpadmin admin sambashare vboxusers
  Working dir:	/home/mimir
  Home dir:	/home/mimir
  Hostname:	orion
  IP (lo):	127.0.0.1/8
  IP (eth1):	192.168.1.102/24
  Gateway:	192.168.1.1
  Name Server:	208.67.222.222
  Name Server:	208.67.220.220
  Date:		Wed Jan 21 19:43:43 EET 2009
  Uptime:	19:43:43 up  9:44,  3 users,  load average: 0.56, 0.42, 0.25
  Kernel:	Linux orion 2.6.28-4-generic #11-Ubuntu SMP Fri Jan 16 21:50:52 UTC 2009 x86_64 GNU/Linux
  Memory:	Total: 3895Mb	Used: 3071Mb	Free: 823Mb
  Swap:		Total: 1953Mb	Used: 7Mb	Free: 1945Mb
  Architecture:
  Processor:	0 : Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz
  Processor:	1 : Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz

All that info is found just by invoking Scott Morris's 'sup script.

Cool script!

Tag Cloud

Categories

Archives

Akismet

Blogroll

Ads