Skip to content

Instantly share code, notes, and snippets.

View joroshiba's full-sized avatar

Jordan Oroshiba joroshiba

View GitHub Profile
@joroshiba
joroshiba / guards.rb
Created April 12, 2018 14:50
Ruby full guards example
class Post
def initialize
@sidebarTypes = [8, 11]
@authorEditTimeout = 2592000
end
def editable?(user)
return true if user.admin?
return true if user.supervisor? && sidebarPost?
return true if user.editor? && editedBy?(user)
module PostgresEnum
extend ActiveSupport::Concern
class_methods do
def postgres_enum_for(column, type_name:)
enums = ActiveRecord::Base.connection.exec_query <<-SQL
SELECT pg_enum.enumlabel AS enumlabel
FROM pg_type
JOIN pg_enum
ON pg_enum.enumtypid = pg_type.oid
@joroshiba
joroshiba / getDiff.js
Last active July 13, 2018 18:03
JS function which takes a new 'object' and the 'currentObj' and returns an object telling you which values have changed on from the currentObj to the object
function getDiff (object, currentObj)) {
let diff = {};
for (let key in object) {
if (!object.hasOwnProperty(key)) continue;
if (typeof object[key] === 'object' && object[key] && typeof currentObj[key] === 'object' && currentObj[key]) {
diff[key] = this.getDiff(object[key], currentObj[key]);
} else if (object[key] !== currentObj[key]) {
diff[key] = object[key];
}
}