Skip to main content

Posts

cURL equivalent in JAVA

I am tasked with writing an authentication component for an open source JAVA app. We have an in-house authentication widget that uses https. I have some example php code that accesses the widget which uses cURL to handle the transfer. My question is whether or not there is a port of cURL to JAVA, or better yet, what base package will get me close enough to handle the task? Update : This is in a nutshell, the code I would like to replicate in JAVA: $cp = curl_init(); $my_url = "https://" . AUTH_SERVER . "/auth/authenticate.asp?pt1=$uname&pt2=$pass&pt4=full"; curl_setopt($cp, CURLOPT_URL, $my_url); curl_setopt($cp, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($cp); curl_close($cp); Heath , I think you're on the right track, I think I'm going to end up using HttpsURLConnection and then picking out what I need from the response.

PHP array comparison algorithm

While trying to simulate a bit of PHP behaviour I stumbled across this: $a=array(0 => 1, 'test' => 2); $b=array('test' => 3, 0 => 1); var_dump($a==$b, $a>$b, $b>$a); According to the output from var_dump $b is bigger than $a . In the PHP manual there is a Transcription of standard array comparison which states that the values of the arrays are compared one by one and if a key from the first array is missing in the second array, the arrays are uncomparable. So far so good. But if I try this (change in the first element of $a only): $a=array(0 => 2, 'test' => 2); $b=array('test' => 3, 0 => 1); var_dump($a==$b, $a>$b, $b>$a); All three comparison results are false . This looks like "uncomparable" to me (because the > result is the same as the < result, while the arrays are not == either, which makes no sense) but this does not fit the transcription from the PHP manual. Both k

shift bits vs multiply in PHP

I have the following code: <?php $start = 1; $timestart = microtime(1); for ($i = 0; $i < 1000000; $i++) { $result1 = $start * 4; } echo "\n"; echo microtime(1) - $timestart; echo "\n"; $timestart = microtime(1); for ($i = 0; $i < 1000000; $i++) { $result2 = $start << 2; } echo "\n"; echo microtime(1) - $timestart; echo "\n"; This outputs: 0.14027094841003 0.12061500549316 I found on the Internet a Google interview question (which I wanted to apply for a developer, but I realize I can't), and one of the questions asked what the fastest way was to multiply a number. My first thought was to use the * sign, so I tested it. My question is, why is shifting bits faster than multiplication?

How to check php syntax of multiple files at once?

i have a svn server that i checkout the repository in my computer the main repositiry is about 2k files 3rd party generic code classes custom classes i have made changes to lots of files (mainly php) and i want to make sure they are all valid before i commit svn commit -m "i fix the bug #293" how can i check all the files at once to make sure they are valid and no php errors so i dont have to manually check all these files thanks

php cronjob interruption

i have a cronjob in php that calculates few business rules (eg: net rev, gross rev, estimated rev, etc... using standard deviation & other math algo) this cronjob calls multiple cron calls 3 php scripts using exec for each calls i start a process in background and tell the system that jobs x started. eg: here's my logic start main cron start - message cron sub 1 start - message run cron sub 1 cron sub 1 end - message wait until cron sub 1 stop process stuff cron sub 2 start - message run background cron sub 2 // this will automaticaly send a message when this jobs end cron sub 3 start - message run background cron sub 3 // this will automaticaly send a message when this jobs end main cron end - message end what i need to fix is this if someone runs the job manually and cancel it (ctrl+c) or something bad happen in the cron (fatal error or cannot connect to db) or anything else (like not enough memory) i want to stop the cronjob and tell what h

What is wrong with my code - circularly sorted array does not show any results

I had an interview today and the person asked me this question: How do you find easily an item in a circularly sorted array Since I didn't know the answer, I tried to find a solution. Here's what I have: Thanks <?php function searchincircularsorterlist($a, $len, $num) { $start=0; $end=$len-1; $mid = 0; while($start<$end) { $mid=$start+$end/2; if ($num == $a[$mid]) { return $num; } if($num<$a[$mid]) { if($num<$a[$start] && $a[$start]<=$a[$start+1]) $start=$mid++; else $end=$mid--; } else { if($num>$a[$end] && $a[$end-1]<=$a[end]) $end=$mid--; else $start=$mid++; } } if ($start == $end && $num == $a[$start]) { return $num; } return -1; } $array = array(7,8,9,0,1,2,3,4,5,6); var_dump(searchincircularsorterlist($array,sizeof(

Parsing Domain From URL In PHP

I need to build a function which parses the domain from a URL. So, with http://google.com/dhasjkdas/sadsdds/sdda/sdads.html or http://www.google.com/dhasjkdas/sadsdds/sdda/sdads.html , it should return google.com ; with http://google.co.uk/dhasjkdas/sadsdds/sdda/sdads.html , it should return google.co.uk .