Entries RSS Comments RSS

Archive for January, 2010

Easy Sinatra Project

Saturday, January 30th, 2010

I lovelovelove Sinatra. (SinatraRB.com) I created a very simple app (the fortune cookie generator I mentioned in an earlier post) to play with styling/views, get and post requests, and the very bare bones workings of Sinatra. I absolutely love how pure and simple it is. The structuring is a bit confusing at first, but the Sinatra Peepcode video helped me a lot on this: http://peepcode.com/products/sinatra

In the Peepcode video, they make a Sinatra app in one file, and then break it down from there into separate files. It’s good to see how everything CAN fit in one file. This is how I learned CSS, actually– by putting my styles in with the rest of my website. Once I realized you put the CSS in a separate file, I had a mini epiphany: sometimes it’s best to put things together before you take them apart. Then you can truly appreciate the fragmentation of a given application and truly understand the purpose of breaking things up for simplicity’s sake. Seeing this helped me understand a lot about Sinatra, and even shed some light for me on why Rails is the way it is, as well.

So, dundundun: I made this: http://fortunefinder.heroku.com

Don’t judge my poor styling and wacky coloration. ;) This really was just a silly little experiment to play with the basic features of Sinatra. Now that I understand the basics, I’m moving on to another project confidently. I’ll still probably tweak this one a little, too. Just for fun.

You can check out the code on github at http://github.com/ashumz/fortunefinder Nothing special, but might help a Sinatra newbie get a feel for the basic set up of a simple app.


Defining Useful Methods in Ruby: Adding a rand method to the Array Class

Tuesday, January 26th, 2010

The ‘rand’ method in Ruby is a method of the Kernel class that generate a random float between 0 and 1 (and thus will always round down to 0 when converting to an int.) Being a new Ruby developer, I decided to make an array and try to pull a random element like so:

@name=%w[bob, judy, don, john]
@get_random_name = @name[rand]

But this will always return ‘bob’, the 0th element of the array.

Instead, to pull a random element from an array (of any length), you need:

@get_random_name= @name[rand(@name.length)]

But that’s icky and unRubyish, and Ruby really SHOULD have a rand method for the Array class, shouldn’t it? So let’s make one, because we can! :)

class Array
def rand
self[super(self.length)]
end
end

@name.rand will now return a random element from the array. Awesome.

A Quick Snack Hack

Monday, January 25th, 2010

I’m always running behind schedule because I got too absorbed in project x or y and forgot to keep track of the time. I have two jobs I have to actually go to (and one I do from home), so I’m crunched for time on days where all three jobs collide. Still, I manage to find time to get absorbed in a crochet project or oblivious to everything because I’m working on some code. Then, I look at the time, and I have 5 minutes to shower, eat, and dress myself in a somewhat appropriate manner for the workplace. Sometimes I work 10 hour shifts between the two jobs, and I need to make sure the vitals are covered before walking out the door in a hurry: apply deodorant, brush teeth, eat.

The most important of those three vital components of the pre-workday is my personally favorite verb in the English language: eat.

Like most people, if I eat a lot of shitty food, I gain a lot of weight. I’m not much (or enough) of a health nut; on the contrary, I usually just grab what’s already prepared (even if it’s just a piece or two of bread) and run out the door. I’m pretty good about putting together balanced meals for dinner in a jiffy, but I am not as much of a breakfast/lunch person, due to the fact that I’m always in a hurry before going to work. And I don’t see that changing any time soon.

Today I am in a little less of a hurry (so far), so I decided to take a minute, breathe, and make a good decision about the food I am going to run on for the next 5 or 6 hours of the day.

One of my personal favorite things to eat before running out the door is tuna. It’s packed with protein, and virtually carb-less. I hate to put it between two pieces of bread and glutenize it, but sometimes that’s just the most convenient thing to do. Enter red peppers: another favorite snack when in a hurry. I eat them as if they were apples (after cutting out the center) and nomnom them to death. Today, I realized I had both of these ingredients (because when don’t I? I love tuna and red peppers and they are a staple on my grocery list), so I whipped this up:

Ingredients:

1 Red Pepper

1 Can of chunk light or solid white tuna

Light ranch dressing to taste

Directions:

Cut the stem end of the red pepper and scoop out the inside seeds.

Drain tuna. Empty contents of can of tuna into the open end of the red pepper.

Drizzle Ranch dressing on top of tuna or pour dressing onto plate for dipping.

Eat red pepper as if it were a wrap, dipping into ranch dressing or other sauce as desired.

YES! It was amazing. And there are so many variations one could take on this simple recipe. If you don’t like tuna, you could stuff the pepper with lunch meat, lettuce, and cheese as well. I am adequately full, feel great, and am ready to take on the workday. And… writing this blog post will probably result in my being late for work (but at least I ate already.)

Interlock – The Rochester, NY Hackerspace

Saturday, January 23rd, 2010

Lately I’ve been spending a lot of free time at Interlock, the hackerspace a bunch of us in Rochester have been working hard to get up and running. We’re about to move into our permanent space next month, and currently we’re in a temporary space until that point comes. We should be transferring to the new space on or before February 5th.

