Brightlight Weblog

Woah! I know ruby-fu!

We are not trying to be flickr or picassa

RailsRumble 2009 was this weekend and what a weekend it was. I never drank this much coffee, energydrink and coke in my life before but neither did I code so much in one weekend.

I’m posting this entry because I felt like I didn’t give enough love to the frontpage and because of that a lot of people are probably unclear about the use of Snapshare. I’m gonna tell you a story of a problem I have faced many times before and what I hope Snapshare might be able to do to fix that problem.

I went to Italy on vacation this year with my girlfriend her family. And not just her parents were there but also here aunts and uncles. Everybody had a camera with them and we calculated that at the end of the vacation had about 1200 photo’s spread over 6 camera’s.
It’s been a few months already and I still only saw a handful of photo’s that people uploaded to various sites and because I’m too lazy to download the photo’s that are available I don’t own the photo’s myself.

With Snapshare I can upload my photo’s of the vacation (and so can everybody else who was there) and give me and the other family members access. My friends/family can then “Snap” photo’s of the vacation to their own album(s) or if they like all my photo’s snap the complete album to their own account. This way everybody has all the photo’s all the time.

From Snapshare it should be possible to export photo’s and albums to social websites like Flickr / Facebook or the dutch variant Hyves.

Snapshare is all about exchanging photo’s and building an complete photo archive. We will be upgrading this prototype after the competition is over so stay tuned.

All that rests is a small demo of the snapping functionality. In the demo I am snapping some vacation pictures my sister uploaded to my own account. I couldn’t get my sound working on Screenr so you must imagine my sexy voice narrating yourself.

Keep Snapping!

iPhonefriendcodes – new Microproject

To test the power of rails (yet again). I worked up this little friendcode-sharing project in less than 8 hours. So if you got an iPhone and play one of those “mmo” games like iMob, iVampires or Mafia Wars take a look at iPhonefriendcodes.com

Suspended, Twitter out

After finally understanding the deal about twitter I was greeted with a suspended message when I tried to log in this morning. As far as I know I’ve done nothing wrong! It did make me realize that I’ve become a little twitter-holic, my hands are shaking I need my Twit-fix!
Anyway, anybody else with a similar story?

Giving your staging database some love

We over at NoXa like to begin every day with a fresh database on our staging enviroment. Problem is it’s a lot of work to do it manually everytime. So altough we like the daily update we often end up with a staging database that gets refreshed once a year. So today I decided the old-database days were over, something had to be done, I whipped up Textmate and made a nifty little ruby script, which unfortunaly hasn’t got a groovy name just yet. This script isn’t a copy + paste solution but it might give you idea’s to tackle your own database issues. (if you even have any).
First off we make backups of all our databases nightly and rsync those to various locations. One of these locations is shared through smb. What this script does is copy the latest backup to the database server drop all the existing tables and import everything. It isn’t the best solution I could think of but it works pretty well.

As always this script can be found on Gist too.

 # 0) Setup
$DATE_FORMAT = "%Y%m%d"
$BACKUP_FILENAME = "mysecret-database-daily-#{Time.now.strftime($DATE_FORMAT)}.sql.gz"
$BACKUP_LOCATION = "/mnt/backups/"
$USERNAME = "ninja"
$PASSWORD = "pirate"
$DATABASE = "japanese_boat"
$MAIL_FROM = "aaarrrgh@brightlight-ict.nl"
$MAIL_TO = "maran@brightlight-ict.nl"
 
mailer = SimpleMailer.new($MAIL_FROM, $MAIL_TO)
 
# 1) Get backup from somewhere
unless system("cp #{$BACKUP_LOCATION}#{$BACKUP_FILENAME} ./ ")
 mailer.sad_mail  "Something went wrong while copying the backup, exiting..."
 exit
end
 
# 2) Dump old tables
unless system("mysql --silent --skip-column-names -u #{$USERNAME} --password=\"#{$PASSWORD}\" #{$DATABASE} -e \"show tables\" | gawk '{print \"drop table \" $1 \";\"}' | mysql -u #{$USERNAME} --password=\"#{$PASSWORD}\" #{$DATABASE}")
  mailer.sad_mail "Couldn't drop tables, exitings.."  
  exit
end
 
# 3) Import new database
unless system("zcat #{$BACKUP_FILENAME} | mysql -u #{$USERNAME} --password=#{$PASSWORD} #{$DATABASE}")
  mailer.sad_mail "Couldn't import tables, exiting.."
  exit
end
 
# 4) Everything went a-ok!
mailer.happy_mail

I wrote a tiny mail script to go with the syncer so I know of everything is working or not.

