Archive for May, 2014

Parsing HTML to find Links

Method 1: using regular expression

	$regexp = "<a\s[^>]*\shref\s*=\s*\"([^\"]*)\"[^>]*>(.*)<\/a>"; //better version
	if(preg_match_all("/$regexp/msiU", $result, $matches, PREG_SET_ORDER)) {
		//print_r($matches);
		foreach($matches as $match){
			echo htmlspecialchars($match[1]);
			echo " - ";
			echo htmlspecialchars($match[2]);
			echo "<br />\r\n";
		}
	}

http://www.the-art-of-web.com/php/parse-links/

 

Method 2: DOM

//handle utf-8 encoding
$result = mb_convert_encoding($result, 'utf-8', mb_detect_encoding($result));
$result = mb_convert_encoding($result, 'html-entities', 'utf-8');

//load the html string into the DOMDocument
$DOM->loadHTML($result);

//get a list of all <A> tags | header link for hkgolden
$a = $DOM->getElementsByTagName('a');

//loop through all <A> tags
foreach($a as $link){
//echo out the href attribute of the <A> tag.
echo $link->getAttribute('href').'<br />';

}
}

&nbsp;

No Comments

Count Distinct in Excel 2010 or earlier

=IF(COUNTIFS($A$4:A41,A41,$B$4:B41,B41)>1,0,1)

 

Where $A$4 is the first row of the value, A41 is the current row of record…

 

There is already a count distinct function built in Excel 2013

No Comments

Nested “Case” in SQL

SELECT COALESCE(
  CASE WHEN condition1 THEN calculation1 ELSE NULL END,
  CASE WHEN condition2 THEN calculation2 ELSE NULL END,
  etc...
)

No Comments

Apache server 2.4.6 hangs after serving requests from Internet Explorer 10/11

Apache server 2.4.6 hangs after serving requests from Internet Explorer 10/11

Symptoms:
Apache 2.4 running on Windows hangs when Internet Explorer 10/11 is used to acces pages on it.

 

Reproduction:

I had a very reproducible scenario: Only the first request to Apache coming from IE would work, all other subsequent requests would hang, in all browsers. As long as I did not use Internet Explorer there did not seem to be a problem, but once that was used everything would hang until Apache was restarted. Strangely enough after I had applied the fix (see below) I reverted it to do some more testing but was not able to reproduce the problem anymore…

 

Migitating factors:
I am not sure of these, just describing the setup I was using when I encountered these problems. If you know more, please leave a comment.

  • Running on Windows 7
  • Using Apache 2.4.6
  • VMWare network drivers installed (see explanation for why this might be relevant)
  • Using an experimental 64-bit build of PHP 5.5: php-5.5.5-Win32-VC11-x64
  • Using Internet Explorer 11
  • Using Twitter Bootstrap, MySQL

Cause:
It seems that I was being hit by an issue with Apache’s Multi-Processing Module optimized for Windows NT. See references below for some sources that describe this problem and the fix.

Fix:
Add this configuration snippet to Apache24/conf/httpd.conf (bottom of file seems fine):

# Apparently this fixes an issue with Apache 2.4.6 on Windows hanging
# when serving requests from Internet Explorer 10/11.
AcceptFilter http none
AcceptFilter https none

Explanation:
From the Apache docs about AcceptFilter:

This directive enables operating system specific optimizations for a listening socket by the Protocol type.

On Windows, none uses accept() rather than AcceptEx() and will not recycle sockets between connections. This is useful for network adapters with broken driver support, as well as some virtual network providers such as vpn drivers, or spam, virus or spyware filters.

Copied from site: http://stijndewitt.wordpress.com/2014/01/10/apache-hangs-ie11/

No Comments

Upgrading AppServ / Moving out from AppServ

AppServ hasn’t been updated since year 2008. The packages are actually outdated.

Below are the tips and tricks for setting up php and apache from sketch in order to switch from plain old app serv to update-to-date apache and php.

 

1.  32 bits or 64 bits?

this must be decided first before downloading the packages, which apache and php must be aligned, i.e. same platform must be selected for both php and apache, either 32bits or 64bits

 

2. php thread safe?

must download the thread safe version for apache. non-thread safe is just for IIS…

I downloaded below packages from the web

