RVM / Bash / OSX installation on Mac

The purpose for this post is simple, get RVM installed so that i can get back to it whenever i format my computer and believe me, it happens very often.

This is actually quite simple, I went to the Github repository (rvm/rvm) and executed the expected command:

\curl -sSL https://get.rvm.io | bash -s stable

Bare in mind that this will create a $HOME/.profile which contains the following:

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Now, since i'm not going to use RVM very often (at least at the moment), i'm going to install the latest and the one i need for work:

rvm install ruby
rvm install ruby-2.3.1

Now, I'm going to make 2.3.1 the default one.

rvm --default use 2.3.1

Resources:

THE END!

Road block using django's ContentType feature

There's a technique for filtering records based on their generic related content that is supported in django 1.5, isn't in 1.6 but there's a fix in 1.7. Consider the following example:

# carts/models.py
class Anchor(models.Model):
   ...
    content_type = models.ForeignKey('contenttypes.ContentType')
    object_id = models.PositiveIntegerField(db_index=True)
    product = GenericForeignKey('content_type', 'object_id')
   ...

# stores/models.py
class PurchasedProduct(models.Model):
   ...
    anchor = GenericRelation('carts.Anchor')
    content_type = models.ForeignKey(
        'contenttypes.ContentType',
        null=True,
        blank=True
    )
    object_id = models.PositiveIntegerField(null=True, blank=True)
    parent = GenericForeignKey('content_type', 'object_id')
   ...

In django 1.5, I would be able to filter anchors that are linked to purchased products that have no parent associated to it like so:

pp_ct = ContentType.objects.get_for_model(PurchasedProduct)
Anchor.objects.filter(content_type=pp_ct, purchasedproduct__content_type=None)

In django 1.7, we have to make the following changes to accomplish the same task:

  1. Add related_query_name to your GenericRelation fields

Turning my PurchasedProduct model to look like so:

# stores/models.py
class PurchasedProduct(models.Model):
   ...
    anchor = GenericRelation('carts.Anchor', related_query_name="purchasedproduct")
    content_type = models.ForeignKey(
        'contenttypes.ContentType',
        null=True,
        blank=True
    )
    object_id = models.PositiveIntegerField(null=True, blank=True)
    parent = GenericForeignKey('content_type', 'object_id')
   ...

Once this change is done, my original query will work as it was.

The end.

Sequel Pro + Heroku's ClearDB MySQL Database + SSL

Here i'm posting the steps i followed to get myself setup with Heroku's MySQL addon ClearDB and Sequel Pro.

Download the certificates

Go to your heroku's app resources, click on ClearDB MySQL Database and download the following files:

  • ClearDB CA Certificate (cleardb-ca)
  • Client Certificate (cleardb_id-cert)
  • Client Private Key (cleardb_id-key)

I renamed all these files to:

  • ClearDB CA Certificate (cleardb-ca.pem)
  • Client Certificate (cleardb_id-cert.pem)
  • Client Private Key (cleardb_id-key.pem)

Modify the SSL Key

While we automatically generate SSL certificates for encryption purposes, the private key file must be modified in order to work with Heroku’s MySQL libraries.

cd {path-to-downloaded-certificates}
openssl rsa -in cleardb_id-key.pem -out cleardb_id-key-no-password.pem

Connect to ClearDB Database using SSL + Sequel Pro

  • Key File: cleardb_id-key-no-password.pem
  • Certificate: cleardb_id-cert.pem
  • CA Cert: cleardb-ca.pem

Save to favourites and you're done

GitHub – opposite-bracket

Jesus Rodriguez

Vancouver, BC