class SimpleMailer
require 'net/smtp'
  attr_accessor :email_from, :email_to
 
  def initialize(email_from, email_to)
    @email_from, @email_to = email_from, email_to
  end
 
  def happy_mail
    message = <<MSG
From: #{@email_from}
To: #{@email_to}
Subject: Succesfully synced database
On #{Time.now.strftime("%d-%m-%Y %H:%M")} the staging database was successfully synced.
MSG
    mail(message)
  end
 
  def sad_mail(problem)
    message = <<MSG
From: #{@email_from}
To: #{@email_to}
Subject: Problem syncing database
On #{Time.now.strftime("%d-%m-%Y %H:%M")} the staging database was NOT synced!
Problem: #{problem}
MSG
    mail(message)
  end
 
  def mail(message)
    Net::SMTP.start('crunch1.c1.noxa.nl') do |smtp|
        smtp.send_message message, @email_from, @email_to
    end
  end
end

Unattended Passenger / Ruby Enterprise Installation on Ubuntu 8

[update @ 15-03-09]
Updated the script to use the latest passenger 2.1.2 and the lastest version of Ruby Enterprise. Also made a few changes as suggested in the comments, thanks guys!

I needed a small project that I could use to learn some basic bash scripting. Since I like automating things a unattended passenger installation seemed like a cool thing. It’s far from perfect but it gets the job done. (on Ubuntu 8.04/8.10 at least).

Feel free to post any improvements you may have.

#!/bin/bash
#!/bin/bash
# Unattended REE/Passenger installation
# Source: http://weblog.brightlight-ict.nl/2008/12/unattended-passenger-ruby-enterprise-installation-on-ubuntu-8/
 
if [ "$(whoami)" != "root" ]; then
  echo "You need to be root to run this!"
  exit 2
fi
 
VERSION="1.2"
REEV="http://rubyforge.org/frs/download.php/51100/ruby-enterprise-1.8.6-20090201.tar.gz"
REEF="ruby-enterprise-1.8.6-20090201.tar.gz"
REEFF=${REEF%".tar.gz"}
PASSENGER="2.1.2"
export PASSENGER
 
echo "#####################################"
echo "Welcome, let's get this party rollin'"
echo "#####################################"
 
echo "Updating Aptitude"
apt-get update
 
echo "Installing build essentials"
apt-get install build-essential zlib1g-dev libssl-dev wget libreadline5-dev -y
 
echo "Installing GIT"
apt-get install -y git-core
 
echo "Installing apache"
apt-get install -y apache2
 
echo "Installing apache headers"
apt-get install -y apache2-prefork-dev
 
echo "Installing Ruby Enterprise from following url"
echo $REEV
wget $REEV
 
if [ -e $REEF ]
then
  echo "File downloaded succesful"
 
else
  echo "Error, file wasn't downloaded!"
  exit
fi
 
tar -zxvf $REEF
# possible options perhaps for checker
# --extra rails --no-tcmalloc
 
if [ -d ./$REEFF ]
then
   ./$REEFF/installer --auto /opt/ruby
  echo "Dir test"
else
  echo "Dir not found, exiting.."
  exit
fi
 
echo "Creating ruby symlinks"
ln -s /opt/ruby/bin/ruby /usr/bin/ruby
ln -s /opt/ruby/bin/gem /usr/bin/gem
ln -s /opt/ruby/bin/rake /usr/bin/rake
ln -s /opt/ruby/bin/rails /usr/bin/rails
 
echo "Installing other gems"
gem install rails
gem install will_paginate
gem install shoulda
gem install mysql
 
echo "Installing passenger"
gem install passenger -v=$PASSENGER
 
echo "Config passenger"
yes '' | /opt/ruby/bin/passenger-install-apache2-module
 
 
echo "Copying passenger files"
touch /etc/apache2/mods-available/passenger.load
touch /etc/apache2/mods-available/passenger.conf
 
echo "LoadModule passenger_module /opt/ruby/lib/ruby/gems/1.8/gems/passenger-$PASSENGER/ext/apache2/mod_passenger.so" >> /etc/apache2/mods-available/passenger.load
echo "PassengerRoot /opt/ruby/lib/ruby/gems/1.8/gems/passenger-$PASSENGER 
PassengerRuby /opt/ruby/bin/ruby" >> /etc/apache2/mods-available/passenger.conf
 
echo "Enabling passenger module"
a2enmod passenger
 
echo "Reloading apache"
/etc/init.d/apache2 reload
 
