Skip to main content

Posts

Showing posts from 2015

configuring apache for python

If you have basic understanding of apache, then this article is highly recommended for setup:
http://httpd.apache.org/docs/1.3/howto/cgi.html


I did setup this in my mac/OSx, was not easy to find info on web, hence I am briefing out the flow:
1) uncomment "LoadModule cgi_module libexec/apache2/mod_cgi.so" ( for me it exists in httpd.conf )
2) edit virtual hosts file to look like this: ( for mac, it is in httpd-vhosts.conf )

Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all


NOTE: "/www" is where my project resides
"ExecCGI" is the option that has to be there
3) Below the directory closing, add this line: ( for mac, it is in httpd-vhosts.conf )
AddHandler cgi-script cgi py

4) Restart apache: "sudo apachectl restart"

Now running your project should give "End of script output before headers" error in error log and 500 internal se…

delete all the values with in a group keeping only the topmost entry in each group in mysql

sometimes you're caught up in a situation where you have multiple entries against an id and you want to keep only single entry against each.

Table structure would be something like this:

Table `temp`

Entries:
user_id tstamp source
100 4/26/2015 app
100 4/26/2014 web
100 4/25/2015 app
101 4/26/2015 app
100 4/23/2015 app
101 4/20/2015 web
100 4/1/2015 app
200 4/26/2015 app
200 4/2/2015 app

Desired Output:
user_id tstamp source
100 4/26/2015 app
100 4/26/2014 web
101 4/26/2015 app
200 4/26/2015 app


Now, I want to delete the rows where source is `app` and keep the entry with max tstamp only with in a group.
Here's the sample query to achieve the same:

DELETE tmp FROM `temp` tmp join (select user_id, max(tstamp) as ts from `temp` where user_id in (select user_id from `temp` where source = 'app' group by user_id having count(user_id)>2) and source = 'app' group by user_id )t on tmp.user_id = t.user_id and tmp.tstamp != t.ts and tmp.source = 'app&…

how to access a private member outside the class in php (php Hack)

If you want to access a private variable/method outside the class... here is a trick to do the same:

class A
{
private $notVisibleOutside = 1;
}


$a = new ReflectionClass("A");
$property = $class->getProperty("notVisibleOutside ");
$property->setAccessible(true);

$a1 = new A();
echo $property->getValue($a1); // Work

So, the basic idea is to
- create a reflection class in php
- make the property or method accessible
- use that property to access the private variables/methods