Entries RSS Comments RSS

Sinatra: The answer to my Ruby GUI problem

November 9th, 2009

Ruby and GUI’s have been on the forefront of my brain lately because I’ve been playing around with fun ways to program with Ruby. I am honestly bored of command line programs, and for good reason: the command line isn’t pretty enough for me. Since I’ve had problems installing Shoes and Hackety Hack on my version of Ubuntu, I asked one of my friends who uses Ruby frequently if there were other GUI options. There are options, but he referred to them as a bit of a mess to implement and pointed out that javascript and the web make for better uses of, what I would call, “fun Ruby.” Better yet, when you program for the web, everyone can use your program without worrying about what platform they are on.

So, I gave this a little thought. I started getting jealous and even a little frustrated at Python programmers and their connectedness with GUI’s and their pride in Python’s support for GUI’s. Apparently, Ruby has similar support, but it’s not nearly as widely embraced amongst Rubyists as it is in the Python community. (True? False? opinions?) Admittedly, I think I should have just learned visual basic and got my GUI fix 10 years ago. (I don’t particularly want to learn Python, and there are issues with it’s syntax that have turned me off pretty heavily.)

So, I have decided that the best course of action, given my new fixation on Sinatra, is to begin a jquery/javascript and Ruby project. Although I’ve been making websites for about 10 years, they have generally been informative, usually static, very low level applications of HTML, CSS, and bits and pieces of PHP. I have used javascript for fun little menus now and again, but honestly I’m a total copy/paster when it comes to js. I started recently on some javascript tutorials, but was then quickly reprimanded: SKIP TO JQUERY, says everyone. Unless you really wanna become a pro in javascript, it sounds like jquery is a nice shortcut to the overwhelming syntax (especially coming from Ruby!) and implementations of javascript. I can’t quite figure out a consistency of why and how something does what in javascript. But, if I can figure out what I want the code to do, I’m pretty sure I can figure out how to use jquery to get the job done. We’ll see.

I am going to begin working on a blog that is purely in javascript, using jquery, and also uses Sinatra. I’m going to use sqlite for the DB. Did I mention I have very little experience with DB’s, too? :) Okay, this project, honestly, seems a little over my head to me right now. But once complete, I think I will have experience with all of these pieces I need to make a pretty, fun, and useful application. Something every programmer craves– right?! :)

Updates to follow. Thanks to Julio for helping me come up with the idea on how to practice messing with all of the components I’m craving: Ruby, Sinatra, Javascript/Jquery, Sqlite, ERB, CSS… wee! This brings up another point about how multilingual and implementation exposure at the early stages of learning a programming language can be so incredibly integral to understanding how to best utilize a programming language like Ruby… but that’s for another post! Cheers!

Ruby on Rails or Sinatra?

November 7th, 2009

My updates have been a little scarce, but I’ve been programming– I promise. :P

I recently have been working on a site, discountcampusbooks.com (psst, buy your books there!) with my husband, alan.dipert.org. The book search is written in Ruby and uses the incredibly cute Ruby framework, Sinatra. I absolutely LOVE Sinatra, and I think for me it is a viable alternative to Rails. I’ve had pretty mixed feelings on ROR lately. I know I am a bit too opinionated for my skill level, but I really have something to say about the differences and advantages of both Rails and Sinatra.

I should say this first, because I feel like it:

For someone like me, who is just learning their first programming language, new to object orientation, and incredibly naive about the power or lack thereof of a given language, I feel blessed to have picked Ruby as my first language to learn. As I have learned Ruby, I’ve also learned the shortcomings of other languages. I am lucky enough to have a multilingual husband who keeps books like toilet paper in our bathroom, so at any given point I can pick up a little reading material and learn a little Clojure (yeah!!) or C (not so much). I’ve explored Python and Haskell pretty thoroughly as well as a few other common programming languages. I can’t argue against any of these languages too much. Why would I? Mostly, as I learn more about other languages, I just feel luckier to have picked Ruby as my devirginizing language. :P I also know it is important to explore the value of other languages. In fact, I know I sometimes need other languages to make the best use of Ruby. There is so much to say about all of this. End interjection (for now.)

