Jahde +

Young djedi in training.

Read this first

Using google maps to build a flight log

Alt text

DEMO HERE

Airplanes and the idea of flight fascinated me as a young boy. I remember the anticipation of traveling to far away places with my family and could not wait to sit down in my blastoff seat and buckle up.

One of my favourite things to do on the airplane was to check the flight log application on the tv in front of me. My brother would watch movies and I was the weird kid constantly clicking the screen to show the temperature, altitude and flight path along the journey. The movement changed very little minute by minute but sitting there watching the small airplane move was enough entertainment for me.

Last night I set out to make my own flight log visualization app using the google maps api.

Customizing your google map object

The google maps api is well documented and gives you very clear code examples to get up and running with a working map. I used a snazzy maps skin...

Continue reading →


What every Ruby developer should know before learning Javascript

How to transition from Ruby to Javascript in one day

After inundating myself with Ruby for close to six consecutive weeks it was time for us to go on a break. We had a lot of fun together and we learned a lot about each other but evidently in the end, we needed a break to really figure some things out.

Enter JavaScript.

JavaScript is a programming language created in 1995 by Brendan Eich while working at Netscape. Over the last 20 years it has become synonymous with front-end web development which makes it a very important language to know.

This week was our introduction to JavaScript. With my past experience learning Ruby it was an interesting experience diving into a new language. I knew that the syntax would be similar but there are certain design patterns that change from language to language.

It is...

Continue reading →


recursion, recursion, recursion

Okay I learned one of the coolest ruby techniques that I’ve seen thus far, it’s called recursion and it’s awesome.

Recursion allows you to define a function(method) then call itself within the body of that function. On first glance it looks very confusing but basically you are using the function within the function itself. Even trying to explain it here is very tough. Let’s try an example.

def countdown(n)
  if n == 0
    puts "Blastoff!"
  else
    puts n
    countdown(n-1)
  end
end

In this program called countdown we take a number “n” and pass it through the code block. The final result is a countdown of numbers until you get to 1 and then it prints out “Blastoff!”. You could also write this program using a while loop:

while n > 0
puts n
n = n -1
end
puts “Blastoff!”

but with recursion we can save time and energy by calling the function on itself. Using recursion we can write...

Continue reading →


Simple things

def englishNumber number
  left = number
  write = left/100               How many hundreds left to write out
  left = left - write*100        Subtract off those hundreds.

  if write > 0
    return 'one hundred'
  end

  write = left/10                How many tens left to write out
  left = left - write*10         Subtract off those tens.
end

puts englishNumber( 32)
puts englishNumber(100)

The above code snippet is part of a program that turns an integer into it’s english version. E.g. if the number “1” passes through the program it will return “one”.

The whole program is relatively simple and pretty straightforward but I wanted to talk about it because it exposes one of the most interesting things I’ve found in programming. Simplicity is the gift and curse of programming.

For the last hour I’ve written out this program then manually went through each step to find out what’s...

Continue reading →


Stop what you’re doing and start using Ruby’s inject method

The Ruby inject method has a few different use cases. For me personally I’m really starting to love summing numbers with the method. It’s still a little confusing for me but I think I’m finally starting to get the hang of it.

Let’s take a look at an example.

Say we have an array of numbers that we want to sum:
[ 5, 6, 7, 8 ]

We could use a loop to sum the numbers:
sum = 0
[5,6,7,8].each { |x| sum += x }
sum

With the inject method, we can sum the numbers on one line:
[5,6,7,8].inject(0) { |x,y| x+y }

The inject method takes an argument and a block. In this example we set the argument as “0” and the block is “|x,y| x+y”. When we call the inject method, the argument gets set as the first parameter of the block. In our case “x” would initialize to “0”. [If there is no argument then inject just takes the first element of the array as the first parameter “x”. ] Next inject takes the...

Continue reading →


Intro to Mandarin (pinyin)

pinyin.jpg

