How to use MongoHQ on Heroku without Verifying your Account

This is a repost of Elliot Bradbury’s article, which I found very useful.

Original source is at:

http://www.elliotbradbury.com/use-mongohq-heroku-without-verifying-account/

 

Disclaimer: This post describes a way to use a free Heroku add-on with a free Heroku account, without verifying the account with a credit card. I am in no way intending to defraud Heroku or Heroku add-on providers. This information is for educational purposes only.

For those developers who have been living under a rock, Heroku is a cloud computing PaaS. It supports many languages and frameworks and provides additional features through add-ons.

For my basic usage of Heroku, I wanted to run a small Bottle app on my free account and use MongoDB for data storage. MongoDB is not directly available through Heroku, but there are third-party add-ons that provide it as a service (with free plans). MongoHQ is one of them.

If my Heroku account was verified, I could easily install the MongoHQ add-on using the following command.

$ heroku addons:add mongohq:sandbox
Adding mongohq:sandbox on foo-bar-1234... failed
 !    Please verify your account to install this add-on
 !    For more information, see http://devcenter.heroku.com/categories/billing
 !    Verify now at https://heroku.com/verify

But as you can see, the command fails, even when trying to add the free (sandbox) add-on.
Account verification requires a credit card, and I don’t like to toss mine around the internet unless I have to.
Luckily, there is a way around this… It turns out that installing the MongoHQ add-on using the Heroku toolbelt just provisions a database on the MongoHQ platform and sets the MONGOHQ_URL configuration variable to contain the correct database connection string. Both of these things can be done “by hand”.

Instructions

First, create a database on MongoHQ. Simply sign-up for an account and follow the instructions on their site. After you have a database, copy the Mongo URI from the Admin > Overview page of the database on MongoHQ. It should look like this (host and port may vary):

mongodb://<user>:<password>@alex.mongohq.com:10007/<database>

Fill in any missing info. Example:

mongodb://foo:bar@alex.mongohq.com:10007/mymongodb

Next, using the Heroku Toolbelt, set the MONGOHQ_URL (can actually be named anything) configuration variable to this value.

$ heroku config:set MONGOHQ_URL="mongodb://foo:bar@alex.mongohq.com:10007/mymongodb"

That’s it.

The configuration variable that we set is exposed as an environment variable and can be used to open a connection to the database. The free MongoDB, provided by MongoHQ, is now ready for use.
A Python example:

con = pymongo.Connection(os.getenv('MONGOHQ_URL'))

Do good, not evil.

TIBCO SPOTFIRE CLIENT – How to Open Direct Connection to Oracle Database

First time using Tibco Spotfire softwares can be a bit confusing, and the not very comprehensive manuals is not really helping too..

Before you go reading any further, take a note that this How To is for those who want to open data from the “File – Open From – Database” menu on the Spotfire Client.

If you want to open data for developing dashboards you should prefer to create Datasource objects, Column objects, and Information Link objects from the Information Designer menu.

So assuming that there is an Oracle DB server somewhere and you want to connect to that from your Spotfire Client installed on your PC. This means that your PC is a client. Connecting to the DB server from a third party software requires you to install an Oracle Client.

So the first step will be to instal Oracle Client.

  1. Download and Install latest version of Oracle Client, for me its ODAC1120320_x64

Configuring database connection in Spotfire requires a server name so we have to make an alias for the Oracle database host to be connected.

Create an alias in the Oracle Client for a database host:

  1. Create an alias in tnsnames.ora in client folder:
    1. Open C:\oraclexe\app\oracle\product\11.2.0\client_1\Network\Admin\tnsnames.ora, add the following lines:

<tns name> =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = <host  ip>)(PORT = 1521))

(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = <SID or service name>))

)

Check connection:

  • Open cmd
  • Sqlplus <user>@<tns name>
  • Enter password

 

Connect using OracleClient Data Provider:

  1. On Spotfire:
    1. Open from Database
    2. Choose OracleClient Data Provider
    3. Open Configuration window, enter the TNS name/alias into Oracle Server Name, enter the Username and Password.
    4. Click OK to save Configuration
    5. Click OK again.

 

Connect using ODBC Data Provider:

  1. Create Datasource:
    1. Open Control Panel – Adminitrative Tools – Data Sources (ODBC)
    2. Add – Oracle in OraClient11g_home1
    3. Define Data Source Name
    4. Type the TNS Service Name
    5. Type the Username
    6. Test Connection
  2. On Spotfire:
    1. Open from Database
    2. Choose ODBC Data Provider
    3. Enter the ODBC object created at step 3

TIBCO SPOTFIRE WEB PLAYER – Installation & Configuration at Localhost

Assuming that you already have a Spotfire Server running at:

localhost:8181/spotfire/

To be able to access the library via web browser you need to install Spotfire Web Player.

Because Spotfire Web Player is build using ASP.NET and runs on IIS so we must first install IIS and ASP.NET Framework.

