Search

Sara Trice

Just a programmin', bellydancin', cake bakin' kinda girl

Uploadify: changing scriptData with dropdowns

Uploadify is a pretty awesome jQuery/flash uploader. It’s made even more awesome by the stuff you can do with it on the fly.

For example, if you want to pass a variable chosen from a dropdown via the uploader, you can use uploadifySettings() to do so. Some people appear to have problems with this part, so here’s how I did it. (I’m not going to show you all the settings, since the docs give you a pretty good idea how to set it up. )

Say you have a dropdown in your form with the id of ‘upload_type’:

<select id="upload_type" name="upload_type">
<option></option>
<option value="1">First type</option>
<option value="2">Second type</option>
</select>

In your jQuery $(document).ready function (but outside the $(‘#upload’).uploadify function), put something like this:

$('#upload_type').change(function() {
var type_val = $(this).val();
$('#upload').uploadifySettings("scriptData", {"upload_type" : type_val});
});

Which means “Whenever the form field identified with ‘upload_type’ changes, update the ‘upload_type’ variable in scriptData if it exists; if it does not already exist in scriptData, add it.”

Note: I’ve only tried this in Uploadify 2.1.4.

Advertisements

Music industry shifts to being a service? Good news, bad news…

Here’s an interesting read from Ars Technica:

Did file-sharing cause recording industry collapse? Economists say no

The most interesting paragraph I see in this article is this one:

So what is emerging is an increasingly “ephemeral” global music culture based not upon the purchasing of discrete physical packages of music, but on the discovery and subsequent promotion of musicians through file sharing. The big winner in this model is not the digital music file seller, but the touring band, whose music is easily discoverable on the ‘Net. As with so much of the rest of the emerging world economy, the shift is away from buying things and towards purchasing services—in this case tickets to concerts and related activities.

So I have to wonder – to my friends (and my husband) who count on selling merch at their unpaid performances – is this a game changer? Will musicians from now on be ultimately unable to make a living unless they go on the road – and stay there?

Testing CKEditor in Ruby on Rails with Cucumber/Capybara

I have a textarea with the id of “request_details”, made into a CKEditor instance by jQuery: $(‘#request_details’).ckeditor();

(Check this page if you need some help getting CKEditor to work with jQuery, it’s dead simple)

Feature looks like this:  And I fill in "Here are some details" in the CKEditor instance "request_details"

Step looks like this:

When /^I fill in "([^"]*)" in the CKEditor instance "([^"]*)"$/ do |value, input_id|
browser = page.driver.browser
browser.execute_script("CKEDITOR.instances['#{input_id}'].setData('#{value}');")
end

My least favorite phrase

I’ve decided on my least favorite phrase in the English language:

“Can’t you just…?”

Why is this my least favorite phrase? Because:

  1. It’s always in conjunction with a task that the questioner does not understand, but assumes should not be difficult at all;
  2. it is inherently second-guessing the person being asked, which is insulting;
  3. and, rather than asking if something is possible, as in “Can you?” or “Could you?”, the speaker is really saying, “This must be possible, and if you can’t do it, you’re an idiot.”

If you don’t understand how the system works, or what is involved with doing a task, please, ask if something is possible. Don’t demean the craftsman or browbeat them into doing whatever it is you want. A resentful craftsman is not on your side, and will not go out of his/her way to help you.

Using mysql2 on Windows

Another edition of Sara uses Rails on Windows! *muppety fanfare*

Trying to get mysql2 to run on Windows is a bit of a pain. I used the lovely installer from Railsinstaller.org and then created an app with :

rails new testapp -d mysql

and then bundled.

By default this installs the mysql2 gem. There are some gotchas, and hopefully this will help:

  1. You have to install mysql first (derp!). Go here and pick either the 32 or 64 bit MSI installer, and use this guide to pick your options during the install (section II). I know, it’s an old guide, but it works fine. And it has pictures!
  2. You may get this error: “%1 is not a valid Win32 application.” This means you need to go here and get libmysql.dll, and copy it into c:RailsInstallerRuby1.8.7bin. Get the right version or your migrations will fail when you try to add indexes – the MySQL 5.5.9 64-bit version of libmysql.dll will NOT work! I got this version and it worked just fine: mysql-connector-c-noinstall-6.0.2-win32-vs2005.zip (you don’t need the MSI installer for this one, just grab a zippy file).
  3. Next error you may get is “rbreadline.rb:4404: uninitialized constant RbReadline::Encoding (NameError)”. Thanks to this blog post I found the answer is to go into c:RailsInstallerRuby1.8.7librubysite_ruby1.8rbreadline.rb, and comment out line 4404.

There you go! Rake away!

Github, https, and you

Banged my head against this for a while. Starting a new rails project, trying to get rails.js from github, but it’s failing every time:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

So (after a lot of googling) I opened up gems/jquery-rails-0.2.7/lib/generators/jquery/install/install_generator.rb and added this just after the beginning of the InstallGenerator class (“class InstallGenerator < ::Rails::Generators::Base”) :

require ‘openssl’
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
All fixed! Pulled down the file with no hiccups.

Movie Theater Coupons

Going to a movie this weekend? Here’s a few handy coupons:
Sign up for Muvico’s newsletter and get a free $5 popcorn.
Going to an AMC theater? Buy a large popcorn, get a large drink free.
Regal: $2 ZAP packs from Dec 17-19.

Have fun!

Pik and Git Bash on Windows 7

Lately I’ve been installing Ruby on Rails on Windows 7, and have run into a few people trying to make my life easier. One is Sarah Mei, a wonderful member of devchix who has posted a guide for getting things running.  Hearts and bunnies and flowers for her.

Pik is a neat project for Windows that helps you switch between installed versions of ruby. I’m using the Git Bash shell (as mentioned in the guide above), so I had to do a bit of tweaking, and maybe you do too, so here goes:

For some reason the installer didn’t create my .pik/.pikrc file in my home directory, so if yours didn’t create either, this is how it should look:

#!/bin/sh
pik_path=C:\pik

function pik {
$pik_path/pik_runner.exe pik.sh $@
[[ -s $USERPROFILE/.pik/pik.sh ]] && source $USERPROFILE/.pik/pik.sh
unset GEM_HOME
unset GEM_PATH
}

Those last two lines within the pik function are because something isn’t working in the current version and the gems aren’t being loaded when you switch versions.

Once you have your .pikrc add this line to your .bash_profile (create one if you don’t have it in your home directory):

[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc

Hooray!

ImageMagick: “convert: color profile operates on another colorspace `icc'”

Another installment of Sara Beats Her Head Against Tech:

When trying to convert images from RGB to CMYK with ImageMagick, the regular command to convert:

convert original.jpg -colorspace CMYK new.jpg

worked – but the converted image’s colors looked absolutely terrible. So I downloaded some color profiles, and tried to use them:

convert original.jpg -colorspace CMYK -profile sRGB_v4_ICC_preference.icc -profile Photoshop5DefaultCMYK.icc new.jpg

which just gave me the error:

convert: color profile operates on another colorspace `icc’

Searching the internet gave me absolutely no answers on any forum. Then I noticed in the docs, the example given for using profiles when the original has no profile embedded already was:

convert rgb_image.jpg -profile sRGB.icc -profile USCoat.icm cmyk_image.jpg

Wait. Something’s missing… AHA! The -colorspace option was missing!

convert original.jpg -profile sRGB_v4_ICC_preference.icc -profile Photoshop5DefaultCMYK.icc new.jpg

Works like a champ. So, if you’re getting the error “convert: color profile operates on another colorspace `icc’,” try making sure you’re not specifying BOTH the colorspace and the profile(s).

Blog at WordPress.com.

Up ↑