Skip to content

Instantly share code, notes, and snippets.

@mltsy
mltsy / Savable.elm
Last active June 8, 2017 19:51
First draft of a Savable package for elm to complement RemoteData
module Savable exposing (..)
type Savable a = Saved a | Unsaved a a | Saving a a
update : Savable a -> a -> Savable a
update savable new =
case savable of
Saved old -> Unsaved old new
Unsaved old _ -> Unsaved old new
Saving old _ -> Unsaved old new
@mltsy
mltsy / deep_include_matcher.rb
Last active September 23, 2021 23:15
RSpec deep include matcher for nested hashes (ignores order and extra keys/values)
RSpec::Matchers.define :deep_include do |expected|
match { |actual| deep_include? actual, expected }
def deep_include?(actual, expected, path = [])
return true if actual == expected
@failing_path = path
@failing_expected = expected
@failing_actual = actual
if actual.is_a? Array
@mltsy
mltsy / all_at_once.rb
Last active December 17, 2015 10:38
This is an extension to the Ruby Enumerable Module that allows you to take any enumerable and run the same block of code on all of the elements simultaneously in separate threads, returning either the fastest result (and terminating all other threads), or all results once all the threads have finished. The intended use-case for the return_fastes…
module Enumerable
# A special exception used to signal that the fastest result has been found
# in execution of all_at_once
class FastestResultFound < Exception
end
# Runs the given block on all items at the same time (in separate threads).
# If return_fastest is false (default), returns an array of all results, in
# the same order as the elements
# This is a quick script for doing a mass rename of all files in an Amazon S3 bucket.
# In this case, the rename operation was to unescape all filenames which had been
# previously escaped in error.
#############################
# Configuration:
bucketname = "YOUR_S3_BUCKET_NAME"
access_key = 'YOUR_ACCESS_KEY_ID'
secret_key = 'YOUR_SECRET_ACCESS_KEY'
@mltsy
mltsy / _post.markdown
Created May 29, 2012 19:42
2012/05/29 | Things I've learned about DataMapper Migrations

Things I discovered while trying to write a DM migration

So, the first Rails project I ever worked on was in DataMapper. I loved it - but I never learned how to use migrations. People say DataMapper is so awesome because you don't need them most of the time (which is so true), but they usually fail to address the question "what about when you do need them?" For instance, when you need to alter a table, or remove a column, etc. Fortunately, there are people who have thought about, and solved, this problem for us, they just haven't had the time, apparently, to document the solution for us very well.

Installing dm-migrations was a piece of cake: just add gem 'dm-migrations' to the Gemfile.

Using it, I ran into a few issues - partly as a result of my never having used ActiveRecord migrations in the first place, and partly because of a lack of conventions, or documentation for DataMapper migrations. So here are a few things I learned while trying to figur