haskell split string by comma, into list


I’ll introduce to you, how to split string into list by comma, make "a,b,c" to ["a", "b", "c"].

Background

You know that there are some function like splitOn in Data.List.Split module, but import Data.List.Split didn’t work on Ideone. So, I, a haskell beginner, thought how to do it without other modules.

Split by comma

The following code do it. It split string, [Char] only by comma.

split "a,b,c" outputs ["a", "b", "c"].

Split by any delimiter

You can specify any delimiter with the following. The delimiter should be a Char.

split ' ' "a b c" outputs ["a", "b", "c"].


Rails How to execute task in seed


Here’s how I executed task in seeds.rb, in Rails.

The Rails 4 Way

Environment

  • Ruby 2.2.2p95
  • Rails 4.1.8
  • Rake 10.4.2

First, create a task with rails g task sample shot. The following code will be generated.

Now, we can execute the task with bundle exec rake sample:shot. The goal is to execute the task when bundle exec rake db:seed is executed. Maybe, it is the same way to execute task in rails code.

Solution

Add the code into seeds.rb, like below.

Environment (test, development, production) is passed, which is valid in rake db:seed. On the above, set 'value' to SOMETHING. It is like FEATURES in rake db:fixture:load FIXTURES=xxxx.


A Life Summary of an Gypsy