This file contains hidden or 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 | |
# applies a transform_function (Proc instance) to an input_file | |
# and writes it out to the output_file | |
def transform_file(transformer_function, input_file, output_file) | |
File.open(output_file, 'w') do |f| | |
f.write transformer_function.call(File.read(input_file)) | |
end | |
end |
This file contains hidden or 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 'enumerator' | |
class Array | |
def column_sort(num_columns, &block) | |
new_array = block ? sort(&block) : self.dup | |
extras = new_array.length % num_columns | |
new_length = extras == 0 ? new_array.length : new_array.length + num_columns - extras | |
new_array.pad(new_length).slices(num_columns).transpose.flatten | |
end |
This file contains hidden or 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 LiquidLayouts (columnSort) where | |
import List | |
columnSort xs n = concat (transpose (slice sliceSize xs)) | |
where | |
sliceSize = | |
ceiling (fromIntegral(length xs) / fromIntegral(n)) | |
slice _ [] = [] | |
slice n xs = firstSlice : remainingSlices |
This file contains hidden or 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 LiquidLayouts (columnSort) where | |
import List | |
columnSort xs n = concat (transpose (slice sliceSize xs)) | |
where | |
sliceSize = | |
ceiling (fromIntegral(length xs) / fromIntegral(n)) | |
slice _ [] = [[]] | |
slice n xs = leftPartition : slice n remainder |
NewerOlder