-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmm.rss
920 lines (663 loc) · 45.6 KB
/
mm.rss
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text" xml:lang="en"></title>
<link type="application/atom+xml" href="http://marizmelo.com/feed/" rel="self"/>
<link type="text" href="http://marizmelo.com" rel="alternate"/>
<updated>2014-03-10T22:02:56-07:00</updated>
<id>http://marizmelo.com</id>
<author>
<name>Mariz Melo</name>
</author>
<rights>Copyright (c) 2013, Mariz Melo; all rights reserved.</rights>
<entry>
<title>Set iTerm2 folder colors</title>
<link href="http://marizmelo.com/2014/02/11/iterm2-folder-color.html"/>
<updated>2014-02-11T01:40:45Z</updated>
<id>http://marizmelo.com/2014/02/11/iterm2-folder-color</id>
<content type="html"><p>I am working on <a href="http://aws.amazon.com">AWS</a> a lot lately. I had notice that before, but on my <a href="http://www.iterm2.com/">iTerm2</a> or Terminal on OSX I could not see colors on my <a href="http://en.wikipedia.org/wiki/Ls">ls</a> command.</p>
<p>The solution was simple. Just follow these steps:</p>
<ol>
<li>
<p>Insert the following command on your ~/.bashrc (or .bash_profile) file (if you don’t have this file, just create it on your home directory)</p>
<pre><code>alias ls=&quot;ls -G&quot;</code></pre>
</li>
<li>
<p>Reload the bashrc file using the following command</p>
<pre><code>$ source ~/.bashrc</code></pre>
</li>
</ol>
<p>Try to list your files now. You will see that folders are highlighted on a different color.</p>
<p>That is it.</p>
<p><strong>UPDATE:</strong></p>
<p>I found this awesome project called <a href="http://iterm2colorschemes.com/">iTerm Themes</a> you may want to check it out.</p></content>
</entry>
<entry>
<title>Newschalk an effortless newsreader!</title>
<link href="http://marizmelo.com/2013/08/08/newschalk.html"/>
<updated>2013-08-08T10:40:45Z</updated>
<id>http://marizmelo.com/2013/08/08/newschalk</id>
<content type="html"><p>Hello everyone, today I am going to talk about <a href="http://www.newschalk.com">Newschalk</a> an effortless newsreader that I have been working on it with my friend Garindra Prahandono. Me and Gary started this project back in 2010 and stop the development because of work. Since Google announced the <strong>Google Reader shutdown</strong> we became again interested in bringing this project to life.</p>
<p>The first version uses <a href="http://en.wikipedia.org/wiki/RSS">RSS</a> to aggregate your favorite news. The next step is transform the application into a <strong>social news hub</strong> where you can be followed and follow interesting people and know what are they reading.</p>
<p>Here a small video preview:</p>
<div class='video-container'><iframe class='vimeo-iframe' frameborder='0' src='http://player.vimeo.com/video/71554424 ' style='width: 100%; height: 400px'> </iframe></div>
<p>I am happy to announce that <strong>Newschalk</strong> is <a href="http://www.newschalk.com">live</a> and almost ready for use. Right now we are working on invitation basis. <a href="http://www.newschalk.com">Request your invitation</a> today and change the way you read news.</p>
<p>We have huge plans for this project and hope everyone enjoys using it.</p></content>
</entry>
<entry>
<title>iOS 7 Revisited</title>
<link href="http://marizmelo.com/2013/07/01/ios7icons.html"/>
<updated>2013-07-01T10:40:45Z</updated>
<id>http://marizmelo.com/2013/07/01/ios7icons</id>
<content type="html"><p>It has been a while since my last post. So this time I wanted to do something different than usual. Let’s talk about design today.</p>
<p>The iOS operating system is on it’s way and to celebrate this I have done some work on the new icons.</p>
<p>I really admire <strong>Jony Ive</strong> work and this is just a sum of my design observations. I have notice that the new icons have a lack of consistency in their design (sorry). This is my attempt of correcting this.</p>
<p><a href="http://www.behance.net/gallery/iOS-7-Revisited/9609109">Behance page</a></p>
<p>Here are the change I’ve made:</p>
<div class='center border-bottom'>
<img src='http://farm6.staticflickr.com/5485/9188875868_68a887f254_o.jpg' width='80%' />
</div>
<p><br /></p>
<p>First I change all gradient directions for dark top to lighter bottom. This way we maintain consistency on all icons. Ive have used some transparency and I also kept that in this example.</p>
<p>Now let’s take a look on the original icons:</p>
<div class='center border-bottom'>
<img src='http://farm8.staticflickr.com/7370/9186575201_95299f2b88_z.jpg' width='80%' />
</div></content>
</entry>
<entry>
<title>Reversing strings in JavaScript</title>
<link href="http://marizmelo.com/2013/04/25/js_reverse_string.html"/>
<updated>2013-04-25T11:40:45Z</updated>
<id>http://marizmelo.com/2013/04/25/js_reverse_string</id>
<content type="html"><p>Today a simple way to reverse string in JavaScript.</p>
<pre><code>var reversed
, name = &quot;Mariz Melo&quot;;
reversed = name.split(&quot;&quot;).reverse().join(&quot;&quot;);
alert(reversed);</code></pre>
<p>That is it. What just happened?</p>
<p>Well we used the JavaScript <code>split</code> method to convert our string into an Array of words. After that we used the <code>reverse</code> method to reverse the order of those words in our newly created Array. Finally, we used the method <code>join</code> to convert the Array into a string again (now with the words in reverse order).</p>
<p>Simple like this.</p></content>
</entry>
<entry>
<title>AngularJS an introduction</title>
<link href="http://marizmelo.com/2013/04/13/AngularJS.html"/>
<updated>2013-04-13T01:40:45Z</updated>
<id>http://marizmelo.com/2013/04/13/AngularJS</id>
<content type="html"><p>Hi again everyone today I will talk about <strong>Google’s</strong> client-side framework <a href="http://angularjs.org/">AngularJS</a>. I have been using AngularJS in my projects for a while now and just decided to share some information here.</p>
<p>AngularJS helps you to control the <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a> and create amazing client-side applications. You don’t need anything else to start using Angular, just download it (or use a <a href="http://en.wikipedia.org/wiki/Content_delivery_network">CDN</a>) to get started. Let’s start with AngularJS.</p>
<p>Create a file called <strong>angular.html</strong> with the following content:</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Hello AngularJS&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Hello World!&lt;/h1&gt;
&lt;h2&gt;Getting started&lt;/h2&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>Include AngularJS JavaScript file on the <strong>header</strong> of your <strong>angular.html</strong> file like this:</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Hello AngularJS&lt;/title&gt;
&lt;script src=&quot;//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js&quot;&gt;&lt;/script&gt;
...</code></pre>
<p>You need to inform AngularJS which elements of the DOM you want to manage. You do this by including the attribute <strong>ng-app</strong> to one of the DOM elements. In our case since I we want to manage the entire DOM tree (more about DOM in another post).</p>
<pre><code>&lt;!DOCYTYPE html&gt;
&lt;html ng-app&gt;
...</code></pre>
<p>You are ready to use AngularJS. Let’s start by using <strong>templates</strong> first:</p>
<pre><code>...
&lt;body&gt;
&lt;h1&gt;{ { hello } } World!&lt;/h1&gt;
...</code></pre>
<p>I have replaced the word <strong>Hello</strong> with an <strong>AngularJS template</strong> syntax (between double curly-braces).</p>
<p>Let’s replace that template value with the string <strong>“Hello”</strong> again, but this time using AngularJS.</p>
<pre><code>...
&lt;h1 ng-controller=&quot;Hello&quot;&gt;{ { hello } } World!&lt;/h1&gt;
&lt;h2&gt;Getting started&lt;/h2&gt;
&lt;!-- SCRIPTS --&gt;
&lt;script&gt;
function Hello($scope) {
$scope.hello = &quot;Hello&quot;;
}
&lt;/script&gt;
...</code></pre>
<p>Notice the newly created attribute <strong>ng-controller</strong> on our <code>H1</code> element. This attribute is responsible for <strong>controlling</strong> everything between the <code>h1</code> tag element. Another new element is <code>$scope</code>. With this variable you can access all template values in a given scope.</p>
<p>In our <code>script</code> tag we included a <code>function</code> that replace the value of your template <strong>{ {hello} }</strong>.</p>
<p>You should see the replaced value on your browser now.</p>
<p>The complete script:</p>
<pre><code>&lt;!DOCYTPE html&gt;
&lt;html ng-app&gt;
&lt;head&gt;
&lt;title&gt;Hello AngularJS&lt;/title&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1 ng-controller=&quot;Hello&quot;&gt;{ { hello } } World!&lt;/h1&gt;
&lt;h2&gt;Getting started&lt;/h2&gt;
&lt;!-- SCRIPTS --&gt;
&lt;script&gt;
function Hello($scope) {
$scope.hello = &quot;Hello&quot;;
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>This was a quick introduction to AngularJS, more is coming. AngularJS is a powerful framework suitable for small and large applications.</p></content>
</entry>
<entry>
<title>Python map method and lambda expressions</title>
<link href="http://marizmelo.com/2013/04/02/python_map_lambdas.html"/>
<updated>2013-04-02T01:40:45Z</updated>
<id>http://marizmelo.com/2013/04/02/python_map_lambdas</id>
<content type="html"><p>I have been studying more <strong>python</strong> these days and decided to share some of my findings. Python has a powerful method called <strong>map</strong> that can apply operations to all items of a list.</p>
<p>Assume the following function definition For example:</p>
<pre><code>def square(x):
return x * x</code></pre>
<p>You can apply this function to a list of elements using python’s map method like this:</p>
<pre><code>print map( square, [1, 2, 3, 4, 5]) // [1, 4, 9 , 16, 25]</code></pre>
<p>But let’s take this power even further using a <strong>lambda</strong> expression. We could rewrite the expression above like this:</p>
<pre><code>print map( lambda(x): x * x, [1, 2, 3, 4 , 5]) // [1, 4, 9 , 16, 25]</code></pre>
<p>Now a third way to do this using an expressive formula in a <strong>list comprehension</strong>:</p>
<pre><code>print [x * x for x in [1, 2, 3, 4 ,5]] // also [1, 4, 9 , 16, 25]</code></pre>
<p>Have fun.</p></content>
</entry>
<entry>
<title>Python Lexical Analyzer </title>
<link href="http://marizmelo.com/2013/03/31/python_lexer.html"/>
<updated>2013-03-31T22:50:45Z</updated>
<id>http://marizmelo.com/2013/03/31/python_lexer</id>
<content type="html"><p>Interrupting our series on JavaScript I will talk about python and lexical analysis. <strong>Lexical analysis</strong> (or lexer) is the process of breaking words into <strong>tokens</strong> (small units).</p>
<p>Today we are going to create a small lexer in python to analyze a small piece of HTML code.</p>
<p>First we will need to import the python’s lexical library called <a href="http://www.dabeaz.com/ply/">ply</a>. To install ply in unix systems you can run the following command:</p>
<pre><code>sudo easy_install ply</code></pre>
<p>Create a file called <strong>lexer.py</strong> and write the following code:</p>
<pre><code>import ply.lex as lex # import lexer library
# token types that will be used by system
tokens = (
&#39;LANGLE&#39;, # &lt;
&#39;LANGLESLASH&#39;, # &lt;/
&#39;RANGLE&#39;, # &gt;
&#39;EQUAL&#39;, # =
&#39;NUMBER&#39;, # 33
&#39;STRING&#39;, # &quot;hello&quot;
&#39;WORD&#39; # any other words
)
t_ignore = &#39; &#39; # ignore white-spaces
# handles errors
def t_error(token):
print(&quot;Illegal character &#39;%s&#39;&quot; % token.value[0])
token.lexer.skip(1)
def t_LANGLESLASH(token):
r&#39;&lt;/&#39; # regular expression
return token
def t_LANGLE(token):
r&#39;&lt;&#39;
return token
def t_RANGLE(token):
r&#39;&gt;&#39;
return token
def t_EQUAL(token):
r&#39;=&#39;
return token
# match numbers strings and convert them to int
def t_NUMBER(token):
r&quot;[0-9]+&quot;
token.value = int(token.value)
return token
# match double quoted string without a &quot; inside
def t_STRING(token):
r&#39;&quot;[^&quot;]*&quot;&#39;
token.value = token.value[1:-1] # substring to strip double quotes
return token
# WORD is any word EXCEPT &lt;&gt; or space
def t_WORD(token):
r&quot;[^ &lt;&gt;]+&quot;
return token
webpage = &#39;&quot;This&quot; is 33 &lt;b&gt;my&lt;/b&gt; webpage!&#39; # string to be analyzed
htmllexer = lex.lex() # tells lex to use all token def (functions) above
htmllexer.input(webpage) # which string to break up
while True:
tok = htmllexer.token() # return next token available
if not tok: break
print tok</code></pre>
<p>This is a complex topic. Write a comment if you have any problems implementing this algorithm.</p>
<p>UPDATE: As pointed by Thiago Moura on the comments, this code and comments was written while following the Udacity programing language course at http://udacity.com. Thank you Thiago.</p></content>
</entry>
<entry>
<title>JavaScript Classes</title>
<link href="http://marizmelo.com/2013/03/31/javascript_classes.html"/>
<updated>2013-03-31T01:20:45Z</updated>
<id>http://marizmelo.com/2013/03/31/javascript_classes</id>
<content type="html"><p>Hi everyone, today we are going to talk about <strong>classes</strong> in JavaScript. JS don’t implement classes as other languages because its prototypical way.</p>
<p>Declare a class in JavaScript is as easy as create a <strong>Function</strong>. This is how you declare a <strong>function constructor</strong> in JavaScript:</p>
<pre><code>function Person(name) {
this.name = name;
}</code></pre>
<p>Define a new method using the function <strong>prototype</strong> (more about prototypes in another post) of our class:</p>
<pre><code>Person.prototype.getName = function() {
return this.name;
};</code></pre>
<p>Let’s now create an <strong>instance</strong> of our class <strong>Person</strong>:</p>
<pre><code>var me = new Person(&quot;Mariz&quot;); // create instance of Person</code></pre>
<p>I can use our method <strong>getName()</strong> to return my name:</p>
<pre><code>me.getName(); // Mariz</code></pre>
<p>Is that simple.</p></content>
</entry>
<entry>
<title>JavaScript - Easily Sorting an Array of Objects</title>
<link href="http://marizmelo.com/2013/03/27/javascript_array_of_objects_sorting.html"/>
<updated>2013-03-27T11:40:45Z</updated>
<id>http://marizmelo.com/2013/03/27/javascript_array_of_objects_sorting</id>
<content type="html"><p>Hi everyone, today we are going to take a look on a sleek technique to sort an <strong>Array of Objects</strong>.</p>
<p>The <strong>sort()</strong> method of JavaScript provide an easy way for us to sort Arrays. Take a look:</p>
<p>Numbers:</p>
<pre><code>[3, 1, 4, 2].sort(); // [1, 2, 3, 4]</code></pre>
<p>Characters:</p>
<pre><code>[&quot;a&quot;, &quot;d&quot;, &quot;c&quot;, &quot;b&quot;].sort(); // [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</code></pre>
<p>Strings:</p>
<pre><code>[&quot;Jose&quot;, &quot;Antonio&quot;, &quot;Ana&quot;, &quot;Michael&quot;].sort(); // [&quot;Ana&quot;, &quot;Antonio&quot;, &quot;Jose&quot;, &quot;Michael&quot;]</code></pre>
<p>Simple right? What about when you have an Array of Objects?</p>
<p>You can still use the <strong>sort()</strong> method to sort your Array, you just need to inform which property in the object you want to sort.</p>
<p>Let’s imagine a contact book for example. You will receive an unordered array of object that you want to sort:</p>
<p>Array of objects</p>
<pre><code>[{name:&quot;Mariz&quot;, age: 32}, {name: &quot;Samira&quot;, age: 25}, {name: &quot;Leticia&quot;, age: 9}]</code></pre>
<p>If you try to sort this array nothing will happen:</p>
<pre><code>[{name:&quot;Mariz&quot;, age: 32}, {name: &quot;Samira&quot;, age: 25}, {name: &quot;Leticia&quot;, age: 9}].sort();</code></pre>
<p>Now lets use a function expression (or callback function) to sort this array of objects:</p>
<p><strong>compareName</strong> callback function:</p>
<pre><code>function compareName(contact1, contact2) {
if (contact1.name &lt; contact2.name) {
return 0;
} else {
return 1;
}
}</code></pre>
<p>Calling sort method with callback function <strong>compareName</strong> that we wrote on the last step:</p>
<pre><code>[{name:&quot;Mariz&quot;, age: 32}, {name: &quot;Samira&quot;, age: 25}, {name: &quot;Leticia&quot;, age: 9}].sort(compareName);</code></pre>
<p>Sorting for age</p>
<pre><code>[{name:&quot;Mariz&quot;, age: 32}, {name: &quot;Samira&quot;, age: 25}, {name: &quot;Leticia&quot;, age: 9}].sort(function(contact1, contact2) {
return contact1.age - contact2.age;
});</code></pre>
<p>That is it for today!</p></content>
</entry>
<entry>
<title>JavaScript - painless decimal multiplication</title>
<link href="http://marizmelo.com/2013/03/22/painlessjavascriptdecimalmultiplication.html"/>
<updated>2013-03-22T03:00:45Z</updated>
<id>http://marizmelo.com/2013/03/22/painlessjavascriptdecimalmultiplication</id>
<content type="html"><p>JavaScript has a problem when multiplying decimals, try yourself:</p>
<pre><code>0.1 * 0.2
&gt; 0.020000000000000004 // NodeJS 0.8</code></pre>
<p>The way to correct this is to multiply the decimals before multiple their values, try yourself:</p>
<pre><code>( 0.1 * 10 + 0.2 * 10 ) / 10
&gt; 0.3</code></pre>
<p>You can create a function for this:</p>
<pre><code>function multdec ( val1, val2 ) {
return ( val1 * 10 + val2 * 10 ) / 10;
}</code></pre>
<p>You can extend the Math object:</p>
<pre><code>Math.multdec = function ( val1, val2 ) {
return ( val1 * 10 + val2 * 10 ) / 10;
}</code></pre>
<p>Now you can call this operation in two ways:</p>
<pre><code>multdec( val1, val2 ); // 0.3
// or
Math.multdec ( val1, val2 ); // 0.3</code></pre></content>
</entry>
<entry>
<title>Pure JavaScript SlideShow</title>
<link href="http://marizmelo.com/2013/03/18/purejavascriptslideshow.html"/>
<updated>2013-03-18T23:40:45Z</updated>
<id>http://marizmelo.com/2013/03/18/purejavascriptslideshow</id>
<content type="html"><p>I have decided to go back in time and learn pure JavaScript again. I was becoming too dependent of libraries like jQuery and that is never good. It is a good exercise and as a result I came up today with this simple SlideShow made completely in JavaScript.</p>
<p>Final result:</p>
<p><strong>index.html</strong></p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Pure JavaScript SlideShow&lt;/title&gt;
&lt;!-- STYLES --&gt;
&lt;style&gt;
.jslide { width: 350px; height: 350px; overflow: hidden; }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;jslide&quot;&gt;
&lt;img src=&quot;http://placehold.it/350&amp;text=01&quot;&gt;
&lt;img src=&quot;http://placehold.it/350&amp;text=02&quot;&gt;
&lt;img src=&quot;http://placehold.it/350&amp;text=03&quot;&gt;
&lt;img src=&quot;http://placehold.it/350&amp;text=04&quot;&gt;
&lt;img src=&quot;http://placehold.it/350&amp;text=05&quot;&gt;
&lt;/div&gt;
&lt;!-- SCRIPTS --&gt;
&lt;script src=&quot;JSlide.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p><strong>jslide.js</strong></p>
<pre><code>var current = 0;
var element = document.getElementById(&quot;jslide&quot;);
var slides = element.getElementsByTagName(&quot;img&quot;);
var size = slides.length;
var start = setInterval(function(){jslide();}, 3000);
function jslide(){
if ( current != size - 1 ) {
slides[ current ].style.display = &quot;none&quot;;
} else {
current = 0;
for ( var i = 0; i &lt; size; ++i ) {
slides[i].style.display = &quot;block&quot;;
}
}
}</code></pre>
<p>Now let’s take a look over the commented source code:</p>
<p><strong>Variables</strong></p>
<pre><code>// CURRENT SLIDE POSITION
var current = 0;
// CACHE SLIDESHOW DIV WRAPPER
var element = document.getElementById(&quot;jslide&quot;);
// CACHE SLIDESHOW IMAGES
var slides = element.getElementsByTagName(&quot;img&quot;);
// COUNT NUMBER OF SLIDES
var size = slides.length;
// LOOP OVER SLIDESHOW EVERY 3 SECONDS
var start = setInterval(function(){jslide();}, 3000);</code></pre>
<p><strong>JSlide slideShow function</strong></p>
<pre><code>function jslide(){
if ( current != size - 1 ) {
// CHECK IF CURRENT SLIDE IS THE LAST SLIDE
slides[ current ].style.display = &quot;none&quot;;
} else {
// IF IS THE LAST SLIDE RESTART SLIDESHOW
current = 0; // RESET &quot;CURRENT&quot; VARIABLE
for ( var i = 0; i &lt; size; ++i ) {
// RESET DISPLAY STYLE
slides[i].style.display = &quot;block&quot;;
}
}
}// jslide() </code></pre></content>
</entry>
<entry>
<title>Copy and Paste from command line</title>
<link href="http://marizmelo.com/2013/03/15/copypastecommandline.html"/>
<updated>2013-03-15T11:00:00Z</updated>
<id>http://marizmelo.com/2013/03/15/copypastecommandline</id>
<content type="html"><p>Use <strong>“pbcopy”</strong> to copy content of file to your clipboard.</p>
<p>For example:</p>
<pre><code>$ pbcopy &lt; file.txt</code></pre>
<p>the command will copy all content from “file.txt” directly on your clipboard.</p>
<p>You can check if the content is there by using the <strong>“pbpaste”</strong> command:</p>
<pre><code>$ pbpaste</code></pre>
<p>The content of “file.txt” will appear on your terminal window.</p></content>
</entry>
<entry>
<title>Are you missing "sudo" on commands in terminal? Don't worry.</title>
<link href="http://marizmelo.com/2013/02/16/dontmisssudo.html"/>
<updated>2013-02-16T01:40:45Z</updated>
<id>http://marizmelo.com/2013/02/16/dontmisssudo</id>
<content type="html"><p>Sometimes you are in your terminal and need to type a command that requires you to have root powers. Well I don’t know you, but I sometimes forget to put sudo in front of those commands. Look at this example:</p>
<pre><code>$ rm somefile
rm: somenewfile: Permission denied</code></pre>
<p>I have some options here. I could retype the entire command or use arrow up and go to the beginning of the line adding “sudo” to it. But a better way to fix my mistake is using the operator “!!”. Like this:</p>
<pre><code>$ rm somefile
rm: somenewfile: Permission denied
$ sudo !!
$ sudo rm newfile </code></pre>
<p>Amazing, your file “newfile” is now removed. Enjoy.</p></content>
</entry>
<entry>
<title>JavaScript - check your properties</title>
<link href="http://marizmelo.com/2013/02/12/checkproperty.html"/>
<updated>2013-02-12T00:40:45Z</updated>
<id>http://marizmelo.com/2013/02/12/checkproperty</id>
<content type="html"><p>Sometimes you need to check if an Object has certain property. JavaScript provide two different methods for this. Let’s start by creating a new Object called <strong>Person</strong>.</p>
<pre><code>var Person = {
name : &quot;Mariz&quot;,
age : 31
}</code></pre>
<p>Now let’s take a look on that methods which I mentioned before.</p>
<p><strong>hasOwnProperty</strong></p>
<pre><code>console.log( Person.hasOwnProperty (&quot;name&quot;) );
&gt; true</code></pre>
<p><strong>in</strong></p>
<pre><code>console.log( &quot;name&quot; in Person );
&gt; true</code></pre>
<p>You can also list all properties of your Objects using the method <strong>keys</strong>.</p>
<pre><code>console.log( Object.keys (Person) );
&gt; [ &quot;name&quot;, &quot;age&quot; ]</code></pre>
<p>That is it, simple and easy.</p></content>
</entry>
<entry>
<title>JavaScript Functions - Names</title>
<link href="http://marizmelo.com/2013/02/06/javascriptfunctionnames.html"/>
<updated>2013-02-06T00:40:00Z</updated>
<id>http://marizmelo.com/2013/02/06/javascriptfunctionnames</id>
<content type="html"><p>Function names in JavaScript can be trick. Consider the following function:</p>
<pre><code>function name(){
alert(&quot;Mariz Melo&quot;);
}</code></pre>
<p>There is nothing wrong with this function, in fact is a perfectly fine function in JavaScript. The problem is JavaScript has some rules for function names. You are not allowed to start the name with numbers or special characters (other than underscore and dollar sign).</p>
<pre><code>function $() {
alert(&quot;dollar sign&quot;);
}
function _() {
alert (&quot;underscore&quot;);
}</code></pre>
<p>Recently I tried to attach some CSS classes as function names in JavaScript and got an error because some of my class names are using “-” to separate names. See an example:</p>
<pre><code>// invalid
function display-none(){
alert(&quot;display none don&#39;t work&quot;);
}</code></pre>
<p>Of course I could use something like <strong>replace</strong> and convert “-” into “_”, but I wanted to keep consistency across the system, so I come up with the following solution:</p>
<pre><code>// valid
var css = {
&quot;display-none&quot; : function(){
alert(&quot;display none&quot;);
}
}</code></pre>
<p>I just used an Object as wrapper to all my functions, and doing so I kept all functions more organized.</p>
<p>Calling my function <strong>display-none</strong>:</p>
<pre><code>css[&quot;display-none&quot;](); // valid call</code></pre>
<p>Happy hacking!</p></content>
</entry>
<entry>
<title>JavaScript OOP - Objects attributes and values</title>
<link href="http://marizmelo.com/2013/02/04/forloopobjectjavascript.html"/>
<updated>2013-02-04T01:40:45Z</updated>
<id>http://marizmelo.com/2013/02/04/forloopobjectjavascript</id>
<content type="html"><p>Let’s create an Object called <strong>Person</strong> in JavaScript.</p>
<pre><code>// Object Literals way
var Person = { name : &quot;Anonymous&quot;, age : null };
// Functions way
function Person() {
this.name = &quot;Anonymous&quot;;
this.age = null;
}</code></pre>
<alert class='margin-bottom'><i class='icon-attention'> </i> Both ways are correct and valid</alert>
<p>Let’s create one <strong>instance</strong> of our object Person. In this case I will create an instance called <strong>Mariz</strong> (my name).</p>
<pre><code>// Object Literals way
var Mariz = Person;
// Functions way
var Mariz = new Person();</code></pre>
<p>Adding values to our new object instance:</p>
<pre><code>// Object Literals and Functions
Mariz.name = &quot;Mariz Melo&quot;;
Mariz.age = 31;</code></pre>
<p>Now here is how you loop over all attributes and return their values:</p>
<pre><code>for( prop in Mariz ) {
console.log( prop + &quot; : &quot; + Mariz[ prop ] );
}
// Output
&gt; name : Mariz Melo
&gt; age : 31</code></pre>
<p>That’s a wrap.</p></content>
</entry>
<entry>
<title>JavaScript Basics - Primitive Types</title>
<link href="http://marizmelo.com/2013/01/31/javascriptintro.html"/>
<updated>2013-01-31T02:00:00Z</updated>
<id>http://marizmelo.com/2013/01/31/javascriptintro</id>
<content type="html"><p>Let’s talk about JavaScript. Lately I’ve been working in a project for <a href="http://xchema.com">xchema</a> that involves the use of JavaScript as primary language. So this will be a good exercise for me.</p>
<h5 id="variables">Variables</h5>
<p>Basic structure to save values (in determined address memory).</p>
<pre><code>var name = &quot;Mariz Melo&quot;;</code></pre>
<h5 id="strings">Strings</h5>
<p>There is no difference between using single or double quotes when writing strings.</p>
<pre><code>&quot;hello world&quot;
&#39;hello world&#39;
&quot;Let&#39;s learn \&quot;JavaScript\&quot;&quot;
// You need to scape (\) the quote-type that holds your string</code></pre>
<h4 id="numbers">Numbers</h4>
<p>JavaScript hava only one type for numbers. Just type the number you want and JavaScript will understand its type (integer, decimal, etc).</p>
<pre><code>var val1 = 10;
var val2 = 0.1;</code></pre>
<p>There is a notable bug while multiplying decimals in JavaScript. You need to multiply the decimals before multiply their values.</p>
<pre><code>0.1 * 0.2
&gt; 0.020000000000000004 // wrong
( 0.1 * 10 + 0.2 * 10 ) / 10
&gt; 0.3 // correct</code></pre>
<h5 id="null_vs_undefined">Null vs Undefined</h5>
<p>Another major point of confusion on JavaScript. A <strong>undefined</strong> variable it means that the variable was declared but does not contain any value. A variable is <strong>null</strong> when the variable it was declared and had its value set to null.</p>
<pre><code>var myvar;
&gt; undefined
typeof myvar
&gt; undefined
myvar = null
typeof myvar
&gt; object
myvar == null
&gt; true
myvar == undefined
&gt; true // what just happen here?
myvar === null // test value + type equality
&gt; true
myvar === undefined
&gt; false // now seems right</code></pre>
<alert class='info margin-bottom'><i class='icon-info'> </i> Prefer === over == for strict comparisons.</alert><alert><i class='icon-attention'> </i> You may get an Exception if you don't declare the variable before using it.</alert></content>
</entry>
<entry>
<title>RequireJS - i18n (internationalization)</title>
<link href="http://marizmelo.com/2013/01/28/requirei18n.html"/>
<updated>2013-01-28T15:00:00Z</updated>
<id>http://marizmelo.com/2013/01/28/requirei18n</id>
<content type="html"><div class='float-right'><img src='http://requirejs.org/i/logo.png' width='200px' /></div>
<p><a href="/2013/01/27/requirejs.html">Last time</a> we talked about RequireJS and how it can load JavaScript files faster and in parallel. But there is much more that this little library can do. Today I will show you how to make your applications available in multiple languages. RequireJS provides an useful set of plug-ins (see complete list <a href="https://github.com/jrburke/requirejs/wiki/Plugins">here</a>) that can help with different tasks.</p>
<p>The plug-in which we are going to use today is called <a href="http://requirejs.org/docs/api.html#i18n">i18n</a> and its used for <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">internationalization</a> of content based on you browser main language. <a href="https://raw.github.com/requirejs/i18n/latest/i18n.js">Download the plugin here</a> and place the file on your script directory defined on your <strong>data-main</strong> attribute (on your script tag).</p>
<ol>
<li>
<p>Create an <code>index.html</code> file with RequireJS on your <code>HEAD</code> tag element:</p>
<pre><code> &lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Hello World&lt;/title&gt;
&lt;script data-main=&quot;scripts/main.js&quot; src=&quot;scripts/require.js&quot;&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;header&gt;&lt;/header&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
</li>
<li>
<p>Place the <code>i18n.js</code> file into the <strong>scripts</strong> folder.</p>
</li>
<li>
<p>Create a directory called <code>nls</code> inside of your <strong>scripts</strong> folder.</p>
</li>
<li>
<p>Create another folder called <code>pt-br</code> (Brazilian Portuguese language) inside of <strong>scripts/nls</strong>.</p>
</li>
<li>
<p>Create a file called <code>speak.js</code> inside of the <strong>scripts/nls</strong> directory.</p>
</li>
</ol>
<h6>scripts/nls/speak.js</h6>
<pre><code> define({
&quot;root&quot; : {
&quot;header&quot; : &quot;I speak English&quot;
},
&quot;pt-br&quot; : true // The system will accept Brazilian Portuguese
});</code></pre>
<ol>
<li>Create another file with the name <code>speak.js</code> inside of <strong>scripts/nls/pt-br</strong>.</li>
</ol>
<h6>scripts/nls/pt-br/speak.js</h6>
<pre><code> define({
&quot;header&quot; : &quot;Eu falo Portugues do Brasil&quot;
});</code></pre>
<ol>
<li>Download <a href="http://jquery.com">JQuery</a> and place it inside your <strong>scripts</strong> folder</li>
<li>Define your <code>main.js</code> in your <strong>scripts</strong> folder with the following content:</li>
</ol>
<h6>scripts/jquery.js</h6>
<pre><code> define([&#39;jquery&#39;, &quot;i18n!nls/speak&quot;], function($, speak) {
$(&quot;header h1&quot;).html(speak.header);
});</code></pre>
<p>If you load this project on your browser you should see <strong>“I speak English”</strong>.</p>
<p>Now what?</p>
<p>Well <strong>i18n</strong> is smart and will change the language automatically for you if your browser accepts Brazilian Portuguese. You can set manually the language which you want to use (good to test if everything is working properly).</p>
<p>Open <code>main.js</code> and include the following code on TOP of the file:</p>
<pre><code>require.config({
locale: &quot;pt-br&quot;
});
...</code></pre>
<p>Reload your browser (cleaning cache if necessary) and you should see the message <strong>“Eu falo Portugues do Brasil”</strong>.</p>
<p>Get the source files: <a href="https://compilr.com/jmarizsf/requirejs-i18n">https://compilr.com/jmarizsf/requirejs-i18n</a>.</p></content>
</entry>
<entry>
<title>Boosting your JavaScript loading time with RequireJS</title>
<link href="http://marizmelo.com/2013/01/27/requirejs.html"/>
<updated>2013-01-27T22:23:00Z</updated>
<id>http://marizmelo.com/2013/01/27/requirejs</id>
<content type="html"><p>There are two common ways to load JavaScript on HTML pages.</p>
<ol>
<li>Scripts on the <code>head</code> tag element</li>
<li>Scripts on the bottom of your <code>html</code> page (right before <code>/body</code>)</li>
</ol>
<p><br /><br /></p>
<p>The first technique has a serious problem, the browser will wait for all scripts to load before showing content to users.</p>
<p>In the second (better) case the page will be presented to your users before loading any script. This is <strong>unobtrusive</strong>, the JavaScript is not in the way between users and content delivery. Do you want anyone waiting for your website to load?</p>
<p>So what is the problem with the second technique? Well, the first problem is that using <code>script</code> tag your scripts will load <strong>sequentially</strong> increasing the total time for users to see your website.</p>
<p>A better approach is to load your scripts in <strong>parallel</strong>, but there is one caveat. Scripts most of the time have dependencies and is complicated to manage them while loading them in parallel. You could come up with your own system to manage dependencies or you could use <strong>Asynchronous Module Definitio (AMD)</strong>.</p>
<p>Using AMD you can load your scripts in parallel while managing their dependencies. So let’s take a look on how to use <strong>RequireJS</strong> a popular AMD solution (see the end of this article for other options).</p>
<p>First, let’s insert RequireJS on the <code>head</code> of our HTML file:</p>
<pre><code>&lt;script data-main=&quot;scripts/main.js&quot; src=&quot;scripts/require.js&quot;&gt;&lt;/script&gt;</code></pre>
<p>You may have noticed the <strong>data-main</strong> attribute on the example above. That defines the location of your configuration file (main.js in this example) and automatically set the <strong>baseUrl</strong>, in this case <strong>scripts/</strong>.</p>
<alert class='info margin-top margin-bottom'><i class='icon-info'> </i> The <strong>baseUrl</strong> can be changed on the configuration file.</alert><alert class='warning margin-top margin-bottom'><i class='icon-attention'> </i> Dependencies shouldn't contain the trailing ".js" suffix on the config file.</alert><alert class='warning margin-top margin-bottom'><i class='icon-attention'> </i> RequireJS load scripts asynchronously and out of order for speed.</alert>
<p>Assuming all my scripts are inside the <code>scripts</code> folder, let’s load some files using RequireJS. The <strong>JQuery</strong> library will be loaded <strong>first</strong> followed by two plugins called <strong>slidejs</strong> and <strong>galleryjs</strong>.</p>
<p>In you <code>main.js</code> write:</p>
<pre><code>//loading jquery as dependency
require([&quot;jquery&quot;], function($){
// JQuery is ready for use
//calling slidejs plugin
require([&quot;slidejs&quot;, &quot;galleryjs&quot;], function(){
$(&quot;#slideshow&quot;).slidejs();
$(&quot;#gallery&quot;).galleryjs();
});
});</code></pre>
<p>Because RequireJS load scripts out of order we have to make sure JQuery is ready before we load our plugins. The plugins are loaded in <strong>parallel</strong>.</p>
<p>RequireJS is powerful and here I just touch the surface of its real power. Make sure you check the <a href="http://requirejs.org/">RequireJS website</a> for a complete overview.</p>
<p>Alternatives to RequireJS:</p>
<ul>
<li><a href="http://labjs.com/">LABjs</a></li>
<li><a href="http://headjs.com/">HEADjs</a></li>
</ul>
<p><br /></p></content>
</entry>
<entry>
<title>Hello World!</title>
<link href="http://marizmelo.com/2013/01/25/hello.html"/>
<updated>2013-01-25T01:40:45Z</updated>
<id>http://marizmelo.com/2013/01/25/hello</id>
<content type="html"><p>Hello, my name is <strong>Mariz Melo</strong>. I am from Brazil. Currently living in San Jose - California and working in Mountain View. I am trying to get <strong>xchema</strong> up and running for next summer. The name is the same as my previous start up company which I opened in Brazil with my dear friends <strong>Ricardo Amaral</strong> and <strong>Marcelo Vasconcelos</strong>.</p>
<p>This blog is an attempt to keep a diary about projects, knowledge base, and a bookmark for useful discoveries around the web.</p>
<p>Tools used to make this blog:</p>
<ol>
<li><a href="http://jekyllrb.com">Jekyll</a> (on github pages)</li>
<li><a href="http://xtyle.xchema.com">xtyle</a> design framework made by <a href="http://xchema.com">xchema</a></li>
<li><strong>xmaker</strong> visual web applications builder (coming soon).</li>
</ol>
<p>This website is open-source. <strong>Fork the github <a href="http://github.com/marizmelo/marizmelo.github.com">repository</a>.</strong></p></content>
</entry>
</feed>