T-5 until assessment00 window closes

  • Rake Screencast – written by Jim Weirich, the name scattered throughout gitimmersion
    • specialized for manipulating files
    • task :hello do ; # stuff ; end  for example, if you “reopen” the task below the original, both will be run, they don’t overwrite
    • $ rake --tasks or $ rake T will show the desc "about the task" and its task name. $ rake -P will print tasks and dependencies
    • a hash rocket => specifies dependencies, will mean that whatever it points to will be run first
    • Rake can use Unix commands like touch to create files (file 'name' do ; touch 'name' ; end)
    • Rake will only run a task if it needs to be run, if a file that it is supposed to create is already there, it won’t run
    • Rake can also create a directory, via directory 'name'

Ruby Notes

  • array.uniq takes out repeated values from arrays
  • combine split with regular expressions! string.split(//) makes an array of each character of a string
    • this yields the same result as string.chars
    • this could be substituted with string.each_char which iterates through letters of strings
  • Both array.delete(member)  and array - [member] will delete all occurrences of the member
    • haven’t figured out an alternative to splice! yet
  • I completely forgot about the times method, can create a count (of indices for example): 9.times { |index| puts index } gives a list from 0 to 8
    • I’ve also not considered the uses of next if in traversing some list
  • Simultaneous switches between values in an array are okay, you don’t need placeholder values, go ahead and do one like: a, z = z, a
  • map is an alias for collect
    • reduce is an alias for inject
  • Sweet Shortcuts:
    • select returns all the original elements that fulfill a condition in its block
    • reject returns all the original elements that fail the condition in its block
  • scan is a useful method to turn a string into an array using RegEx’s, works better than split
  • From Ruby Idioms Screencast:
  • Struct reminder
    • Could use a Struct to set attributes, and then inherit those attributes
      • either class ClassName < Struct.new(:attr1, :attr2) ; #methods ; end
    • Or, could be fun to use it with SimpleDelegator (require 'delegate').
      1. First, create a Class1 with some attributes with Struct
      2. then create an object of it, obj1.
      3. Then, create another Class2 containing all the methods, and have it inherit from SimpleDelegator
      4. when creating a new object: obj2 = Class2.new( obj1 ) you will import all the data from obj1 created with the convenience of Struct
    • Remember that Struct will give your attributes a value of nil – so probably no ArgumentErrors when constructing an object later with the wrong number of arguments
  • split without an argument defaults to splitting at spaces: " "
  • Pry? Do I want it?
    • customizing colors in pryrc
    • show-doc shows the documentation straight from the terminal

Rails Tutorial (finishing the non-Rails parts)

  • A little setup on Github:
  • Following this… I set up git to use HTTPS instead of the old SSH key method Hartl talks about
  • I set up a new repo, and then did a remote add, and then a git push -u origin master...unfortunately I was not asked if this were to be saved in the keychain like it was suggested on the Github page… but the next time I did git push, I didn’t have to enter in a password
    • the -u flag is a shortcut for git --set-upstream which sets some kind of association between the local and remote branches
  • Git notes
    • -b with checkout creates a new branch and switches to it  (visible if you do git branch)
    • git commit -a will commit all changes to existing files, no re-adding necessary (if a file hasn’t been added already then it needs to be added)
    • git branch -d will delete a branch that you’ve merged with and that you’re done with
      • git branch -D will delete a branch that you haven’t merged with (because its a terrible branch)
  • Heroku notes
    • added a :development group with the right PostgreSQL gem in the Gemfile
      • then a bundle install --without production installs the gems needed, but not installing the production gems locally – this is necessary at this point so that Gemfile.lock is updated
    • Signed up for Heroku and installed the toolbelt
    • logged in in Terminal and generated a new SSH key
    • heroku create
    • git push heroku master to deploy
    • heroku rename namehere to rename the URL that the app appears under (more heroku commands)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s