Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Wednesday, February 1, 2012

A Beginner's View on Emacs

So first off, I was hired by Expected Behavior this week. I'd been doing some SEO and marketing consulting work with these guys for a while, and this is a fantastic opportunity. I'm excited about working with such a talented group of guys.

A great deal of my first week has been getting this computer set up and doing right. It's already been named Pazuzu, continuing my trend of naming my computers after famous demons, and also a delicious reference to the Exorcist.

That said, Expected Behavior is an Emacs shop. So I thought a great first post for CODETOBER would be about how I got my feet wet with Emacs.

For a long time, I really didn't understand why programmers preferred one text editor over another. But now I'm getting it. My understanding of Emacs so far is it's a text editor (as well as virtual machine, compiler, debugger, and so on and so forth) with a fanatical insistence on efficiency. If you ever leave home row, you're doing it wrong.

My initial impression? I was intimidated by Emacs, not only by the learning curve (which I understand is steep) but also by its reputation. But I don't want to be put off just because Emacs is 40 years old and doesn't work the way text editors I'm more familiar with do. If I can get past this steep ass learning curve, think of how POWERFUL I will become!

I haven't done much with Emacs so far, but my goal for this week is to get a few basic commands memorized: opening files, saving files, going to a certain line, etc. I estimate there are probably around 10 to 15 command I'll definitely use a lot of the time. Then I plan to expand the commands I've memorized, and we'll take it from there.

I also understand my friend Miles is using Emacs this month, even though he's a Vim guy. Let's all use Emacs, all the time!

Thursday, January 12, 2012

Announcing CODETOBER

Awesome IndyRB meetup last night. I got a lot of great recommendations for books to check out, and then had a ton of fun drinking beers and talking about projects at the Brockway pub afterwards. It's pretty awesome that we get so many new people coming to the meetups, partly because it's awesome to see such interest in Ruby and partly because it's also awesome that I'm no longer the newest coder around. After the meetup, I may have had some beers and spent some time hassling other developers about why they should be blogging more often. And then I realize I haven't blogged in what? 9 days? Who am I to hassle other people for not blogging?

But I've got an idea to remedy this. I absolutely SHOULD be blogging more often, and I'm going to take a page from my friend Miles' book and try to learn something new every day in February and then blog about it. I want to have an awesome name for this month, so I'm probably just going to call it CODETOBER. Also it's a leap year this year. WEIRD!

I've got a list going for things I want to look into or try to understand a bit. Mostly things I've heard mentioned often enough that I want to look into them, or how to use tools I'm already familiar with more effectively.