The biggest issue for me, as I mentioned earlier, is the fact that ROR is the largest use/implementation of Ruby and the easiest for which you can find tutorials, screencasts, support groups, chatrooms, etc etc. Overwhelmed by ROR, I started using a “joke” (literally) framework my friend wrote to get my Ruby programs off the command line and on the web. After dealing with the shortcomings of his babyframework (again, it was written as a “joke” and was actually put together as a way to use Ruby as if it were PHP), I started branching out on my own. It became clear to me that, though you can use Ruby in a similar way to PHP using ERB, it’s not necessarily the best way. I had been working on a dungeon text adventure in Ruby and I was trying to figure out how to make it work via the web using ERB. I was, for the most part, successful. My tech support was limited, but I started to see the parallels of his framework and Sinatra after checking out Sinatra earlier in the week. Enter Sinatra. Things like Rack ran on both the joke framework and Sinatra. I could even use shotgun to run a webserver on my computer. WHOA. All of these things were exposed to me in small doses, and then adding Sinatra to the mix just blew my mind further. Ruby is fuckin’ cool. Noted. And I continued to compute.

When my husband asked me to help with the book search, I was pretty excited. I was so excited to see an actual implementation of a Sinatra-based web app. There was so much Ruby involved!! :) During my first experience with rails, I was hardly able to figure out where I should even put my Ruby. :) Weeks earlier, I had spent time creating a ’sample blog’ in rails, and figuring out the MVC framework. In rails, so much of the work is done for you. A large part of the process is accepting MVC framework, also seen in zend and django in PHP and python, respectively. You don’t need to be a Ruby expert to do Rails. (But you can be, and you will be better for your knowledge, that’s for sure. I have never doubted that.) Likewise, I truly believe you could suck at Rails and excel at Ruby. In fact, you’d probably prefer and have already used Sinatra if this is the case. They are not mutually inclusive. One of my favorite things about Ruby is the power and extensiveness of the language. Frameworks as light as Sinatra give creative freedom and your exposure to Ruby and the web can be vast or minimal– you can most likely get something to work for you. If you want something big, you’ll have to build it yourself. On the other hand, larger frameworks provide you an out of the box, large-scale solution that subsequently requires more knowledge and familiarity of the framework before you can customize it creatively.

Sinatra allows you a very simple, lightweight framework that requires you build off your own knowledge rather than, as my friend Julio would put it, David’s skills. Honestly, if you know the scope of your site will be huge, you know your DB infrastructure, and you’ve been through all of this before, Rails is probably your answer. From what I hear, you’ll love it, and it’s worth learning the MVC framework aspects that may be, at first, completely fuckin’ confusing (for me, it’s slowly coming along after using Sinatra more). However, if you’re like me, and you wanna start from small potatoes and build it yourself (yeah!!), use Sinatra. I feel like I may be making my way towards Rails, but I may also never get there. I enjoy the freedom of Sinatra, and I’m not building any gigantic web applications for the time being. Sinatra just rules if you love Ruby, but Rails seems to big and Ruby command line programs aren’t GUI enough. The web is an excellent agnostic platform for development. So embrace it. I have noticed many programmers are reluctant to do so for various reasons, but Sinatra has opened my eyes to the fact that you can write painless, creative Ruby apps with a little hassle and a lot of fun.

Cheers :)


Ruby Scope Confusion

September 18th, 2009