Xiansheng (Mr., husband, teacher)
Ni hao (how do you do/ hello)
Xiaojie (miss/ young lady)
Qing (please)
Wen (to ask)
Nin (you-polite)
Gui xing (what is your honorable surname?)
Wo (I)
Ne
Jiao (to be called; to call)
Shenme (what)
Mingzi (name)
Wang Peng
Li You
Shi (to be)
Laoshi (teacher)
Ma
Bu (not; no)
Xuesheng (Student)
Ye (too; also)
Zhongguoren (chinese people)
Meiguoren (american people)
Pengyou (Friend)
Taitai (wife/Mrs.)
Na (that)
Zhang (measure word for flat object)
Zhaopian (picture; photo)
De (‘s)
Zhe (this)
Baba (Father)
Mama (mother)
Zhe ge (this)
Nanhaizi (boy)
Shei (who)
Ta (he)
Ta (she)
Didi (younger brother)
Nuhaizi (girl)
Meimei (younger sister)
Nu’er (daughter)
You (to have)
Erzi (son)
Mei (not)
Xiao (small; little)
Gao (tall)
Jia (family)
Ji (how many)
Gege (older brother)
Liang (two; couple of)
Jiejie (older sister)
He (and)
Zuo (to do)
Yingwen (english language)
...

Continue reading →


How to write a switch statement in ruby

case a
when 1..10
  puts "It's between 1 and 10"
when 8
  puts "It's 8"
when String
  puts "You passed a string"
else
  puts "You gave me {a} -- I have no idea what to do with that."
end

Programming languages are very similar to spoken languages. One of the closest similarities is the translation of certain words or concepts from language to language.

In English we say “Hello” while a Spanish speaking person might say “Hola”. Generally these two definitions mean same thing and are direct translations of each other. With programming languages there are also certain concepts and definitions which are translatable from one language to the other.

I have a friend that codes in ActionSCript and he has been very helpful when I get stuck on a problem or concept in Ruby. It amazes me that he is just as able to solve a problem based in Ruby by looking at it through the eyes of his chosen...

Continue reading →


hash browns

person 1 = { first: "Papa", last: "Jah" }
{:first=>"Papa", :last=>"Jah"}
person 2 = { first: "Mama", last: "Jah" }
{:first=>"Mama", :last=>"Jah"} 
person 3 = { first: "Jah", last: "Jah" }
{:first=>"Jah", :last=>"Jah"} 

params = { father: person1, mother: person2, child: person3 }
{:father=>{:first=>"Papa", :last=>"Jah"}, :mother=>{:first=>"Mama", :last=>"Jah"}, :child=>{:first=>"Jah", :last=>"Jah"}} 

params[:father][:first]   verify it has the right value
=> "Papa"

Working with rails you will see a lot of hashes. It’s an efficient way to store data from your web application in a particular way. A common example where you would use a hash in your application is in the collection of user data that you have for your website.

When users sign up for your website you will undoubtedly collect a heap of information regarding that particular person. Name, address, email, telephone number...

Continue reading →


How to add date/time created to your ruby on rails application

<p&gt
  <h1><%= @article.title %></h1>
</p>
<p>
  Posted by:
  <strong><%= current_user.email%></strong>
</p>
<p>
  On<%= @article.created_at.strftime("%B %d %Y, %l:%M%P") %>
</p>
<p>
  <h4><%= @article.text %></h4>
</p>

After a good time spent searching how to do this online, I thought it would be helpful to write a blog post about it.

I am building a message board using rails and I wanted to add the date/time a post was created on the site. E.g. when a user creates a new post, the date and time that post was entered into the database should show on the page.

To do this we can use a rails built-in method called “created_at”. In the above example I have a snapshot of my codebase in the show.html.erb file. In order to show the date/time created I called the “created_at” method on an instance of my @article class which contains all of the posts for each user. However, this will output...

Continue reading →


List of sublime text shortcuts, tips and tricks

I started using sublime text over the past couple months (RIP textmate) and it’s been awesome so far. I wanted to create a short list of the shortcuts, tips and tricks that I’ve found most useful:

Files
cmd+p — Go to Anything
cmd+ctrl+p — Switch Project

Codes
cmd+shift+d — Duplicate Line
ctrl+enter — Insert line after
ctrl+shift+enter — Insert line before
cmd+l — Expand Selection to Line
ctrl+shift+w — Wrap Selection with Tag
ctrl+r — Go to symbols (finding methods)

Multi Edits
ctrl+d — Select the current word and the next same word
ctrl+click — Every place you click will create a cursor to edit
ctrl+shift+f AND alt+enter — Find a word in your files and then select them all
ctrl+] — Indent
ctrl+[ — Unindent
Ctrl+Shift+UP — Move lines up
Ctrl+Shift+Down — Move lines down

Multi Selection
To enable multi-selection, you have several options:

Alt or Command — then click in each region
...

Continue reading →