layout | title | description | tags | ||
---|---|---|---|---|---|
default |
SQL Style Guide |
A guide to writing clean, clear, and consistent SQL. |
|
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
# Service objects are classes that inherit from this base and implement two instance methods: | |
# * initialize(*args, **params) => void | |
# * perform() => Promise | |
class ServiceBase | |
include ActiveModel::Validations | |
# invokes the service and returns a Promise | |
def self.perform(*args, **params) | |
klass = params.any? ? new(*args, **params) : new(*args) | |
klass.perform_in_transaction |
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
require 'keyword_struct' | |
Mobiledoc = KeywordStruct.new(:version, :markups, :atoms, :cards, :sections) do | |
Markup = Struct.new(:tag, :attrs) | |
Atom = Struct.new(:name, :text, :payload) | |
Card = Struct.new(:name, :payload) | |
# Parses a serialized Mobiledoc into a collection of Ruby objects | |
def self.parse(str) | |
json = JSON.parse(str) |
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
/** | |
* Mobiledoc 0.3.1 | |
* https://github.com/bustlelabs/mobiledoc-kit/blob/master/MOBILEDOC.md#specification | |
*/ | |
interface Mobiledoc { | |
version: '0.3.1'; | |
markups: Markup[]; | |
atoms: Atom[]; | |
cards: Card[]; |
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
# forgiveness is faster than permission | |
private def catch_uniqueness_errors | |
yield | |
rescue ActiveRecord::RecordNotUnique => e | |
field = e.cause.message.match(/index_([a-z_]*)_on_([a-z_]*)/)[2] | |
raise unless field | |
errors.add(field, :taken) | |
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
#!/usr/bin/env ruby | |
X = 'hello' | |
module A | |
X = 'world' | |
end | |
module A::B | |
def self.tst |
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 QueueTimeMiddleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if env['CONTENT_LENGTH'].to_i > 10000 | |
env['HTTP_X_QUEUE_START'] = nil | |
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
module Retriable | |
# This will catch any exception and retry twice (three tries total): | |
# with_retries { ... } | |
# | |
# This will catch any exception and retry four times (five tries total): | |
# with_retries(:limit => 5) { ... } | |
# | |
# This will catch a specific exception and retry once (two tries total): | |
# with_retries(Some::Error, :limit => 2) { ... } | |
# |
NewerOlder