PG::DatatypeMismatch: ERROR: column "column_name" cannot be cast automatically to type integer

Rails has given us a very easy way to create, add columns, change data types on our tables. Everything can’t be done for us. There are still some glitches, especially when there are database specific functionalities.

PG::DatatypeMismatch: ERROR: column “column_name” cannot be cast automatically to type integer
HINT: You might need to specify “USING column_name::integer”.

The above problem shows when you change a string column to an integer column. What’s a Rails programmer going to do? Change the migration.

def up
  change_column :table_name, :column_name, :integer
def down
  change_column :table_name, :column_name, :string
def up
  change_column :table_name, :column_name, 'integer USING CAST(incident_id AS integer)'
def down
  change_column :table_name, :column_name, :string

Voila! Fixed!

== 20160812114845 ChangeDataTypeOfColumn: migrating 
-- change_column(:table_name, :column_name, "integer USING CAST(incident_id AS integer)")
   -> 0.0279s
== 20160812114845 ChangeDataTypeOfColumn: migrated (0.0281s)

 Conditionally Chain Scopes in Rails

Scopes are ways to easily retrieve information by creating callable methods on the model. These callable methods are in turn methods that represent queries. These scopes when used return ActiveRecord::Relation that you can chain with other scopes.

class Incident < ActiveRecord::Base
  scope :draft_incidents, -> { where(draft: true)}
  scope :verified_incidents, -> { where(verified: true)}
  scope :this_year, -> {where("EXTRACT(YEAR FROM incidents.incident_date) = ?",}

To chain scopes you can simply concatenate them using dots

[1] pry(main)> Incident.this_year.draft_incidents
  Incident Load (23.6ms)  SELECT "incidents".* FROM "incidents" WHERE "incidents"."deleted_at" IS NULL AND (EXTRACT(YEAR FROM incidents.incident_date) = 2016) AND "incidents"."draft" = $1  [["draft", "t"]]
=> []

To conditionally chain scopes you can do this.

def some_method
  @incidents = Incident.all
  @incidents = @incidents.draft_incidents unless params[:draft].nil?
  @incidents = @incidents.draft_incidents unless params[:this_year].nil?

So unless the params are available, you would get all incidents in the table.

 Edit an incorrect Git Message

We make mistakes. One such mistake we usually do are git messages. There could be a number of things we did wrong.

  • We need it be in a certain format to talk to some API i.e. Pivotaltracker
  • You have a format that you use in your workplace
  • You simply wrote the wrong commit message for some reason

It is so much easier if your commit is still on your local machine

You should of course go to the folder root of your git repository

This is where I mistakenly added the commit message,

$ git commit -m "nothing important"
[staging 1e65441] nothing important
 1 file changed, 1 deletion(-)
Type git commit —amend and press Enter.
git --amend

This will open up vim or your preferred editor

nothing important

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Date:      Fri Jul 1 17:55:42 2016 +0800
# On branch staging
# Your branch and 'origin/staging' have diverged,
# and have 2 and 15 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
Type in your preferred commit message, there is really nothing important and then save
[staging 41de22f] there is really nothing important
 Date: Fri Jul 1 17:55:42 2016 +0800
 1 file changed, 1 insertion(+), 1 deletion(-)

Your commit message has now been changed.

git log
commit 41de22f1af956be5e38c2ed377d26672ae0c7bb1
Author: meme <>
Date:   Fri Jul 1 17:55:42 2016 +0800

    there is really nothing important

Good luck!

Commit message

Changed commit message

 How to fix OpenSSL Padding Oracle vulnerability (CVE-2016-2107) on Ubuntu

OpenSSL Padding Oracle vulnerability (CVE-2016-2107) is a memory vulnerability that allows users to run malicious code. It is real simple to update Ubuntu to fix this issue.

Option 1

apt-get install --only-upgrade libssl1.0.0
root@localhost:~# apt-get install --only-upgrade libssl1.0.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libssl1.0.0 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

This will magically be fixed!

Option 2

You will just need to update your Ubuntu by way of

apt-get update -y
Ign trusty InRelease
Get:1 trusty-security InRelease [65.9 kB]     
Get:2 trusty-updates InRelease [65.9 kB]             
Get:3 trusty-backports InRelease [65.9 kB]
Removing debian:spi-cacert-2008.pem
Removing debian:SG_TRUST_SERVICES_RACINE.pem

Check your website through SSL Labs and you will notice a nice A+ instead of an automatic F

Ssllabs cve 2016 2107

Ssllabs cve 2016 2107 fixed