Skip to content
Browse files

Have a Clear and Concise Purpose. Close #1.

  • Loading branch information...
1 parent f39d500 commit 0bbea71303df24b2df8b21219bdd362e1a557f6e @mariusbutuc committed Feb 21, 2012
Showing with 215 additions and 1 deletion.
  1. +81 −0 .rvmrc
  2. +20 −1 README.md
  3. +17 −0 db_backup/db_backup.rb
  4. +20 −0 todo/todo-done.rb
  5. +14 −0 todo/todo-list.rb
  6. +8 −0 todo/todo-new.rb
  7. +55 −0 todo/todo.rb
View
81 .rvmrc
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+environment_id="ruby-1.9.3-p0@ruby-cli"
+
+#
+# Uncomment the following lines if you want to verify rvm version per project
+#
+# rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
+# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
+# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
+# return 1
+# }
+#
+
+#
+# Uncomment following line if you want options to be set only for given project.
+#
+# PROJECT_JRUBY_OPTS=( --1.9 )
+#
+# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
+#
+# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
+#
+
+#
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+#
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
+ then
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create use "$environment_id"
+ then
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ fi
+fi
+
+#
+# If you use an RVM gemset file to install a list of gems (*.gems), you can have
+# it be automatically loaded. Uncomment the following and adjust the filename if
+# necessary.
+#
+# filename=".gems"
+# if [[ -s "$filename" ]]
+# then
+# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
+# fi
+
+# If you use bundler, this might be useful to you:
+# if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
+# then
+# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
+# gem install bundler
+# fi
+# if [[ -s Gemfile ]] && command -v bundle
+# then
+# bundle install
+# fi
+
+if [[ $- == *i* ]] # check for interactive shells
+then
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
+else
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
+fi
+
View
21 README.md
@@ -1,3 +1,22 @@
# [Build Awesome Command-Line Applications in Ruby](http://pragprog.com/book/dccar)
+&mdash; [TL;DR](http://awesome-cli-ruby.heroku.com/)
+> There are developers who demand polish and usability from their command-line tools,
+> and there are developers who are interested in delivering it!
+
+## Backing Up Data
+*[simple]*
+
+Save a backup of the state of each database
+
+ - after every single *day* of the current iteration,
+ - at the end of every *iteration*.
+
+So, if we're on the fifth day of our third iteration, we want to be able to access a backup for iterations 1 and 2, as well as backups for the first four days of the third iteration.
+
+## Managing Tasks
+*[command suite]*
+
+Ability to *create*, *list*, and *complete* tasks in order.
+
+That way, any time we come back to our computer, we can easily see how much progress we've made and what's next to do.
-> There are developers who demand polish and usability from their command-line tools, and there are developers who are interested in delivering it!
View
17 db_backup/db_backup.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+database = ARGV.shift
+username = ARGV.shift
+password = ARGV.shift
+end_of_iter = ARGV.shift
+
+databases.each do |name, config|
+ if end_of_iter.nil?
+ backup_file = databases + Time.now.strftime('%Y%m%d')
+ else
+ backup_file = databases + end_of_iter
+ end
+ puts "creates #{backup_file}.sql.gz"
+ # mysqldump = "mysqldump -u#{username} -p#{password} #{database} > #{backup_file}.sql"
+ # `gzip #{backup_file}.sql`
+end
View
20 todo/todo-done.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+task_number = ARGV.shift.to_i
+
+File.open('todo.txt', 'r') do |file|
+ File.open('todo.txt.new', 'w') do |new_file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = line.chomp.split(/,/)
+ if task_number == counter
+ new_file.puts("#{name},#{created},#{Time.now}")
+ puts "Task #{counter} completed"
+ else
+ new_file.puts("#{name},#{created},#{completed}")
+ end
+ counter += 1
+ end
+ end
+end
+`mv todo.txt.new todo.txt`
View
14 todo/todo-list.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env/ ruby
+
+File.open('todo.txt', 'r') do |file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = line.chomp.split(/,/)
+ printf("%3d - %s\n", counter,name)
+ printf("\tCreated\t: %s\n",created)
+ unless completed.nil?
+ printf("\tCompleted\t: %s\n",completed)
+ end
+ counter += 1
+ end
+end
View
8 todo/todo-new.rb
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+new_task = ARGV.shift
+
+File.open('toxdo.txt', 'a') do |file|
+ file.puts "#{new_task},#{Time.now}"
+ puts "Task added."
+end
View
55 todo/todo.rb
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+
+TODO_FILE = 'todo.txt'
+
+def read_todo(line)
+ line.chomp.split(/,/)
+end
+
+def write_todo(file,name,created=Time.now,completed='')
+ file.puts("#{name},#{created},#{completed}")
+end
+
+command = ARGV.shift
+
+case command
+when 'new'
+ new_task = ARGV.shift
+
+ File.open(TODO_FILE, 'a') do |file|
+ write_todo(file,new_task)
+ puts 'Task added.'
+ end
+when 'list'
+ File.open(TODO_FILE, 'r') do |file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = read_todo(line)
+ printf("%3d - %s\n",counter,name)
+ printf("\tCreated\t: %s\n",created)
+ unless completed.nil?
+ printf("\tCompleted\t: %s\n",completed)
+ end
+ counter += 1
+ end
+ end
+when 'done'
+ task_number = ARGV.shift.to_i
+
+ File.open(TODO_FILE, 'r') do |file|
+ File.open("#{TODO_FILE}.new", 'w') do |new_file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = read_todo(line)
+ if task_number == counter
+ write_todo(new_file,name,created,Time.now)
+ puts "Task #{counter} completed"
+ else
+ write_todo(new_file,name,created,completed)
+ end
+ counter += 1
+ end
+ end
+ end
+ `mv #{TODO_FILE}.new #{TODO_FILE}`
+end

0 comments on commit 0bbea71

Please sign in to comment.
Something went wrong with that request. Please try again.