Hacking Lightbox

Posted about 1 year ago

In case it wasn’t obvious I use Lightbox to make my photo album a little flashy. However, I never really read the Lightbox documentation, I simply used the Rails plugin view helper. I have for a while been wondering how to pass in an array of pictures and have the ability to click through them in the light box. When I looked at the HTML generated by the view helper I realized it wasn’t doing much. See the Lightbox homepage for more info. Then after seeing how easy it is to tell Lightbox about having more than one picture I dove in. Bear in mind I have always steered clear of JavaScript. I just never liked it. Aw, forget it I’ll cut right to the point! I didn’t like the default layout of the light box. A hover property splits the light box 50/50 and uses that to display the previous and next buttons. I just wanted them to always be displayed at the bottom with the close button and other data.

I am not in the mood to describe everything I did with the code so here is a diff of the lightbox.js. I won’t post my hackish style sheet modifications…I won’t even go there….I hate writing CSS.

For some unexplainable reason I deleted some code while only commenting other code. Whatever, maybe someone will find this useful:

==
65,68c65
< //var fileBottomNavCloseImage = "/images/closelabel.gif";
< var fileBottomNavCloseImage = "/images/custom-close-label.png"
< var fileBottomNavNextImage = "/images/custom-nextlabel.png"
< var fileBottomNavPrevImage = "/images/custom-prevlabel.png"
---
> var fileBottomNavCloseImage = "/images/closelabel.gif";
73c70
< var resizeSpeed = 8;          // controls the speed of the image resizing animations (1=slowest and 10=fastest)
---
> var resizeSpeed = 7;          // controls the speed of the image resizing animations (1=slowest and 10=fastest)
296a294,303
>               var objPrevLink = document.createElement("a");
>               objPrevLink.setAttribute('id','prevLink');
>               objPrevLink.setAttribute('href','#');
>               objHoverNav.appendChild(objPrevLink);
>
>               var objNextLink = document.createElement("a");
>               objNextLink.setAttribute('id','nextLink');
>               objNextLink.setAttribute('href','#');
>               objHoverNav.appendChild(objNextLink);
>
335,352d341
<               var objPrevLink = document.createElement("a");
<               objPrevLink.setAttribute('id','prevLink');
<               objPrevLink.setAttribute('href','#');
<               objBottomNav.appendChild(objPrevLink);
<
<                 var objPrevLinkImage = document.createElement("img");
<                 objPrevLinkImage.setAttribute('src', fileBottomNavPrevImage);
<                 objPrevLink.appendChild(objPrevLinkImage);
<
<               var objNextLink = document.createElement("a");
<               objNextLink.setAttribute('id','nextLink');
<               objNextLink.setAttribute('href','#');
<               objBottomNav.appendChild(objNextLink);
<
<                 var objNextLinkImage = document.createElement("img");
<                 objNextLinkImage.setAttribute('src', fileBottomNavNextImage);
<                 objNextLink.appendChild(objNextLinkImage);
<
425,426c414,415
<               //Element.hide('prevLink');
<               //Element.hide('nextLink');
---
>               Element.hide('prevLink');
>               Element.hide('nextLink');
472,473c461,462
<               //Element.setHeight('prevLink', imgHeight);
<               //Element.setHeight('nextLink', imgHeight);
---
>               Element.setHeight('prevLink', imgHeight);
>               Element.setHeight('nextLink', imgHeight);
==

I am dirty, tired and don’t feel like writing about this anymore.

Sean

Posted in ,  | no comments

All Apologies

Posted about 1 year ago

Sorry for all the 503 errors lately. It seems to be a bug in Haproxy 1.3.12 which is the latest package available to the Ubuntu distribution running on my VPS (running this site). I don’t feel like compiling the latest version which sounds to have a fix. Instead I will be dropping Apache2 → Haproxy entirely, in favor of Nginx. This suits my VPS much better, the current setup is total overkill anyway.

I’m really excited about this, and it should greatly increase the response time of the site. I hope to have this going before the weekend so I can spend some time adding features and fixing code for the site.

