I never took notes when following a book or online tutorial but now that I've dropped a lot of money on an online coding school, I want to make sure I type out information I'm learning. If I'm taking notes I'm kind of talking to myself as I do so that I'm going over the material a second time. Now that I need to go back to refer to my notes, I figured out that I started out in a disorganized way.
Something that I learned when starting this school is that you can create a wiki or you can create Gists on Github.com. I'm using Gists as a note taking method. You can save each Gist as a certain file. The suggested way of taking notes (from what I've been told) is to use the Markdown language. A cheatsheet can be found here. I had heard of Markdown briefly before in some article I read but never gave it any notice. If you give your Gist a file extension of .md, it will display what you typed in as a formatted Markdown page. Oh, because I didn't want people seeing my stupid comments and questions to myself, I flagged my notes as "secret" so that only I can see them. If I share the link with anyone else, that would be able to see my notes as well.
Now that I'm getting into some material/topics in the online school where I'm needing to refer back to my notes, I'm wishing I had organized my notes in a completely different way. I created a secret Gist for every single module or as Bloc calls them, checkpoints. I wish I had started a Gist for every topic. For example, I wish I had a Gist for all of my git notes, a gist for RSpec type notes, a Gist for command line notes and so on.
If I can get ahead in the material a little, I'm going to go back to combine my notes into topics rather than checkpoints. If I could figure out how to search just my own Gists, it wouldn't be that bad but when I want to refer back to material I need to look at again, I have to remember what checkpoint Gist to go back to.
Anyway, hopefully I'll have more technical topics to share next week along with lessons learned.
Sunday, July 17, 2016
Friday, July 1, 2016
Signed up for a coding school
Well, I signed up for an online coding school that's going to take me roughly 2 years to get through. Hopefully I get through it faster than that. =)
I'm going to be learning Ruby on Rails, JavaScript, Angular and a few others. After my conference call with my instructor last night, I am now charged with creating a blog post once a week. The topics will be either a few notes I took going over the material or anything new that I've learned. The first module from what I can tell so far, covers Ruby, Markdown, Rails, Git, command line concepts and I just forked my first repository (a Jekyll template) 2 days ago and created a blogging application. Once I get more confident in knowing what I'm doing, I might move this blog over to the app that I created (well, forked, modified etc).
As far as my first post is concerned, I thought I'd give just the basic information of what I've gone over for the past 3 weeks.
I signed up with an online school called Bloc. The tuition isn't cheap by any means but so far I think it's worth it.
I'm signed up for the Software Engineering track which currently is divided up into 4 sections.
The first 2 are probably self explanatory. Number 3 entails learning more computer science type topics like data structures, algorithms, databases and SQL and design patterns. Number 4 basically has 2 sections...creating an open source project and then contributing to an existing open source project.
From what I can tell, I'm going to learn about the topics in the order that they appear in list above.
I'll post more detail about what I'm learning in my next blog entry which will probably be this weekend or if I get stuck on one of the exercises or assignments that I'm going back to now.
Cheers!
I'm going to be learning Ruby on Rails, JavaScript, Angular and a few others. After my conference call with my instructor last night, I am now charged with creating a blog post once a week. The topics will be either a few notes I took going over the material or anything new that I've learned. The first module from what I can tell so far, covers Ruby, Markdown, Rails, Git, command line concepts and I just forked my first repository (a Jekyll template) 2 days ago and created a blogging application. Once I get more confident in knowing what I'm doing, I might move this blog over to the app that I created (well, forked, modified etc).
As far as my first post is concerned, I thought I'd give just the basic information of what I've gone over for the past 3 weeks.
I signed up with an online school called Bloc. The tuition isn't cheap by any means but so far I think it's worth it.
I'm signed up for the Software Engineering track which currently is divided up into 4 sections.
- Rails Web Development
- Front End Development
- Software Engineering Principles
- Open Source Apprenticeship
The first 2 are probably self explanatory. Number 3 entails learning more computer science type topics like data structures, algorithms, databases and SQL and design patterns. Number 4 basically has 2 sections...creating an open source project and then contributing to an existing open source project.
From what I can tell, I'm going to learn about the topics in the order that they appear in list above.
I'll post more detail about what I'm learning in my next blog entry which will probably be this weekend or if I get stuck on one of the exercises or assignments that I'm going back to now.
Cheers!
Monday, February 29, 2016
Ruby warning message: (...) interpreted as grouped expression
While following along with a tutorial I was asked to write a short program that asked the user for a sentence and then a number. After that was complete, type out the sentence backwards the number of times that was keyed in by the user. For example when typing in a string "ABCDEF GHI" three times, I would get something that looked like this...
IHG FEDCBA
IHG FEDCBA
IHG FEDCBA
Here's the code that I typed out at first which works but I did get a warning message within Aptana Studio...
IHG FEDCBA
IHG FEDCBA
IHG FEDCBA
Here's the code that I typed out at first which works but I did get a warning message within Aptana Studio...
print "Type any sentence: " sent = gets.chomp print "Type a whole number: " num = gets.chomp.to_i puts "here are your sentences backwards times the number you keyed in..." puts (sent.reverse + "\n") * num
The warning message was...
(...) interpreted as grouped expression
After doing a google search, I came across a post that read...
"...This warning is emitted when Ruby thinks that you want an argument list but wrote a grouped expression instead. The most common cause is whitespace between the name of the message and the argument list in a message..."
...which made a lot of sense. I don't like warnings in anything I'm coding out so I changed the code on line 7 to read...
After the change was made, the warning in Aptana went away.
(...) interpreted as grouped expression
After doing a google search, I came across a post that read...
"...This warning is emitted when Ruby thinks that you want an argument list but wrote a grouped expression instead. The most common cause is whitespace between the name of the message and the argument list in a message..."
...which made a lot of sense. I don't like warnings in anything I'm coding out so I changed the code on line 7 to read...
puts "#{sent.reverse}\n" * num
After the change was made, the warning in Aptana went away.
Thursday, February 25, 2016
Installing Aptana Studio 3
Updated for Ubuntu 16.04:
I'm one that likes intellisense/code completion and the benefits of an IDE and until I can make a living as a developer, I'm using a free tool that is available called Aptana Studio 3 onto a Ubuntu 16.04 vm image.
I'll be taking most of the steps on how to install from the WordPress tutorial. In order to make Aptana work with Ubuntu 16.04, I had to make some changes to the steps mentioned in the tutorial.
https://pratapsatve.wordpress.com/2015/05/20/install-aptana-studio-3-in-ubuntu-14-04/
1. Install the dependencies
sudo apt-get install openjdk-8-jdk nodejs libwebkitgtk-1.0-0
2. Download the appropriate Aptana file from the website...
http://www.aptana.com/products/studio3/download
3. I used FireFox to download the file so it ended up in the ~/Downloads folder. Open up the terminal and navigate to the folder that it downloaded into
unzip Aptana_Studio_3_Setup_Linux_x86_64_3.6.1.zip
(change the version number to match the version you downloaded)
4. Move the newly created folder to the /opt directory...
sudo mv Aptana_Studio_3 /opt
I don't like zip files just hanging out so I remove them after unzipping them.
rm Aptana_Studio_3_Setup_Linux_x86_64_3.6.1.zip
5. Have to create an app launcher for Aptana Studio by installing gnome-panel if you haven't already done so...
sudo apt-get install --no-install-recommends gnome-panel
6. Navigate to the /opt/Aptana_Studio_3 folder and type the following...
gnome-desktop-item-edit ~/Desktop/ --create-new
7. A Create Launcher window will open. Type in a name that you want to see to open up Aptana. I typed Aptana Studio 3.6.1 so that I'll know what version I have. Click on the browse button which should open up right in the Aptana directory and select AptanaStudio3 file and click the Open button. Click on the icon button to select icon.xpm file and click the Open button. Finally click on the OK button and you should now have an Aptana icon on your desktop.
Almost all of the above steps did come from the WordPress site mentioned above. I decided to retype all of the steps in case that site does go away at any point.
I'm one that likes intellisense/code completion and the benefits of an IDE and until I can make a living as a developer, I'm using a free tool that is available called Aptana Studio 3 onto a Ubuntu 16.04 vm image.
I'll be taking most of the steps on how to install from the WordPress tutorial. In order to make Aptana work with Ubuntu 16.04, I had to make some changes to the steps mentioned in the tutorial.
https://pratapsatve.wordpress.com/2015/05/20/install-aptana-studio-3-in-ubuntu-14-04/
1. Install the dependencies
sudo apt-get install openjdk-8-jdk nodejs libwebkitgtk-1.0-0
2. Download the appropriate Aptana file from the website...
http://www.aptana.com/products/studio3/download
3. I used FireFox to download the file so it ended up in the ~/Downloads folder. Open up the terminal and navigate to the folder that it downloaded into
unzip Aptana_Studio_3_Setup_Linux_x86_64_3.6.1.zip
(change the version number to match the version you downloaded)
4. Move the newly created folder to the /opt directory...
sudo mv Aptana_Studio_3 /opt
I don't like zip files just hanging out so I remove them after unzipping them.
rm Aptana_Studio_3_Setup_Linux_x86_64_3.6.1.zip
5. Have to create an app launcher for Aptana Studio by installing gnome-panel if you haven't already done so...
sudo apt-get install --no-install-recommends gnome-panel
6. Navigate to the /opt/Aptana_Studio_3 folder and type the following...
gnome-desktop-item-edit ~/Desktop/ --create-new
7. A Create Launcher window will open. Type in a name that you want to see to open up Aptana. I typed Aptana Studio 3.6.1 so that I'll know what version I have. Click on the browse button which should open up right in the Aptana directory and select AptanaStudio3 file and click the Open button. Click on the icon button to select icon.xpm file and click the Open button. Finally click on the OK button and you should now have an Aptana icon on your desktop.
Almost all of the above steps did come from the WordPress site mentioned above. I decided to retype all of the steps in case that site does go away at any point.
Wednesday, December 23, 2015
Step by step to install Ruby on Ubuntu 14.04 to prep for Rails
I am using the gorails.com website for most of the information but if you follow that guide, you'll undoubtedly run into errors. I'm mostly documenting this for personal use but feel free to reference.
Here are the details to my environment...
- Laptop/Desktop with enough ram to run virtual machines on Oracle VirtualBox.
- I normally give each machine 2GB of RAM and about 30GB of hard drive space.
- Fresh install of XUbuntu or plain Jane Ubuntu 14.04
These notes are if you will be installing Ruby 2.2.4. I'm only going up to the part on the gorails.com site where it installs Ruby before you get to the Git section. The last step on this post should get you past the errors I encountered while installing Rails.
Setup/prepwork...
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
Before performing this next step, click on the Edit menu option of your Terminal window. Click on Profile Preferences --> Title and Command tab --> Put a check mark in Run command as a login shell. In XUbuntu it's Edit --> Preferences --> Put a check mark in Run command as login shell within the General tab.
Not on the gorails.com guide...
command curl -ssl https://rvm.io/mpapis.asc | gpg --import
Setup for RVM...
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
I ran across a forum post to run this command or you could close your terminal window and re-open it...
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Update RVM...
rvm requirements
RVM install...
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v
This tells Rubygems not to install documentation locally and then installs the bundler...
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
At this point, you can navigate over to the gorails.com webpage to finish your install if you plan on installing Rails. Good luck!
Ubuntu 15.10 and Rails (unable to install nodejs)
The guide I'm following gives this command as one of the steps to install Rails...
sudo add-apt-repository ppa:chris-lea/node.js
When typing that out in version 15.10, I got an error.
I read two forum posts suggesting to use 14.04 because 15.10 wasn't supported.
Rails install on XUbuntu 14.04 (ERROR: Failed to build gem native extension)
I am following the steps on this page verbatim but came across an error when I got to the point of installing Rails. This is the error I got...
Fetching: nokogiri-1.6.7.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-2.2.4/bin/ruby -r ./siteconf20151223-26597-j3i7to.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/user/.rvm/rubies/ruby-2.2.4/bin/$(RUBY_BASE_NAME)
--help
--clean
/home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
from extconf.rb:80:in `nokogiri_try_compile'
from extconf.rb:87:in `block in add_cflags'
from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
from extconf.rb:86:in `add_cflags'
from extconf.rb:336:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /home/user/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.7.1 for inspection.
Results logged to /home/user/.rvm/gems/ruby-2.2.4/extensions/x86_64-linux/2.2.0/nokogiri-1.6.7.1/gem_make.out
I read many forum posts where I tried a handful of suggestions and none of them worked. I finally came across a stack overflow post where the suggestion of running this command was towards the bottom...
sudo apt-get install libgmp-dev
...or...sudo apt-get install libgmp3-dev
Many of the suggestions I found on a few different forum posts stated that I needed to run...sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
...but given the setup guide I'm following (along with a few notes I've take), I'd already installed all of those packages. The extra package needs to be installed for XUbuntu 14.04 and the regular Ubuntu 14.04 images in order to install Rails.
Installing Ruby onto XUbuntu 14.04 (kept installing source)
Trying to install ROR on an XUbuntu 14.04 VirtualBox vm. Thought I'd mention one of the problems I ran into. At first I was trying to install RVM/ROR etc from this page on an xubuntu-14.04.3-desktop-i386 image and every time I got to the part of running this line...
rvm install 2.2.3
...the install would download the source and then have to compile. After some troubleshooting and reading some forum posts, I found out that the binaries weren't available. I did that by typing...
rvm list remote
...and only 2 JRuby binaries were showing up. When I typed in...
rvm info
...I then noticed I was in a 32 bit environment and not a 64 bit environment like my other Ubuntu image. After downloading and installing the 64 bit image (xubuntu-14.04.3-desktop-amd64.iso), I no longer had this issue.
Tuesday, January 6, 2015
My RoR install
I've discovered and decided to follow through with the free online tutorial/class on the Odin Projects website. Because I'm trying to become a full stack Ruby developer, I figured it would be good material to read and try to absorb.
I'm currently on the Web Development 101 >> The Basics >> Project Installations section where it's instructing all those following along to decide on an environment. Yes, I did go ahead and sign up for a free account on the Nitrous website just to check it out. If you click the link on the Odin Project website that takes you to the Nitrous website, you do get a free account. Going directly to the Nitrous website won't allow you to setup a free account.
Even though I setup an account on Nitrous, if I am going to want to plant myself into a development position, I need to get as familiar with the Linux platform as best as I can so I'm following along with the Linux environment setup. The Odin Project points it's followers to the RailsBridge Installfest webpage to setup an environment. If you get errors setting up your environment, they strongly encourage you to go through Nitrous.
I went ahead and followed the directions found on RailsBridge but ran into an error trying to install RVM. They also don't mention anything about modifying your bashrc file. In the past, I've also followed the setup instructions on the GoRails website. I'm going to list below the steps I took to get my environment setup but will give the readers digest version. If you want more of an explanation on these steps, please click on the appropriate link above.
I use Windows because that is what I'm most familiar as well as that is the platform that we must use where I work. So I use virtual machines with Linux installed. My current choice of Linux flavor is Ubuntu. I created a brand new machine with version 14.04. I installed SPE (for when I do get back to learning Python). I was using Scite but then I tried Geany out one day and fell in love with it because of the option to have a terminal window within one program and I don't have to switch back and forth when I want to try something out in IRB. To each their own on which editor you choose.
From the point of having Ubuntu installed and updated along with having an editor ready to go, I performed the following steps in the terminal...
If you are running Ubuntu 12.04 or 14.04, click on the Edit option on your terminal window, choose the Profile Preferences option, select the Title and Command tab and finally make sure there is a check mark next to the Run command as a login shell box. Click on the close button and then restart your terminal session.
Now to install RVM (assuming you don't want to use rbenv). Instructions I've read from a few websites state to run this line...
...I get a "GPG signature verification failed..." message when I try and download rvm. A few lines below that error message it tells me to run...
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
If that fails, you can run the following...
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
The line on your screen may be different. After obtaining the key, I'm now able to run the curl line above.
When I try and run...
...I get "-bash: type: rvm: not found". When I close the terminal again and restart it and run the above command, I get...
rvm is a function
...which is a good thing. Next, enter the following two lines to update your environment and to make the appropriate change to your bashrc profile...
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Next install RVM with the following...
rvm install 2.2
This process took 5 minutes on my machine. On the last line you see after the above process completes is "Ruby was built without documentation, to build it run: rvm docs generate-ri". I personally like to have my documentation local so I went ahead and ran...
rvm docs generate-ri
This process took 1-2 minutes. Next, type in the following two commands...
rvm use 2.2
rvm --default use 2.2
To test your installation, type the following...
ruby -v
Last but not least, install rails with the following...
gem install rails
That's all I will cover for this entry. I'm still new to all of this but I've read a lot of blogs and documentation on the install. If I've messed something up, by all means, please comment.
I'm currently on the Web Development 101 >> The Basics >> Project Installations section where it's instructing all those following along to decide on an environment. Yes, I did go ahead and sign up for a free account on the Nitrous website just to check it out. If you click the link on the Odin Project website that takes you to the Nitrous website, you do get a free account. Going directly to the Nitrous website won't allow you to setup a free account.
Even though I setup an account on Nitrous, if I am going to want to plant myself into a development position, I need to get as familiar with the Linux platform as best as I can so I'm following along with the Linux environment setup. The Odin Project points it's followers to the RailsBridge Installfest webpage to setup an environment. If you get errors setting up your environment, they strongly encourage you to go through Nitrous.
I went ahead and followed the directions found on RailsBridge but ran into an error trying to install RVM. They also don't mention anything about modifying your bashrc file. In the past, I've also followed the setup instructions on the GoRails website. I'm going to list below the steps I took to get my environment setup but will give the readers digest version. If you want more of an explanation on these steps, please click on the appropriate link above.
I use Windows because that is what I'm most familiar as well as that is the platform that we must use where I work. So I use virtual machines with Linux installed. My current choice of Linux flavor is Ubuntu. I created a brand new machine with version 14.04. I installed SPE (for when I do get back to learning Python). I was using Scite but then I tried Geany out one day and fell in love with it because of the option to have a terminal window within one program and I don't have to switch back and forth when I want to try something out in IRB. To each their own on which editor you choose.
From the point of having Ubuntu installed and updated along with having an editor ready to go, I performed the following steps in the terminal...
sudo apt-get install autoconf automake bison build-essential curl git-core libapr1 libaprutil1 libc6-dev libltdl-dev libreadline6 libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev libxslt1-dev libyaml-dev ncurses-dev nodejs openssl sqlite3 zlib1g zlib1g-devNote: Do not copy and paste the above into your terminal window. Type it all out.
If you are running Ubuntu 12.04 or 14.04, click on the Edit option on your terminal window, choose the Profile Preferences option, select the Title and Command tab and finally make sure there is a check mark next to the Run command as a login shell box. Click on the close button and then restart your terminal session.
Now to install RVM (assuming you don't want to use rbenv). Instructions I've read from a few websites state to run this line...
curl -L get.rvm.io | bash -s stable
...I get a "GPG signature verification failed..." message when I try and download rvm. A few lines below that error message it tells me to run...
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
If that fails, you can run the following...
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
The line on your screen may be different. After obtaining the key, I'm now able to run the curl line above.
When I try and run...
type rvm | head -1
...I get "-bash: type: rvm: not found". When I close the terminal again and restart it and run the above command, I get...
rvm is a function
...which is a good thing. Next, enter the following two lines to update your environment and to make the appropriate change to your bashrc profile...
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Next install RVM with the following...
rvm install 2.2
This process took 5 minutes on my machine. On the last line you see after the above process completes is "Ruby was built without documentation, to build it run: rvm docs generate-ri". I personally like to have my documentation local so I went ahead and ran...
rvm docs generate-ri
This process took 1-2 minutes. Next, type in the following two commands...
rvm use 2.2
rvm --default use 2.2
To test your installation, type the following...
ruby -v
Last but not least, install rails with the following...
gem install rails
That's all I will cover for this entry. I'm still new to all of this but I've read a lot of blogs and documentation on the install. If I've messed something up, by all means, please comment.
Saturday, December 27, 2014
Try googling 'Ruby question mark'...without the quotes
I've been following the exercises on RubyMonk and at least 2 exercises so far use a question mark. This symbol is not at the end of empty? or include? etc. It's not even being used in a regex. When I can't figure something out, I get frustrated. I've given up on a few of these exercises and had to hit the option "See the solution". It was even more frustrating when the solution uses syntax not introduced in the lesson or even hinted at on the page asking you to solving a problem. RubyMonk is not the only site that has this problem. Had to vent...sorry.
Some Ruby beginners but most intermediate and all advanced will know that what I speak of above is the ternary or conditional operator. I have been googling Ruby question mark and adding words like symbol and comparison. Right now, I'm working on the problem named Number Shuffle. I had to click on the "See the solution" option which is the second time I'm seeing a question mark. Here's the specific line...
no_of_combinations = number.to_s.size == 3 ? 6 : 24
Searching for this kept sending me to pages that discussed array/string elements ending with a question mark or pages discussing regular expressions. I finally found a page that talks about [value] ? [value] : [value] I guess I wasn't using the right search terms or something.
I found the explanation on this page...
http://ruby.about.com/od/beginningruby/a/The-Ternary-Or-Conditional-Operator.htm
Here is the text that set me straight and answered my question...
The general format of this expression is as follows: conditional ? true : false. If the conditional expression is true, then the operator will evaluate as the true expression, otherwise it will evaluate as the false expression.
Now that I found out that this is a ternary operator, I can google and find all kinds of explanations on it. It would be nice if online tutorials explained or gave references to all syntax used.
Some Ruby beginners but most intermediate and all advanced will know that what I speak of above is the ternary or conditional operator. I have been googling Ruby question mark and adding words like symbol and comparison. Right now, I'm working on the problem named Number Shuffle. I had to click on the "See the solution" option which is the second time I'm seeing a question mark. Here's the specific line...
no_of_combinations = number.to_s.size == 3 ? 6 : 24
Searching for this kept sending me to pages that discussed array/string elements ending with a question mark or pages discussing regular expressions. I finally found a page that talks about [value] ? [value] : [value] I guess I wasn't using the right search terms or something.
I found the explanation on this page...
http://ruby.about.com/od/beginningruby/a/The-Ternary-Or-Conditional-Operator.htm
Here is the text that set me straight and answered my question...
The general format of this expression is as follows: conditional ? true : false. If the conditional expression is true, then the operator will evaluate as the true expression, otherwise it will evaluate as the false expression.
Now that I found out that this is a ternary operator, I can google and find all kinds of explanations on it. It would be nice if online tutorials explained or gave references to all syntax used.
Wednesday, December 17, 2014
Learning Regex con't (xxxxxxx-xxxx where x's are digits)
This one (regex) didn't take me as long to figure out given all that I read about regular expressions.
As part of my homework for Learning Ruby the Hard Way, I'm still working on my editor that takes 8 pieces of information and inserts it all into a tab delimited format .txt file. The second column needs to be in the format of xxxxxxx-xxxx where the x's are digits and the hyphen needs to be included. This is an account id in the system I'm working with where I'm going to eventually create a script to combine rows from files a 3rd party agency is giving to us.
Back to the editor, I created a regex to only accept an account id that has 7 digits, a hyphen followed by 4 more digits. This one was easy compared to the online tutorials I was reading over. Just inserting the regex here so I'll have it for future reference.
/^\d{7}\-\d{4}$/
Maybe by the time I'm finished with the 2 projects I want to complete, I'll have a cook book of regex's.
As part of my homework for Learning Ruby the Hard Way, I'm still working on my editor that takes 8 pieces of information and inserts it all into a tab delimited format .txt file. The second column needs to be in the format of xxxxxxx-xxxx where the x's are digits and the hyphen needs to be included. This is an account id in the system I'm working with where I'm going to eventually create a script to combine rows from files a 3rd party agency is giving to us.
Back to the editor, I created a regex to only accept an account id that has 7 digits, a hyphen followed by 4 more digits. This one was easy compared to the online tutorials I was reading over. Just inserting the regex here so I'll have it for future reference.
/^\d{7}\-\d{4}$/
Maybe by the time I'm finished with the 2 projects I want to complete, I'll have a cook book of regex's.
Tuesday, December 16, 2014
Learning Regex (file name with .txt extension)
I've gone through 6-7 web pages and 2 tutorials. I did an initial search for a regex for a file name. I didn't search but a minute or two then decided I need to learn a little more about regular expressions than just how to come up with one to recognize a file name.
After reading through a lot of documentation, I believe I came up with what I needed but first a little background.
I'm on lesson 36 of Learn Ruby the Hard Way. I'm not making a game like the home suggests to. Instead, I'm making a script that will ask for eight pieces of information and it will create a tab delimited file with each piece of information. I'm giving the user the option to name the file. The requirements will be that it must only contain letters (upper/lower case), digits, a hyphen and an underscore character and the file extension must end with a ".txt" (without the double quotes). If the user types in anything else, it won't be accepted.
So I'm still at the beginning of creating this script and had to stop for a few days to learn how to put together regular expressions. This is what I have so far for an acceptable file name.
I chose this type of project over creating a game because I need to ultimately create a script that parses a tab delimited file and combines rows/records based on values in 2 columns. That will be my next project.
Here's the regex that I came up with to accept a file name with the above mentioned requirements.
/^[^\W+]\w+\-?(.txt$)/
I'm always open for suggestions on simplifying my code. I'm in no way an expert but the above expression works for what I need it for. I'll be studying regular expressions in more depth as I continue on with my projects.
After reading through a lot of documentation, I believe I came up with what I needed but first a little background.
I'm on lesson 36 of Learn Ruby the Hard Way. I'm not making a game like the home suggests to. Instead, I'm making a script that will ask for eight pieces of information and it will create a tab delimited file with each piece of information. I'm giving the user the option to name the file. The requirements will be that it must only contain letters (upper/lower case), digits, a hyphen and an underscore character and the file extension must end with a ".txt" (without the double quotes). If the user types in anything else, it won't be accepted.
So I'm still at the beginning of creating this script and had to stop for a few days to learn how to put together regular expressions. This is what I have so far for an acceptable file name.
I chose this type of project over creating a game because I need to ultimately create a script that parses a tab delimited file and combines rows/records based on values in 2 columns. That will be my next project.
Here's the regex that I came up with to accept a file name with the above mentioned requirements.
/^[^\W+]\w+\-?(.txt$)/
I'm always open for suggestions on simplifying my code. I'm in no way an expert but the above expression works for what I need it for. I'll be studying regular expressions in more depth as I continue on with my projects.
Sunday, November 30, 2014
User input stored as a string ($stdin.gets.chomp)
Following along with LRtHW on exercise 31 and I was wondering why the author was testing the user input as a string.
There was an exercise that covered gets.chomp but I never thought about it returning a string. Then I found this documentation...
I was assuming that it would take the user input as is but the above link states...
- chomp is a string method (String#chomp).
- gets returns (gives you back) a string.
puts "You enter a dark room with two doors. Do you go through door #1 or door #2?"
print "> "
door = $stdin.gets.chomp
if door == "1"
puts "There's a giant bear here eating cheese cake. What do you do?"
end
...to...
puts "You enter a dark room with two doors. Do you go through door #1 or door #2?"
print "> "
door = $stdin.gets.chomp.to_i
if door == 1
puts "There's a giant bear here eating cheese cake. What do you do?"
end
..it worked as expected.
Ruby naming
Following along with the online LRTHW exercises and lesson 25. I copied the code as it was stated from the web page. Well, I typed it in manually rather than doing a copy and paste. Just to take a shortcut to type it in as fast as possible, I didn't capitalize the module name and I got the following error...
2.1.3 :001 > require "./ex25.rb"
SyntaxError: /home/.../ruby/ex25.rb:1: class/module name must be CONSTANT
from /home/.../.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/.../.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /home/.../.rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
After going back and capitalizing the module name, function names and references to the functions, I was able to get it run without error.
2.1.3 :001 > require "./ex25.rb"
=> true
Found official documentation that discusses naming. The exercise didn't cover the topic of naming...
http://www.ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
http://www.ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
Friday, November 28, 2014
Escape sequence r
While trying out the escape sequence 'r', I again didn't get the results I expected.
I thought that there would be a blank line after the word return when keying this in...
2.1.3 :001 > puts "return\r"
return
=> nil
After finding out about \b, I decided to put a space after \r and the double quotation mark and this was what I got...
2.1.3 :002 > puts "return\r "
eturn
=> nil
This confused me even more until a few minutes later when I remembered that a carriage return was not what I thought it was. I remembered reading some documentation some time ago that \r returned the "focus", if you will, to the beginning of the line and that the line feed was a separate escape sequence altogether. That wasn't the terminology I read but that's how I remembered it.
2.1.3 :003 > puts "return\f"
return
=> nil
This is what I was expecting at first when using \r. I do know that the \f switch/option just moves the "focus" down a line in the same spot...kind of like using a typewriter and moving the page up one line. The type writer is going to type right where it's at unless it's moved to the beginning of that line. Necessary to know if using Ruby to look through strings or text files etc.
Starting at the beginning of the next line (just like you would with a typewriter), I'd need to use \r\f options like so...
2.1.3 :004 > puts "return\r\f"
return
=> nil
I thought that there would be a blank line after the word return when keying this in...
2.1.3 :001 > puts "return\r"
return
=> nil
After finding out about \b, I decided to put a space after \r and the double quotation mark and this was what I got...
2.1.3 :002 > puts "return\r "
eturn
=> nil
This confused me even more until a few minutes later when I remembered that a carriage return was not what I thought it was. I remembered reading some documentation some time ago that \r returned the "focus", if you will, to the beginning of the line and that the line feed was a separate escape sequence altogether. That wasn't the terminology I read but that's how I remembered it.
2.1.3 :003 > puts "return\f"
return
=> nil
This is what I was expecting at first when using \r. I do know that the \f switch/option just moves the "focus" down a line in the same spot...kind of like using a typewriter and moving the page up one line. The type writer is going to type right where it's at unless it's moved to the beginning of that line. Necessary to know if using Ruby to look through strings or text files etc.
Starting at the beginning of the next line (just like you would with a typewriter), I'd need to use \r\f options like so...
2.1.3 :004 > puts "return\r\f"
return
=> nil
Escape sequence b
I'm currently reading the website (online e-book) Learn Ruby the Hard Way and I'm on exercise 10.
It covers using the escape sequence with the various options.
I was stuck for a moment on why it wasn't working like I thought it should.
2.1.3 :001 > puts "backspace\b"
backspace
=> nil
I felt the entry should have removed the 'e' but the 'e' still showed up. On another attempt, I got the result I was looking for.
2.1.3 :002 > puts "backspace\b "
backspac
=> nil
Putting a space between the letter 'b' and the double quote worked. I have no technical explanation for this. My guess is that the backslash b is not given any space to "do it's thing". I've googled but couldn't find anything on this topic. Any comments welcome. If I do find the explanation, I'll post what I find.
It covers using the escape sequence with the various options.
I was stuck for a moment on why it wasn't working like I thought it should.
2.1.3 :001 > puts "backspace\b"
backspace
=> nil
I felt the entry should have removed the 'e' but the 'e' still showed up. On another attempt, I got the result I was looking for.
2.1.3 :002 > puts "backspace\b "
backspac
=> nil
Putting a space between the letter 'b' and the double quote worked. I have no technical explanation for this. My guess is that the backslash b is not given any space to "do it's thing". I've googled but couldn't find anything on this topic. Any comments welcome. If I do find the explanation, I'll post what I find.
Subscribe to:
Posts (Atom)