Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nathancolgate's full-sized avatar

Nathan Colgate nathancolgate

View GitHub Profile
@joshwlewis
joshwlewis / scss_format_validator.rb
Created November 19, 2012 20:09
Rails validation for scss (or sass)
# 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 January 23, 2012 15:17
Example of using Amazon's DynamoDB to store user activity
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 = {}