Installing IIS & ASP.NET Framework:

  1. Open Control Panel – Programs and Features or appwiz.cpl.
  2. Click Turn Windows features on or off
  3. Tick the following features:
    • Internet Information Services – Web Management Tools, IIS Management Console, IIS Management Service (optional – not sure)
    • World Wide Web Services – Application Development Features
    • ASP.NET (it will automatically tick all other dependencies)
  1. Go to cmd.exe, right click and choose “Run as Administrator”
  2. Type %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe –i
  3. Restart IIS Server (go to Control Panel – Administrative Tools – Internet Information Services (IIS) Manager, there is a Restart link on top right corner of the local IIS server)

Installing Spotfire Web Player:

  1. Run the installer and follow the wizard
  2. When you prompted to specify the name of the Virtual Directory it means the domain name or part of URL to the server used when pointing out Spotfire Web Player files. It is recommended to leave this as “SpotfireWeb”.
  3. Specify the port (must be different from the server port (8181), and IIS default port (80)), for example use “9090”
  4. Specifiy the Spotfire Server URL, in this case it will be:

http://localhost:8181/spotfire/

  1. Continue until finish.

Accessing Spotfire Web Player:

  1. Open web browser, type the Web Player URL, in this case:

http://localhost:9090/SpotfireWeb/Library.aspx

  1. Login using your Spotfire Server login or you can add more user from your Spotfire Server.

 

Notes: Make sure the Spotfire Web Player have the same (or higher) version than the Spotfire Server or it won’t be able to display the visualisation.

TIBCO SPOTFIRE CLIENT – connecting to MYSQL Datasource

Connecting to an Oracle MYSQL Server from Spotfire Datasource & Information Link objects is easy to do. It requires no installation and and only a few additional settings on the Spotfire Server.

Here is the steps:

  1. Download the latest MYSQL Connector library for java:

mysql-connector-java-5.0.8-bin.jar

  1. Place the library into Spotfire Server tomcat lib folder, in my case it is:

C:\tibco\tss\5.5.0\tomcat\webapps\spotfire\WEB-INF\lib\

3.  Open the “Configure TIBCO Spotfire Server” app:

  • Open Configuration Tab – Data Source Templates
  • Enable MYSQL5
  • Save Configuration

4.  Restart the Spotfire Server. Go to Control Panel – Administrative Tools – Services (or simply type services.msc at the Windows Run window), search for TIBCO Spotfire Server and click Restart.

 

It’s done. Open the Spotfire Client, connect to the server, open Information Designer, Setup Data Source. MYSQL5 Data Source Type will be available on the dropdown list.

Notes:

MYSQL (DataDirect) Data Source Type only supports MYSQL Commercial version, doesn’t work with the Community version.

The immortal IntellijIDEA on Mac

Using IntellijIDEA 12 on Mac you can try for 30 days free. However it doesn’t have to live that short. After it dies (expires), don’t uninstall, instead you can reset it through these easy steps:
delete:
~/Library/Application Support/IntellijIdea12
~/Library/Logs/IntellijIdea12
~/Library/Caches/IntellijIdea12
~/Library/Preferences/IntellijIdea12

That’s it, relaunch and it starts young again.

Thread lagi : Penggunaan wait() dan synchronized().

Pada awalnya kita sering bingung mengenai penggunaan synchronized() dan wait().

Misalnya pada contoh berikut :

class SuatuThread {

Object obj;

public SuatuThread(Object obj){

this.obj = obj;

}

public void run(){

synchronized (obj) {

obj.wait();

}

}

}

Disini kita sering rancu mengenai baris : obj.wait();

Pengertian awal kita adalah method wait() ini mestinya dipanggil oleh thread untuk menunggu giliran memakai Object obj, tetapi yang kita lihat adalah wait() dipanggil oleh obj itu sendiri (resource yg sedang di-sharing/di-lock/di-synchronized).

Untuk membenahi hal ini kita perlu mengingat bahwa method wait() bukan method dari kelas Thread, melainkan method bawaan dari kelas Object.

Jadi pengertian dari obj.wait()bukan berarti si obj yang menunggu (wait), melainkan berarti thread yang bersangkutan akan menunggu (wait) sampai thread lain selesai menggunakan obj (bisa dilihat di javadoc bagian penjelasan method wait()).

Locking/synchronizing lebih dekat hubungannya dengan suatu object bukan dengan thread, karena thread hanya memerlukan synchronization ketika dia bekerja dengan shared-object.

Maka dari itu di Java, wait() and notify() diasosiasikan dengan kelas Object.

Sinkronisasi, notify() dan notifyAll(), siapa membangunkan siapa?

“Bahwasanya sebuah resource bisa digunakan secara bersama-sama (sharing) tidak hanya oleh dua thread tetapi bisa banyak thread”. Ilustrasinya mungkin bisa dibayangkan pada WC umum (ahaha..):

Ketika thread A memakai resource WC, maka thread-thread yang lain harus menunggu (wait) thread A selesai memakai WC. Setelah A selesai, dia membuka pintu WC yang memberi tanda pada semua thread yang lain (notifyAll) bahwa WC sudah free of charge. Thread-thread yang lain pun berebut untuk mendapatkan hak berikutnya untuk memakai WC.

Dalam praktek Java, thread mana yg memperoleh hak tergantung dari JVM.

Notify() dan notifyAll() hampir sama, hanya saja pada notify() JVM hanya membangunkan salah satu thread secara random.