Saturday, March 22, 2008

And the winner is...

I've run ab on the current rails project at work using Apache and Nginx as the proxy frontend to a mongrel cluster. On average I've seen about a 10% increase in performance using Nginx (ymmv). There's plenty of easy mongrel configurations for Nginx that you can find online. Working with Fedora, made this extra simple. Yum install, configure, chkconfig to turn on nginx, chkconfig to turn off apache if you already have that on. More fun to explore is how it does with cached static content.

Tuesday, August 28, 2007

Rails: calendar_field helper

Yet another long overdue update. I'm currently working at a fun company where I've been doing some Ruby on Rails applications. We've settled on the javascript calendar from Dynarch for date fields in our projects. Of course, there's a bit of tedium involved with setting up the calendar for each field you want to use it in. Hooray for Rails.. my very first helper method eases some of this tedium. Just copy the two following functions into your application_helper.rb


def calendar_field(object_name, method, options = {})
object = instance_variable_get("@#{object_name}")
field_value = object.send(method) ? object.send(method).strftime("%m/%d/%Y") : ''
output = text_field object_name , method , :value => field_value
output += calendar_helper(object_name + "_" + method)
output
end

def calendar_helper(field_id)
'<script type="text/javascript">
Calendar.setup({
inputField : "'+ field_id + '", // id of the input field
ifFormat : "%m/%d/%Y", // format of the input field
showsTime : false,
timeFormat : "24",
singleClick : true
});
</script>'
end


and call it in your views like so


<%= calendar_field 'object', 'method' %>


Sure, you can combine both functions into one and add a date format as a param but so far this serves my quick and dirty needs.

Monday, September 04, 2006

Beginning with Xoops

So I just recently finished a contract job where they wanted a whole portal type deal with wiki, blog, forum etc. And they wanted all of this managed under centralized login ala CMS. After some digging, I landed on the Xoops page. This is a real neat project which makes it possible to integrate other php web apps such as mediawiki, wordpress etc. Some of the software I wanted to try out would only work well with xoops-2.2.3a-Final. Here's some little tweaks I had to do along the way to make things work just right.

Mediawiki in the xoops environment does lock out anonymous users from making edits, however you can't seem to restrict edit access to any particular user group(s) from xoops.

This little workaround did it for me. Mind you there's probably a nicer way to do it but the quick and dirty method worked for me.
In mediawiki/includes/User.php I modified the isAllowed function (which seems to get run on every page load) as such.

function isAllowed($action='') {
if ( $action === '' )
// In the spirit of DWIM
return true;

$this->loadFromDatabase();
global $xoopsUser;
ini_set("register_globals", "on");
#checking for edit page, edit action and whether user is logged in
if( ($_GET['action'] == "edit") && ($action == "edit") && ($this->mId) && is_object($xoopsUser) )
{
$usergroups =
$xoopsUser->getGroups();
#check if admin or a developer
if( in_array( 1 , $usergroups ) || in_array( 4 , $usergroups ) ){
return true;
}
else{
#deny edit access
return false;
}

}
else{
return in_array( $action , $this->mRights );
}
}
`

All I do right now is check for the usergroup ID's I'm interested in that big if statement but ideally you can build your array of ID's that you want to give access to and compare against. This is an exercise I leave upto you.

Another module that needed some work was the Edito module. This provides a nice and neat way to post static content on the site. There's even hooks to use an HTML editor. However this module didn't seem to even get to the install part right (I'm doing this on a Linux machine, not sure what the behavior is on Windows). The best thing to do before doing the install is turn on the debug mode in xoops. Right away I noticed that permission problems were keeping me from loading the module.
Moving on ..
In edito/admin/index.php
I changed.
include_once ("../include/nav.php");
include_once("../include/myblockslist.php");
to...
include_once ("../../include/nav.php");
include_once("../../include/myblockslist.php

Hope this was actually helpfull to someone. Let me know what you guys think.

Monday, August 08, 2005

Linksys WUSB11 in Debian GNU/Linux

Been meaning to write this for a while now and by this point most of the information isn't even fresh in my mind so please bear with me...Hopefully this debian method will make your life a tad bit easier... So here we go...
I'm lazy so I'm using a stock kernel. If you are doing the same, get the matching kernel headers package (I'm using 2.6, should work with late 2.4s... I wouldn't even try 2.2). Another thing to note is that the verion of the WUSB11 I am using is ver 2.8. Hopefully this will be useful for WUSB11s in general. First, you can apt-get some important components.
# apt-get install gcc hotplug at76c503a-source atmel-firmware wireless-tools module-assistant modconf

That's about it for packages.. as far my recollection goes. Next you need to build the module. The easiest way to this is ..
# module-assistant auto-install at76c503a

This should compile the module against the matching headers for your kernel. If you want to compile it against another kernel .. I'm sure it's possible by editing stuff in the source directory for at76c503a. If all goes well, you should see a deb package for the kernel module in your /usr/src directory. Use dpkg -i to install this package. You might see the results of this in dmesg. Use modconf and make sure you select this module. This puts the module into /etc/modules to load when you startup. (yes, editing the file by hand also works..). It might not be quite there yet. There might be a line in hotplug that you need to change so it can properly load the firmware upon loading the module. Try running..
#/etc/init.d/hotplug restart

Then take a look at dmesg and proceed.

If things don't look right. The line you are looking for in /etc/init.d/hotplug is
#echo /sbin/hotplug > /proc/sys/kernel/hotplug .... you just need to uncomment this line and restart hotplug.

The line that needs to be edited in the hotplug startup script might be fixed by now. If so, you won't see any issues about not being able to find the firmware. Also, don't forget to update your /etc/network/interfaces with the information for your new interface.. such as the WEP the key. You can also put the info in /etc/network/if-pre-up.d/wireless-tools . Good luck.

Thursday, March 10, 2005

Manorama in Firefox

If you want to view http://www.manoramaonline.com in firefox, the steps to accomplish this is very easy. These steps work in linux and in windows.
First you want to install the Manorama font. http://geocities.com/peringz/fonts/manorama.zip

For Linux users, make sure you have true type font support. In Debian this is fairly easy by installing the right packages. Most stock linux distro should come with all the support you need out of the box. On Debian if you install ttf-malayalam-fonts package, it provides a nice place to store the Manorama.ttf file.
/usr/share/fonts/truetype/ttf-malayalam-fonts/ is where I put my font file.

In windows XP you can use, c:\WINDOWS\Fonts . I'm pretty sure this is the directory for other versions of windows as well.

Next you need to install an extension for AutoCharacterCoding switching for Malayalam in Firebird/Mozilla from http://quicktools.mozdev.org. That's it. Restart firefox and try out http://www.manoramaonline.com. There's a delay from when it initially loads the page and then switches the character coding, but this is only a small annoyance for me. Let me know if you kids come across any issues. Later.

UPDATE: Just use the Padma extension.

Thursday, March 03, 2005

First Post

My first post on blogger. Huzzah. Not much to discuss right. This blog will be used primarily to discuss tech related news in my life. At the moment, things of interest are XMLhttp especiallly in conjunction with PHP, Ubuntu linux, random hardware. I'll have something more interesting in the next post. bye..