Was great to see the sun again after weeks for rain and shitty weather…
Author Archives: ayn
daily photo: photographer and birds
daily photo: rays
Tyson the Skateboarding-bulldog
Been a while since I’ve blogged, moving on, again…
Sorry for the lack of updates and daily photos, I’ve been busy with work, new puppy, and then the holiday. I got back to San Francisco and decided I’ve had enough unpaid employment (well, paid with equity that is pretty much worth nothing until proven otherwise), so I updated my resume and started a series of interviews with the a number of startups in and around SF. After sorting through a lot of bullshit, strange business models, or just stupidity in general, I found a startup I really like: Context Optional. I am starting next Tue. The founders are really chilled and the work is really exciting. We work with some of the top brands to use social applications for promotions in social networks. You can read more about what we do here. So you can look forward to new and cool Facebook and Open Social apps by me. I will continue to be using RoR and RFacebook, and probably also something like Shindig and Caja for OpenSocial.
I will move into a background role at OnMyList, we have yet to figure out what to do with it. We plan to keep the site running coz we do have people who are really into the site. I had a great time doing OML, learned a shit load of stuff, and worked with some awesome people.
How to use attachment_fu in a rake task (i.e., without using a form)
We’re launching a new Facebook app soon at OnMyList, and we need to pre-populate hundreds of celebrity images, so instead of doing it manually I wrote a cute little rake task to do them all. Took me a little while to figure this out, the trick is to do a class_eval to add the required fields to make attachment_fu happy. This works pretty sweet, the images are resized and uploaded to Amazon S3.
Thought I’ll blog it hoping someone out there will find this useful. 🙂
desc 'adding celebs' task :add_celebs => :environment do dir = '/tmp/celeb_images' Dir.foreach(dir) do |img| path = File.join(dir, img) if File.file?(path) f = File.new(path, "r") (class < < f; self; end).class_eval do alias local_path path define_method(:original_filename) {img} define_method(:content_type) {"image/jpeg"} define_method(:size) { File.size(path) } end u = User.new u.celeb_name = File.basename(img, '.jpg').titleize u.picture = Picture.new u.picture.uploaded_data = f u.save! p "added user #{u.celeb_name}" end end end |
Technorati Tags: attachment_fu, rails, rake task, RoR, ruby, rubyonrails
Happy new year!
It’s 2008! oh yeah! 2007 sucked so 2008 is gonna be badass… Haven’t blogged for a while coz been busy with work and then xmas/family stuff, went to Minnesota and even drove up to Duluth, kindda liked it up there… Didn’t do much of anything except snowboarding… 🙂
Happy new year!
Please sign this petition to stop Petland from opening in Austin
Say No to Petland in Austin!
Why is Petland Bad for Austin?
Over 12,000 animals are already dying at Town Lake Animal Center every year. If Petland moves into Austin, thousands of unaltered animals will be brought into the community contributing to the pet overpopulation crisis. This influx of unaltered animals will reverse all of the spay/neuter progress and efforts made over the last few years, and will create an even greater crisis and thousands of more unnecessary pet deaths in the years to come.The arguement that Petland sells purebred animals and that people that are willing to spend hundreds or even thousands of dollars to buy them, will take better care of them and keep them for their lifetime, simply isn’t true. The truth lies at shelters all over the country, including Town Lake Animal Center where thousands of purebreds are dumped every year. And right behind them are thousands of purebred rescue groups trying to save their lives, but there are just too many and many die at the shelter waiting to be saved. Just in the greater Austin area, we have many purebred rescue groups including;
All Texas Dachshund Rescue
Austin Aussie Rescue
Austin Boxer Rescue
Austin German Shepherd Dog Rescue
Border Collie Rescue Texas, Inc
Cavalier King Charles Spaniel Club Rescue
Chako Rescue Association (Pit Bulls)
Chesapeake Bay Retriever Relief and Rescue
Cocker Spaniel Rescue of Austin
Central Texas Dachshund Rescue
DFW Pug Rescue
Fila Rescue
German Shepherd Rescue of Central Texas
German Shorthaired Pointer Rescue
Gold Ribbon Rescue (Golden Retrievers)
Great Dane Rescue of North Dallas
Greyhound Pets of America
Heart of Texas Lab Rescue
Helping Hands Basset Rescue
Hound Rescue (Beagles)
Katys Promise Rottweiler Rescue
Lil’ Paws Maltese Rescue
Lone Star Catahoula Rescue
Lone Star Shih Tzu and Lhasa Apso Rescue
Luck & Legends Saint Bernard Rescue
Nationwide Boston Terrier Rescue
Ponderosa Pomeranian Rescue Inc
Reunion Rescue (Pit Bulls)
Rottilove Rescue (Rottweilers)
Shiba Inu Rescue of Texas
Spindletop Rescue (Pit Bulls)
Texas Airedale Rescue Team
Texas Alaskan Malamute Rescue Association
Texas Great Pyrenees Rescue
Weimaraner Rescue of Texas
Westie Rescue
Grimalkin Rescue (cats)
Maine Coon Rescue (cats)
Maine Coon Rescue Alliance (cats)
Texas Siamese Rescue (cats)Why Single out Petland?
Petland purchases their animals from Hunte Corp out of Goodman, Mo, who in turn purchase their animals from from puppy mills. The Hunte Corporation is the largest puppy dealer in the U.S., selling 90,000 puppies every year to retail pet stores. Say No to Petland and the exploitation of innocent pets!What is a Puppy Mill?
Puppy mills are commercial breeding facilities where dogs live in horrible conditions. The entire goal of a puppy mill is to raise a cash crop, puppies. With profit as the only motivator, puppy millers keep the parents of these puppies known as the breeding stock, in horrible conditions. Most are kept in small, wire cages their entire lives, sweltering in the summer, freezing in the winter. They live in their own filth, with poor food and minimal vet care. They receive no exercise and no socialization with people or other dogs. The puppies the mills produce often have a host of health and behavior problems. Once the breeding dogs are no longer useful, they are killed.The Hunte Corporation is a wholesaler of puppies. While the Hunte Corporation ads and website show a sparkling clean and modern facility for the puppies, what is not shown is where the puppies come from before they arrive at Hunte, the same filthy puppy mills described above. The parents of these puppies are prisoners of greed, spending their entire existences in these deplorable conditions.
We urge all Austin residents to Say No To Petland by signing this Petition and calling, faxing and emailing your City Council Members. Check out http://www.austinspetdirectory.com [sic] for more information about getting involved with stopping Petland set-up shop in Austin.
Flickr stats!
I’ve used Flickr exclusively for my pics for years now even though I have my own server and can do it myself. One thing I really miss is web stats and logs to see referrers and where my images are linked from. Flickr just announced yesterday that they added stats! You have to activate it though, they don’t collect data for you by default. I just activated mine and should see some information tomorrow.
Activate your stats today!
FBJS autocomplete/typeahead in Rails
Facebook released FBJS a while back to allow some JavaScript in Facebook applications. It is basically a JavaScript parser that modifies the scripts to make them a little bit safer. Ray and I have been working on a new app for OnMyList and we want an text input box with autocomplete to suggest names. If you’re using Rails outside of Fb, or if you’re using IFRAME for your Fb app, then autocomplete is really easy, you basically only need to add 2 lines, one like this in the controller:
auto_complete_for :user, :name |
where user is the model name and name is the field you want to autocomplete for inside the users table. And in the view, you add something like this:
< %= text_field_with_auto_complete :user, :name %> |
This will generate everything you need to have an autocomplete textbox. However, this assumes that you can load the Prototype and Script.aculo.us js libraries, and if you want your app to use FBML, these libraries do not work as FBJS.
Autocomplete with FBML is a little bit more work. Facebook’s Developer Wiki has an FBJS typeahead with AJAX example, I don’t love hacking JavaScript so I just borrowed the code there to use in my view. That page shows you how to write a PHP AJAX endpoint, to make it work with Rails, I tried to make it so it would take the data returned by the auto_complete_for method, it turned out to be a bit too much JS changes for me, I’d like to leave the FBJS as close to original as possible. I also prefer writing Ruby more than JS so I ended up implementing the endpoint in the controller, it took a while to get it working, so to possibly save you some time, here’s how it looks like at the end:
def auto_complete_for_user_name names = User.find(:all, :conditions => [ 'LOWER(name) LIKE ?', params[:suggest_typed].downcase + '%'], :order => 'name ASC', :limit => 10).map { |n| n.name } render :text => "{fortext:#{params[:suggest_typed].to_json},results:#{names.to_json}}" end |
I tried render :json but it didn’t work, coz the typeahead JS is expecting a certain format, but render :text works just fine. Hope you find this post helpful. I will also edit that Wiki entry to include the Rails version of the handler.
Technorati Tags: ajax, autocomplete, facebook, fbjs, fbml, javascript, js, typeahead