from the desk of aniketh

code and ideas

Search only within posts in WordPress

without comments

If you only want search to look within posts and not in pages for a wordpress site, then a quick and easy way to be to add the following code to your theme’s functions.php file :

add_filter('pre_get_posts', 'aa_search_query_vars');
 
function aa_search_query_vars($public_query_vars) {
    global $wp_query;
    if(is_search()) {
        $wp_query->query_vars['post_type'] = 'post';
    }
    return $wp_query;
}

Written by aniketh

February 24th, 2011 at 5:26 pm

Posted in Uncategorized

Shorten URLs in strings with bit.ly

without comments

Here is a simple class that shortens the URLs within a string using the bit.ly shortening service. Example is at the bottom of the file.

If you only need to shorten a list of URLs (not within the string), then use the “shorten” function. Bitly api documentation is at http://code.google.com/p/bitly-api/wiki/ApiDocumentation .

Written by aniketh

November 2nd, 2010 at 9:22 am

Posted in Uncategorized

Hiding Hosting Providers Nameservers

without comments

If you need to use custom nameservers that show up when someone does a whois query, then here is what you do:
Get the IP addresses of the nameservers that your host gives you. They may give it in the welcome mail, or via support. You can also get this by using dig

Now set up child name servers with the IP addresses obtained previously. After this is setup it should look like the following :
Setup of child name servers

Once this is done, you can then set up your nameservers to these child name servers. This setup should look like the following :

Written by aniketh

November 2nd, 2010 at 8:59 am

Posted in Uncategorized

Google App Engine as a CDN

without comments

If you are looking to offloading some of your bandwidth costs to the great google, and were thinking of using the google app engine as a free content delivery network, then have a look at the cirrux cache project.

Installing it is pretty straightforward, considering you follow the quick installation guide as stated in the readme. If you are looking to use this along with your wordpress installation, then have a look at this link, which gives a much better and easier explanation and a step by step approach on what you really need in order to set up.

Using this technique may also help because the HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel.

If you are feeling lazy and just want to use something, then have a look at http://cdn-cloud.appspot.com/.

Written by aniketh

October 12th, 2010 at 12:49 am

Posted in Uncategorized

Monokai Komodo Edit/IDE Color Scheme

without comments

Looking through the interwebs for a suitable dark color scheme for Komodo Edit did not turn up favorable results, other than the one three year old topic over at the Activestate forums.

The only one that did stand out was the Monokai theme (and the Django theme, but that was too green), but the fonts were too big and too italicized for my tastes.

Here is a file with saner values :

Monokai Komodo Theme Updated

Hope you enjoy it.

Written by aniketh

October 8th, 2010 at 1:03 am

Posted in Uncategorized

Quick SSH Proxy

without comments

If you have access to ssh to a server, its very simple to use the connection as a proxy server. To do so go to the terminal and run the following command :

ssh -C2qTnN -D 8081 youruser@yourhost.com

The number after -D (8081) specifies which port to listen on. Change it to something else of your liking if something else is using this port.

Then use localhost with the port number you specified as the SOCKS proxy, like so :

You can use ipchicken.com to check that everything is set up correctly.

Written by aniketh

October 7th, 2010 at 12:42 am

Posted in Uncategorized

Download files from a 4chan post

without comments

If you need to download all images (or files) from a 4chan post, then here is a quick script to do it. You can run it using PHP on the command line. Saves a lot of time when you see interesting wallpapers and things like that.

Once you save the file, make it executable by using chmod a+x download-4chan.phpand then you can start downloading all the images using something like

./download-4chan.php http://boards.4chan.org/wg/res/2508871

-

Written by aniketh

October 7th, 2010 at 12:30 am

Posted in Uncategorized

Hello world!

with one comment

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Written by aniketh

June 18th, 2010 at 8:51 pm

Posted in Uncategorized