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
# Elixir solution for http://www.codewars.com/kata/dont-drink-the-water | |
defmodule Liquids do | |
@density %{ ?H => 1.36, ?W => 1.00, ?A => 0.87, ?O => 0.8 } | |
def separate_liquids([]), do: [] | |
def separate_liquids([h|_] = glass) when is_list(h) and length(h) > 0 do | |
List.flatten(glass) |> Enum.sort_by(&(@density[&1])) |> Enum.chunk(length(h)) | |
end | |
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
""" | |
An IPython magic function to pretty-print objects with syntax highlighting. | |
Updated to also pretty print the object's __dict__ if it's available. | |
See, "Defining your own magics": | |
http://ipython.org/ipython-doc/stable/interactive/reference.html#defining-your-own-magics | |
For more on Pygments: | |
http://pygments.org/docs/quickstart/ | |
Usage |
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
# Use this file to configure the Overcommit hooks you wish to use. This will | |
# extend the default configuration defined in: | |
# https://github.com/brigade/overcommit/blob/master/config/default.yml | |
# | |
# At the topmost level of this YAML file is a key representing type of hook | |
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can | |
# customize each hook, such as whether to only run it on certain files (via | |
# `include`), whether to only display output if it fails (via `quiet`), etc. | |
# | |
# For a complete list of hooks, see: |
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
# Originally referenced from https://medium.com/treehouse-engineering/continous-improvements-4741fc3c7daa | |
RSpec.configure do |config| | |
config.before(:suite) do | |
Thread.current[:query_counter] = Hash.new(0) | |
end | |
config.around(:example) do |procsy| | |
callback = lambda do |*args| | |
event = ActiveSupport::Notifications::Event.new(*args) |
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
# app/serializers/indifferent_hash_serializer.rb | |
# Used for converting a json or jsonb column into a useable Rails hash instead | |
# of the psuedo-json hash that is normally returned by Rails. | |
class IndifferentHashSerializer | |
def self.dump(hash) | |
hash.to_json | |
end | |
def self.load(hash) |
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 TinyMCESpecHelper | |
# Fill in a TinyMCE editor with the specified value. | |
# Pass in the same id you give to TinyMCE, (such as "editorContent") | |
# *not* TinyMCE's generated one. | |
# | |
# NOTE: The first argument is not a css selector, just an element id. | |
# | |
# May require selenium chromedriver! | |
# Adapted from https://gist.github.com/eoinkelly/69be6c27beb0106aa555 | |
# |
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
# app/models/validators/array_inclusion_validator.rb | |
class ArrayInclusionValidator < ActiveModel::EachValidator | |
include ActiveModel::Validations::Clusivity | |
def validate_each(record, attribute, values) | |
values.each do |value| | |
unless include?(record, value) | |
message = (options[:message].try(:gsub, '%{value}', value) || "#{value} is not included in the list") | |
record.errors.add(attribute, :array_inclusion, message: message, value: value) | |
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
Warming up -------------------------------------- | |
subtract 233.432k i/100ms # higher is better | |
bitwise & == 164.352k i/100ms | |
bitwise & size 218.548k i/100ms | |
bitwise & [] 200.794k i/100ms | |
contains_all 74.648k i/100ms | |
contains_all_count 112.634k i/100ms | |
set 19.238k i/100ms | |
set cached 194.675k i/100ms | |
all? include? 144.048k i/100ms |
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
import { ApolloClient } from 'apollo-client' | |
import { split } from 'apollo-link' | |
import { HttpLink } from 'apollo-link-http' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
import { getMainDefinition } from 'apollo-utilities' | |
import { createPersistedQueryLink } from 'apollo-link-persisted-queries' | |
import { setContext } from 'apollo-link-context' | |
// AC: IMPORT ACTIONCABLE | |
import ActionCable from 'actioncable' |
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
// use with <i class="svg-icon bank-icon"></i> | |
.svg-icon { | |
vertical-align: middle; // you may not need this line depending on your icons | |
} | |
// borrowed from icomoon's font output | |
.svg-icon::before { | |
font-weight: normal; | |
font-style: normal; | |
font-variant: normal; |