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 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
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 Palindrome | |
def self.palindrome?(n) | |
n == reverse(n) | |
end | |
def self.reverse(n) | |
rs = 0 | |
while n > 0 | |
n, r = n.divmod 10 | |
rs = rs * 10 + r |
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 Vigenere | |
def self.encrypt(key, phrase) | |
exec key, phrase | |
end | |
def self.decrypt(key, phrase) | |
exec key, phrase, -1 | |
end | |
def self.exec(key, phrase, direction=1) |
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
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
user = ENV['OPSCODE_USER'] || ENV['USER'] | |
base_box = "precise64" | |
# ------------------------------------------------------------------------------ | |
# Short-hand node defs. | |
# ------------------------------------------------------------------------------ | |
nodes = { | |
:eh_app_node => { |
NewerOlder