Posted in , , ,  | no comments

New HP Photosmart Printer

Posted about 1 year ago

Well my first blog of 2009 is going to be a great one! All Linux enthusiasts and supporters should read on! Long story short and getting up to the point, I wanted a nice networked printer for the home. Since all computers are going through a switch including the wireless router, everyone would be able to print to the same printer, without messing around with sharing it on a computer. So I start shopping around a bit, and surprisingly didn’t think much of Linux support. I suppose the main reason for this is that I have now used a slew of cheap HP, Brother and Lexmark printers on Linux without any issues.

Meet my nemesis of December 2008, Kodak! I was at the nearest Best Buy browsing the printers. To my misfortune so was a Kodak sales representative. Please understand that I am not much for typical sales people. Anyway this guy wasn’t so bad but still had that unlikable edge to him. Enough about that, let me get on to the bigger issue. Basically Kodak does not support Linux, no drivers are provided or schematics released to the Linux community. Ok, I am going to jump around some here. Here is an overview of my conversation with the representative, mind you I tried to represent the Linux community with some dignity by not cursing his company!

Me: I’m almost sold on Kodak’s printers, ink cartridge standardization, low printing costs. Now, I don’t expect you to necessarily know this, but do you know whether or not Kodak has support for Linux.

Representative: To be honest I don’t know, but I don’t think so.

I buy the printer available, something I normally wouldn’t do but in hopes that maybe Kodak will change and realize Linux is not the evil cult that it has been labeled as. Now, Best Buy did not have in stock the model I originally wanted but a step down yet. The Kodak representative clearly stated to me, more than once the only features lost are the wireless and double-sided printing. Maybe I expect too much but in my mind this was ok. I don’t NEED wireless, I only NEED wired networking. Which took five minutes to explain in the very beginning. That conversation went like this:

Me: I am looking for a printer that has a NIC in the back.

Representative: You want wireless.

Me: No, wireless is good, but I really want a network connection you know cat-5.

Representative: Oh, printers don’t have serial connections anymore.

Me: (thinking oh my, what is it going to take! so I start using other means of communication like using my hands to simulate a network cable)

Representative: Oh, ethernet!

Me: (BINGO! Ok, do you need a break now? Or can I continue?)

Ok, sorry about that rant! Now we are back to where I was a moron and actually bought this thing! So I get home, unpack it all load the cartridges yada, yada. I soon realize there is nothing but a mere USB connection in the rear. I was not terribly upset as I should have payed more attention anyway whatever, so I go back and return the damn thing! It must have been a blessing from Tux, because I suddenly realized how I had betrayed all of my beliefs. Kodaks gooney is still hovering around, so I walk up to him and with a massive smile announce that I bought a Kodak printer, and had brought it back then my reasons as you can imagine. I again breached the subject of Linux support this is the juicy part people, listen up!

Me: I just can’t buy something that doesn’t have Linux support, otherwise I would be sold on Kodaks printers.

Representative: I’m sorry to hear that. Do other manufacturers support Linux?

Me: Yes, matter of fact some even distribute their own drivers and support, while others release their schematics so the community may develop its own drivers. (I just dropped some big names I knew worked HP, Lexmark, Brother).

Representative: Oh I see. Well, to be honest you are the first person who has asked me about Linux. I’m sure if it was that popular Kodak would support it, but obviously not enough people to use it for us to bother.

Me: Completely dumbfounded at this great mass of ignorance in front of me. But I sense that it will get worse so I stick around!

Representative: We won’t release our information to the Linux community until there is more security that our information won’t be released to our competitors and the rest of the world. If we release our ink technology to the Linux community, everyone could then duplicate it…

Me: At this point I stopped listening because I realized there was no hope but then I did inform him. Not only was he completely incorrect and probably misinformed that there is not enough demand for Linux. Who told this poor guy anything about giving our their super secret ink technology.