php-5.5.12-Win32-VC11-x64.zip

httpd-2.4.9-win64-VC11.zip

 

3. Unzip all those files into certain folder, i used the same “c:\AppServ” with different folder name as AppServ used to prevent conflicts first.

i.e. c:\AppServ\

– apache24

– php55

– mysql (didn’t upgrade yet… it’s more complicated when upgrading DB…)

 

4. Setup Apache configuration, note the changes in config setting from apache web site

http://httpd.apache.org/docs/trunk/upgrading.html

 

5. Link apache to php

LoadModule php5_module “C:/AppServ/php55/php5apache2_4.dll”
AddHandler application/x-httpd-php .php
PHPIniDir ‘C:\AppServ\php55\php.ini’

*Remember the PHPIniDir must be in normal slash and single quote ‘ *

 

6. Setup extension for php to MySQL

extension_dir = “C:\AppServ\php55\ext\”

* use full path!!! *

php still refer to c:\windows\ as the root path even apache pointing to the correct ini file. phpinfo() can help!

 

7. Performance Turning

in php.ini, i set output_buffering = Off . Seems it’s even faster, don’t know why…

added below config to httpd.conf as well for performance reasons…

HostnameLookups Off

SendBufferSize 1048576

 

8. Special Setup for Windows

Apache 2.4 hangs randomly while the httpd.exe is running.

The solution is to add the following to your httpd.conf:

AcceptFilter http none
AcceptFilter https none

On Windows, this has the effect of disabling the AcceptEx() API (part of WinSock), which offers some performance improvements, but probably conflicts with Comodo Firewall.

Putting Comodo Firewall in “Disabled” mode doesn’t help because requests probably still go through Comodo’s networking code. I think Comodo would have to be uninstalled completely to eliminate the problem (though I haven’t tried it).

If you have a similar problem with Apache 2.2, you should use the Win32DisableAcceptEx directive instead.

Explanation:

From the Apache docs about AcceptFilter:

This directive enables operating system specific optimizations for a listening socket by the Protocol type.

On Windows, none uses accept() rather than AcceptEx() and will not recycle sockets between connections. This is useful for network adapters with broken driver support, as well as some virtual network providers such as vpn drivers, or spam, virus or spyware filters.

No Comments

SSO for Business Objects (BOBJ) in FireFox

Copied from: http://scn.sap.com/thread/3456167

Here are the notes we have for configuring Firefox and Chrome config for SSO with Kerberos

 

A. To configure Mozilla Firefox (Version 15 and above only) for SSO:
1. Open Mozilla Firefox
2. In the URL field type in “about:config” and hit the enter key
3. Accept the warning
4. It will open the configuration console of Firefox
5. In the search bar type in “network.negotiate-auth.delegation-uris”
6. Double click and it will open one window
7. Type “http://hostname ” here which should be the FQDN of the server you want to access via SSO.(you can do multiple entries separated by a comma)
Example: http://sapqbw.insummit.com,http://sapportal.insummit.com,http://sapdbw.insummit.com,http://sapcrmd.insummit.com
8. Click OK
9. Now in the search bar type “network.negotiate-auth.trusted-uris”
10. Double click
11. Type “http://hostname ” here which should be the FQDN of the server you want to access via SSO.(you can do multiple entries separated by a comma)
12. Click OK
13. Restart the Firefox
14. Open your website
15. SSO should be working now

B. To configure Google Chrome for SSO:
1. run regedit and navigate   to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome on a workstation that has Google Chrome installed, if it isn’t there you need to create the key
2. add the string value AuthNegotiateDelegateWhitelist
3. Enter the value either http://*insummit.com (to allow all hosts in your domain, or the FQDN and hostname of each URL separated by a semicolon
4. i.e. your webapps URLs are http://dev-bi.insummit.com and http://bi.insummit.com add the following http://*dev-bi.insummit.com; http://*bi.insummit.com
5. If you have multiple or many Chrome clients please consult your AD admin to see if he can deploy this setting via group policy to save on all the manual registry edits

 

 

No Comments

Connect Cisco VPN in Mac

URL: http://anders.com/guides/native-cisco-vpn-on-mac-os-x/

Native Cisco VPN on Mac OS X – With Group Password Decoder!

No Comments