I’ve moved my site to my own domain! Check out the full blog at Clare Codes at ClareGlinka.com.
MakerSquare Career Day Recap – November 7
Congrats to all of our amazing second cohort graduates! This is a very select group of students. Only 18% of the people that applied were accepted, which says something about the students graduating. These students are extremely passionate about programming and want to live and breathe programming moving forward. They’ve put in a lot of hard hours in and you’ll be amazed to see what they’ve made in the last three weeks of bootcamp which was jump-started during our hack-a-thon. Now, imagine what they are going to do in their careers!
hack_app: Joe Wagner and John Reagan Moore
The idea behind hack_app is to be able to research and apply to any of the coding bootcamps throughout the nation within a common app. It shows location, price, description, details, etc. When a student is ready to apply, hack_app will help them find the perfect bootcamp. Joe and John built this…
View original post 1,146 more words
Writing a Ruby gem!
For my final project, I’m working with Bonnie Matteson on a Ruby gem, currently called ‘Wikiwhat’, for the Wikipedia API! This is a really fun project, and also really challenging. The last few weeks of class have focused on working with frameworks and engines, and less on writing basic Ruby code, so it has been a nice change of pace.
One of the first challenges for this project has been getting the gem to build and install correctly. We use bundler
to install and manage gems for our projects. Awesomely, we can also use it to build our gem too!
Here is a short outline of the process.
1. Use bundler to create a scaffold directory for the gem. This is nice because it takes care of a lot of details that are potentially easy to forget, like listing all the files that should be included in the gem.
bundle gem <GEMNAME>
2. Write your gem! (no, it didn’t go that quickly, but you get the idea)
3. Build your gem! A hint here is that you need to include the version number in your build command. Also, include the .gemspec file ending. EX: gemname-0.0.0.gemspec
gem build <GEMNAME-version>.gemspec
This will build your gem in the directory where you run this command.
4. In the same directory, run the install command:
gem install <GEMNAME-version>.gem
It did take us quite a while to get to this point. We definitely had some malformed files and/or structure in our gem such that it either would not build or would not install. A few of the problems we had:
- Bad require statements – It does not like it if things are named badly, or if you are trying to
require ''
or similar. I can’t remember why we thought we needed it, but you don’t! Don’t do it! - Incorrect naming or file structure – The gem builder/installer really really wants things to follow a semi-strict naming convention. Inside
lib/
, the main.rb
file needs to be named the same as your gem name. If you have any additional code files, those need to be stored inside a folder that is named the same as your gem and main file.
EXAMPLE:. ├── wikiwhat.gemspec └── lib ├── wikiwhat │ └── api_call.rb └── wikiwhat.rb
The final challenge was to be able to require it in IRB and run a command!
5. Open IRB and require the gem:
require 'GEMNAME'
If it returns true
, you’re 99% of the way there!
6. Run a command! Obviously, this one is going to vary from gem to gem. If it works the way you expect, you are done! In our case, we ran our call method:
Wikiwhat.call("Albert Einstein")
And got back the first paragraph of the wiki article on Albert Einstein, just like we wanted. Yay!
Resources:
1. So far, we have mainly used this great guide from RubyGems.org.
2. I also really enjoyed this podcast on Ruby Gems from Ruby Rogues.
Listening for Events with Backbone Views
This is something that I’ve learned before, and I think I even have it in my notes from when we first learned this, but on Friday, we used two ways to listen for events in Backbone, and I wanted to really solidify this in my mind so I stop getting confused!
One kind of events we can listen for are browser events like click, hover, or focus. The way to ‘listen’ for these kinds of events in a Backbone View is to use an events property in the Backbone View, like so:
events: { '.delete click': 'removeComment' }
The property of the events object is what event we are looking for. In this example, we are listening for a click action on something with the class ‘delete’. The value of the property is what View property should be called when the event occurs.
The other kind of events we can listen for are Backbone events. These are events like ‘add’, ‘remove’, or ‘change’ in Views, Models, or Collections that can trigger further actions. They are set via the listenTo();
function in the initialize property in the View, like so:
initialize: function (options) { this.listenTo(this.collection, 'add', this.addCommentToWall); }
Here, we are saying that we want this instance of the Backbone View to listen to the instance of a Backbone Collection that has been assigned to it. It is listening for something to be added. When something is added, we want to call addCommentToWall, which is a property of the same instance of the Backbone View.
Recap: I have learned two ways to listen for events using Backbone.js. The events property is for listening for browser events. The listenTo() function in the initialize property is for listening for changes in backbone objects.
Git: Adding Remote Repositories
Git and version control are some of the wierdest and funnest things I’ve been introduced to. I love the idea of taking continuous snapshots of the small steps of my work, and then being able to sift through them and pick the ones I want. I think I’m still at a fairly basic level, but within that context, I’ve learned so much!
Remote Repositories
Remote repositories are basically copies of your git repo that are not stored on your hard drive. This seems kind of obvious, but didn’t really click for me until I learned that you could have as many remote repositories (remotes, for short) as you want!
Step 1: Take a look at the remote repositories you already have.
git remote -v
You will see a list that looks something like this:
origin https://github.com/cglinka/urdb-1.git (fetch) origin https://github.com/cglinka/urdb-1.git (push)
Or like this, if you have multiple remotes already set:
mks https://github.com/makersquare/urdb.git (fetch) mks https://github.com/makersquare/urdb.git (push) origin https://github.com/cglinka/urdb-1.git (fetch) origin https://github.com/cglinka/urdb-1.git (push)
You can see the remote name (or ‘alias’, if you want to get technical about it) followed by the URL that actually describes the location of each remote repository.
All of my remotes are on GitHub, but you can have remotes on other servers, or so I’m told. I have not tried to set up my own git server yet. :D
NOTE: The repo you clone from and/or the first remote you add will by default be called your origin. So when you are reading tips and tricks about Git, origin is just your ‘default’ remote alias, which may or may not be true for your particular repo. This may or may not cause a lot of confusion and/or frustration, but checking your remote names/aliases will save you a lot of troubleshooting time.
Step 2: Add a new remote.
git remote add <ALIAS> <url>
Fill in ALIAS with the name you want to use to access that remote. You can’t use origin if you already have an origin assigned. I try and give them easy-to-remember names based on the GitHub username. For the last several weeks, we’ve been working on the same repos in class, with new branches every day for that day’s lesson. Instead of making a million folders with a million copies of the same repo, I added a second remote as ‘mks’ that pointed to the correct repo on the makersquare account so I could just update my local copy of the repo every day! I added a third remote that pointed to my partner’s repo of the same assignment.
Step 3: But I want to change the remote that origin points to!
It’s cool, you can do that! First, remove the current origin:
git remote rm origin
Then, check make sure you removed the origin:
git remote -v
Last, add the new origin;
git remote add origin <URL>
And just to be sure, check your remotes again:
git remote -v
Ta-dah! New origin added!
More keyboard shortcuts
No matter how many cheat sheets I read, I seem to only manage to make one or two new keyboard shortcuts stick at a time. I hope you all are enjoying the fact that this is now a keyboard shortcut blog. :D
My new awesome trick is a general trick that appears to apply to all programs on OS X.
alt + ARROW
lets you jump by word instead of having to key past every single character. Hat tip to Greg, my partner this week for the trick!
And it gets even better! If you do
alt + delete
you can delete an entire word at a time!
I feel that it would also be important to mention that
⌘ + delete
works the same way as
⌘ + ARROW
which I mentioned earlier. It will delete an entire line, the way that you can jump to the end or beginning of a line!
Git Tricks: git diff
I think one of the first things you learn in git is the
git diff
command. This one is really important for me, because I forget exactly what I’ve changed since I last committed. But sometimes, I forget to run
git diff
before I add my files to the staging area. Whoops!
I feel like I should have figured this out sooner (that’s how learning works, right? obvious once you know it), but there is a very nice command that fixes this problem for me!
git diff --cached
show the git diff for files I’ve already staged! Huzzah! My commit messages will never be a series of “Ummmmm, I don’t remember what I just did.”
Sublime Text 2 keyboard shortcuts
Until I started MakerSquare, I hadn’t used a OS X on a regular basis for about 2 years. Since MakerSquare, I’ve hardly touched Windows. I’ve remembered most of the keyboard shortcuts for OS X, and I’ve learned a few new ones for cool apps like SizeUp and the suggested text editor Sublime Text 2. However, I’ve been trying to figure out how to ‘jump to the end of a line’ aka how to replicate the function of the ‘end’ key for a couple weeks now, and just now figured it out. On accident. /o\ And now I realize why I was getting nowhere with Google. It’s on OS level shortcut, not specific to my text editor.
⌘ + left arrow
So there is the secret for anyone who is new to OS X and trying to find the ‘home’ key or the ‘end’ button. This appears to work for any program, including Sublime Text. And now, I can stop banging my head against this wall!
And for the record:
⌘ + right arrow
gets you to the beginning of the line, and up and down take you to the top and bottom of the entire document.
Github repo confusion
Last week, I accidentally cloned down the wrong repo from GitHub. Whoops! I forked the repo for one of our class assignments, but I grabbed the URL for the MakerSquare repo, not mine. Fortunately, there was Google to the rescue!
Turns out, this is actually a little bit easy, though I read through the first 5 or so google search results before I did anything. This blog post was the most helpful because the commands were explained very nicely. It probably also helped that it was the 4th or so thing I read, so I was beginning to understand what I needed to do.
I did the following:
1. Check the current remote to make sure it is actually what I think it is
git origin -v
2. Remove the current origin
git remote rm origin
3. Add the new (correct!) origin
git remote add origin https://github.com/my_username/correct_repo.git
And tah-dah! All fixed! And in even nicer news, there is actually an even easier way of doing this that might be newer than said blog post. On GitHub Help, there is some information about using
git remote set-url
to do the same thing as the above step 3 and allows you to skip step 2 entirely.
Since this was an early mistake in a very simple single-branch repo, I didn’t have to take any other steps to make sure the HEAD was in the right spot or that any changes were correctly synced.
Day 1: GIT AND GITHUB!
Today, I am very thankful that I have ‘previous experience’ using the command line. Turns out, I need to stop underestimating how much I know, because turns out, I remember quite a lot! Which was really useful, because today, we jumped right in to learning about git and github, and I think I understand! No longer do I have mysterious incantations or un-remember-able commands. I (mostly) know what I’m doing with basic Git commands. And I’m comfortable typing stuff into the command line, and even more comfortable when I know what it is supposed to do. As part of our exercise today, we wrote up a nice little ‘git cheat sheet’, which will really come in handy while I get more practice using git.
I’m also really pleased that ‘writing webpages in Notepad in college’ translates really well into ‘I remember how to do this’ when doing our beginning HTML and CSS work. Thanks, past self! You did good!
I also learned a valuable lesson in making sure you have scrolled alllllll the way down to the bottom of the documentation for the thing you are having trouble with, because there might be some help all the way down there at the bottom. I’m not sure if I could have fixed my problem with the boxen install with that knowledge, but when I saw that today, I definitely had a bit of a ‘d’oh’ moment. Lessons learned all around.