-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
2147 lines (1599 loc) · 107 KB
/
atom.xml
File metadata and controls
2147 lines (1599 loc) · 107 KB
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[Paulo de Tarço]]></title>
<link href="http://ptarcode.github.io/atom.xml" rel="self"/>
<link href="http://ptarcode.github.io/"/>
<updated>2018-03-14T22:26:36-03:00</updated>
<id>http://ptarcode.github.io/</id>
<author>
<name><![CDATA[Paulo de Tarço]]></name>
<email><![CDATA[ptarcode@gmail.com]]></email>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[3 Profilers Tools]]></title>
<link href="http://ptarcode.github.io/blog/2018/03/14/3-profilers-tools/"/>
<updated>2018-03-14T21:12:00-03:00</updated>
<id>http://ptarcode.github.io/blog/2018/03/14/3-profilers-tools</id>
<content type="html"><![CDATA[<!--more-->
<h3>What is it?</h3>
<p>In software engineering, profiling (“program profiling”, “software profiling”) is a form of dynamic program analysis that measures, for example, the space (memory) or time complexity of a program, the usage of particular instructions, or the frequency and duration of function calls. Most commonly, profiling information serves to aid program optimization.</p>
<p>Profiling is achieved by instrumenting either the program source code or its binary executable form using a tool called a profiler (or code profiler). Profilers may use a number of different techniques, such as event-based, statistical, instrumented, and simulation methods.</p>
<p><a href="https://en.wikipedia.org/wiki/Profiling" title="Title">Font: https://en.wikipedia.org</a></p>
<h3>Gprof</h3>
<p>Gprof produces an execution profile of C, Pascal, or Fortran77 programs. The effect of called routines is incorporated in the profile of each caller. The profile data is taken from the call graph profile file (gmon.out default) which is created by programs that are compiled with the -pg option of cc, pc, and f77. The -pg option also links in versions of the library routines that are compiled for profiling. Gprof reads the given object file (the default is a.out) and establishes the relation between its symbol table and the call graph profile from gmon.out. If more than one profile file is specified, the gprof output shows the sum of the profile information in the given profile files.
Gprof calculates the amount of time spent in each routine. Next, these times are propagated along the edges of the call graph. Cycles are discovered, and calls into a cycle are made to share the time of the cycle.
Several forms of output are available from the analysis.
The flat profile shows how much time your program spent in each function, and how many times that function was called. If you simply want to know which functions burn most of the cycles, it is stated concisely here.
The call graph shows, for each function, which functions called it, which other functions it called, and how many times. There is also an estimate of how much time was spent in the subroutines of each function. This can suggest places where you might try to eliminate function calls that use a lot of time.
The annotated source listing is a copy of the program’s source code, labeled with the number of times each line of the program was executed.</p>
<p>Step 1. Enable profiling during compilation (use -pg option)</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'>$ gcc -pg -o TestGprof TestGprof.c</span></code></pre></td></tr></table></div></figure>
<p>Step 2. Execute the binary so that profiling data is generated</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'>$ ./TestGprof</span></code></pre></td></tr></table></div></figure>
<p>If the profiling is enabled then on executing the program, file gmon.out will be generated.</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'>$ ls gmon.out TestGprof TestGprof.c</span></code></pre></td></tr></table></div></figure>
<p>Step 3. Run gprof on profiling data</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'>$ gprof -b TestGprof gmon.out > analysis.out</span></code></pre></td></tr></table></div></figure>
<p>Below are the contents of analysis.out</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>
<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>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Flat profile:
</span><span class='line'>
</span><span class='line'>Each sample counts as 0.01 seconds.
</span><span class='line'> % cumulative self self total
</span><span class='line'> time seconds seconds calls s/call s/call name
</span><span class='line'>100.55 20.38 20.38 100 0.20 0.20 StaticFunc
</span><span class='line'> 0.00 20.38 0.00 1 0.00 20.38 TestFunc
</span><span class='line'>
</span><span class='line'> Call graph
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>granularity: each sample hit covers 2 byte(s) for 0.05% of 20.38 seconds
</span><span class='line'>
</span><span class='line'>index % time self children called name
</span><span class='line'> 20.38 0.00 100/100 TestFunc [2]
</span><span class='line'>[1] 100.0 20.38 0.00 100 StaticFunc [1]
</span><span class='line'>-----------------------------------------------
</span><span class='line'> 0.00 20.38 1/1 main [3]
</span><span class='line'>[2] 100.0 0.00 20.38 1 TestFunc [2]
</span><span class='line'> 20.38 0.00 100/100 StaticFunc [1]
</span><span class='line'>-----------------------------------------------
</span><span class='line'>
</span><span class='line'>[3] 100.0 0.00 20.38 main [3]
</span><span class='line'> 0.00 20.38 1/1 TestFunc [2]
</span><span class='line'>-----------------------------------------------
</span><span class='line'>
</span><span class='line'>Index by function name
</span><span class='line'>
</span><span class='line'> [1] StaticFunc [2] TestFunc</span></code></pre></td></tr></table></div></figure>
<p><a href="https://www.tutorialspoint.com/unix_commands/gprof.htm" title="Title">Font: https://www.tutorialspoint.com</a></p>
<h3>Valgrind</h3>
<p>Valgrind is a GPL’d system for debugging and profiling Linux programs. With Valgrind’s tool suite you can automatically detect many memory management and threading bugs, avoiding hours of frustrating bug-hunting, making your programs more stable. You can also perform detailed profiling to help speed up your programs.</p>
<h4>Memcheck</h4>
<p>Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck’s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:
• Accesses memory it shouldn’t (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack).
• Uses uninitialised values in dangerous ways.
• Leaks memory.
• Does bad frees of heap blocks (double frees, mismatched frees).
• Passes overlapping source and destination memory blocks to memcpy() and related functions.
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10—30x slower than normal.</p>
<h4>Cachegrind</h4>
<p>Cachegrind is a cache profiler. It performs detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code. It identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries. It is useful with programs written in any language. Cachegrind runs programs about 20—100x slower than normal.</p>
<h4>Callgrind</h4>
<p>Callgrind, by Josef Weidendorfer, is an extension to Cachegrind. It provides all the information that Cachegrind does, plus extra information about callgraphs. It was folded into the main Valgrind distribution in version 3.2.0. Available separately is an amazing visualisation tool, KCachegrind, which gives a much better overview of the data that Callgrind collects; it can also be used to visualise Cachegrind’s output.</p>
<h4>Massif</h4>
<p>Massif is a heap profiler. It performs detailed heap profiling by taking regular snapshots of a program’s heap. It produces a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations. The graph is supplemented by a text or HTML file that includes more information for determining where the most memory is being allocated. Massif runs programs about 20x slower than normal.</p>
<h4>Helgrind</h4>
<p>Helgrind is a thread debugger which finds data races in multithreaded programs. It looks for memory locations which are accessed by more than one (POSIX p-)thread, but for which no consistently used (pthread_mutex_) lock can be found. Such locations are indicative of missing synchronisation between threads, and could cause hard-to-find timing-dependent problems. It is useful for any program that uses pthreads. It is a somewhat experimental tool, so your feedback is especially welcome here.</p>
<p>You invoke Valgrind like this:</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'>valgrind [valgrind-options] your-prog [your-prog-options]</span></code></pre></td></tr></table></div></figure>
<p>The most important option is —tool which dictates which Valgrind tool to run. For example, if want to run the command ls -l using the memory-checking tool Memcheck, issue this command:</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'>valgrind --tool=memcheck ls -l</span></code></pre></td></tr></table></div></figure>
<p><a href="http://valgrind.org/" title="Title">Font: http://valgrind.org/</a></p>
<h3>Gperftools</h3>
<p>Gperftools is a collection of a high-performance multi-threaded malloc() implementation, plus some pretty nifty performance analysis tools.</p>
<p>Gperftools is distributed under the terms of the BSD License. Join our mailing list at <a href="mailto:gperftools@googlegroups.com">gperftools@googlegroups.com</a> for updates:
<a href="https://groups.google.com/forum/#!forum/gperftools">https://groups.google.com/forum/#!forum/gperftools</a></p>
<p>Gperftools was original home for pprof program. But do note that original pprof (which is still included with gperftools) is now deprecated in favor of golang version at <a href="https://github.com/google/pprof">https://github.com/google/pprof</a></p>
<h4>TCMALLOC</h4>
<p>Just link in -ltcmalloc or -ltcmalloc_minimal to get the advantages of tcmalloc — a replacement for malloc and new. See below for some environment variables you can use with tcmalloc, as well.</p>
<p>Tcmalloc functionality is available on all systems we’ve tested; see INSTALL for more details. See README_windows.txt for instructions on using tcmalloc on Windows.</p>
<p>NOTE: When compiling with programs with gcc, that you plan to link with libtcmalloc, it’s safest to pass in the flags when compiling.</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'>-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free</span></code></pre></td></tr></table></div></figure>
<p>Gcc makes some optimizations assuming it is using its own, built-in malloc; that assumption obviously isn’t true with tcmalloc. In practice, we haven’t seen any problems with this, but the expected risk is highest for users who register their own malloc hooks with tcmalloc (using gperftools/malloc_hook.h). The risk is
lowest for folks who use tcmalloc_minimal.</p>
<h4>HEAP PROFILER</h4>
<p>As a quick-start, do the following after installing this package:</p>
<p>1) Link your executable:</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'>-ltcmalloc</span></code></pre></td></tr></table></div></figure>
<p>2) Run your executable with the HEAPPROFILE environment var set:</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'>$ HEAPPROFILE=/tmp/heapprof <path/to/binary> [binary args]</span></code></pre></td></tr></table></div></figure>
<p>3) Run pprof to analyze the heap usage</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ pprof <path/to/binary> /tmp/heapprof.0045.heap # run 'ls' to see options
</span><span class='line'> $ pprof --gv <path/to/binary> /tmp/heapprof.0045.heap</span></code></pre></td></tr></table></div></figure>
<p>You can also use LD_PRELOAD to heap-profile an executable that you didn’t compile.</p>
<p>There are other environment variables, besides HEAPPROFILE, you can set to adjust the heap-profiler behavior; c.f. “ENVIRONMENT VARIABLES” below.</p>
<p>The heap profiler is available on all unix-based systems we’ve tested; see INSTALL for more details. It is not currently available on Windows.</p>
<h4>HEAP CHECKER</h4>
<p>In order to catch all heap leaks, tcmalloc must be linked <em>last</em> into your executable. The heap checker may mischaracterize some memory accesses in libraries listed after it on the link line. For instance, it may report these libraries as leaking memory when they’re not.</p>
<p>Here’s a quick-start for how to use:</p>
<p>1) Link your executable:</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'>-ltcmalloc</span></code></pre></td></tr></table></div></figure>
<p>2) Run your executable with the HEAPCHECK environment var set:</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'>$ HEAPCHECK=1 <path/to/binary> [binary args]</span></code></pre></td></tr></table></div></figure>
<p>Other values for HEAPCHECK: normal (equivalent to “1”), strict, draconian</p>
<p>You can also use LD_PRELOAD to heap-check an executable that you didn’t compile.</p>
<p>The heap checker is only available on Linux at this time.</p>
<h4>CPU PROFILER</h4>
<p>As a quick-start, do the following after installing this package:</p>
<p>1) Link your executable:</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'>-ltcmalloc</span></code></pre></td></tr></table></div></figure>
<p>2) Run your executable with the CPUPROFILE environment var set:</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'>$ CPUPROFILE=/tmp/prof.out <path/to/binary> [binary args]</span></code></pre></td></tr></table></div></figure>
<p>3) Run pprof to analyze the CPU usage</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ pprof <path/to/binary> /tmp/prof.out # -pg-like text output
</span><span class='line'> $ pprof --gv <path/to/binary> /tmp/prof.out # really cool graphical output</span></code></pre></td></tr></table></div></figure>
<p>There are other environment variables, besides CPUPROFILE, you can set to adjust the cpu-profiler behavior; cf “ENVIRONMENT VARIABLES” below.</p>
<p>The CPU profiler is available on all unix-based systems we’ve tested; see INSTALL for more details. It is not currently available on Windows.</p>
<p>NOTE: CPU profiling doesn’t work after fork (unless you immediately do an exec()-like call afterwards). Furthermore, if you do fork, and the child calls exit(), it may corrupt the profile data. You can use _exit() to work around this. We hope to have a fix for both problems in the next release of perftools (hopefully perftools 1.2).</p>
<p><a href="https://github.com/gperftools/gperftools" title="Title">Font: https://github.com/gperftools/gperftools</a></p>
<hr />
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Eliza - First computer programs to process natural language.]]></title>
<link href="http://ptarcode.github.io/blog/2016/02/19/eliza-first-computer-programs-to-process-natural-language/"/>
<updated>2016-02-19T23:01:00-02:00</updated>
<id>http://ptarcode.github.io/blog/2016/02/19/eliza-first-computer-programs-to-process-natural-language</id>
<content type="html"><![CDATA[<!--more-->
<p>One of the first computer programs to process natural language was “Eliza,” named after the gabby heroine in Shaw’s play Pygmalion. The Eliza software was written in 1965 by Joseph Weizenbaum, a professor at MIT, and it simulated the responses of a Rogerian psychiatrist talking to a patient. The program made a superficial analysis of the text typed to it, and spat back one of a large number of canned responses built into it. The illusion that the computer understood any of the conversation fooled quite a number of com-puter-naive people.</p>
<p>Weizenbaum got the first indication of this phenomenon when he invited his secretary to try the system. After a couple of minutes typing with Eliza, the secretary (who had watched Weizenbaum work on the software for many previous months, and could be expected to understand better than most that it was just a computer program) asked Weizenbaum to leave the room so that she could continue her dialogue in private!</p>
<p>The Turing test failed on its first outing, as the secretary plainly regarded this elementary software (with no pretensions to artificial intelligence) as human. Rather than the software showing intelligence, the humans showed gullibility. Eliza proved to be a popular program, and was adapted by Bolt Berenek and Newman, a Boston computer consul-tancy. This led to a more severe test when a BBN vice president found himself connected to Eliza instead of the programmer he was expecting.</p>
<p><img class="right" src="http://ptarcode.github.io/images/post/siri_eliza_chat.png" width="400" title="Eliza" ></p>
<h4>Eliza Chat bot – NLP Addiction <a href="http://nlp-addiction.com/eliza/" target="_blank">Try online</a></h4>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Erlang Basics]]></title>
<link href="http://ptarcode.github.io/blog/2016/02/07/erlang-basics/"/>
<updated>2016-02-07T20:07:00-02:00</updated>
<id>http://ptarcode.github.io/blog/2016/02/07/erlang-basics</id>
<content type="html"><![CDATA[<!--more-->
<p>Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging. Erlang’s runtime system has built-in support for concurrency, distribution and fault tolerance.</p>
<h3>History</h3>
<p>The name “Erlang”, attributed to Bjarne Däcker, has been presumed by those working on the telephony switches (for whom the language was designed) to be a reference to Danish mathematician and engineer Agner Krarup Erlang or the ubiquitous use of the unit named for him, and (initially at least) simultaneously as a syllabic abbreviation of “Ericsson Language”.</p>
<h5>1982 – 1985</h5>
<p>Experiments with programming of telecom using > 20 different languages. Conclusion: The language must be a very high level symbolic language in order to achive productivity gains ! (Leaves us with: Lisp , Prolog , Parlog …)</p>
<h5>1985 – 1986</h5>
<p>Experiments with Lisp,Prolog, Parlog etc. Conclusion: The language must contain primitives for concurrency and error recovery, and the execution model must not have back-tracking. (Rules out Lisp and Prolog.) It must also have a granularity of concurrency such that one asyncronous telephony process is represented by one process in the language. Rules out Parlog. We must therefore develop our own language with the desirable features of Lisp, Prolog and Parlog, but with concurrency and error recovery built into the language.</p>
<h5>1987</h5>
<p>The first experiments with Erlang.</p>
<h5>1988</h5>
<p>ACS/Dunder Phase 1. Prototype construction of PABX functionality by external users Erlang escapes from the lab!</p>
<h5>1989</h5>
<p>ACS/Dunder Phase 2. Reconstruction of 1/10 of the complete MD-110 system. Results: >> 10 times greater gains in efficency at construction compared with construction in PLEX!Further experiments with a fast implementation of Erlang.</p>
<h5>1990</h5>
<p>Erlang is presented at ISS’90, which results in several new users, e.g Bellcore.</p>
<h5>1991</h5>
<p>Fast implementation of Erlang is released to users. Erlang is represented at Telecom’91 . More functionality such as ASN1 – Compiler , graphical interface etc.</p>
<h5>1992</h5>
<p>A lot of new users, e.g several RACE projects. Erlang is ported to VxWorks, PC, Macintosh etc. Three applications using Erlang are presented at ISS’92. The two first product projects using Erlang are started.</p>
<h5>1993</h5>
<p>Distribution is added to Erlang, which makes it possible to run a homgeneous Erlang system on a heterogeneous hardware. Decision to sell implementations Erlang externally. Separate organization in Ericsson started to maintain and support Erlang implementations and Erlang Tools.</p>
<h3>Installation</h3>
<p>Erlang Solutions offers a number of installs at <a href="http://www.erlang.org/downloads.">http://www.erlang.org/downloads.</a>
Erlang/OTP Platform is a complex system composed of many smaller applications (modules). Installing the erlang package automatically installs the entire OTP suite. Since some of the more advanced users might want to download only a specific selection of modules, Erlang/OTP has been divided into smaller packages, all with the prefix ‘erlang-’, that can be installed without launching the erlang package.</p>
<p>Most OS package managers provide pre-built binary packages. You can also download the latest stable releases from Erlang Solutions or try install with package managers.</p>
<pre><code>For Homebrew on OS X: brew install erlang
For MacPorts on OS X: port install erlang
For Ubuntu and Debian: apt-get install erlang
For Fedora: yum install erlang
For FreeBSD: pkg install erlang
</code></pre>
<h3>Shell</h3>
<p>On Windows command line type <strong>werl</strong> on Linux or Mac OS X type <strong>erl</strong>.</p>
<pre><code>Erlang/OTP 18 [erts-7.2] [source-e6dd627] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.2 (abort with ^G)
1>
</code></pre>
<h4>Browsing the archives</h4>
<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'>pwd().
</span><span class='line'>/Users/ptarcode
</span><span class='line'>ok</span></code></pre></td></tr></table></div></figure>
<p>Argument in parentheses but in quotes, preferably double quotes.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>5> cd("..").
</span><span class='line'>/Users
</span><span class='line'>ok
</span><span class='line'>6> cd("ptarcode"). /Users/ptarcode
</span><span class='line'>ok
</span><span class='line'>7></span></code></pre></td></tr></table></div></figure>
<h4>Doing …</h4>
<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>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Eshell V5.9 (abort with ^G) 1> 2+2.
</span><span class='line'>4
</span><span class='line'>2> 39-9.
</span><span class='line'>30
</span><span class='line'>3> 10*43.
</span><span class='line'>430
</span><span class='line'>4> 100 div 15.
</span><span class='line'>6
</span><span class='line'>6> 100 rem 15.
</span><span class='line'>10
</span><span class='line'>7> 3*(5+3).
</span><span class='line'>24</span></code></pre></td></tr></table></div></figure>
<h4>Functions …</h4>
<p>Mathematical functions supported by Erlang’s math module simple examples.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>4> math:pi().
</span><span class='line'>3.141592653589793
</span><span class='line'>
</span><span class='line'>5> math:cos(math:pi()).
</span><span class='line'>-1.0</span></code></pre></td></tr></table></div></figure>
<h4>Numbers</h4>
<p>Erlang recognizes integers and floating-point numbers. Uses the 64-bit IEEE 754-1985 “double precision” representation. This means that it keeps track of about 15 decimal digits plus an exponent.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>7> 8888888888888888888888888888888888888888888.0.
</span><span class='line'>8.888888888888889e42
</span><span class='line'>
</span><span class='line'>9> 88888888888.88888888888888 .
</span><span class='line'>88888888888.88889</span></code></pre></td></tr></table></div></figure>
<p>Digits+Exponent notation</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>7> 2.923e127. 2.923e127
</span><span class='line'>8> 7.6345435e-231. 7.6345435e-231</span></code></pre></td></tr></table></div></figure>
<p>Base2+Value notation</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=''><span class='line'>11> 2#10101.
</span><span class='line'>21
</span><span class='line'>12> -2#10101.
</span><span class='line'>-21</span></code></pre></td></tr></table></div></figure>
<p>Base16+Value notation</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=''><span class='line'>16> 16#fa81.
</span><span class='line'>64129
</span><span class='line'>17> -16#fa81.
</span><span class='line'>-64129</span></code></pre></td></tr></table></div></figure>
<h4>Variables</h4>
<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>
</pre></td><td class='code'><pre><code class=''><span class='line'>19> V=3 .
</span><span class='line'>3</span></code></pre></td></tr></table></div></figure>
<p>Variable can’t be signed with a new value.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>20> V=4 .
</span><span class='line'>** exception error: no match of right hand side value 4
</span><span class='line'>21>
</span><span class='line'>
</span><span class='line'>21> V2= V*4 .
</span><span class='line'>12
</span><span class='line'>22> V2 .
</span><span class='line'>12</span></code></pre></td></tr></table></div></figure>
<p>Show bounded variables <strong>b() . </strong></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=''><span class='line'>23> b() .
</span><span class='line'>V = 3
</span><span class='line'>V2 = 12
</span><span class='line'>ok</span></code></pre></td></tr></table></div></figure>
<p>Clearing bounded variables <strong>f(variable) . </strong></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>
</pre></td><td class='code'><pre><code class=''><span class='line'>23> b() .
</span><span class='line'>V = 3
</span><span class='line'>V2 = 12
</span><span class='line'>ok
</span><span class='line'>24> f(V) .
</span><span class='line'>ok
</span><span class='line'>25> b() .
</span><span class='line'>V2 = 12
</span><span class='line'>ok</span></code></pre></td></tr></table></div></figure>
<p>Clearing all bounded variables <strong>f() . </strong></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>
</pre></td><td class='code'><pre><code class=''><span class='line'>23> b() .
</span><span class='line'>V = 3
</span><span class='line'>V2 = 12
</span><span class='line'>ok
</span><span class='line'>24> f() .
</span><span class='line'>ok
</span><span class='line'>25> b() .
</span><span class='line'>ok</span></code></pre></td></tr></table></div></figure>
<p>Continue …</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Latex to Html]]></title>
<link href="http://ptarcode.github.io/blog/2015/04/26/latex-to-html/"/>
<updated>2015-04-26T18:51:00-03:00</updated>
<id>http://ptarcode.github.io/blog/2015/04/26/latex-to-html</id>
<content type="html"><![CDATA[<!--more-->
<h3>MathJax</h3>
<p>Perfect to render equations but don’t have structures support like tables and lists.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'><html>
</span><span class='line'><head>
</span><span class='line'><title>MathJax TeX Test Page</title>
</span><span class='line'><script type="text/x-mathjax-config">
</span><span class='line'> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</span><span class='line'></script>
</span><span class='line'><script type="text/javascript"
</span><span class='line'> src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</span><span class='line'></script>
</span><span class='line'></head></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>
</pre></td><td class='code'><pre><code class=''><span class='line'><body>
</span><span class='line'>When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
</span><span class='line'>$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</span><span class='line'></body></span></code></pre></td></tr></table></div></figure>
<h5>Saiba mais em <a href="http://www.mathjax.org/.">http://www.mathjax.org/.</a></h5>
<h3>Latex2html5</h3>
<p>This project is the frontend only version of the code that originated from Mathapedia to enable real-time, dynamic authorship of mathematical ebooks</p>
<script type="text/x-mathjax-config">
// <![CDATA[
MathJax.Hub.Config({
TeX: {extensions: ["AMSmath.js", "AMSsymbols.js"]},
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
showProcessingMessages : false,
messageStyle : "none" ,
showMathMenu: false ,
tex2jax: {
processEnvironments: true,
inlineMath: [ ['$','$'], ["\(","\)"] ],
displayMath: [ ['$$','$$'], ["\[","\]"] ],
preview : "none",
processEscapes: true
},
"HTML-CSS": { linebreaks: { automatic:true, width: "latex-container"} }
});
// ]]>
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<p>LaTeX2HTML5 Installation</p>
<p>Simply download the JS and CSS files and include them on your MathJax enabled website:</p>
<pre><code> <link rel="stylesheet" href="latex2html5.min.css">
<script type="text/javascript" src="latex2html5.min.js"></script>
</code></pre>
<p>If you want the same font as the rendered examples:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Arbutus+Slab" type="text/css"></p>
<p>You have three options for parsing the LATEX:
You can put LATEX inside of the current page within a script tag with the type set to “tex/latex”:</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>
</pre></td><td class='code'><pre><code class=''><span class='line'><script type="tex/latex">
</span><span class='line'> ... LaTeX here ...
</span><span class='line'> </script>
</span><span class='line'> <script type="text/javascript">
</span><span class='line'> $('body').latex();
</span><span class='line'> </script></span></code></pre></td></tr></table></div></figure>
<p>or you can read a .tex file from somewhere else, which is nice for editing .tex files:</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=''><span class='line'><latex src="path/to/my/latex.tex">
</span><span class='line'> <script type="text/javascript">
</span><span class='line'> $('latex').LaTeX();
</span><span class='line'> </script></span></code></pre></td></tr></table></div></figure>
<p>or you can write it from scratch!</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>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>MathJax.Hub.Register.StartupHook("End",function () {
</span><span class='line'>
</span><span class='line'> $('[type="tex/latex"]').each(function (i, el) {
</span><span class='line'> var $el = $(el);
</span><span class='line'> var TEX = new LaTeX2HTML5.TeX({
</span><span class='line'> tagName: 'section',
</span><span class='line'> className: 'latex-container',
</span><span class='line'> latex: $el.text()
</span><span class='line'> });
</span><span class='line'> TEX.render();
</span><span class='line'> $el.replaceWith(TEX.$el);
</span><span class='line'> });
</span><span class='line'>
</span><span class='line'> });</span></code></pre></td></tr></table></div></figure>
<p>Examples:</p>
<h5>pstricks <a href="http://latex2html5.com/examples/pstricks.html">http://latex2html5.com/examples/pstricks.html</a></h5>
<h5>interactive <a href="http://latex2html5.com/examples/interactive.html">http://latex2html5.com/examples/interactive.html</a></h5>
<h5>graphs <a href="http://latex2html5.com/examples/graphs.html">http://latex2html5.com/examples/graphs.html</a></h5>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[First peripheral only with radio static.]]></title>
<link href="http://ptarcode.github.io/blog/2015/04/26/first-peripheral-only-with-radio-static/"/>
<updated>2015-04-26T00:08:00-03:00</updated>
<id>http://ptarcode.github.io/blog/2015/04/26/first-peripheral-only-with-radio-static</id>
<content type="html"><![CDATA[<hr />
<!--more-->
<p>In March 1975, thirty-two computer enthusiasts met in Gordon French’s garage around an Altair 8800 computer. No one had seen anything like it, and they shared whatever information they had. Steve Dompier had actually been to MITS in Albuquerque to pick up an Altair, and he described an overworked staff trying to catch up with a flood of orders. They had already shipped 1500 machines and were working hard to get the next 1100 out the door. What’s more, the company would deliver none of the much-needed accessories until they filled the outstanding orders for the basic machine. This news was about all Dompier had to show for his trip: he ended up leaving Albuquerque without significant chunks of the Altair kit he had bought and paid for.</p>
<p>The Altair actually on display at the meeting had been sent to the editorial department of Bob Albrecht’s People’s Computer Company for review, and he showed it off to the club. It was a marvel, the first small, affordable computer that could actually do something, and there it was in Gordon French’s garage, blinking, maybe even computing—though the only real evidence of that was the blinking, since the machine had no screen or keyboard.</p>
<p>The group agreed to continue meeting and called themselves the Homebrew Computer Club. Over the next weeks they dissected the Altair. Everything about it, good and bad, inspired and excited them, and they would go away into the night planning their own projects—memory boards for the Altair, peripherals, a better bus, even competing computers.</p>
<p>Steve Dompier finally got the remainder of his kit, and he put it together in two sleepless days. Testing it he discovered that its unshielded circuits interfered with a nearby radio, turning everything into static. Interestingly, though, the static changed pitch as the Altair went through its test programs. Dompier stayed up another eight hours working out the musical scale and writing a demo program for Homebrew.</p>
<p>At the next meeting he toggled in the program (twice because someone tripped over the plug the first time) and tuned his radio between stations to get uninterrupted fuzz. At the final flick of a switch, the Altair began playing a wispy version of The Beatles’ “Fool on the Hill” in pure radio static. It was possibly the first program beyond test routines ever written for the Altair. As an encore, the machine then went into a short rendition of “Daisy Bell,” an homage to a pioneering piece of computer music performed at Bell Labs back in the ’50s.</p>
<p>The significance of “Daisy” was obvious, and the room went wild. The Homebrew Computer Club was staking its claim to a world that once belonged only to university labs, corporations, and government agencies. After that night, the power of computing would be open to all.</p>
<hr />
<hr />
<p>Altair plays “The Fool on the Hill”</p>
<p><video width='640' height='340' preload='none' controls poster='http://ptarcode.github.io/images/cover-movie.png'><source src='http://ptarcode.github.io/images/movie-audio/Altair_Fool_On_the_Hill_music.mp3' ></video></p>
<hr />
<hr />
<p>Homebrew Computer Club</p>
<p><video width='640' height='340' preload='none' controls poster='http://ptarcode.github.io/images/cover-movie.png'><source src='http://ptarcode.github.io/images/movie-audio/homebrew.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'></video></p>
<hr />
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Rails 4 Turbolinks]]></title>
<link href="http://ptarcode.github.io/blog/2013/11/26/rails-4-turbolinks/"/>
<updated>2013-11-26T23:36:00-02:00</updated>
<id>http://ptarcode.github.io/blog/2013/11/26/rails-4-turbolinks</id>
<content type="html"><![CDATA[<hr />
<!--more-->
<h3>What is it?</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'>gem 'turbolinks'</span></code></pre></td></tr></table></div></figure>
<p>“This is a gem that works similar to pjax, but instead of worrying about what element on the page to replace, and tailoring the server-side response to fit, we replace the entire body. This means that you get the bulk of the speed benefits from pjax (no recompiling of the JavaScript or CSS) without having to tailor the server-side response. It just works.”</p>
<h3>PJAX</h3>
<p>Uses AJAX and PushState to deliver a faster browsing experience by only loading and updating parts of the page HTML each page load. PushState makes it possible to add real permalinks, page titles, and a working back button so that your visitors won’t be able to tell the difference between PJAX page load and ordinary full page loads.</p>
<p><a href="http://www.youtube.com/watch?v=CKv9C2qUL-8" title="Title">Tutorial</a></p>
<h3>Using the gem</h3>
<p>Gemfile:</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'>gem 'turbolinks'</span></code></pre></td></tr></table></div></figure>
<p>Add this line on app/assets/javascripts/application.js:</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'>//= require turbolinks</span></code></pre></td></tr></table></div></figure>
<p>app/views/layouts/application.html.erb:</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>
</pre></td><td class='code'><pre><code class=''><span class='line'><%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
</span><span class='line'><%= javascript_include_tag "application", "data-turbolinks-track" => true %></span></code></pre></td></tr></table></div></figure>
<p>If you wont use Turbolink in some link, you can manually exclude:</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'><a href="http://ptarcode.github.io/examples" data-no-turbolink>Examples</a></span></code></pre></td></tr></table></div></figure>
<p>“With Turbolinks pages will change without a full reload, so you can’t rely on DOMContentLoaded or jQuery.ready() to trigger your code. Instead Turbolinks fires events on document to provide hooks into the lifecycle of the page.”
Runtime Dependencies coffee-rails, but if you want use javascript.You can manually download and compile the turbolinks.js.coffee to JavaScript.</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>
</pre></td><td class='code'><pre><code class=''><span class='line'>ready = ->
</span><span class='line'>
</span><span class='line'> ...your coffeescript goes here...
</span><span class='line'>
</span><span class='line'>$(document).ready(ready)
</span><span class='line'>$(document).on('page:load', ready)</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>
<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=''><span class='line'>var ready;
</span><span class='line'>ready = function() {
</span><span class='line'>
</span><span class='line'> ...your javascript goes here...
</span><span class='line'>
</span><span class='line'>};
</span><span class='line'>
</span><span class='line'>$(document).ready(ready);
</span><span class='line'>$(document).on('page:load', ready);</span></code></pre></td></tr></table></div></figure>
<h3>Links</h3>
<p><a href="https://github.com/rails/turbolinks" title="Turbolinks Project">Turbolinks Project</a></p>
<p><a href="http://railscasts.com/episodes/390-turbolinks" title="Railscasts Turbolinks">Railscasts Turbolinks</a></p>
<hr />
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Clima tempo module for Node.js]]></title>
<link href="http://ptarcode.github.io/blog/2013/09/09/clima-tempo-module-for-node-dot-js/"/>
<updated>2013-09-09T11:33:00-03:00</updated>
<id>http://ptarcode.github.io/blog/2013/09/09/clima-tempo-module-for-node-dot-js</id>
<content type="html"><![CDATA[<hr />
<!--more-->
<h3>version : 0.0.9</h3>
<p>Communication with Clima Tempo accessing information about the weather of Brazil.</p>
<h2>Installation</h2>
<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'>npm install clima-tempo</span></code></pre></td></tr></table></div></figure>
<h2>Usage</h2>
<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>
</pre></td><td class='code'><pre><code class=''><span class='line'>var clima = require(clima-tempo);
</span><span class='line'>
</span><span class='line'> var callback = function(error, result) {
</span><span class='line'> if (error) {
</span><span class='line'> console.error(error);
</span><span class='line'> }
</span><span class='line'> else{
</span><span class='line'> ......
</span><span class='line'> }
</span><span class='line'> }</span></code></pre></td></tr></table></div></figure>
<h3>.days</h3>
<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>
</pre></td><td class='code'><pre><code class=''><span class='line'>//type = Default or Extended
</span><span class='line'> clima.days(codCity,"Extended",callback);</span></code></pre></td></tr></table></div></figure>
<h4>return</h4>
<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>
<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>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[ { dia: '2013-09-09',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '30',
</span><span class='line'> minima: '17' },
</span><span class='line'> { dia: '2013-09-10',
</span><span class='line'> tempo: undefined,
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '18' },
</span><span class='line'> { dia: '2013-09-11',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '18' },
</span><span class='line'> { dia: '2013-09-12',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '18' },
</span><span class='line'> { dia: '2013-09-13',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '17' },
</span><span class='line'> { dia: '2013-09-14',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '17' },
</span><span class='line'> { dia: '2013-09-15',
</span><span class='line'> tempo: 'Parcialmente Nublado',
</span><span class='line'> maxima: '29',
</span><span class='line'> minima: '17' } ]</span></code></pre></td></tr></table></div></figure>
<h3>.nowFromPage</h3>