Forgive the overblown title, just leaving myself a quick note...

ActiveRecord::Base.metaclass.class_eval do
  def named_scope_with_existence_assertion(*args)
    named_scope_without_existence_assertion(*args)
    define_method("#{scope_name = args.first}?"){self.class.send(scope_name).exists?(id)}
  end
  alias_method_chain :named_scope, :existence_assertion
end

Usage:

class Item < ActiveRecord::Base
  named_scope :featured, :conditions => {:featured => true}
end

# obviously, this works...
Item.featured.find :all

# and now we get
Item.find(:first).featured? # does this instance satisfy the scope conditions?

Thanks for the idea, BB

NIU Shooting

February 15th, 2008

I've been gone from NIU for years now (pretty much as long as I've had children), yet, I must say that all of this press coverage about the shooting is terrifying. I learned C/C++ in that damn Cole Hall. My friends and I had Unix together there, and assembly, and various other classes. Somehow, Virginia Tech was a million miles away, but, this is so close to home. Its all so lame, there is nothing to be learned from crap like this. Its just senseless. Bogus * 10 ^ 23.

Words of the Day for Google

December 12th, 2007

Recently, I blurted out some words at work that sounded unique. Indeed, Google search results proved their uniqueness. Here, I present you with my never-heard-in-our-hemisphere bits to add to your vocabulary...

  1. HamShagger
  2. TinderPost

Use them sparingly, but effectively.

TECH Cocktail Chicago 2007

November 17th, 2007

I won't blab too much about this years TECH Cocktail in Wrigleyville, other than to say that it was oddly fun. Free drinks, overly enthusiastic entrepeneurs, and even some slimeball journalists contributed to an already exciting event. My ThePoint.com bandmates (Ken, Jim, and the bossman Andrew) made our rounds, met some people, and ran into familiar faces. Sadly, I took a lone picture, but, here's proof that not only is Shane Vitarana a great developer, he also knows how to get down.

El Punto

November 6th, 2007

For anyone wondering if I had been abducted by aliens.. Yes. Anyway, I've been holed up at ThePoint.com working my ass off to get us closer to launch. Although there is a ton left to do, just be aware that I'm committed to getting the ball rolling there, so please forgive my lack of communication in the mean time!

Also, my other dirty little secret is that I'm busy preparing 3-4 of my songs for recording next month. Craig Martinez will do the drums. My chops need alot of work before I go in there!. I'll post a pre-recording demo for you to check out.

I check my Yahoo mail about 86399 times a day. I’m also an avid Safari user (FF has become morbidly obese IMO). The fact that I haven’t been able to use the Yahoo Beta Mail client has been a sore spot with me for quite a while. I woke up today, checked my mail, and now it just plain works! Fan-!@#$-ing-tastic. Rails 1.2.4 a few days ago, Mac Leopard in a few weeks, iPhone hackery/de-brickification…. Its good to be a geek.

If you’re migrating a Capistrano1.x site, over to Capistrano 2, and your SVN repository happens to be behind HTTP authentication, then you probably already know about using this..

1
2
set :svn_username, "username"
set :svn_password, "password"

When you switch to Capistrano 2, make sure that you change those :svn_ arguments to :scm_*, eg..

1
2
set :scm_username, "username"
set :scm_password, "password"

Happy Deployment!

SimpleObject Update

April 15th, 2007

I haven’t had the time to set my svn up to be multi-contributor safe (permissions are a pain in the ass, plus, some of the people that I host are massive targets for hackers/attacks). However, I did update SimpleObject with some fantastic auto-sensing mime-type code, contributed by Mark Kufner over at Kufner Futures. Their product is insanely awesome looking, I wanna get one when I move downtown to Chicago.

Speaking of Chicago, I have failed to mention that I work for a great startup downtown. It should turn out to be a fun experience, as I really believe in the product (which shall remain anonymous until its launch). The good thing is, although it might not be as much $$$ as doing the 24-7 contracts that I have been for the last 2 years, the piece of mind of being an employee and getting a monothilic check, having my opinion respected by other developers (instead of those that can’t do a HelloWorld in our chosen language), and working with a bunch of great developers/dudes is fantastic. Between, Thinkhost, this job, and Will at Highend3d, I have the best group of people I could possibly ask to work with. Anyway, sappy ranting aside, I’m commuting around 4 hours a day, making my 8hour job a 12 hour excursion, which is KILLING me!!! So, as soon as I get my next payment from basically anyone, I’m moving my happy ass downtown into a killer condo, or a nice loft. Hell, I’d even rent a house, having kids might mandate such a choice.

The last of my personal updates… My solo album is gearin’ up for a recording. I’m busy charting out my songs so that my drummer/keyboardists can fill in the parts. The only sucky thing is that I wrote these tunes over the course of the last 15 years, and many of them are interesting but lacking in the harmonic/motific development of which I can produce currently. So, I wasn’t prepared to delve back in and start working on all of them, but, hell, I better. I do believe I have WAY more to contribute to the music world, than I do the programming world, even though I love both nearly equally. The time of reckoning draws nigh, peeps. Peace out!

