A micro-gem DSL for compound conditionals.
Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.
#!/usr/bin/env ruby | |
# A pre-commit hook script to ensure that no local gem dependencies (gem 'asdf', path: '~/local') | |
# exist in your Gemfile before commiting.` | |
# Allows gems to be loaded from source within the current project directory, but not from outside. | |
puts 'Checking for local dependencies in your Gemfile.' | |
ROOT_PATH = File.expand_path('../../..', __FILE__) | |
NESTED_GEMSPECS = Dir["#{ROOT_PATH}/**/*.gemspec"] | |
GEMFILE = ENV['BUNDLE_GEMFILE'] || File.join(ROOT_PATH, 'Gemfile') |
A micro-gem DSL for compound conditionals.
Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.
# Elixir v1.0.2 | |
defmodule Prime do | |
def stream do | |
Stream.unfold( [], fn primes -> | |
next = next_prime(primes) | |
{ next, [next | primes] } | |
end ) | |
end |
defmodule Guard.Helpers do | |
@moduledoc """ | |
Tools for creating custom guards. Deprecated in favor of `Kernel.defguard`. | |
""" | |
@doc """ | |
Creates a macro that's aware of its presence in a guard. | |
Taken from https://github.com/elixir-lang/elixir/blob/df8b216357e023e4ef078be396fed6b873d6a938/lib/elixir/lib/kernel.ex#L1601-L1615, |
# Put in your .iex, and `require Pattern` | |
defmodule Pattern do | |
defmacro match?(pattern, input, code_block // []) do | |
code = Dict.get(code_block, :do, nil) | |
quote do | |
case unquote(input) do | |
unquote(pattern) -> | |
unquote(code) | |
:ok | |
_ -> |
These are my personally cultivated styleguides for different types of text (normally code or markup).
They're less about common conventions (ie. put single spaces between sentences or new lines between different contexts) and more about what syntax features to prefer or avoid in which contexts. As such, they expect the reader to be familiar with the language or markup in question. They are not suitable introductory material to a syntax.
Comments and discussion are welcome, otherwise I'd just keep these in my head instead of on a publicly available forum. I especially invite you to try and change my mind: these, like all opinions and code, are works in progress; not absolutes.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in the OXFORD ENGLISH DICTIONARY.
namespace :secret do | |
desc "Replace application's secret_key_base in the secret_token initalizer with a new one" | |
task :reset do | |
# Rails default location | |
@secret_token_file ||= Rails.root.join('config', 'initializers', 'secret_token.rb') | |
# Find first string in file | |
@secret_token_finder ||= /(?<=config\.secret_key_base\s\=\s["'])(.*?)(?=["'])/ | |
File.open(@secret_token_file, 'r+') do |file| |
// Colors selected to match the Twilight theme | |
@git-added-color: #8F9D6A; | |
@git-modified-color: #7587A6; | |
@git-removed-color: #CF6A4C; | |
// Blur inactive windows | |
body.is-blurred .workspace { | |
-webkit-filter: blur(0.13em) hue-rotate(19deg); | |
} |
Gem::Specification.new do |s| | |
s.name = 'quack' | |
s.summary = '' | |
s.description = '' | |
s.version = '0.0.1' | |
s.platform = Gem::Platform::RUBY | |
s.files = ['quack.rb'] | |
s.require_path = '.' | |
require 'active_model/serializer/associations' | |
module ActiveModel | |
class Serializer | |
def initialize(object, options={}) | |
@object = object | |
@scope = options[:scope] | |
@root = options.fetch(:root, self.class._root) | |
@meta_key = options[:meta_key] || :meta | |
@meta = options[@meta_key] |