I ran into some confusion when messing around with a sample program I created that creates new instances of a class Car and names the car. I wanted to store my list of “funnynames” in an array and have my naming method grab a random name from the array via my “name” method which would be “initialized” (using the initialize method) upon creation of each new instance of the Car class. Blahblahblah. So my problem: class variables work for me, but instance variables don’t! I couldn’t find much on instance variables, because everything seemed to start talking about instance methods once they mentioned instance variables. It seemed like everyone was reluctant to point out that INSTANCE VARIABLES ARE INVISIBLE!?!?! outside of the class. You can’t access them outside of the class unless you use an accessor method (easiest) or other method.  If I’m wrong here, someone correct me. But to my knowledge, that’s how it works. However, if you store the data you’d like to access in a class variable, it works! Unfortunately. Since it’s so easy, but a bad idea, from what I hear.  Inheritance happens. Right? :)

And to think… these three ways to do the same thing in Ruby (minus side effects in the future if I were to use the class variable) aren’t even the only ways to do this.

It’s interesting for me that I discovered this basically on my own when developing a simple practice program. Wee! :)

class Car
  def name
    @funnynames=%w[bob judy mabel wiener]
    puts "Your car's name is #{@funnynames[rand(4)]}!"
  end
end

#defining array within method 

class Car
  @@funnynames=%w[bob judy mabel wiener]
  def name
    puts "Your car's name is #{@@funnynames[rand(4)]}!"
  end
end

#array as a class variable (thus I'm able to access it)

class Car
  @funnynames=%w[bob judy mabel wiener]
  class << self  #makes the accessor method relevant to the class rather than a single instance
  attr_accessor :funnynames
  def name
    puts "Your car's name is #{Car.funnynames[rand(4)]}!"
  end
end

# Voila! More on this later as I continue to learn the in's and out's

Currently Computing: Revisiting my text analyzer with the use of ARGV[] to analyze files via the command line rather than hardcoding in the file to access within the program. SO cool! Then back to more OO sample programs. Rails will happen. I’m just busy nerding out on Ruby itself for the time being. :)

What is Ruby without some rails?

September 16th, 2009

Why the lucky stiff vanished off the face of the earth by the way…  Grrr…

I’ve been struggling lately with that book of mine. While it is great reading, I feel like I’m getting a bit stuck. I want to move on to practical applications of Ruby. I thought Shoes might be my answer (I [allegedly] can develop desktop applications with Ruby!) Nope. _Why took that all with him when he vanished. (Along with Hackety Hack! Which I LOVED and which used Shoes, too!) Ughhh. (Note: I have since discovered after posting this that many people are still working on his projects, and many are available via github.) There are ways to use Ruby “practically” (or what connotates practically in my head anyways) via various GUIs, but the fact is that Ruby’s most popular and practical application is Ruby on Rails– via the web. That’s just how it is.I’m not mad about it. I just need a new course of action.

So, as of last night, I’ve started reading Ruby tutorials all over the web that prepare one for use of RoR. I now know the most important features of Ruby that help one with Rails implementations. Of course, these are all things I learned previously via my Ruby book, but it’s nice to know which items I will use often and which I can discard as “unimportant” temporarily. I foresee my difficulty with Rails being the structure itself, particularly the MVC backbone. I don’t have a lot of experience with the web, or with programming even. I have limited experience with PHP, CSS, and HTML. But I’m ready to fuse my skills together and see what happens. I’m lucky to have help just a few feet away, too. But I try not to bug him too much. :)

I have not yet created my first Rails application. I’ll keep you all posted. I can tell you that my first idea for a “project” is as ridiculous as it is cute. I am truly a female.  Let’s see how this goes though. Honestly, I’m confident this escapade will be interesting. At very least, it will be worth giggling over. :x

P.S. – Thank you to Alan for explaining some of the more complex features and implementations of OO to me over coffee and toast. I love you.

On Learning to Program

August 28th, 2009

I’ve continually breezed through my Ruby book day by day, learning more as I go, and supplementing my knowledge with various aspects of computers with which I am completely dumb. (IE: how did I spend 4+ hours on the computer for the last 10 years of my life and never learn how to navigate the command line?!) I blame Windows.