DRY is a great concept. As one of philosophies upon which Rails is established, Do-Not-Repeat-Yourself is a mantra that is starting to become ever-pervasive in my coding as well as my daily work ethic. So, with that in mind, I’ve decided to NOT respond to the latest email inquiry about how to Encrypt your outgoing email messages from your Rails applications, and just write up a quick tutorial.

I use my GnuPG plugin mainly for e-commerce applications, where secure credit-card storage opens many API integration possibilities with the myriad of Merchant-processor options that are available. It works just as well for any data that necessitates two-way encryption. Lets say you whip up a quick formmail action in rails that emails you live credit card information or top-secret addresses, you’ll wanna provide the rails application with your public key (to properly encrypt the message). Here’s a super-brief overview on how you can do it.

Step 1: Install the plugin


ruby script/plugin install svn://ahgsoftware.com/gnupg/trunk

Step 2: Generate a mailer


ruby script/generate mailer test_mailer hello_world

Now we’ve got a TestMailer object with a default hello_world action. Before you move on, remember to add a recipient to the ‘recipient’ field in the model class (otherwise, our test will go nowhere!)

Step 3: Fire up the console

Lets run through the process of loading the gnupg plugin and encrypting a mailout from the console (you can apply this code in your controller at your own discretion).

1
2
3
4
5
6
7
8
9
10
11
12
13
## Load GnuPG and the public key of your choice
gnupg = GnuPG.new :recipient=>"Key Recipient whomever it may be"
gnupg.load_public_key File.read("/path/to/pubkey.asc")

## If its loaded, create the mail, encrypt, send
if gnupg.public_key_loaded?
        email = TestMailer::create_hello_world
        email.body = gnupg.encrypt(email.body)
        TestMailer::deliver(email)
end

## You probably don't need this, but, for a test, might as well
gnupg.drop_public_key

That should be about it. I’ve used several other methods (including capturing the output buffer and encrypting multi-part mail messages) in a few production sites, and I can’t settle on which method I prefer or where even to place the GnuPG instantiation. Thats what we love about Rails though, a million ways to do anything, and most of them just flow from the code like natural language. I love being a Rubyist. Better than a being a PHPist (masochist?).

PunBB SDK Update

March 14th, 2007

Aight kiddies, in response to a few concerned emails, I’ve changed the auto-login in the PunBB Plugin for Rails to directly log the user in via cookies/db instead of AJAX.

Just to refresh you on how this plugin is used..

Install your Rails app

Install PunBB in the public dir (or even a subdir)

Generate the login code with the punbb path


./script/generate punbb_authentication account /forums

Email support@ahgsoftware.com when/if it blows up

JUST KIDDING, you’ll be fine

That command generates the skeleton files needed for login/logout. You MUST specify a relative path to PunBB installation (e.g. /forums). All other variables are pulled from the config.php file via a neat regex (including the db table prefix, cookie name, etc). You krafty little koder peers of mine, might wanna check out that little regex scanner, you can use it to pull variables out of all kinds of config files (Wordpress, Joomla, etc).

I really do agree with 99% of the principles that Rails and Dave’s pet project stand for, but, I am firmly in the camp that HATES writing login code. I’d say 2 out of 15 total large-scale Rails projects that I’ve designed have necessitated a highly targeted and advanced User engine. The rest have just needed a quick user db with a simple administration panel. Wordpress or PunBB work fantastically for this. Most of my wordpress + Rails integration code is buggy and not ready for primetime (and neither is my PunBB plugin, use at your own risk!), but, I do plan to release it soon. For now, happy posting!

PunBB SDK for Ruby on Rails

March 12th, 2007

After my last post about getting IPB SDK working for the latest IPB Release, I realized that, regardless of my dislike of forums as forums for online communication (PUN intended, shapap, double-entendre in yo face, mother!@#$%^), I have tons of code and projects that revolved around PHP Forums, and Rails backend applications.

In keeping with my New Years Resolution of sharing those tidbits that make my life easier, here is a PunBB SDK/Wrapper! It creates ALL of the models needed for the punbb’s database objects, as well as a VERY simple controller/views for auto-login capabilities. The projects that I’ve used this on are very niche-oriented and don’t lend themselves to extracting much generic code. I can say, that a simple PunBB installation plus this generator can you have you running a fairly pimptastic site in no time! If you like forums, that is ;)

To use it, install your rails app, install your punbb installation, then grab the plugin


./script/plugin install svn://ahgsoftware.com/punbb_sdk/trunk

