Turning off STI for a table in Rails
If you’re adding an ActiveRecord::Base subclassing model for a legacy table, and that legacy table has a column named “type’, Rails will assume that the “type” column is supposed to contain the names of classes.
If this isn’t the case for you, and if it’s a legacy table from before Rails chances are it’s not, you can disable this behavior with this snippet in your class:
def self.inheritance_column
nil
end
Using indexOf on an array for IE versions under 9
No, Array in IE versions before version 9 does not have an indexOf function. Adding one that can be used is easy enough. You just have to basically add an indexOf function to the Array prototype. Mozilla just happens to have a code snippet that does just that:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 0) {
n = Number(arguments[1]);
if (n !== n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}
fixing yasnippet and ruby-mode
So i decided to give yasnippet a whirl the other day and for the most part, the installation and usage was all pretty easy and straightforward. The only problem I had was that the TAB expansion just would not work in ruby-mode.
The issue was ruby-mode had already bound some alignment function to TAB which was clobbering yasnippet. The fix was to just have yasnippet try to find and expand a snippet and then fall back to the ruby-mode function. This is what worked for me:
(defun yas/advise-indent-function (function-symbol)
(eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
,(format
"Try to expand a snippet before point, then call `%s' as usual"
function-symbol)
(let ((yas/fallback-behavior nil))
(unless (and (interactive-p)
(yas/expand))
ad-do-it)))))
(yas/advise-indent-function 'ruby-indent-line)
If this doesn’t work for you, you can try some other possible solutions listed on their FAQ page.
Upgrading openssh to 5x on centos
So I have this old centos box (vers 5.3 x86_64) that’s running a relatively old version of openssh (4.3p2). I got dinged on PCI compliance because it’s not running a more recent version. “A more recent version” being 5.x. So I went to upgrade it via yum but the latest version it found in the repos I was using was the same version I already had on there.
Now at this point, I do some digging and find out that many (if not all) security vulnerabilities get backported to earlier releases. This is something I’m not 100% sure the PCI compliance checkers took into account but still, instead of going back and forth with them, I decided to see if I could find a repo or some other quick way to upgrade openssh to a 5.x version. It appears to be the case that there is a repo out there that has a pretty recent version, 5.5p1.
I found it in the comment thread on this post
This is the comment:
Basically, you add the CentALT repo (as detailed here) and run a simple
yum update openssh
and that’s all there is to it. If I’m missing anything, feel free to let me know.