-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
1082 lines (814 loc) · 72.8 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Screw diamonds. Ruby is a girl's best friend.]]></title>
<link href="http://www.innatewonderer.github.com/atom.xml" rel="self"/>
<link href="http://www.innatewonderer.github.com/"/>
<updated>2013-03-08T00:44:47-05:00</updated>
<id>http://www.innatewonderer.github.com/</id>
<author>
<name><![CDATA[Jenya Zueva]]></name>
<email><![CDATA[jzueva@gmail.com]]></email>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Sorting Hash Values]]></title>
<link href="http://www.innatewonderer.github.com/blog/sorting-hash-values/"/>
<updated>2013-02-23T18:07:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/sorting-hash-values</id>
<content type="html"><![CDATA[<p>Have a huge <code>Array</code> of hashed and need to find how many times the same event occur?</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">h</span> <span class="o">=</span> <span class="o">[</span> <span class="p">{</span><span class="s2">"a"</span> <span class="o">=></span> <span class="mi">10</span><span class="p">},</span> <span class="p">{</span><span class="s2">"b"</span> <span class="o">=></span> <span class="mi">20</span><span class="p">},</span> <span class="p">{</span><span class="s2">"a"</span> <span class="o">=></span> <span class="mi">10</span><span class="p">},</span> <span class="p">{</span><span class="s2">"b"</span> <span class="o">=></span> <span class="mi">20</span><span class="p">},</span> <span class="p">{</span><span class="s2">"c"</span> <span class="o">=></span> <span class="mi">30</span><span class="p">},</span> <span class="p">{</span><span class="s2">"a"</span> <span class="o">=></span> <span class="mi">10</span><span class="p">}</span> <span class="o">]</span>
</span><span class='line'><span class="n">count_h</span> <span class="o">=</span> <span class="n">h</span><span class="o">.</span><span class="n">inject</span><span class="p">(</span><span class="no">Hash</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="mi">0</span><span class="p">)){</span> <span class="o">|</span><span class="nb">hash</span><span class="p">,</span> <span class="n">i</span><span class="o">|</span> <span class="nb">hash</span><span class="o">[</span><span class="n">i</span><span class="o">]</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span> <span class="nb">hash</span> <span class="p">}</span>
</span><span class='line'><span class="nb">puts</span> <span class="n">h</span> <span class="c1">#=> {{"a"=>10}=>3, {"b"=>20}=>2, {"c"=>30}=>1} </span>
</span></code></pre></td></tr></table></div></figure>
<p>Looking for awesome ways to sort <code>Hash</code> by its values?</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">h</span> <span class="o">=</span> <span class="p">{{</span><span class="s2">"a"</span><span class="o">=></span><span class="mi">10</span><span class="p">}</span><span class="o">=></span><span class="mi">3</span><span class="p">,</span> <span class="p">{</span><span class="s2">"c"</span><span class="o">=></span><span class="mi">30</span><span class="p">}</span><span class="o">=></span><span class="mi">1</span><span class="p">,</span> <span class="p">{</span><span class="s2">"b"</span><span class="o">=></span><span class="mi">20</span><span class="p">}</span><span class="o">=></span><span class="mi">2</span><span class="p">}</span>
</span><span class='line'><span class="no">Hash</span><span class="o">[</span><span class="n">h</span><span class="o">.</span><span class="n">sort_by</span> <span class="p">{</span><span class="o">|</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="o">|</span> <span class="o">-</span><span class="n">value</span> <span class="p">}</span><span class="o">]</span> <span class="c1">#=> will sort in descending order</span>
</span><span class='line'><span class="nb">p</span> <span class="n">h</span> <span class="c1">#=> {{"a"=>10}=>3, {"b"=>20}=>2, {"c"=>30}=>1} </span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Bash and zsh]]></title>
<link href="http://www.innatewonderer.github.com/blog/bash-and-zsh/"/>
<updated>2013-02-22T19:24:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/bash-and-zsh</id>
<content type="html"><![CDATA[<p>As I’ve been struggling with setting up my new Mac to be proper RoR utility I need it to be, I can across <a href="https://github.com/thoughtbot/laptop">Laptop</a> script that took care of most installation work for me. It did prompt me to switch to <codde>zsh</code>.</p>
<p>For reasons yet unknown to me, <code>zsh</code> doesn’t follow instructions in <code>.bash_profile</code>. And I like my aliases and prompt line settings, so I’m going to switch it back to <code>bash</code></p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>exec bash</span></code></pre></td></tr></table></div></figure>
<p>When I figure out what is the power of <code>zsh</code> and would like to switch back to it:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>exec zsh</span></code></pre></td></tr></table></div></figure>
<p>To set <code>bash</code> back as a default login shell</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>chsh -s /bin/bash</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Ruby exercise 1: Triangle of numbers]]></title>
<link href="http://www.innatewonderer.github.com/blog/ruby-exercise-1-triangle-of-numbers/"/>
<updated>2013-02-22T17:02:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/ruby-exercise-1-triangle-of-numbers</id>
<content type="html"><![CDATA[<p>Fun exercise that will allow you to practice iteration and loops as well as look into <a href="http://www.ruby-doc.org/core-1.9.3/ARGF.html">ARGV</a> in Ruby. I will include my detailed logic how I came to resolve this issue because I find it most helpful when learning new concepts in any language to see all nuts and bolts that went into it.</p>
<p>Assignment:<br/>
Create an application that will take a number in Terminal and output the same number of lines with the same number of digits in each line. Note: elements continue to grow in order.</p>
<p>Enter in terminal:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="err">$</span> <span class="n">ruby</span> <span class="n">triangle</span><span class="o">.</span><span class="n">rb</span> <span class="mi">4</span>
</span></code></pre></td></tr></table></div></figure>
<p>Expected result:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="mi">1</span>
</span><span class='line'><span class="mi">2</span> <span class="mi">3</span>
</span><span class='line'><span class="mi">4</span> <span class="mi">5</span> <span class="mi">6</span>
</span><span class='line'><span class="mi">7</span> <span class="mi">8</span> <span class="mi">9</span> <span class="mi">10</span>
</span></code></pre></td></tr></table></div></figure>
<!-- more -->
<p>If you don’t need a full step-by-step explanation of this exercise, please scroll to the bottom of this page for final solution.</p>
<p>Being yet a newbie, I quickly have found myself struggling with logic of this application. Obviously, you need to loop through the numbers but where do you ensure that the first element of the next line is the next element in the original array.</p>
<p>Quick sketch on paper and it becomes visible that we are dealing with two elements:
One (we’ll call it <code>number</code>) is responsible for line number and number of displayed elements. And another one (<code>order</code>) that is responsible for the location of the next element that will be displayed.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1">#1 // 1</span>
</span><span class='line'><span class="c1">#2 // 2 3</span>
</span><span class='line'><span class="c1">#3 // 4 5 6</span>
</span><span class='line'><span class="c1">#4 // 7 8 9 10</span>
</span></code></pre></td></tr></table></div></figure>
<p>We are working with an <code>array[1, 2, 3, 4, 5, 6, 7 .. n]</code> or<code>array[1..n]</code>. Keeping in mind that we start counting elements in an array from 0, let’s quickly write the logic:</p>
<p>When we need to show one number on first row: <code>number = 1</code>, position of this element <code>order = 0</code><br/>
Second row, two numbers, <code>number = 2</code>, position in an array <code>order = 1</code><br/>
Third row, three numbers, <code>number = 3</code>, <code>order = 3</code><br/>
Fourth row, four number, <code>number = 4</code>, <code>order = 6</code></p>
<p>It becomes a little more clear that in order to find our next order element we need to add the value of the number to previous order element.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># we have to set default value for order</span>
</span><span class='line'><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.n</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">number</span><span class="o">|</span>
</span><span class='line'> <span class="n">number</span> <span class="c1"># number will grow continuously from 1 to finite number n</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'><span class="n">order</span> <span class="o">+=</span> <span class="n">number</span> <span class="c1"># order will grow proportionally to the increase in value of number </span>
</span></code></pre></td></tr></table></div></figure>
<p>Great.<br/>
Now, let’s look into <a href="http://www.ruby-doc.org/core-1.9.3/ARGF.html">ARGV</a>. We can pass arguments to our ruby program from command line of our terminal. Will look something like this:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="err">$</span> <span class="n">ruby</span> <span class="n">triangle</span><span class="o">.</span><span class="n">rb</span> <span class="mi">4</span>
</span></code></pre></td></tr></table></div></figure>
<p>We are asking our terminal to run file <code>triangle.rb</code> with <code>ruby</code> while passing the value <code>4</code> to the application. ARGV’s responsibility is to accept given arguments and make them available within our application.<br/>
Your goal is to provide a place for these values and ensure its correct format.</p>
<p>While testing the format of my argument, I found that 4 came into the application as an <code>Array</code> and I needed it to be an <code>Integer</code> so I could use it to set the limit of my array. There is no easy way to turn array to an integer(please leave comments if you have any suggestions), for the purpose of simplicity and my sanity:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">limit</span> <span class="o">=</span> <span class="no">ARGV</span><span class="o">[</span><span class="mi">0</span><span class="o">].</span><span class="n">to_i</span>
</span></code></pre></td></tr></table></div></figure>
<p>This took an array of arguments that were passed from the terminal, picked the first value and turned it into an integer while saving it in a variable <code>limit</code> for future use.</p>
<p>Final solution:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">array</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="mi">100000</span><span class="p">)</span><span class="o">.</span><span class="n">to_a</span>
</span><span class='line'><span class="n">order</span> <span class="o">=</span> <span class="mi">1</span>
</span><span class='line'><span class="n">limit</span> <span class="o">=</span> <span class="no">ARGV</span><span class="o">[</span><span class="mi">0</span><span class="o">].</span><span class="n">to_i</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.limit</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">number</span><span class="o">|</span>
</span><span class='line'> <span class="n">array</span><span class="o">[</span><span class="n">order</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">number</span><span class="o">].</span><span class="n">each</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="nb">print</span> <span class="s2">"</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2"> "</span> <span class="p">}</span> <span class="c1"># will print it in line</span>
</span><span class='line'> <span class="n">order</span> <span class="o">+=</span> <span class="n">number</span>
</span><span class='line'> <span class="nb">puts</span> <span class="c1"># will print a break between your lines </span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>P.S. Note to anyone (and my future self) whoever laughs at how long it took me to solve this: <strong>@#%&@#<em>$@#%</em>@#</strong> you!</p>
<p>Now, that ARGV finally makes sense, I’m going to work on another interview exercise for one really awesome company in DC. As I was told on my first day <a href="www.flatironschool.com">@Flatironschool</a>, <strong>“It will all make sense one day”</strong></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Organize your development folder]]></title>
<link href="http://www.innatewonderer.github.com/blog/organize-your-development-folder/"/>
<updated>2013-01-22T12:43:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/organize-your-development-folder</id>
<content type="html"><![CDATA[<p>While setting up my new Mac, I came to the task of rebuilding my development folder. Most developers will find what works for them. I’m going to provide a list that I am starting with for you to use at your discretion.</p>
<!-- more -->
<h2>Recommended subfolders (by <a href="https://twitter.com/aviflombaum">Avi Flombaum</a>)</h2>
<ul>
<li>books</li>
<li>code</li>
<li>data</li>
<li>designs</li>
<li>Email Templates</li>
<li>framework</li>
<li>gawker</li>
<li>opensource</li>
<li>projects</li>
<li>resource (icons, fonts)</li>
<li>scripts</li>
<li>source</li>
<li>themes</li>
</ul>
<h2>Additional folders:</h2>
<ul>
<li>keynote presentaions</li>
<li>octopress blog</li>
<li>tuitorials</li>
</ul>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Testing Tools in Rails Application Development]]></title>
<link href="http://www.innatewonderer.github.com/blog/test-your-way-through-app-development/"/>
<updated>2012-11-29T16:41:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/test-your-way-through-app-development</id>
<content type="html"><![CDATA[<p>Did you ever wake up and thought “Today, I’m going to write the entire app in one attempt”? How did it go for you?</p>
<p>One of the hardest thing for me while learning coding was to understand what my lines of code actually do. I would write ten lines of code only to see it do nothing, and have no idea where to start debugging it. I would assume my entire logic was incorrect, erase it all only to find out later that I used <code>.each</code> instead of <code>.map</code>.</p>
<!-- more -->
<p>My biggest AHA moment was to discover tools available to test what my code does as I develop my functionalities. Let’s take a look at few examples I cannot imagine my day without.</p>
<h3>Use Irb to Master Ruby</h3>
<p>Run <code>irb</code> in your console to access Interactive Ruby console. Can’t figure out if you need to use <code>.map</code> or <code>.each</code> Test it.</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="o">[</span><span class="mi">17</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mo">06</span><span class="o">]</span> <span class="p">(</span><span class="n">master</span><span class="p">)</span> <span class="n">brainpickings</span><span class="o">-</span><span class="n">scraper</span>
</span><span class='line'><span class="err">$</span> <span class="n">irb</span>
</span><span class='line'><span class="mo">001</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="n">var</span> <span class="o">=</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span>
</span><span class='line'><span class="o">=></span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span>
</span><span class='line'><span class="mo">002</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="n">var</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">i</span><span class="o">+</span><span class="n">i</span><span class="p">}</span>
</span><span class='line'><span class="o">=></span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span>
</span><span class='line'><span class="mo">003</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="n">var</span><span class="o">.</span><span class="n">map</span> <span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">i</span><span class="o">+</span><span class="n">i</span><span class="p">}</span>
</span><span class='line'><span class="o">=></span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>
<p>Ohhh, now it makes sense. My <code>.each</code> returns the original value, and <code>.map</code> returns the outcome. Easy!</p>
<h3>“Puts” in Ruby</h3>
<p>Nokogiri scraper goes through the page and collects values that you can store in the database for later use in the application. Simplified version of my personal scraper project looked like this:</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="nb">require</span> <span class="s1">'nokogiri'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'open-uri'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'sqlite3'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'FileUtils'</span>
</span><span class='line'>
</span><span class='line'><span class="no">FileUtils</span><span class="o">.</span><span class="n">rm</span><span class="p">(</span><span class="s2">"books.db"</span><span class="p">)</span> <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="s2">"books.db"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">db</span> <span class="o">=</span> <span class="ss">SQLite3</span><span class="p">:</span><span class="ss">:Database</span><span class="o">.</span><span class="n">new</span> <span class="s2">"books.db"</span>
</span><span class='line'>
</span><span class='line'><span class="n">db</span><span class="o">.</span><span class="n">execute</span> <span class="o"><<-</span><span class="no">SQL</span>
</span><span class='line'><span class="sh"> CREATE TABLE books (</span>
</span><span class='line'><span class="sh"> id INTEGER PRIMARY KEY,</span>
</span><span class='line'><span class="sh"> title TEXT,</span>
</span><span class='line'><span class="sh"> );</span>
</span><span class='line'><span class="no">SQL</span>
</span><span class='line'>
</span><span class='line'><span class="n">books_url</span> <span class="o">=</span> <span class="s2">"http://bookpickings.brainpickings.org/"</span>
</span><span class='line'><span class="n">doc</span> <span class="o">=</span> <span class="ss">Nokogiri</span><span class="p">:</span><span class="ss">:HTML</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">books_url</span><span class="p">))</span>
</span><span class='line'><span class="n">books</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">css</span><span class="p">(</span><span class="s2">".photo"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">books</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">book</span><span class="o">|</span>
</span><span class='line'> <span class="n">title</span> <span class="o">=</span> <span class="n">book</span><span class="o">.</span><span class="n">at_css</span><span class="p">(</span><span class="s2">".post_title h1"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="n">db</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">"INSERT INTO books (title) </span>
</span><span class='line'><span class="s2"> VALUES (?)"</span><span class="p">,</span> <span class="n">title</span><span class="p">)</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>Run this file in your Console to see the result:</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="o">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">47</span><span class="p">:</span><span class="mi">26</span><span class="o">]</span> <span class="p">(</span><span class="n">updated</span><span class="p">)</span> <span class="n">bookshelf</span><span class="o">-</span><span class="n">static</span>
</span><span class='line'><span class="err">$</span> <span class="n">ruby</span> <span class="n">brainpickings</span><span class="o">-</span><span class="n">scraper</span><span class="o">.</span><span class="n">rb</span>
</span></code></pre></td></tr></table></div></figure>
<p>It might or might NOT show lines that look like this:</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby]</span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="sr">/Users/</span><span class="n">jenya</span><span class="o">/.</span><span class="n">rvm</span><span class="o">/</span><span class="n">gems</span><span class="o">/</span><span class="n">ruby</span><span class="o">-</span><span class="mi">1</span><span class="o">.</span><span class="mi">9</span><span class="o">.</span><span class="mi">3</span><span class="o">-</span><span class="n">p194</span><span class="o">/</span><span class="n">gems</span><span class="o">/</span><span class="n">sqlite3</span><span class="o">-</span><span class="mi">1</span><span class="o">.</span><span class="mi">3</span><span class="o">.</span><span class="mi">6</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">sqlite3</span><span class="o">/</span><span class="n">statement</span><span class="o">.</span><span class="n">rb</span><span class="p">:</span><span class="mi">41</span><span class="ss">:in</span> <span class="sb">`bind_param': can't prepare Nokogiri::XML::Element (RuntimeError)</span>
</span><span class='line'><span class="sb"> 5/lib/nokogiri/xml/node_set.rb:238:in `</span><span class="n">each</span><span class="s1">'</span>
</span><span class='line'><span class="s1"> from brainpickings-scraper.rb:25:in `<main>'</span>
</span></code></pre></td></tr></table></div></figure>
<p>We got an error. (Surprised? Don’t be). Let’s start debugging.
I’m going to comment out the call to the database and ask <code>ruby</code> to print the value of <code>title</code> on the screen.</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="n">books_url</span> <span class="o">=</span> <span class="s2">"http://bookpickings.brainpickings.org/"</span>
</span><span class='line'><span class="n">doc</span> <span class="o">=</span> <span class="ss">Nokogiri</span><span class="p">:</span><span class="ss">:HTML</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">books_url</span><span class="p">))</span>
</span><span class='line'><span class="nb">puts</span>
</span><span class='line'><span class="n">books</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">book</span><span class="o">|</span>
</span><span class='line'> <span class="nb">puts</span> <span class="n">title</span> <span class="o">=</span> <span class="n">book</span><span class="o">.</span><span class="n">at_css</span><span class="p">(</span><span class="s2">".post_title h1"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># db.execute("INSERT INTO books (title) </span>
</span><span class='line'><span class="c1"># VALUES (?)", title)</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>This will return:</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="o"><</span><span class="n">h1</span><span class="o">></span><span class="ss">Sketchbooks</span><span class="p">:</span> <span class="no">The</span> <span class="no">Hidden</span> <span class="no">Art</span> <span class="n">of</span> <span class="no">Designers</span><span class="p">,</span> <span class="no">Illustrators</span><span class="p">,</span> <span class="ow">and</span> <span class="no">Creatives</span><span class="o"><</span><span class="sr">/h1></span>
</span></code></pre></td></tr></table></div></figure>
<p>What does this tell us? <strong>Too much information!!!</strong> Let’s refactor our code to only return the text from the <code>title</code> tag.</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="n">books_url</span> <span class="o">=</span> <span class="s2">"http://bookpickings.brainpickings.org/"</span>
</span><span class='line'><span class="n">doc</span> <span class="o">=</span> <span class="ss">Nokogiri</span><span class="p">:</span><span class="ss">:HTML</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">books_url</span><span class="p">))</span>
</span><span class='line'><span class="nb">puts</span>
</span><span class='line'><span class="n">books</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">book</span><span class="o">|</span>
</span><span class='line'> <span class="n">title</span> <span class="o">=</span> <span class="n">book</span><span class="o">.</span><span class="n">at_css</span><span class="p">(</span><span class="s2">".post_title h1"</span><span class="p">)</span><span class="o">.</span><span class="n">text</span>
</span><span class='line'>
</span><span class='line'> <span class="n">db</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">"INSERT INTO books (title) </span>
</span><span class='line'><span class="s2"> VALUES (?)"</span><span class="p">,</span> <span class="n">title</span><span class="p">)</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>Fantastic. This works. Database is populated.</p>
<h3>Rails C in Rails Environment</h3>
<p>Consider these two methods:</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="k">def</span> <span class="nf">cached_repos</span>
</span><span class='line'> <span class="n">cache</span><span class="o">[</span><span class="ss">:repos</span><span class="o">]</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">repos_not_on_gitbo</span>
</span><span class='line'> <span class="n">cache</span><span class="o">[</span><span class="ss">:repos</span><span class="o">].</span><span class="n">select</span> <span class="k">do</span> <span class="o">|</span><span class="n">repo_name</span><span class="o">|</span>
</span><span class='line'> <span class="kp">true</span> <span class="k">unless</span> <span class="no">Repo</span><span class="o">.</span><span class="n">find_by_owner_name_and_name</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">nickname</span><span class="p">,</span> <span class="n">repo_name</span><span class="p">)</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>One will show you all of the repos available, the other will only show repos that do not already belong to the user. How can I make sure that this method works correctly? Fire <code>rails c</code> in your <strong>active application folder</strong> and test it.</p>
<figure class='code'><figcaption><span>[brainpickings-scraper.rb] [lang: Ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="o">[</span><span class="mi">17</span><span class="p">:</span><span class="mi">26</span><span class="p">:</span><span class="mi">28</span><span class="o">]</span> <span class="p">(</span><span class="n">master</span><span class="p">)</span> <span class="n">gitbo</span>
</span><span class='line'><span class="err">$</span> <span class="n">rails</span> <span class="n">c</span>
</span><span class='line'> <span class="no">Loading</span> <span class="n">development</span> <span class="n">environment</span> <span class="p">(</span><span class="no">Rails</span> <span class="mi">3</span><span class="o">.</span><span class="mi">2</span><span class="o">.</span><span class="mi">8</span><span class="p">)</span>
</span><span class='line'><span class="mo">001</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="c1">#check all available attributes for Repo</span>
</span><span class='line'><span class="sc">?></span> <span class="no">Repo</span><span class="o">.</span><span class="n">first</span>
</span><span class='line'> <span class="no">SCHEMA</span> <span class="p">(</span><span class="mi">6</span><span class="o">.</span><span class="mi">8</span><span class="n">ms</span><span class="p">)</span> <span class="no">PRAGMA</span> <span class="n">table_info</span><span class="p">(</span><span class="s2">"repos"</span><span class="p">)</span>
</span><span class='line'> <span class="no">SCHEMA</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">2</span><span class="n">ms</span><span class="p">)</span> <span class="no">SELECT</span> <span class="nb">name</span> <span class="no">FROM</span> <span class="n">sqlite_master</span> <span class="no">WHERE</span> <span class="n">type</span> <span class="o">=</span> <span class="s1">'table'</span> <span class="no">AND</span> <span class="no">NOT</span> <span class="nb">name</span> <span class="o">=</span> <span class="s1">'sqlite_sequence'</span> <span class="no">AND</span> <span class="nb">name</span> <span class="o">=</span> <span class="s2">"repos"</span>
</span><span class='line'> <span class="no">SCHEMA</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">2</span><span class="n">ms</span><span class="p">)</span> <span class="no">PRAGMA</span> <span class="n">table_info</span><span class="p">(</span><span class="s2">"repos"</span><span class="p">)</span>
</span><span class='line'> <span class="no">Repo</span> <span class="no">Load</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">2</span><span class="n">ms</span><span class="p">)</span> <span class="no">SELECT</span> <span class="s2">"repos"</span><span class="o">.</span><span class="n">*</span> <span class="no">FROM</span> <span class="s2">"repos"</span> <span class="no">LIMIT</span> <span class="mi">1</span>
</span><span class='line'> <span class="no">Repo</span> <span class="no">Load</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">2</span><span class="n">ms</span><span class="p">)</span> <span class="no">SELECT</span> <span class="s2">"repos"</span><span class="o">.</span><span class="n">*</span> <span class="no">FROM</span> <span class="s2">"repos"</span> <span class="no">LIMIT</span> <span class="mi">1</span>
</span><span class='line'><span class="o">=></span> <span class="c1">#<Repo id: 17, name: "omniauth", owner_name: "intridea", description: nil, watchers: 3450, open_issues: 26, created_at: "2012-11-16 21:45:21", updated_at: "2012-11-19 16:04:48", slug: "omniauth", git_updated_at: "2012-11-19 13:37:13"></span>
</span><span class='line'><span class="mo">003</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="c1">#test method</span>
</span><span class='line'><span class="sc">?></span> <span class="no">Repo</span><span class="o">.</span><span class="n">find_by_owner_name_and_name</span><span class="p">(</span><span class="s2">"innatewonderer"</span><span class="p">,</span> <span class="s2">"Test-Repo-for-Gitbo"</span><span class="p">)</span>
</span><span class='line'> <span class="no">Repo</span> <span class="no">Load</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">3</span><span class="n">ms</span><span class="p">)</span> <span class="no">SELECT</span> <span class="s2">"repos"</span><span class="o">.</span><span class="n">*</span> <span class="no">FROM</span> <span class="s2">"repos"</span> <span class="no">WHERE</span> <span class="s2">"repos"</span><span class="o">.</span><span class="s2">"owner_name"</span> <span class="o">=</span> <span class="s1">'innatewonderer'</span> <span class="no">AND</span> <span class="s2">"repos"</span><span class="o">.</span><span class="s2">"name"</span> <span class="o">=</span> <span class="s1">'Test-Repo-for-Gitbo'</span> <span class="no">LIMIT</span> <span class="mi">1</span>
</span><span class='line'> <span class="no">Repo</span> <span class="no">Load</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mi">3</span><span class="n">ms</span><span class="p">)</span> <span class="no">SELECT</span> <span class="s2">"repos"</span><span class="o">.</span><span class="n">*</span> <span class="no">FROM</span> <span class="s2">"repos"</span> <span class="no">WHERE</span> <span class="s2">"repos"</span><span class="o">.</span><span class="s2">"owner_name"</span> <span class="o">=</span> <span class="s1">'innatewonderer'</span> <span class="no">AND</span> <span class="s2">"repos"</span><span class="o">.</span><span class="s2">"name"</span> <span class="o">=</span> <span class="s1">'Test-Repo-for-Gitbo'</span> <span class="no">LIMIT</span> <span class="mi">1</span>
</span><span class='line'><span class="o">=></span> <span class="c1">#<Repo id: 22, name: "Test-Repo-for-Gitbo", owner_name: "innatewonderer", description: nil, watchers: 0, open_issues: 2, created_at: "2012-11-16 21:52:15", updated_at: "2012-11-18 16:16:16", slug: "test-repo-for-gitbo", git_updated_at: "2012-11-16 16:10:46"></span>
</span><span class='line'><span class="mo">005</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="c1">#SUCCESS</span>
</span></code></pre></td></tr></table></div></figure>
<h3>‘Inspect Element’ in Chrome</h3>
<p>Chrome offers several nifty features that make developer’s life easier. Right-click on the element => ‘Inspect Element’ or Command+Shift+c will bring up Developer Tools window on the bottom of the screen. <a href="https://developers.google.com/chrome-developer-tools/docs/console"><code>Console Tab</code></a> can be used to inspect the DOM, debug JavaScript or analyze HTML parse errors.</p>
<p>Remember the example I displayed at the beginning of this post in my Nokogiri project?</p>
<p><img src="http://www.innatewonderer.github.com/images/bookpickings.jpg"></p>
<p>Looks familiar?</p>
<p>Be smart and seek out helper tools to do your work efficiently.<br/>
Test lines your don’t understand.<br/>
Test methods you just created.<br/>
PLEASE, Work off a separate branch.<br/>
Test your commits.<br/>
Enjoy it :)</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Upstream and update]]></title>
<link href="http://www.innatewonderer.github.com/blog/upstream-and-update/"/>
<updated>2012-11-07T17:49:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/upstream-and-update</id>
<content type="html"><![CDATA[<p>You forked something, cloned it to your machine, but didn’t setup remote connection to the origin repository.</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>git remote add upstream *url to original repository*
</span><span class='line'>git fetch upstream
</span><span class='line'>git merge upstream/master</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Decode Object Oriented Design]]></title>
<link href="http://www.innatewonderer.github.com/blog/decode-object-oriented-design-easier/"/>
<updated>2012-11-07T10:10:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/decode-object-oriented-design-easier</id>
<content type="html"><![CDATA[<!-- Instead of writing a post and then finding a good title, I am going to commit to finding at least five facts that will make OOD clear for me... As long as it takes :) -->
<p>OOD has been around since mid 60’s. The concept didn’t really pick up untill early 90’s with C++. It’s receiving a lot of attention in Rails/Ruby community as well. The concept might appear hard to understand, but it’s important. Below, I have attempted to collected resources and statements that suppose to make it clear to me.</p>
<!-- more -->
<h3>OOD includes:</h3>
<ul>
<li>Code that is broken down into separate objects that help to organize data</li>
<li>Data isolated into restricted area where only specific procedured had access to it</li>
<li>Objects that encourage reuse of code (minimal inner dependancies)</li>
<li>Data that stays separate from actions</li>
<li>Objects that represent one item</li>
</ul>
<h3><a href="http://www.tonymarston.net/php-mysql/what-is-oop.html">Object Oriented</a> Language should include:</h3>
<p><strong>Class</strong>
Blueprint/prototype that defined variables or methods common to all objects of a certain kind.</p>
<p><strong>Object</strong>
An instance of a class. A class must be instantiated into an object before it can be used in the software. More than one instance of the same class can be in existence at any one time.</p>
<p><strong>Encapsulation</strong>
Placing data and the operations that perform on that data in the same class. The class becomes a ‘capsule’ or container for the data and operations.</p>
<p><strong>Inheritance</strong>
The reuse of base classes (superclasses) to form derived classes (subclasses). Methods and properties defined in the superclass are automatically shared by any subclass.</p>
<p><strong>Polymorphism</strong>
Same interface, different implementation. The ability to substitute one class for another. This means that different classes may contain the same method names, but the result which is returned by each method will be different as the code behind each method (the implementation) is different in each class.</p>
<p>What ODD helps you do is to delegate most of the repetititve logical work <em>to the data itself</em>. Data is becoming active, instead of staying passive.</p>
<h3>Lost yet?</h3>
<p>Ask yourself the following questions. If you answer yes to any, refactor:</p>
<ol>
<li>Is it the role of this class to know how to do something?</li>
<li>What should be defined as a class?</li>
<li>What sort of class hierarchy would be best?</li>
</ol>
<h3>What’s that smell? (simplified)</h3>
<p>If you see any of the following in your code, refactor:</p>
<ol>
<li>Duplication of code</li>
<li>Extensive length of class or method</li>
<li>Large amount of parameters</li>
</ol>
<p>Resources:<br/>
1. <a href="http://nicksda.apotomo.de/2011/07/are-class-methods-evil/">Are Class Methods Evil?</a> by Nick Sutterer
2. <a href="https://speakerdeck.com/styliii/object-oriented-design">Object Oriented Desing. Li Ouyang</a><br/>
3. <a href="http://www.codinghorror.com/blog/2006/05/code-smells.html">Code Smells by Jeff Atwood</a><br/>
4. <a href="http://mlomnicki.com/programming/ruby/2011/07/20/class-vs-instance-methods.html">Class vs instance methods</a> by Michal Lomnicki
5. <a href="http://blog.codeclimate.com/blog/2012/11/14/why-ruby-class-methods-resist-refactoring/">Why Ruby Class Methods Resist Refactoring</a> by</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[If I ever fix this blog]]></title>
<link href="http://www.innatewonderer.github.com/blog/if-i-ever-fix-this-blog/"/>
<updated>2012-11-07T00:46:00-05:00</updated>
<id>http://www.innatewonderer.github.com/blog/if-i-ever-fix-this-blog</id>
<content type="html"><![CDATA[<p>Debugging</p>
<p>If you are reading this post, I was able to save this blog and debug this #$!#%#%)&$ error. Pardon my french.</p>
<!-- more -->
<p>When running octopress</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rake preview</span></code></pre></td></tr></table></div></figure>
<p>the followng error showed up:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:16] "GET /stylesheets/screen.css HTTP/1.1" 200 42533 0.0037
</span><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:16] "GET /images/line-tile.png?1352246753 HTTP/1.1" 200 636 0.0027
</span><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:16] "GET /images/rss.png?1352246753 HTTP/1.1" 200 490 0.0025
</span><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:16] "GET /images/noise.png?1352246753 HTTP/1.1" 200 17742 0.0141
</span><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:18] "GET /stylesheets/screen.css HTTP/1.1" 304 - 0.0011
</span><span class='line'>[2012-11-06 19:06:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
</span><span class='line'>127.0.0.1 - - [06/Nov/2012 19:06:19] "GET / HTTP/1.1" 304 - 0.0013</span></code></pre></td></tr></table></div></figure>
<p>After several attempts at googling it, numerous pulls and pushs and rebase commands, I decided to get to the very bottom of it
Locate file</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpresponse.rb</span></code></pre></td></tr></table></div></figure>
<p>Set and set it to <strong>true</strong>
Liquid error: ClassNotFound: no lexer for alias ‘Ruby’ found</p>
<p>This should get rid of your error.</p>
<p>For whatever reason, Octopress was having issue with my markdown and syntax. I used [lang:Ruby] within my codeblock as <a href="http://octopress.org/docs/plugins/codeblock/">Octopress blog recommends</a>.<br/>
Removing lang:Ruby did it for the time being, but I have a feeling there is more to it.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Tracking Sandy nerd style]]></title>
<link href="http://www.innatewonderer.github.com/blog/tracking-sandy-nerd-style/"/>
<updated>2012-10-29T11:16:00-04:00</updated>
<id>http://www.innatewonderer.github.com/blog/tracking-sandy-nerd-style</id>
<content type="html"><![CDATA[<p>A beautiful representation of the wind currents</p>
<p><img src="http://www.innatewonderer.github.com/images/Wind_Map.jpg"></p>
<p>For realtime wind map, <a href="http://hint.fm/wind/">click here</a></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[7 easy steps to start with TDD]]></title>
<link href="http://www.innatewonderer.github.com/blog/7-easy-steps-to-start-with-tdd/"/>
<updated>2012-10-24T18:26:00-04:00</updated>
<id>http://www.innatewonderer.github.com/blog/7-easy-steps-to-start-with-tdd</id>
<content type="html"><![CDATA[<p>1:00 pm - TDD is a very useful tool in software development…</p>
<p>3:30 pm - Test driven development or TDD can be extremely frustrating, time consuming and sole devouring experience.</p>
<p>6:00 pm - Be patient. Like a sorority club, TDD will put you through a tidious initiation ceremony. Once, accepted, you will be able to produce a much cleaner code and improve your style.</p>
<!-- more -->
<p>Few easy steps to get you started with TDD using <strong><a href="https://rubygems.org/gems/rspec">rspec</a></strong>.</p>
<p>Tools used:</p>
<ul>
<li>Sublime Text 2</li>
<li>Terminal</li>
<li>gem of choise: rspec</li>
<li>original assignment: by <a href="http://twitter.com/aviflombaum">Avi Flombaum</a> can be found in my <a href="https://github.com/innatewonderer/playlister-jenya">GitHub repo</a>.</li>
</ul>
<h3>Step 1 : Installing rspec</h3>
<p>Create a new folder for your project, cd to that folder and run <strong>gem install rspec</strong>.</p>
<p><img src="http://www.innatewonderer.github.com/images/rspec_tdd-Jenya@Flatiron-Air-1-bash-122×30.jpg"></p>
<pre><code>**TIP**
**spec_helper.rb** will hold all of the required paths for you.
Do not forget to include all necessary files, gem names, and libraries.
_require 'spec_helper'_ will be the only line needed in your testing files.
</code></pre>
<figure class='code'><figcaption><span>spec_helper.rb </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'rspec'</span>
</span><span class='line'> <span class="n">require_relative</span> <span class="s1">'../artist'</span>
</span><span class='line'> <span class="n">require_relative</span> <span class="s1">'../artist'</span>
</span><span class='line'> <span class="n">require_relative</span> <span class="s1">'../song'</span>
</span><span class='line'> <span class="n">require_relative</span> <span class="s1">'../genre'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'yaml'</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span>artist.rb </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'spec_helper'</span>
</span></code></pre></td></tr></table></div></figure>
<h3>Step 2 : Identify what needs to be accomplished</h3>
<p>I had a sample of tests completed for Ruby assignment using <em>assert_method</em>. By running this test, I can test if my program is able to create an instance of <em>artist</em>.</p>
<figure class='code'><figcaption><span>[assert_test] [ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>test 'Can initialize an Artist' do
</span><span class='line'> assert Artist.new
</span><span class='line'>end</span></code></pre></td></tr></table></div></figure>
<h3>Step 3 : Write your test</h3>
<p><img src="http://www.innatewonderer.github.com/images/artist_spec.rb-final_ruby_tdd.jpg"></p>
<p>In artist_spec.rb, I need to be able to test that</p>
<ul>
<li>by calling <em>#new</em> method on class variable <strong>@artist</strong></li>
<li>I will be able to create a new instance of artist</li>
<li>that should be_an_instance_of Artist class.</li>
</ul>
<p> (<em>What? Yes! It is all one sentence.
You don’t like my overly explicit coding syntax? Sorry, get over it.</em>)</p>
<pre><code>**TIP**
</code></pre>
<p>Stay on a safe side. Commit your code to a GitHub repository. Here is a great post on <a href="http://cjbrock.github.com/blog/2012/10/23/5-easy-guides-to-help-you-get-started-with-github/">how to get started with Git</a>.</p>
<h3>Step 4 : Run your test - FAIL</h3>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rspect artist_spec.rb</span></code></pre></td></tr></table></div></figure>
<p>Terminal will tell you exactly what is wrong with your test.</p>
<p><img src="http://www.innatewonderer.github.com/images/spec_jenya@Flatiron-Air-1_bash_107×13.jpg"></p>
<h3>Step 5 : Fix your code</h3>
<p>To pass this test we need to initiate class Artist.</p>
<figure class='code'><figcaption><span>[artist.rb] [ruby] </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="k">class</span> <span class="nc">Artist</span>
</span><span class='line'>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<h3>Step 6 : Run your test again - PASS</h3>
<p><img src="http://www.innatewonderer.github.com/images/Arc.jpg"></p>
<h3>Step 7 : Do a happy dance</h3>
<p><img src="http://www.innatewonderer.github.com/images/original_art.jpg"><br/>
Original Work</p>
<h4>Here is an example of a more complex test:</h4>
<p>Create the test<br/>
Test and Fail<br/>
Fix your code</p>
<p><img src="http://www.innatewonderer.github.com/images/Skitch-1.jpg"></p>
<p> Test and Pass</p>
<p><img src="http://www.innatewonderer.github.com/images/spec-jenya@Flatiron-Air-1-bash-164×8.jpg"></p>
<p> Happy dance anyone???</p>
<p><img src="http://www.innatewonderer.github.com/images/original_art.jpg"></p>
<p> <strong>NOTE</strong><br/>
I plan to transofrm all test cases from original state to rspect. Feel free to <a href="https://github.com/innatewonderer/final_ruby_tdd">fork it here</a>.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Variable Scope]]></title>
<link href="http://www.innatewonderer.github.com/blog/variable-scope/"/>
<updated>2012-10-18T20:02:00-04:00</updated>
<id>http://www.innatewonderer.github.com/blog/variable-scope</id>
<content type="html"><![CDATA[<p><img class="right" src="http://public.arnau-sanchez.com/ruby-functional/pics/functional-programming-joke.png" width="350" height="190">
Variable is an essential building block of any programming language. It is a way to store information and assign a name to it for future use. Variables come in all shapes and sizes. Anything from an integer to a string of characters can be used to reference data in the program.</p>
<!-- more -->
<h3>There are four main types of variables:</h3>
<ul>
<li>$global_variable</li>
<li>@@class_variable</li>
<li>@instance_variable</li>
<li>local_variable (use [a..z] or _ )</li>
</ul>
<p>Ruby comes with two pseudo-variables <em>nil</em> and <em>self</em> that do not accept values. <em>Nil</em> is assigned to uninitialized variables. <em>Self</em> will always refer to the object currently being executed.</p>
<p>Looks simple, right? It gets somewhat confusing when you try to define the scope of each variable. Even more confusing, when you try to call on a variable that is does not belong to your current scope.</p>
<p>Ruby is always here to help you. <strong>defined? variable</strong> will show you the what the scope of selected variable.</p>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'> <span class="vc">@@var</span> <span class="o">=</span> <span class="s2">"class variable"</span>
</span><span class='line'>
</span><span class='line'><span class="err">$</span> <span class="n">irb</span>
</span><span class='line'><span class="mo">001</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="n">defined?</span> <span class="vc">@@var</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'> <span class="k">class</span> <span class="nc">Code</span>
</span><span class='line'> <span class="n">var</span> <span class="o">=</span> <span class="s2">"class variable"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="err">$</span> <span class="n">irb</span>
</span><span class='line'><span class="mo">001</span><span class="p">:</span><span class="mi">0</span> <span class="o">></span> <span class="n">defined?</span> <span class="n">var</span>
</span></code></pre></td></tr></table></div></figure>
<h4>Debugging</h4>
<p>If you run this code, it will give Object(NameError), which means that the variable you are trying to call on is currently out of scope. To solve this error locate where you first introduced the variable and either change its scope or rename the second variable.</p>
<h2>Local Variable</h2>
<p><strong>local_variable</strong> can be declaired and referenced only within given scope (method, loop, etc).</p>
<h2>Instance Variable</h2>
<p><strong>@instance_variables</strong> only belong to the given instance of an object. In an example below, when @instance_variable is changed in some_method, it retains its value when called in some_other_method.</p>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">CodeBlock</span>
</span><span class='line'> <span class="vi">@instance_variable</span> <span class="o">=</span> <span class="s2">"string"</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">some_method</span>
</span><span class='line'> <span class="vi">@instane_variable</span> <span class="o">=</span> <span class="mi">15</span> <span class="o"><==</span> <span class="mi">15</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">some_pther_method</span>
</span><span class='line'> <span class="vi">@instane_variable</span> <span class="o"><==</span> <span class="mi">10</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<h2>Global Variables</h2>
<p><strong>$global_variables</strong> are set to access anywhere in the program. It is ruby’s convention NOT to use global variables.</p>
<blockquote><p>“… global variables? <br/>They pollute the planet. <br/>You know who uses global variables? <br/>PHP”</p><footer><strong>@aviflombaum</strong> <cite><a href='https://twitter.com/aviflombaum'>twitter.com/aviflombaum/…</a></cite></footer></blockquote>
<p>Debugging will become a nightmare, if you redefine a global variable somewhere in your program, and then try to call on its original value.
Ruby offers us a number of major system variables. Aliases will come handy when working on bigger applications.</p>
<table>
<thead>
<tr>
<th></th>
<th align="center"> <strong>Symbol</strong> </th>
<th align="center"> <strong>Description</strong> </th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td align="center"> $! </td>
<td align="center"> latest error message</td>
</tr>
<tr>
<td></td>
<td align="center"> $@ </td>
<td align="center"> location of error</td>
</tr>
<tr>
<td></td>
<td align="center"> $_ </td>
<td align="center"> string last read by gets</td>
</tr>
<tr>
<td></td>
<td align="center"> $. </td>
<td align="center"> line number last read by interpreter</td>
</tr>
<tr>
<td></td>
<td align="center"> $& </td>
<td align="center"> string last matched by regexp</td>
</tr>
<tr>
<td></td>
<td align="center"> $~ </td>
<td align="center"> the last regexp match, as an array of subexpressions</td>
</tr>
<tr>
<td></td>
<td align="center"> $n </td>
<td align="center"> the nth subexpression in the last match (same as $~[n])</td>
</tr>
<tr>
<td></td>
<td align="center"> $= </td>
<td align="center"> case-insensitivity flag </td>
</tr>
<tr>
<td></td>
<td align="center"> $/ </td>
<td align="center"> input record separator</td>
</tr>
<tr>
<td></td>
<td align="center"> $\ </td>
<td align="center"> output record separator</td>
</tr>
<tr>
<td></td>
<td align="center"> $0 </td>
<td align="center"> the name of the ruby script file</td>
</tr>
<tr>
<td></td>
<td align="center"> $* </td>
<td align="center"> the command line arguments</td>
</tr>
<tr>
<td></td>
<td align="center"> $$ </td>
<td align="center"> interpreter’s process ID</td>
</tr>
<tr>
<td></td>
<td align="center"> $? </td>
<td align="center"> exit status of last executed child process</td>
</tr>
</tbody>
</table>
<h2>Class Variables</h2>
<p>A class variable are defined and availbale <strong>only</strong> inside that class, meaning that only <strong>one variable value exists for all objects represented by that instance within that class</strong>. @@variable will be available for reference in any methods that might be defined for that class.</p>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>