Couchbase Sync Gateway Setup in 5 minutes to use with Couchbase Lite

Couchbase Lite is a nice schemaless (NoSQL) database for mobile (iOS, Android,…).
It is good for local storage and easy to use in mobile app. And it also has super feature: Ability to Syncornize to remote database (or across multiple devices).

Preparing demo for local event I configured environment for synchronization using AWS EC2 Micro instance with standard Ubuntu x64. Alternatively it could be setup locally on variety of different Unix systems.

Couchbase Server, Sync Gateway and Couchbase Lite framework can be downloaded from official site.

OpenShift: Ruby on Rails Deployment Steps

This is a simple list of deployment steps to setup Ruby on Rails app on OpenShift.

Well, I assume we have OpenShift account and rhc tool installed and logged in. We also have a git repo with a brand new Ruby on Rails app.

What’s next:

  1. Create MyApp
rhc app-create -a MyApp --scale -t ruby-1.9 --no-git
  1. Setup Database. I used postgresql, but mysql-5.1/5.5 and mongoDB-2.4 are also available.
rhc cartridge add postgresql-9.2 -a MyApp
  1. Prepare database.yml:
production:
adapter: postgresql
database: <%=ENV['OPENSHIFT_APP_NAME']%>
username: <%=ENV['OPENSHIFT_POSTGRESQL_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_POSTGRESQL_DB_PASSWORD']%>
host: <%=ENV['OPENSHIFT_POSTGRESQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_POSTGRESQL_DB_PORT']%>
min_messages: ERROR
reconnect: false
pool: 5
timeout: 5000
encoding: utf8
  1. Check everything working:
bundle install
rspec
rails s
  1. Add the OpenShift repository as one of your remote repositories
    • Show you all the information about your application (Remote URL)
rhc app-show MyApp
  • Add Git Remote
git remote add openshift <REMOTE_URL>
  • Take whatever OpenShift is adding by merging (saving our code)
git merge openshift/master -s recursive -X ours
  • Let’s push it:
git push openshift master

It usually takes a few minutes (not seconds). And should be finished like this:

...
remote: Starting Ruby cartridge
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
  1. Connect SSH:
rhc ssh MyApp
  1. Navigate to App folder:
cd app-root/repo
  1. Migrate Database:
bundle exec rake db:migrate RAILS_ENV="production"
  1. Seed
bundle exec rake db:seed RAILS_ENV="production"

Now, it is time to open it in your browser. Happy Deployment!

Grabbing Multi Monitor Screenshot using Qt

You all (who works with Qt Framework) know an example of how to grab the Screenshot using Qt.

But, I’ve found that this example just grubs screenshot only from primary screen in Multi Monitor Environment.

So I had method like this:

QPixmap ScreenshotMaker::makeScreenshot() {
return QPixmap::grabWindow(QApplication::desktop()->winId());
}

I was thinking of writing somthing in WinAPI, like this :
Creation of Multi-monitor Screenshots Using WinAPI, and after that, searching for Linux and Mac platform dependent solutions…

But, after some researching and experiments with Qt, I’ve found interesting, but easy solution:

QPixmap ScreenshotMaker::makeScreenshot() {
QDesktopWidget * desktop = QApplication::desktop();
// Fix for multi screen
return QPixmap::grabWindow(desktop->winId(),
desktop->x(),
desktop->y(),
desktop->width(),
desktop->height());
}

That gives very good results. It takes screenshot of whole desktop area.

Hopefully it will save somebody’s time.