Ok enough of all that! Let me just finish that part of this massive blog off with, I will not buy ANYTHING Kodak until they open up their eyes, oh yeah and get out of bed with Microsoft!

Relative Links:

Kodak’s Official Version Of Why They Do Not Supply Drivers For Linux

Linux drivers for kodak 5100 printer

kodak printer driver

Ok, let me talk about positive things now! Well as long as the subject is Linux! Long story short, I bought an HP Photosmart C6380 AiO from the same Best Buy for $200, well OfficeMax had it for $159 so I price matched. So far I am thrilled with it. I set it all up on the wireless, booted up my laptop running Xubuntu 8.04 (now using Gnome). Went into the printer configration, searched for printers, oh! What do you know it found a HP Photosmart C6380, connected installed its own driver, and I was printing just like that. Of course I then ran another cat-5 down to the switch, and now everyone is printing! Really though, talking strictly printer, putting my Linux fanboy attitude aside. I am happy with the printer. I will save an in depth opinion on it for later after I have really used it through and through.

Coming to a close here, the website design will soon change drastically, which is what I’m going to work on now!

Sean

Posted in , ,  | no comments

My Very Own Email

Posted about 1 year ago

I spent some time today and setup email on the new server. Much credit given to this how-to. It is now that I’m starting to fully enjoy my Linode. I basically have Postfix as the MTA and Dovecot performing IMAP/IMAPS and SASL. I am hitting the ceiling by now with memory usage, but I may be looking at taking Apache out of the picture in favor of something a bit smaller. Either Lighttpd or Nginx, leaning towards Nginx, if for no other reason than to just try something new.

Before all that I want to polish out my email setup by adding virus scanning solution which I haven’t decided on yet. I also will probably add postgrey but I don’t know anything about its resource usage yet, or even how it operates so that is another topic to research.

I also need to reconfigure the firewall so I can accept pings while resisting DoS attacks and the like. I actually took the time for once to write a SysV startup script for iptables. If I get some time to revise it and clean it up perhaps I’ll make it publicly available in case anyone wants to look at it.

Well I have plenty to do and as usual will pretend there is a chance of me going to bed at a good time tonight!

Sean

Posted in , ,  | no comments

Website moved

Posted about 1 year ago

Well as far as the website goes, the move has been made. It wasn’t a total success but I’m just glad I now have full control to configure everything the way I want it. I unfortunately answered wrong when I told the BlueHost representative that I didn’t need any files off the server. I had a backup of my files but not the database. Which really sucks because two days earlier I had written a database backup script and put it in cron. I did take the content out of Google’s page caches and recreated some of the blogs from it. Anyway things will be much better now and I can’t wait to test my capabilities. It may not look different but the site will have a much faster response time now. FastCGI was just bogging it down especially on shared hosting. I will also be able to set up better caching. I have yet to setup a mail server but I have other things to focus on at the moment, perhaps I will get that done either later today or more likely tomorrow.

I am using “Capistrano” to deploy now so I have been heavily customizing its tasks as well. You can do some interesting things with “Capistrano” many of which are even beyond my skill and creativity. For instance the default deploy:restart task wasn’t working with my application. I could have investigated the issue but instead I figured why not just write a new one since its a simple command to restart my Mongrel clusters. I took this code snippet I found here and modified it to just replace the default tasks as shown below.

namespace :deploy do
  [ :start, :restart, :stop ].each do |t|
    desc "#{t.to_s.capitalize} mongrel using mongrel_cluster_ctl"
    task t, :roles => :app do
      sudo "mongrel_cluster_ctl #{t.to_s} -c #{mongrel_conf}"
    end
  end
end

Since we are using the same namespace:task scheme these will get called in place of the default tasks. If you want to keep the defaults in place just change the namespace to suit your needs and add in the proper hooks.

I’m out of here for now

Sean

Posted in , , ,  | no comments

Cause for MIA

Posted about 1 year ago

