Skip to content

Instantly share code, notes, and snippets.

View moonmaster9000's full-sized avatar

moonmaster9000 moonmaster9000

View GitHub Profile
#!/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
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
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
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