echo "##########################"
echo "# Installation Complete"
echo "##########################"
sleep 2
echo "##########################"
echo "# Installed Ruby Version #"
echo "##########################"
ruby -v
echo "##########################"
echo "# Installed Gems Version #"
echo "##########################"
gem -v
/opt/ruby/bin/passenger-status

You can find the gist here

Some small updates

My mother used to say “He who doesn’t appreciate the little things, isn’t worth the big things”. So be happy and perhaps bigger things lay ahead. That being said I’ve rolled out a few small changes today.

- You can now see which users uploaded a project as long as that person had an account during the time he uploaded.
- It now shows how many times a project has been downloaded.
- There is a new tab on the frontpage with the “Top Users”. “Top Uploaders” could have been a better name but the tab is too small. It shows the top 5 users who uploaded the most projects.

That’s all folks!

Screenshots gives me headaches

I’m fighting a war against the evil that is screenshots, and I am losing…

I’m having some major problems with the screenshots in The DStillery’s gallery. That’s why today I made the decision that all project screenshots on the front page will be stretched (if they do not meet the requirements) to a resolution of 256×384 (a standard ds screenshot resolution). So no more distorted screenshots on the frontpage as long as you upload a normal ds screenshot.
If anyone out there can make it so that no matter what resolution the screenshots are in, the boxes containing them will still be the same size, please do! Because I just can’t seem to make it work.

Thanks to James I discovered my site looks totally bullocks in Internet Explorer 7 (and 6 for that matter but I think only my grandma uses that ancient thing), I’ve made some changes that should make it somewhat better but for The Full DStillery experience(™) please turn to Firefox.
Edit: Nevermind, still not working correctly in IE7…it will probably look messed up till the weekend, so little time, so much too do!

Capistrano and Glassfish

There is enough documentation when it comes to installing JRuby and Glassfish. What was lacking was a simple capistrano recipe to get you started, let’s get cracking.

1
2
3
4
5
6
7
namespace :app do
  desc "Warble and Deploy"
  task :warble_and_deploy , :roles => [:app] do
    run "cd #{release_path}/ && warble"
    run "/bin/asadmin deploy --user admin --virtualservers #{virtual_server} --passwordfile /home/rails/passwordfile --contextroot / #{release_path}/#{warfile_name}"
  end
end

Now, that doesn’t look so hard does it? The recipe makes a few assumptions. First you will need to create a asadmin password file. To do so make a simple textfile with a simple string: “AS_ADMIN_PASSWORD=ieathashbrowniesonce”. The second thing is that we assume that your capistrano user has rights to access the warble gem.
Now all that is left is to define two extra capistrano variables. virtual_server is the virtualserver that your application is attached to and warfile_name the name of the warfile you are trying to deploy (as configured in your warble.rb file).
I’m not sure if this is actually the best way to deploy on glassfish using capistrano so if you know a better way please let me know.

The DStillery is open!

When you’re reading this that must mean The DStillery has officially opened, welcome!

I got my shiny black Nintendo DS a few weeks back. Before that I always hijacked my girlfriend’s DS but sitting on the public transport with a pink DS just go a bit weird when I received Guitar Hero. A pink DS is one thing, hitting your DS like a madman while ranting lyrics become really awkward so that’s why I finally bought one for myself. With my DS came a DSTT and since a DSTT is not so fun empty I decided to look around for some good homebrew. But the homebrew out there was like my heart after my first ex-girlfriend was done with it, scattered all over the place.

Around the same time I came across a great piece of open source software by RailsJedi called opensourcerails. The software powers a software gallery by the same name filled with Ruby on Rails projects. This would be perfect for a DS homebrew site! I made some minor modifications to the code, registered myself a fancy webdomain and filled it up so it wouldn’t be completely empty and this is where you come in. Every users/developer of DS homebrew is welcome to upload the games / applications they enjoy and host them here on The DStillery. Let’s take a look at some of the feautures.

  • You can create projects
  • Upload multiple screenshots for a project
  • Upload multiple versions for a project
  • Tag a project
  • Leave comments
  • See the number of downloads for a project
  • Rate projects
  • Bookmark projects

And the best thing is you don’t even need to create an account to do all these things! So show me you guys can handle that responsibility. The adjustments I made to the code are open source too so if you want to help out coding new features or just use it for your own projects please do.

My heart is all in one place again, let’s try to do the same for all that great homebrew out there.

Maran

ps. If you are the author of one of the projects listed on The DStillery and want admin access over your project, register a user and then email us here and we’ll grant you project ownership access.

Hello world!

Hand me some cake it’s time to celebrate; an other incarnation of my weblog is live. This time it will be a bit more work related and fully english.

Yes, this is a portal reference.