I see its been almost a full week since I wrote anything, not that anyone is really reading yet. Anyway there is very good reason for this. Nobody died, I'm not sick or anything. I did however buy Fallout 3, and have been playing as if it is earning me money or something. The game is really amazing, it isn't too harsh on hardware requirements either. So I have been playing that a lot and haven't really touched anything on this site or the code for it. I did add RSS feeds before buying the game though :).

I am taking a break tonight however, I am going to work on some code for another half hour or so. I have just added RedCloth to the mix. I did use FCKEditor before, but all it did was piss me off. Its not really meant for people who know HTML well.

I am also hoping to squeeze in time after finishing this blog to do some SEO for the site which I haven't done any of yet. Also on the task list is some controller caching, that way at least some of that is done once my SEO earns me some traffic!

As far as whats going on in my personal life, nothing has changed much lately. Since winter is arriving I have been lifting in my room more, and trying to pack on a few pounds, while still keeping my hands fast and muscles toned. Trying to sell junk to make some cash and open up space. Thats about it!

Back to the code!
Sean

Posted in , , ,  | no comments

Methods Madness

Posted about 1 year ago

Ever call a method on a class in Rails or even just Ruby and got this:

NoMethodError: undefined method `never’ for Time:Class

Now you swear on everyone that means anything to you, that the method you are using exists. Sure it does! No, really we believe you, but lets ask Ruby since, after all she should know best right! Now before I continue I wouldn’t know about this if some time ago my co-worker, Crazy Chicken Fingers, would not have told me about the methods method. So lets see what happens:

irb(main):003:0> Time.methods
=> ["inspect", "pretty_print", "private_class_method", "const_missing", "clone", "method", "public_methods", "public_instance_methods", "instance_variable_defined?", "method_defined?", "superclass", "equal?", "freeze", "mktime", "included_modules", "const_get", "pretty_print_instance_variables", "methods", "respond_to?", "_load", "module_eval", "class_variables", "now", "dup", "protected_instance_methods", "instance_variables", "public_method_defined?", "__id__", "pretty_inspect", "eql?", "object_id", "const_set", "id", "at", "singleton_methods", "send", "class_eval", "taint", "utc", "frozen?", "instance_variable_get", "include?", "private_instance_methods", "__send__", "instance_of?", "private_method_defined?", "to_a", "name", "autoload", "type", "new", "<", "protected_methods", "instance_eval", "<=>", "display", "==", ">", "===", "instance_method", "gm", "instance_variable_set", "kind_of?", "extend", "protected_method_defined?", "const_defined?", ">=", "ancestors", "to_s", "<=", "public_class_method", "pretty_print_cycle", "allocate", "hash", "pretty_print_inspect", "class", "instance_methods", "tainted?", "=~", "private_methods", "class_variable_defined?", "nil?", "untaint", "local", "times", "constants", "is_a?", "autoload?"]
irb(main):004:0>

Saweet! By the time I read through all of that I could have found the methods nicely formatted in the API, and my eyes will be burned up anyway. So lets add a little help using the pp helper. But first we need to require it in, unless you have it in your .irbrc file, and in that case why are you still reading?

irb(main):002:0> pp Time.methods
["inspect",
 "pretty_print",
 "private_class_method",
 "const_missing",
 "clone",
 "method",
 "public_methods",
 "public_instance_methods",
 "instance_variable_defined?",
 "method_defined?",
 "superclass",
 "equal?",
 "freeze",
 "mktime",
 "included_modules",
 "const_get",
 "pretty_print_instance_variables",
 "methods",
 "respond_to?",
 "_load",
 "module_eval",
 "class_variables",
 "now",
 "dup",
 "protected_instance_methods",
 "instance_variables",
 "public_method_defined?",
 "__id__",
 "pretty_inspect",
 "eql?",
 "object_id",
 "const_set",
 "id",
 "at",
 "singleton_methods",
 "send",
 "class_eval",
 "taint",
 "utc",
 "frozen?",
 "instance_variable_get",
 "include?",
 "private_instance_methods",
 "__send__",
 "instance_of?",
 "private_method_defined?",
 "to_a",
 "name",
 "autoload",
 "type",
 "new",
 "<",
 "protected_methods",
 "instance_eval",
 "<=>",
 "display",
 "==",
 ">",
 "===",
 "instance_method",
 "gm",
 "instance_variable_set",
 "kind_of?",
 "extend",
 "protected_method_defined?",
 "const_defined?",
 ">=",
 "ancestors",
 "to_s",
 "<=",
 "public_class_method",
 "pretty_print_cycle",
 "allocate",
 "hash",
 "pretty_print_inspect",
 "class",
 "instance_methods",
 "tainted?",
 "=~",
 "private_methods",
 "class_variable_defined?",
 "nil?",
 "untaint",
 "local",
 "times",
 "constants",
 "is_a?",
 "autoload?"]
=> nil
irb(main):003:0>

Pretty cool eh? As I said a co-worker showed me the methods method some time ago and I have used it quite a bit since then. However, I often found myself having an idea of what functionality I’m searching for, therefore I can make an educated guess on what the method might be called. In this case this random list is still very inconvenient. So me being me I started looking for a method to sort the results, wouldn’t you know I found one called…SORT! Yes, amazing I know.

irb(main):004:0> pp Time.methods.sort
["<",
 "<=",
 "<=>",
 "==",
 "===",
 "=~",
 ">",
 ">=",
 "__id__",
 "__send__",
 "_load",
 "allocate",
 "ancestors",
 "at",
 "autoload",
 "autoload?",
 "class",
 "class_eval",
 "class_variable_defined?",
 "class_variables",
 "clone",
 "const_defined?",
 "const_get",
 "const_missing",
 "const_set",
 "constants",
 "display",
 "dup",
 "eql?",
 "equal?",
 "extend",
 "freeze",
 "frozen?",
 "gm",
 "hash",
 "id",
 "include?",
 "included_modules",
 "inspect",
 "instance_eval",
 "instance_method",
 "instance_methods",
 "instance_of?",
 "instance_variable_defined?",
 "instance_variable_get",
 "instance_variable_set",
 "instance_variables",
 "is_a?",
 "kind_of?",
 "local",
 "method",
 "method_defined?",
 "methods",
 "mktime",
 "module_eval",
 "name",
 "new",
 "nil?",
 "now",
 "object_id",
 "pretty_inspect",
 "pretty_print",
 "pretty_print_cycle",
 "pretty_print_inspect",
 "pretty_print_instance_variables",
 "private_class_method",
 "private_instance_methods",
 "private_method_defined?",
 "private_methods",
 "protected_instance_methods",
 "protected_method_defined?",
 "protected_methods",
 "public_class_method",
 "public_instance_methods",
 "public_method_defined?",
 "public_methods",
 "respond_to?",
 "send",
 "singleton_methods",
 "superclass",
 "taint",
 "tainted?",
 "times",
 "to_a",
 "to_s",
 "type",
 "untaint",
 "utc"]
=> nil

Now that is something useful! Can’t tell you how many times I have used this and realized the method really does exist, that is was just a spelling mistake on my part…very frustrating to say the least!

There is a great article on how to pimp out your irb here.

Why is it that I just can’t remember to close my damn tags! Is it just me or all programmers?

Sean

Posted in ,  | no comments

Recovering my svn repository

Posted about 1 year ago

I recently killed Mandriva Spring 2008 on my home server in favor of Debian based Ubuntu Server 8.04 64bit. Now of course I have an automated backup system, which is not great but it certainly gets the job done. My system was and to this moment is using the dump tool, in a very archaic manner with cron jobs. Its very simple but not all too efficient, I do a monthly level 0 dump, weekly level 4 dump, and a daily level 8 dump.

Here is the actual script, it just gets run from 3 different cron jobs:

        #-----------------#
        #    Variables    #
        #-----------------#
        Date=`date +%F`
        MonthlyDir="/artemis/backup/linux/server/monthly"
        WeeklyDir="/artemis/backup/linux/server/weekly"
        DailyDir="/artemis/backup/linux/server/daily"
        MonthlyLog="/artemis/backup/linux/server/monthly/${Date}.log"
        WeeklyLog="/artemis/backup/linux/server/weekly/${Date}.log"
        DailyLog="/artemis/backup/linux/server/daily/${Date}.log"
        #---------------#
        #     Checks    #
        #---------------#
if [ "$UID" != '0' ]
then

        printf "`date +'%F %H:%m:%S'`\nServer backup failed with:\tUser $USER is not root!" \
        | mail -s "Backup failure!" sean@localhost

        exit 1
fi

if [ ! -d /artemis/backup/linux/server ]
then
        printf "Server backup failed with:\nDestination drive, artemis not mounted or path invalid!" \
        | mail -s "Backup failure!" sean@localhost

        exit 2
fi

for e in ${MonthlyDir} ${WeeklyDir} ${DailyDir}
do
        if [ ! -d ${e} ]
        then
                printf "Server backup failed with:\nDirectory (${e}) does not exist or is not mounted!\n" \
                | mail -s "Backup failure!" sean@localhost

                exit 2
        fi
done

case $1 in
        #-----------------------------#
        #    Monthly Backup           #
        #-----------------------------#
        --monthly|--full)

        # Do dump on /home
         /sbin/dump 0 -u -A ${MonthlyDir}/home_${Date}.archive \
        -f ${MonthlyDir}/home_${Date}.dump -j9 /home 2>&1 >> $MonthlyLog
        # Do a dump on /
         /sbin/dump 0 -u -A ${MonthlyDir}/root_${Date}.archive \
        -f ${MonthlyDir}/root_${Date}.dump -j9 / 2>&1 >> $MonthlyLog
        ;;

        #-----------------------------#
        #     Weekly Backup           #
        #-----------------------------#
        --weekly)

        # Do dump on /home
         /sbin/dump 4 -u -A ${WeeklyDir}/home_${Date}.archive \
        -f ${WeeklyDir}/home_${Date}.dump -j9 /home 2>&1 >> $WeeklyLog

        # Do a dump on /
         /sbin/dump 4 -u -A ${WeeklyDir}/root_${Date}.archive \
        -f ${WeeklyDir}/root_${Date}.dump -j9 / 2>&1 >> $WeeklyLog
        ;;

        #-----------------------------#
        #      Daily Backup           #
        #-----------------------------#
        --daily)

        # Do dump on /home
         /sbin/dump 8 -u -A ${DailyDir}/home_${Date}.archive \
        -f ${DailyDir}/home_${Date}.dump -j9 /home 2>&1 >> $DailyLog

        # Do a dump on /
         /sbin/dump 8 -u -A ${DailyDir}/root_${Date}.archive \
        -f ${DailyDir}/root_${Date}.dump -j9 / 2>&1 >> $DailyLog
        ;;

        #-----------------------------#
        #      Help Menu              #
        #-----------------------------#
        --help)
        echo -e "\nThis script is used to backup Brutus using the dump command.\n"
        echo -e "It is truly intended to be used in conjunction with Cron.\n"
        echo -e "Valid options are as follows:\n
        Option:                   Meaning:
        ------------------------|-------------------------------------------
        --help                  | Show this menu.
        --monthly|--full        | Make a full backup.
        --weekly                | Make an incremental weekly backup.
        --daily                 | Make an incremental daily backup."
        ;;

        #-----------------------------#
        #      Anything Else          #
        #-----------------------------#
        *)
        printf "Server backup failed with:\tInvalid or missing option!" | mail -s "Backup failure!" sean@localhost
        echo "server_backup: Invalid or missing option: please see --help"
        ;;
esac

I have read a little about The Tower of Hanoi but never thoroughly enough to completely understand it, let alone use it. This also seems to be geared more toward admins who are using tape to backup their systems where I simply use a hard drive.

Anyway, since I installed a completely new distribution I used nothing but a few server configs from my backups. So I didn’t really have to do any overly complex restoration. Matter of fact I pretty much just dumped the most recent monthly backup and pulled what I needed out and that sufficed fairly well. Until I came to subversion! Duh, duh, duh!!! Obviously that did not work very well and I have been holding off on figuring it out, and because my svn repo was very bare, I nearly just started a new one instead. However, I am always up for a challenge and could not help myself with this one.

It was actually really easy, but restoring from 20 different backups really wasn’t much fun! Anyway I started with my oldest monthly backup, and went to the last. Then began with the weekly backup dated just after the last monthly, and again went through to the newest. Then finally restored the remaining daily backups in the same manner.

My restore command looked like this:

sudo restore -x /svn -f /artemis/backup/linux/server/daily/root_2008-11-13.dump -T /

Yeah, I was restoring di rectly to the svn directory in root rather than /tmp, so what!? I probably could have taken extra time and scripted this, or perhaps just have a better backup rotation. However I think after actually having to use my backups, I will be changing more than just that. I think I am going to go to rsnapshot instead of dump. It just seems much cleaner and simpler to use. I will blog about it once I have it configured.

Well I’m off to bed at 3:00AM once again! I need to get a good workout in tomorrow so I’m going to get some rest, and hammer out chins and pull-ups tomorrow until I drop.

Good night,

Sean

Posted in , ,  | no comments

Feel like death!

Posted about 1 year ago

The title says it all! Please excuse any typos and neglect of: proper english, formatting or anything you would expect in a decent writing. It is 6:27AM and I feel like I am about to keel over. On a lighter note I have made a bit of overhaul for the better on the site. Please do comment and let me know your thoughts. Don’t hold back I’m a programmer not a designer and I’m known for having thick skin so you won’t hurt my feelings.

Aside from hanging out and watching the free UFC with my friends, tonight sort of sucked. I was anticipating the Pavlik vs. Hopkins fight for weeks now and was no less than unprepared. None of the usual spots around town were ordering the event! Neither myself or anyone I know were going to order the event. Then Pavlik lost to polish off the night. Not that I’m dissatisfied to see Hopkins win, I am also a huge fan of Hopkins…he’s just not from Ohio!!! I still look forward to watching the fight for FREE next week! I think it will be re-aired on HBO but I could be wrong about the HBO part.

I did have a good workout today. I don’t know how far I ran but I’d estimate a good 3 miles. I expect my shins to be throbbing tomorrow. The inner side of my left ankle has also been giving me problems and I haven’t been able to shake that yet either. Hopefully I’ll get some shoe inserts and my running form straightened out so I can run further and more often soon.

I’m just going to go to bed now, as I forsee a very short day tomorrow as far as being awake and competent. Then Monday morning MORE PROGRAMMING wooooooohoooo!

Going to go pass out

Sean

Posted in , , ,  | no comments

A Quickie

Posted about 1 year ago

No! Not that kind of quickie!!!

I should already be asleep but I feel like talking code. So lately I was blown away that the ActiveRecord contained a count method but ActionSupport did not. For instance to find the number of comments for each blog I ended up doing this in my controller:

@comment_count = Comment.count(:conditions => "blog_id = #{params[:id]}")

So in my blogs controller I have a class defined show that looks like this:



def show

    @blog = Blog.find(params[:id])

    @comment = Comment.new

    @ip = request.remote_ip

   

    respond_to do |format|

      format.html

      format.xml  { render :xml => @blog }

    end

  end

 

All I really need to do in my view for show is:

<%= @blog.comments.count %>

Since blog.comments actually performs an ActiveRecord find it is of that class, and therefore has the count method available.

If you are not operating on an ActiveRecord class, then what you can do instead is use the size method. For example:

@posts = [1, 2, 3, 5, 10]

=> [1, 2, 3, 5, 10]

@posts.size

=> 5

I really need to go to bed but I’m going to write tomorrow about some other fun things I’ve learned about Rails in the past couple days. Such as the lightbox plugin and more.

Sean

Posted in ,  | no comments