This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class V1::AddressBooksController < V1::BaseController | |
def create | |
@address_book = AddressBook.new address_book_params | |
unless @address_book.save | |
errors = @address_book.errors.to_hash(true) | |
render status: 422, json: { errors: errors } | |
end | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord::UnionScope | |
def self.included(base) | |
base.send :extend, ClassMethods | |
end | |
module ClassMethods | |
def union_scope(*scopes) | |
id_column = "#{table_name}.#{primary_key}" | |
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ") | |
where "#{id_column} IN (#{sub_query})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module Scopes | |
module SetOperations | |
extend ActiveSupport::Concern | |
class_methods do | |
def union_scope(*scopes) | |
apply_operation 'UNION', scopes | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function jankylog(msg) { | |
let konsole = document.getElementById('jankylog'); | |
if(!konsole) { | |
konsole = document.createElement('pre'); | |
konsole.id = 'jankylog'; | |
konsole.style.backgroundColor = 'white'; | |
konsole.style.padding = '1rem'; | |
document.body.append(konsole); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sluggo::Controller | |
MATCHER = /(^.+)-(.*$)/ | |
def self.included(base) | |
base.send :include, InstanceMethods | |
end | |
module InstanceMethods | |
private | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord::OrScope | |
def self.included(base) | |
base.send :extend, ClassMethods | |
end | |
module ClassMethods | |
def or_scope(*scopes) | |
conditions = | |
scopes | |
.map { |scope| "(#{scope.where_clauses.map{ |clause| "(#{clause})"}.join(" AND ")})" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LocationMatch "^/assets/.*$"> | |
Header unset ETag | |
FileETag None | |
# RFC says only cache for 1 year | |
ExpiresActive On | |
ExpiresDefault "access plus 1 year" | |
RewriteEngine On | |
RewriteCond %{HTTP:Accept-Encoding} gzip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
user = ENV['OPSCODE_USER'] || ENV['USER'] | |
base_box = "precise64" | |
# ------------------------------------------------------------------------------ | |
# Short-hand node defs. | |
# ------------------------------------------------------------------------------ | |
nodes = { | |
:eh_app_node => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quickly thrown together, but it works, and maybe it'll get YOU started on | |
# a better solution to the problem. Enjoy! | |
class TextLayout | |
attr_reader :page_width, :tab_width | |
def initialize(tab_width=4, page_width=80) | |
@tab_width, @page_width = tab_width, page_width | |
end | |
# Takes a title and an optional character which will be used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def play(m) | |
a,c=%w(Rock Scissors Paper),rand(4);[a[c%3],%w(Draw Lose Win)[a.index(m)-c]]*',' | |
end |
NewerOlder