When developing a Rails application that requires at least ‘autologin’ integration with a PHP forum application, I usually have to decide between several routes.

    The direct DB/cookie method: You replicate the entire logic path of the forum system (PunBB/Vanilla EASY, IPB not so much).
    By Proxy: You use Net::HTTP, or libcurl, to submit the login form, intercept the cookie, and set the user’s browser cookies. This sucks, because some software makes the submitted variables jump through hoops of its own creation (coughJoomla/cough)
    AJAX: I am beginning to love this method, you just have your login form submit directly to your own software AND to the forum application via some nifty ajax. This PunBB SDK uses that particular technique

As far as forums go, PunBB is at the top of my list, because its developer friendly, and I just like the overall attitude that Rickard has over there! Consider donating to their cause if you end up using this plugin (the cause of bringing a SIMPLE forum to the world).

IPB SDK How-to for IPB 2.2

March 6th, 2007

After a slew of upgrades and massive internal reworking over at Highend3d, Will and I decided to upgrade his Invision Power Board installation. Its been a few months since the latest Boards version 2.2 as well as IPBSDK, so you’d think we were in the ‘safe zone’. HECK NO! Ipbsdk threw a fit. After gathering a few horror stories, I think I have a good idea of how to fix it, involving 2, possibly 3, steps!

Our main file to edit..
ipbsdk/ipbsdk_class.inc.php

Step 1: New Bootstrap Method

Right before the inclusion of the main IPS file..


require_once ROOT_PATH   . "sources/ipsclass.php";
Add this line

require_once ROOT_PATH   . "init.php";

Step 2: Instantiation

Previously, the basic instantiation of the ipbsdk libs could be done multiple times, e.g.

1
2
3
4
5
6
7
8
9
10
11
require_once "ipbsdk/ipbsdk_class.inc.php";
global $SDK;
$SDK =& new IPBSDK();
$SDK->create_forum(....);

.... some code....

require_once "ipbsdk/ipbsdk_class.inc.php";
global $SDK;
$SDK =& new IPBSDK();
$SDK->write_pm(....);
As of 2.2, the second instantiation of the SDK classes will make the internal $SDK->DB object just disappear. So, don’t liberally sprinkle
$SDK =& new IPBSDK;
commands all over the place.
If you see this error

Fatal error: Call to a member function on a non-object in /home/tm/domains/public_html/forum/sources/handlers/han_parse_bbcode.php on line 380 
then you are suffering from the aforementioned problem. BBcode seems rather unrelated, but, its cache-check method is one of the first places that a missing DB adapter manifests itself, hence the ubiquity of that error message!
At this point, most people’s boards should work just fine!

Step 3 (Optional): Corrupt Group Data

We had some corrupt group/user data that would throw up IPS DB Driver errors as well. If you’re having issues, do a grep for ‘IN(’ in the class file. if you see a statement like..


 g_id IN(".$info['mgroup_others'].")";
change it, so that ’’ occupies the parenthesis in case there is missing group data, i.e. (IN () is not valid, at least IN(’’) is needed).

 g_id IN(".(strlen($info['mgroup_others']) ? $info['mgroup_others'] : "''").")"

I’m not a big fan of forum software in general. Its always big, bloated, ugly, and appeals to stats-whores of the worst kind (oh look, I have a shiny new counter for xxxx feature). Digging through forums for a fix like this drives me nuts! Hopefully, being in a blog makes this more easily accessible for those of us that enjoy blogs! Converge, oh IPB users, converge I say ;)

Darwinports does some weird shtuff. I think its highly convenient, but I don’t have time to debug the myriad of issues that crop up from multiple ruby and mysql installations. So, I wiped my Darwinports /opt folder, and started anew, with native versions of everything.

Since mysql’s header libs don’t include the proper type definitions to build the mysql gem, just add it to the mysql header, and the gem will compile just fine.

In /usr/local/mysql/include/mysql.h

Put this near the top, preferably after the redundancy-check in the preprocessor directives.


#define ulong unsigned long

Then install the gem with the dependencies like so..


gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Happy Compiling!

* Update

The Cat is out of the bag (Leopard) and a new set of issues has cropped up. Check out this wiki for some very useful commands to install the mysql gem easily

Back to Software

January 30th, 2007

Ok, that didn’t last very long. After amassing a list of musical rants, and ideas for the musical portion of my site, I decided, the scope of it all is far too large for a development site! Anyway, I have some big-ticket software/support packages coming up, for interested parties. I’ll make info available shortly!

Infant Plugin, what the heck!

January 20th, 2007

Someone actually searched for “Infant Plugins” and arrived at my site. The only thing scarier than someone searching for Infant Plugins, is AHG Software being #2 on google for it. What the !#@$ is with that, I feel like I’ve joined some creepy society for god knows what.

 

Michael Cerna Chicago-based Rails Developer and Avid Musician. More ...

Search

Categories

  • Home (15)
  • Rails Plugins (5)
  • Pages (9)
  • Archives

    Tags

    BlogRoll