This list is pretty short, though. I'm definitely interested in learning how to dry up my code, since I feel that's a big weak point for me. And getting more familiar using Git for source control, learning more terminal shortcuts, Sass, Cucumber, HTML5 (since I'm a sucker for front-end design anyway) and I'm interested in getting more recommendations. What do you think would be beneficial to look into? Useful gems, fun tutorials, etc? I'M COUNTING ON YOU, INTERNET!

In more concrete coding news, I hung out with my friend Eli and he showed me how to dry up my Dungeon Crawler code quite a bit. I've now got one method that generates the rooms as opposed to 10 different methods! Still pretty soggy around the edges, though. And through the middle. It's actually mostly still pretty soggy.

Monday, November 7, 2011

Random Name Generator with Ruby

I like making stupid things with Ruby. Last week I was working on a MadLibs generator, not because I have an uncontrollable urge to make MadLibs, but because it was a project I could understand and I wanted to build.

My friend Eli showed me how to refactor the code so it was less specific and therefore much more versatile. Whereas the code I wrote was very specific to one MadLib, the one Eli helped me write is far more general, and can make MadLibs out of any text file that's been prepared (substituting all instances of a noun with NOUN, or NOUN1, NOUN2, etc, for repeating nouns)

It's obvious to me how valuable separating logic and data is, but it's going to take some work for me to really wrap my head around this. I've been coding with my logic and data entwined in a big hot nasty mess for a while.

Here's a gist of the finalized, objectified MadLibs generator:

MadLibs Generator

So my next goal is to take what I learned with refactoring the MadLibs generator and make another stupid project. I ran across this site a few nights ago:

Video Game Name Generator

So I've decided to build one using Ruby. I'm calling it aan so far (adjective, adjective, noun) and I've got a version working that will generate random combinations from pre-defined arrays, but I'm working on expanding it so it will read text files and generate lists from those files.

Once I get THAT up and running, I want to work on making it a bit more complex. Adding support for generating names that may or may not include a prefix or a suffix in addition to the standard adjective-adjective-noun, for example.

I think I'm having a lot more fun with coding when I'm working on stupid things like this than when I was working on larger-scale projects (long tutorials, Manticore, Chorenivore) but it's hard for me to objectively say which is more valuable.

Thursday, August 11, 2011

Adding two columns in a table with Rails

I figured out a way to calculate totals from two different columns in a table, but I'm having trouble extracting that logic and moving it out of my view. In this case, an Initiative's total is the sume of the Dexterity and Miscellaneous modifiers. Here's the code I've got so far:

Initiative Total:
<%= (@initiative.dex + @initiative.misc) %>

Pretty easy, right? But I'd like to just call this something like init_total and call it that way, but I'm not quite sure how to write that code. Also, does it matter if I throw a .to_s on the end of this? I noticed it displays the same either way, but I don't know if a .to_s is strictly required. I'm guessing since this information is already a string, converting it to a string is redundant.

Just a quick update. Feels good to be making daily progress on Manticore, especially since I spent a long time spinning my wheels.

Wednesday, August 10, 2011

Implementing new methods in Rails

I think it's important that every time (or nearly every time) I sit down to code that I try to do something I don't know how to do. I'm making good progress with using the code I've figured out and applying it to other similar things. For example, with my Manticore app I can use the same methods to create Items to also create Special Abilities and Spells.

But what I want is a way to sum totals from different columns in a table, then display that total in the view. I was messing around with the sum and count methods I found in the Rails API, but haven't quite gotten this figured out. The result is a pleasant headache, and that's what I'm going for. I can't just rest on what I know, I need to be stretching my boundaries when I code.

I think the end result will be I'll learn new things faster and be able to work around road blocks more quickly when they DO arise. My ultimate goal isn't simply to build this or that application; I want to understand how Rails applications work, how they go together and how they're built.

Also, I'm going to start blasting out my rails blog posts in Google+ in addition to Twitter, so if you're seeing this twice? Sorry about your luck!

Tuesday, August 9, 2011

If and Unless Methods in Rails

Sometimes shit just works.

Sometimes I sit down to code for an hour or two and everything I try either works right away, or is broken in such a way that the first fix I attempt works.

Today was one of those days! I had some minor successes straight off the bat, such as moving Delete methods into Edit methods, moving Edit methods into the Menu partial along with navigation and changing the Show method for Characters in the Index view to display character.name instead of a generic 'Show'.

But here's the big triumph of the heart tonight.

You may recall in my last post I was talking about how in the menu partial I didn't want to display pages that didn't apply to all characters. I don't want a spell tab in the menu for a character that doesn't learn spells, for example. So I figured out a way to solve this problem, and the really beautiful thing is the solution was maybe two lines of code. Why did I think this would be such a big deal?

Here's what I had originally:

<%= link_to_unless_current 'Special Abilities', character_specials_path(@character) %>

Changing this code so the Special Abilities page only shows up if it's been created is easy enough:

<%= link_to_unless_current 'Special Abilities', character_specials_path(@character) if @character.specials.exists? %>

But then I run into a problem. With the previous code, it was simple enough to create a Special Ability, since you just clicked on the Special Ability link and the show page would render the form, allowing you to create a Special Ability, or edit a previous Special Ability. So obviously I need to land a link to create that page somewhere.

The Character show page seems a logical choice, since it will exist before a Special Ability will, and a Special Ability's existence will depend upon a Character's existence, right? So let's wire that up:

<%= link_to 'Create Special Abilities Page', character_specials_path(@character) unless @character.specials.exists? %>

Making pretty good use of those if and unless methods!

I know Rails programmers often talk about how they can't believe something is so easy to do with Rails, but shit, I can't believe this was so easy to do. And it feels good to make this much progress on my own, because I feel like a lot of the time I'm just asking for help. This is a pretty good indicator that I'm figuring out how things work, where things go and how to make Rails sing and dance for me.

Monday, August 8, 2011

Working on personal Rails projects

So I've made some pretty serious progress with Manticore. So far, here's what I've got:

The ability to create a new character, with several attributes includine statistics, hit points, armor information and so on.
The ability to create and destroy items that belong to said character.
The ability to create and destroy special abilities that belong to said character.

Not bad! I feel like I'm making some real progress here. Here's a few screen shots:




When I work on a Rails application (and especially when I work on one for myself) I like to keep a to-do list of features I want to implement. It feels GREAT to have a roadmap when working on any project, and Rails is no exception. Here's what I've got so far:

Add Skills - Every character will need skills, and I haven't started to tackle this yet because I'm not quite sure how to do it. I think simplest would be to make Skill a model with several defining attributes that belongs_to Character, with a has_many relationship. This would allow users to create skills as necessary, and not add Skills they either don't have or don't use. Actually, you know what? I just talked myself into doing it this way. BINGO!

Add Feats - Feats are going to be similar to Special Abilities, and I'm not sure if I want them to be in their own tab in the menu partial or lumped in with Special Abilities. I like the idea of keeping them separate, because some characters won't have Special Abilities, though most (if not all) characters will have Feats. I also don't want that menu partial to get too bulky.

Add Animal Companions / Spells - Here's another thing I want to do. As of right now, my menu partial displays the same things for all Characters (although some of these are just placeholder text) - Character | Items | Skills | Special Abilities | Spells - and it struck me the other day that I shouldn't be displaying these pages if the character doesn't have them yet. After all, a fighter doesn't learn spells or gain an animal companion, so why show them in the menu partial? So once I get some of these other relationships hammered out, I'll be looking for a way to add these, perhaps from the Character's view page, and have pages populate into the menu partial only if they've been created. Eventually I'll want the ability to drag and drop these to organize them by user preference, but let's not get too deep into the styling woods just yet.

And finally, I'll want to clean up the actual code I'm using. @unixmonkey showed me a way to get what I want done, but said it was messy and he was right. Still, it's more valuable to me right now to have code that works and not the most efficient code possible.

Remember when I said I find myself focusing more on my own projects than the tutorials and books I've been using? That still holds true.

Sunday, April 24, 2011

Lightening the overload

The longer I work with Ruby on Rails, the more things become clear to me. The more I understand what various acronyms stand for, what they do and how they work. Here's an example, torn from the pages of REAL LIFE:

I work for an e-commerce website, mostly doing SEO work, photography and editing products for the store. The IT manager recently changed our shopping cart because customers were having problems with the Ajax based shopping cart. Before this weekend, I didn't have a clear understanding of what Ajax was. I assumed it was another coding language like Ruby, but it turns out it's just a tool used in web application design. It stands for Asynchronous JavaScript and XML and Agile Web Development had me use it to create an indicator that the shopping cart has been updated in the application I'm working on.

So what have I learned this weekend? I got familiar with Ajax, what it can do and what it's used for (not to mention what it actually IS) and it's given me a better understanding of how everything, from development to design, works together. I first got interested in web design a few years ago, when I fell in love with CSS, and learning Ruby has been nice because I've had to learn how to implement CSS within a Rails application.

When I got started with Ruby a few months ago, I felt like there was a ton of information to process and somehow wrap my head around. That's still true, but the information overload gets lighter every day.

Tuesday, February 22, 2011

Working with MySQL and Ruby

Whoa, what's up SQL and MySQL?

Here's something I've recently realized about learning Ruby: I can't just learn Ruby. Ruby is going to be the thrust of what I'm learning and I'll spend the bulk of my time with it, but if my ultimate goal is to make a career change and become a full time Ruby programmer, I'll have to learn other languages as well.

This idea isn't as daunting as it might have been a month and a half ago, before I even had the seed of a desire to learn Ruby.

So here's something I've noticed about working with a bit of SQL and MySQL tonight. Computer languages share a lot of the same ideas. Sure, Ruby is more elegant than something like C++ and more modern than the Basic I learned in 9th grade, but the idea is the same. So the teeny, tiny little snippet of MySQL I wrote tonight was easier to understand than it would be if I hadn't also been working with Ruby for a month and a half or so.

I actually had to cut my database work short tonight because I couldn't get the MySQL gem to install, but I WAS able to write a program that allowed me to write to a database and retrieve information from it. Pretty cool, considering that's what I've been hot balls to learn since I cracked open Beginning Ruby.

Monday, February 21, 2011

More about Ruby, Databases and Syntax

So I was extremely lazy this weekend and only spent a couple hours working with Ruby. Awful! However, I think a little time away from actively learning caused a few things to click in my head. Imagine a pair of gears, left to their own devices after hours of meddling and tinkering, that suddenly come together and begin to move. Not smoothly, perhaps, but real motion!

It's hard to describe what clicked for me. The syntax seems to make more sense the more I work with it. While working through Beginning Ruby, I've been typing every bit of code out, then attempting to run it. It's good practice, both to get used to how Ruby is written as well as learning what will cause Ruby to throw up AND how to fix those little problems. How often do you guys do something stupid like this?

class Person
  attr_accessor :name, :age
end

fred = Preson.new
fred.name = "Fred"
fred.age = 35

puts fred.name
puts fred.age

Only to have Ruby throw up everywhere because of two little letters that got switched?

I'm guessing this transposition kind of crap is something that will haunt me FOREVER, but I'll get better at spotting it as I go along.

Also I would like to say that I wrote this bit of example code almost ENTIRELY from memory. So things are sticking. I still have a hard time believing how easy some of this is, but there's still plenty I don't really understand yet. Still, let's not get ahead of ourselves here.

Still working through Chapter 9. I just installed my_sql. How do you pronounce this, anyway? I heard a guy at the meetup a couple weeks ago call it "My Sequel" which seems better than "MY SQL" but I don't know.