One thing I’m really excited about is an event called “First Friday” (firstfridayrochester.org) that happens on the first Friday (imagine that) of every month here in the city of Rochester, NY. First Friday is an event to promote the exposure of all of the awesome art that is happening in Rochester. From what I understand, it is an effort to maintain sustainability, promote the value of, and encourage collaboration amongst art venues and artists within the city. A large part of the mission is also to establish ties between university students and the wealth of art within the city. As soon as we heard about this event, we knew Interlock would be a regular part of it.

Interlock’s vision and goals are very much in line with the ideas of sustaining art and culture within Rochester and promoting collaboration between makers of all kinds. Many of our members are students and it’s certainly worthwhile to encourage them to make Rochester their home by providing limitless technical and artistic opportunities with the comfort of an open, socially collaborative environment outside of the university grounds. To accomplish this goal, a bus (or two or three? not sure on the details) takes people from universities to galleries within the downtown. The bus stops at the building that we’re located in, which is packed with many artsy organizations — 1115 East Main St. Exciting!

Organizations can register officially for the event for a small fee, or they can informally open their doors and welcome people with snacks, drinks, and a display of their art/projects. Last first Friday was pretty dead being that it was New Years day, but the previous first Friday in December at our building was booming. We had just moved in that night into our temporary space, so we didn’t have an event. This upcoming first Friday, on February 5th, we plan on having our doors to our new space open, with some projects and/or demos to show off to the public. We are in the basement of our building so signage will be key in trafficking people downstairs to check out our space. If we even get 3 people to come down, it will be a success. Next month, we will plan even bigger, given that we will be settled in and ready for a larger event. In general, I’m pretty excited that we’re positioned to become a significant part of First Friday festivities each month, and I’m anxious to see people’s reactions to Interlock’s dynamic and culture.

Currently computing: A simple ‘fortune cookie’ Sinatra app. More on that next time. :)

Judging books by covers: Learning a programming language

Saturday, January 16th, 2010

Today I ditched a work meeting to go grocery shopping, and then ditched the grocery shopping idea to go to Barnes & Noble and browse the programming section.

So far, I have read the Apress Beginning Ruby book and some of The Pragmatic Programmer book on Ruby.

I spent two hours looking at different approaches to teaching different levels of different languages. Lately I have taken an interest in software developed for the purpose of teaching basic concepts and implementations of computer programming. It was incredibly interesting to see the vast number of approaches to conveying the basics and also the intricacies of languages like Javascript, PHP, Ruby, and Python. I even found some colorful illustrated books attempting to teach C and C++! From those particular titles, though, I came to the hasty conclusion that colored illustrations and comic sans’y fonts don’t necessarily make it easier to grasp concepts. In fact, sometimes such a flowery approach can even distract from the concepts being taught. For me (and arguably most new learners), the delivery of the author and the clarity of examples and structure make or break the author’s approach. (I did buy one of the said ‘flowery’ books and will review once I am finished.)

For a compromised solution of visuals and thorough structure/delivery, I found Peachpit Press has a line of books called “Visual Quickstart Guide”’s. I can deal with the slightly presumptious title of the series, only because such a line of books exists that claims you can learn a language in 10-24 hours (depending on the thickness of the book and the complexity of the subject, I guess.) Compared to that claim, visual quickstart didn’t irk me too much. In the Visual Quickstart Guide series, there is a strong visual component, though I’m unsure as to how well these visualizations aid the teaching of the subject matter. I did buy one of these books as well– on Javascript and Ajax. I will review my experience with this book at some point, too.

The Head Start O’Reilly books looked really interesting in their approach, as well. These books utilize comic sansy fonts and waste a lot of space with illustrations, but cover a lot of ground from beginner to intermediate throughout the course of the text. Throughout the books, readers are prompted to solve problems (on lines meant for text! write your code in pencil!) and to think critically about a given problem or prospective solution. I was deciding between their book on Programming (actually an intro to Python that also covers basic programming concepts) and Hello World! Computer Programming for Kids and Other Beginners (which also uses Python the same way.) In the end, the latter was roughly $20 cheaper, so it won. I was also attracted to the fact that it was geared towards kids, but not explicity limited to kids by welcoming beginners as its readers as well. The Head Start books do not explicitly state that they are for kids or beginners in their title, but it is clearly implied when reading the book description and flipping through the illustrated pages and goofy fonts. In fact, the two books covered basically the same items (and utilized similar tools for their tutorials even.) After I am finished with Hello World! perhaps I will invest in a Head Start book for another subject. I’d be interested to know if anyone has read any of those books to learn a language, and how it went.

On an entirely unrelated note, first Linux workshop at Interlock was a success! I need to go home now though. I will regail my blog with my readings and childish Python adventures soon.

Redefining the “+” method in Ruby

Friday, January 15th, 2010

This is still one of my favorite things to do on a rainy day:

class Fixnum
  def + (x)
    self - x
  end
end

1 + 1
=> 0

Don’t forget to redefine the + sign for floats as well! 1.3 + 2.1 would still equal 3.4, unless you do the same thing for class Float. :)

Conclusion

Sunday, January 3rd, 2010

Squeak does not work on my netbook. If it doesn’t work on my netbook, I can’t use it. I’m going to try to install it on a computer at Interlock in the near future. We’ll see. Etoys/squeak worked on Alan’s Mac. But that’s Alan’s Mac, and not my netbook. :(

’til next time, smalltalk.

Edit: I got a hold of an XO at Interlock and played for some time with Etoys. I also got it working on my netbook shortly after, but it’s faster on the XO. Haha. A revised conclusion soon to follow…