Skip to content

Instantly share code, notes, and snippets.

View moonmaster9000's full-sized avatar

moonmaster9000 moonmaster9000

View GitHub Profile
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
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
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
#!/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
import System.Environment (getArgs)
import LineEndingConverter
main =
do
args <- getArgs
case args of
[input,output] ->
transformFileWith transformerFunction input output
module LineEndingConverter
where
-- splits a string into substrings based on the newlines
-- and handles both windows and unix style line endings
splitLines [] = []
splitLines string = firstLine : remainingLines
where
(firstLine, rest) = break carriageReturnOrLineFeed string
remainingLines =
class Author
attr_accessor :name, :books
def initialize(name)
@name = name
@books = []
end
end
class Book
clarke = Author.new "Arthur C. Clarke"
odyssey = Book.new "2001: A Space Odyssey"
clarke.books << odyssey
odyssey.authors << clarke
module Library where
data Author =
Author {
name :: String,
books :: [Book]
} deriving (Show)
data Book =
Book {
clarke = createAuthor "Arthur C. Clarke" ["2001: A Space Odyssey", "Rama!"]