Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Colgate nathancolgate

View GitHub Profile
@joshwlewis
joshwlewis / scss_format_validator.rb
Created Nov 19, 2012
Rails validation for scss (or sass)
View scss_format_validator.rb
# app/validators/scss_format_validator.rb
class ScssFormatValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
begin
# Attempt to parse SCSS
Sass::Engine.new(value, syntax: :scss).render
rescue Exception => e
# Add error if parsing fails
object.errors.add(attribute, :invalid_scss, error: e.inspect)
end
@chaslemley
chaslemley / dynamoDB_example.rb
Created Jan 23, 2012
Example of using Amazon's DynamoDB to store user activity
View dynamoDB_example.rb
require "aws-sdk"
class Dynamo
attr_accessor :attributes
def initialize(hash)
raise ArgumentError, "argument passed to .new must be a Hash" unless hash.is_a? Hash
raise ArgumentError, "hash must contain key :#{self.class.hash_key}" unless hash.has_key? self.class.hash_key.to_sym
raise ArgumentError, "hash must contain key :#{self.class.range_key}" unless self.class.has_range_key? && hash.has_key?(self.class.range_key.to_sym)
@attributes = {}
You can’t perform that action at this time.