Anyways, my Ruby book has basically become my end-all source for information when it comes to Ruby. In fact, I no longer bug my husband incessantly about the basic in’s and out’s because I can just as easily find my answer somewhere in my book– which I’m sure, to some degree, alleviates his headache named Ashley. The progression of this particular book is incredibly comprehensive and helpful. I’d definitely recommend it to anyone (new or existing programmers) interested in learning Ruby. I’ve caught my husband borrowing it on more than one occasion as a reference guide, too. :)

The first few chapters of the book were pretty simple to digest. Just in case I might have been fooling myself, I decided to read it twice, and some sections three times. I took extensive notes the second and third times. I would say I now have a firm understanding of the basics of object orientation, the Ruby kernel, and the basic syntax and grammar of the Ruby language. I also have a pretty firm footing on the history of Ruby and the basic ideas behind its most popular, current uses (ROR). Every day I try to relate one or more tasks I complete in my daily life to something for which I could write a program (usually something that involves manual repetition.) Then, I think about how I’d get started. Sometimes I start computing the idea, and move forward until I don’t know what to do next; other times I just brainstorm how the knowledge I have so far would apply to executing my idea. Basically, I’m trying to get out of “idea world” and  into the mindset of a programmer (though I know the best programmers must be the ones who have a firm footing in both of these realms). It sounds ridiculous when I write out my thought process, but my reasoning is simple. I’m good with ideas, but I would be stuck in “idea world” without any clue of how to practically apply the things I’m reading if I didn’t spend time each day trying to “think like a programmer.”

Currently Computing: I am working on a text analyzer as my first “complete” Ruby program. I’m struggling a bit with some of the more intermediate forms of regular expressions so I’m reviewing that for the 5th or 6th time. I should be on to the next project shortly, where I will be learning more in depth features of Ruby’s object orientation abilities and creating a program that utilizes these features in depth. (Up to now my experience with object orientation is limited to simple people and pet examples.) Exciting!



Facebook “Affiliate Marketing”

August 1st, 2009

So last week I spent about $50 running an ad on facebook for a “Free” Victoria’s Secret gift card from productestpanel.com. I quickly (in 10-15 minutes) doubled my money with affiliate leads. (Productestpanel pays out $3 per lead on Commission Junction. I joined their parent affiliate, Addrive, thinking I’d get even better commissions, and they offered me $1.50/lead for the same ads, but that’s another story.)

I thought, wow, this is awesome. Facebook had just announced their new “targeting” and I was able to target this specific ad to users who like Victoria’s Secret. Easy, right? Too easy.

As of July 29th, they’ve updated their advertising guidelines to be as strict as they really want them to be. Vague wording and lots of stipulations frost the policies. I was surprised there wasn’t something as detailed as this earlier; but there is now. I have not tried to run another one of my targeted “free offer” ads, but I have an inkling it’s not going to fly for much longer, if at all. I just logged into facebook and was not greeted with a !free macbook offer! for the first time in weeks. Damn.

Hurray for short-lived loopholes, at very least. It all goes to show that you have to be ready for any opportunity at any time, and then be prepared to have your bliss nipped in the ass once you really hit the point of success.

Edit: So, I was still able to run my existing ads and get a few new ones approved. Looks like Facebook’s revisions were simply for show or extreme cases of blatant false advertising that were slipping through the cracks. The major problem  I noticed was a spike in CPC prices from my first attempt at advertising with facebook– big time. Surely several factors affect the price, but with the same targeted audience and exact same campaign, I paid up to $.10 more for both CPC and CPM! I decided to quit this venture while I was ahead, or at least until View Postany new opportunity sticks out at me. The Victoria’s Secret ad was great, but I definitely experienced diminishing returns, as to be expected. Tried a few other ads to targeted audiences and didn’t make much money.. Still not at all negative on this. I just need to figure out how to sell my own services on Facebook now so I can increase my profit margin and generate my own leads… (cheap web design)