Created
February 20, 2012 08:18
-
-
Save DouglasAllen/1868386 to your computer and use it in GitHub Desktop.
Some debugging techniques that I'm learning to use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby | |
# a neat trick to block with. | |
=begin | |
[code ruby] | |
It never hurts to document your code | |
vars | |
a_word = "" # a nill string | |
words = [] # an empty array for input and sorting | |
words2 = [] # an empty array for output and sorting | |
j = 0 # inner iterater counter | |
b=word = '' # was used but not now | |
i = 0 # outter iterator | |
[code] | |
=end | |
#~ puts "Type your word and then press <Enter>. When finished just press <Enter>." | |
puts "debug line 17 #{words = []}" | |
#~ a_word = "" | |
#~ while a_word != "" | |
#~ a_word = gets.chomp | |
#~ if a_word != "" | |
#~ words.push a_word | |
#~ i = i + 1 | |
#~ end | |
#~ end | |
#~ puts i # nill? okay, we're out of scope range. | |
#~ # what if i = nill? | |
#~ words = [] | |
words = %w( ant bat cat dog about dot com ruby loops) | |
i = words.length | |
puts "debug line 33 #{i}" | |
words2 = [] | |
puts "debug line 37 #{words}" | |
until i == words2.length | |
a_word = words[0] | |
@sort_index = 0 | |
#=begin | |
# not yet working, why? | |
for j in 0..i | |
puts "debug line 48 #{words[j]}" | |
puts "debug line 49 #{a_word}" | |
if a_word > words[j] # compare the two words | |
a_word = words[j] | |
@a_index = j | |
puts "debug line 54 #{@sort_index}" | |
end | |
end | |
#=end | |
puts "debug line 59 #{@sort_index}" | |
words2.push a_word # push smallest word onto new array | |
words.delete_at(@sort_index) # delete the lowest element in the original array | |
end | |
puts "debug line 64 #{words2}" | |
=begin | |
this is my test run | |
kb9agt@mepis1:~/Documents$ ./ok_scope | |
debug line 17 [] | |
debug line 33 7 | |
debug line 37 ["ant", "bat", "cat", "dog", "about", "dot", "com"] | |
debug line 48 ant | |
debug line 49 ant | |
debug line 48 bat | |
debug line 49 ant | |
debug line 48 cat | |
debug line 49 ant | |
debug line 48 dog | |
debug line 49 ant | |
debug line 48 about | |
debug line 49 ant | |
debug line 54 0 | |
debug line 48 dot | |
debug line 49 about | |
debug line 48 com | |
debug line 49 about | |
debug line 48 | |
debug line 49 about | |
./ok_scope:51:in `>': comparison of String with nil failed (ArgumentError) | |
from ./ok_scope:51:in `block in <main>' | |
from ./ok_scope:46:in `each' | |
from ./ok_scope:46:in `<main>' | |
kb9agt@mepis1:~/Documents$ | |
=end |
Author
DouglasAllen
commented
Feb 21, 2012
via email
I added a few words to list just for fun ['ruby', 'ant', 'bat',
'loops', 'cat', 'grep', 'dog', 'about', 'dot', 'com']
Good job.
No for loops here.
It flows like a Rubyistic Expression Model.
[code ruby]
=begin On Tue, Feb 21, 2012 at 3:14 AM, EdwinRozario
reply@reply.github.com
wrote:
=end
# require 'anything?'
words_unsorted = ['ant', 'bat', 'cat', 'dog', 'about', 'dot', 'com']
words_sorted = []
def get_the_least_word(list)
mark = list[0]
list.each do |word|
mark = word if word < mark
end
return mark
end
while true
break if words_unsorted.length == 0
least = get_the_least_word(words_unsorted)
words_unsorted.delete(least)
words_sorted << least
end
puts words_sorted
=begin
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1868386
Now I challenge you to display the output in json.
=end
[/code]
require 'json'
words_unsorted = ['ant', 'bat', 'cat', 'dog', 'about', 'dot', 'com']
words_sorted = []
def get_the_least_word(list)
mark = list[0]
list.each do |word|
mark = word if word < mark
end
return mark
end
while true
break if words_unsorted.length == 0
least = get_the_least_word(words_unsorted)
words_unsorted.delete(least)
words_sorted << least
end
json_data = JSON.generate(words_sorted)
puts json_data
I owe you these links that we chatted about.
here:
https://gist.github.com/1877086
plus one:
http://rubycms.org/
You should put the link for the gem at rubygem.org in your read me and maybe an
example of how to use it in a folder called example. That could help
you get some
usage. Great looking I'm just not sure how to use it. Help!
Yes you are right.
I asked about the Documentation for the gem to Victor. Need to do rdoc or
Yard. I need to learn it. If you check out the homepage in
https://rubygems.org/gems/rubykeyword you can find my README in GitHub.
Anyways our course dosent cover the documentation part.
On Thu, Feb 23, 2012 at 1:26 PM, Douglas Allen < ***@***.*** > wrote:
You should put the link for the gem at rubygem.org in your read me and
maybe an
example of how to use it in a folder called example. That could help
you get some
usage. Great looking I'm just not sure how to use it. Help!
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1868386
##
Edwin.A.Rozario
Software Engineer - Production & Telephony
MobME Wireless Solutions Pvt. Ltd.
What day are you one Edwin? I only mean for us github folks who find
that readme and know how access your folder for viewing. Don't you
know that I could just copy and paste your code if I wanted to. You
asked me to test it remember? I'm only on day 5 and am a ruby core
drop out. Not dead yet.
lol
Just an old wanna be geek but I learned some things the hard way.
see you in ircx
Hi Douglas
```
Remember i told you about the colorize gem. Its about 200 lines of
```
code. The same thing can be done in Python with just over 25 lines of code.
http://edwinrozario.posterous.com/python-colour-printing
On Fri, Feb 24, 2012 at 6:05 AM, Douglas Allen < ***@***.*** > wrote:
What day are you one Edwin? I only mean for us github folks who find
that readme and know how access your folder for viewing. Don't you
know that I could just copy and paste your code if I wanted to. You
asked me to test it remember? I'm only on day 5 and am a ruby core
drop out. Not dead yet.
lol
Just an old wanna be geek but I learned some things the hard way.
see you in ircx
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1868386
##
Edwin.A.Rozario
Software Engineer - Production & Telephony
MobME Wireless Solutions Pvt. Ltd.
## LinkedIn
I'd like to add you to my professional network on LinkedIn.
- Douglas
Douglas Allen
Independent Consumer Electronics Professional
Greater Chicago Area
Confirm that you know Douglas Allen:
https://www.linkedin.com/e/952q9f-gz1no2z6-5n/isd/6057559138/WrtNDWzT/?hs=false&tok=03eHZSm33WgR81
##
You are receiving Invitation to Connect emails. Click to unsubscribe:
http://www.linkedin.com/e/952q9f-gz1no2z6-5n/C5Eg2Q8O1DXKgMRSCPkbTc2ZEbIN-CWWhemfnqhvYbGRR10cAeQDU_JwYzr-gCUfUeh9UmCr3mO9R1URUZkbGs1HEQ61cJWxp5teLHjoPs2l13xv/goo/reply%2Bg-1868386-ce0c45c6a311123a05d00b492185a8cf6ab48f59-887598%40reply%2Egithub%2Ecom/20061/I2105260250_1/?hs=false&tok=3-PDZFtIfWgR81
(c) 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.
Thanks Edwin,
See you in class. We may talk Python in the chat or here though.
I have Python on this system. Just not real familiar with Python.
Have you ever used SciTE?
The first thing you will see on the web site
http://www.scintilla.org/SciTEDoc.html
is a python run and I also have scite installed as it is a handy
little text editor.
I also have http://eric-ide.python-projects.org/ but it is complex to
install in a system without the prepackaged modules like debian or
ubuntu has. /*.deb that is.
Have you ever written debian packages before. They like to keep that
debian.org up to date as much as possible but any packages have to get
approved for posting to the distro. But they do have testing distr'o's
in beta.
Good [code ruby] Coding [/code]
P.S. Are you the guy I chatted with about organizing bookmarks?
Take a look at this:https://www.google.com/search?q=how+to+organize+your+bookmarks&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a#q=how+to+organize+your+bookmarks&hl=en&safe=off&client=firefox-a&hs=JuO&rls=org.mozilla:en-US:official&prmd=imvns&tbo=u&sa=X&psj=1&ei=lAdIT6SXIPGpsAKu9ZzrCA&ved=0CIYBEM0V&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=239ed407df9948f7&biw=1024&bih=619
I get 3,230,000 hits.
We sure could use a simple program hint hint.
No i am not the guy. Well dont you too much worry about the editor.
Use whatever is available to you. For python i used Geany.
On Sat, Feb 25, 2012 at 3:33 AM, Douglas Allen < ***@***.*** > wrote:
P.S. Are you the guy I chatted with about organizing bookmarks?
Take a look at this:
https://www.google.com/search?q=how+to+organize+your+bookmarks&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a#q=how+to+organize+your+bookmarks&hl=en&safe=off&client=firefox-a&hs=JuO&rls=org.mozilla:en-US:official&prmd=imvns&tbo=u&sa=X&psj=1&ei=lAdIT6SXIPGpsAKu9ZzrCA&ved=0CIYBEM0V&bav=on.2,or.r_gc.r_pw.r_cp.r_qf
.,cf.osb&fp=239ed407df9948f7&biw=1024&bih=619
I get 3,230,000 hits.
We sure could use a simple program hint hint.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1868386
##
Edwin.A.Rozario
Software Engineer - Production & Telephony
MobME Wireless Solutions Pvt. Ltd.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment