Jahde +

Young djedi in training.

Page 2

Refactoring your code

There was once a time when I had a deep affection for mathematics. I think we fell apart sometime during college but my quest to learn programming has renewed this relationship.

A major concept in computer science that I’m still getting a hang of is refactoring. It’s very similar to factorization in mathematics where you have an expression that you want to reduce to “basic building blocks”. E.g. if “x = a + b + c” and “y = a + b” then you can factor “x = y + c”.

This same concept lends itself to computer programming by the name of refactoring. Similarly this process involves rearranging a program to facilitate code re-use and improve the readability of your code.

Here’s an example from today. I’m working on a procedure “add_page_to_index” that takes three inputs and updates the index to include all of the words found in the page content by adding the url to the associated word’s url...

Continue reading →

Building a Rails 4 app using the Twilio API

This weekend I wanted to challenge myself by building a functional web application using the rails framework. My goal for this project was to use an API that I was unfamiliar with and that could be used from my iPhone.

I settled on the Twilio API. Twilio is a company who services voice calling and SMS messaging integration into your app. On the messaging side the service works by essentially turning all text messages into a RESTful architecture. By utilizing a RESTful architecture for your incoming/outgoing SMS requests, you are able to map those requests to the routes in your rails application.

Behind the scenes Twilio figures out how to handle your app requests by using a construct known as webhooks. This is done for you on Twilio’s side. When someone makes a request to your twilio number, either by phone or SMS message. The webhook which is simply an URL will handle that request...

Continue reading →

Object feels and introspection

One of the most interesting concepts I’ve learned so far about the Ruby programming language is the idea of introspection. In computing, type introspection is the idea that an object or program knows about it’s own properties at runtime.

Specifically in regards to Ruby this means that an object is self-aware and knows what it is, what values it contains and what’s going on around it at a given moment in time. In short, Ruby objects can have feels.


Similar to our good friend Keanu, a Ruby object can have a moment of reflection at a given moment in time. Let us make code:

x = "hello world"      
x.class     => String

x = :hello_world
x.class     => Symbol

This is a relatively straightforward example that shows how Ruby is able to reflect on itself at two separate moments in life. We can ask Ruby what type of object it is, what type of methods we can call it and then infer more...

Continue reading →

The layman’s guide to RegEx: What is RegEx exactly?

RegEx stands for regular expression and it is a common tool used by programmers to match patterns of string data. “WAIT, I thought this was the layman’s explanation?!” Let us continue.

A good way to think about regular expressions is a sifter for string data. Let’s say you have a recipe for an amazing cake but your string flour is too lumpy and stuck together. The regular expression sifter will allow you to collect the string flour of your choosing so that you can finish the recipe. And you can keep adding filters to the sifter to make your flour even more fine.

At the most fundamental level, a regular expression allows us to find, manipulate and collect data within strings. A string is one of the most common data types in computer science and it is usually just a squence of characters between a pair of quotes.

"This is a string"

With regular expressions we can take a string like...

Continue reading →

Ruby class shortcuts

class Person
  attr_accessor :name, :age
 same as:

class Person
  def name

  def name=(name)
    @name = name

  def age 

  def age=(age)
    @age = age

Ruby is awesome. I think it has to do with the ease and beauty of Textmate but I really look forward to typing out code using the language. Additionally I’ve been introduced to many shortcuts which make writing code a lot easier.

One recent shortcut which I’ve been trying to wrap my head around is attraccessor. In the above code you will see the one line “attraccessor :name, :age” re-writes everything below.

It basically performs the read and write methods on a function. This allows you to call x.name and return whatever x is and also allows you to assign x.name = “Jahde”.

I’m sure I’ll be seeing other shortcuts that make writing code easier but this one stood out to me. I...

Continue reading →