forked from gotchacode/gotchacode.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
785 lines (698 loc) · 88.6 KB
/
Copy pathatom.xml
File metadata and controls
785 lines (698 loc) · 88.6 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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Gotchacode]]></title>
<link href="http://gotchacode.com/atom.xml" rel="self"/>
<link href="http://gotchacode.com/"/>
<updated>2014-02-26T11:59:13+05:30</updated>
<id>http://gotchacode.com/</id>
<author>
<name><![CDATA[Vinit Kumar]]></name>
<email><![CDATA[vinitcool76@gmail.com]]></email>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Simple State Machine Framework in Csharp]]></title>
<link href="http://gotchacode.com/blog/2014/02/26/simple-state-machine-framework-in-c-number/"/>
<updated>2014-02-26T11:37:18+05:30</updated>
<id>http://gotchacode.com/blog/2014/02/26/simple-state-machine-framework-in-c-number</id>
<content type="html"><![CDATA[<p>This blog post covers a very simple, light weight, yet flexible state machine framework in csharp.</p>
<p><a href="https://www.nuget.org/packages/SSM/">Download NuGet package</a>__</p>
<p>Please see SSM.Tests folder for an example as well as test cases_</p>
<h2>Concept</h2>
<p><strong>State :</strong> The state of a stateful entity. Represented by <code>IState</code></p>
<p><strong>Stateful entity :</strong> An entity that has a defined state. Represented by <code>IStatefulEntity</code></p>
<p><strong>Context :</strong> A context in which a state machine executes a transition. It is simply a set of configuration and data that governs the execution of a state machine. Represented by <code>IStateMachineContext</code></p>
<p><strong>Transition handler :</strong> A component that handles a transition of a stateful entity between a source state to target state. Represented by <code>ITransitionHandler</code></p>
<h2>Usage</h2>
<p>Start by creating an entity that represents a state.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'> <span class="k">public</span> <span class="k">class</span> <span class="nc">ServiceTicketState</span> <span class="p">:</span> <span class="n">IState</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">public</span> <span class="kt">string</span> <span class="n">Code</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'> <span class="k">public</span> <span class="kt">string</span> <span class="n">Name</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'> <span class="c1">// ...</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span></code></pre></td></tr></table></div></figure>
<p>Now, create a stateful entity by implementing <code>IStatefulEntity</code> interface. For exmaple:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'><span class="k">public</span> <span class="k">class</span> <span class="nc">ServiceTicket</span> <span class="p">:</span> <span class="n">IStatefulEntity</span><span class="p"><</span><span class="n">ServiceTicketState</span><span class="p">></span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'> <span class="k">public</span> <span class="n">ServiceTicketState</span> <span class="n">State</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'> <span class="k">public</span> <span class="kt">string</span> <span class="n">Name</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'> <span class="c1">// ...</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>Next comes transition handlers. A transition hadler is created by implementing <code>ITransitionHandler</code> interface. Below is an example of a generic transition handler that can be used to abstract common functionalities in our Service Ticket example.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<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>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'> <span class="k">public</span> <span class="k">class</span> <span class="nc">GenericTransitionHandler</span> <span class="p">:</span> <span class="n">ITransitionHandler</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">></span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">public</span> <span class="k">virtual</span> <span class="kt">string</span> <span class="n">TransitionKey</span> <span class="p">{</span> <span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="s">""</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="k">virtual</span> <span class="n">ServiceTicket</span> <span class="nf">Execute</span><span class="p">(</span><span class="n">ServiceTicket</span> <span class="n">entity</span><span class="p">,</span> <span class="n">ServiceTicketState</span> <span class="n">nextState</span><span class="p">,</span> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="kt">object</span><span class="p">></span> <span class="n">argumentsMap</span> <span class="p">=</span> <span class="k">null</span><span class="p">)</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="n">entity</span><span class="p">.</span><span class="n">State</span> <span class="p">=</span> <span class="n">nextState</span><span class="p">;</span>
</span><span class='line'> <span class="k">return</span> <span class="n">entity</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="k">virtual</span> <span class="n">ServiceTicket</span> <span class="nf">ValidateTransition</span><span class="p">(</span><span class="n">ServiceTicket</span> <span class="n">entity</span><span class="p">,</span> <span class="n">ServiceTicketState</span> <span class="n">nextState</span><span class="p">,</span> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="kt">object</span><span class="p">></span> <span class="n">argumentsMap</span> <span class="p">=</span> <span class="k">null</span><span class="p">)</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="n">entity</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="k">virtual</span> <span class="k">void</span> <span class="nf">BeforeTransition</span><span class="p">(</span><span class="n">ServiceTicket</span> <span class="n">entity</span><span class="p">,</span> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="kt">object</span><span class="p">></span> <span class="n">argumentsMap</span> <span class="p">=</span> <span class="k">null</span><span class="p">)</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="k">virtual</span> <span class="k">void</span> <span class="nf">AfterTransition</span><span class="p">(</span><span class="n">ServiceTicket</span> <span class="n">entity</span><span class="p">,</span> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="kt">object</span><span class="p">></span> <span class="n">argumentsMap</span> <span class="p">=</span> <span class="k">null</span><span class="p">)</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>Next and final step is to create a ‘context’ by implementing <code>IStateMachineContext</code> interface. This interface declares following methods that need to be implemented to create a context.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'><span class="n">ICollection</span><span class="p"><</span><span class="n">StateTransition</span><span class="p">></span> <span class="n">GetTransitions</span><span class="p">();</span>
</span><span class='line'><span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="n">ITransitionHandler</span><span class="p"><</span><span class="n">T</span><span class="p">,</span><span class="n">M</span><span class="p">>></span> <span class="n">GetTransitionHandlersMap</span><span class="p">();</span>
</span><span class='line'><span class="n">ICollection</span><span class="p"><</span><span class="n">M</span><span class="p">></span> <span class="n">AllStates</span><span class="p">();</span>
</span></code></pre></td></tr></table></div></figure>
<p>Implementation approach is left to the user. It could from just hard coding for simple cases to database backed storage and retrieval for more advanced cases.</p>
<p>Here is an example implementation (hard coded for simplicity)</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<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>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'> <span class="k">public</span> <span class="n">ICollection</span><span class="p"><</span><span class="n">StateTransition</span><span class="p">></span> <span class="n">GetTransitions</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="n">ICollection</span><span class="p"><</span><span class="n">StateTransition</span><span class="p">></span> <span class="n">map</span> <span class="p">=</span> <span class="k">new</span> <span class="n">List</span><span class="p"><</span><span class="n">StateTransition</span><span class="p">>();</span>
</span><span class='line'> <span class="c1">// Define all possible transitions, and its source and target states</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">StateTransition</span><span class="p">(</span><span class="s">"?"</span><span class="p">,</span> <span class="s">"Transition_New"</span><span class="p">,</span> <span class="s">"New"</span><span class="p">));</span> <span class="c1">// ? means null or undefined state</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">StateTransition</span><span class="p">(</span><span class="s">"New"</span><span class="p">,</span> <span class="s">"Transition_Open"</span><span class="p">,</span> <span class="s">"Open"</span><span class="p">));</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">StateTransition</span><span class="p">(</span><span class="s">"Open"</span><span class="p">,</span> <span class="s">"Transition_Close"</span><span class="p">,</span> <span class="s">"Closed"</span><span class="p">));</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">StateTransition</span><span class="p">(</span><span class="s">"Closed"</span><span class="p">,</span> <span class="s">"Transition_ReOpen"</span><span class="p">,</span> <span class="s">"Open"</span><span class="p">));</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">StateTransition</span><span class="p">(</span><span class="s">"?"</span><span class="p">,</span> <span class="s">"Transition_Cancel"</span><span class="p">,</span> <span class="s">"Cancelled"</span><span class="p">));</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="n">map</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="n">ITransitionHandler</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">>></span> <span class="n">GetTransitionHandlersMap</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="n">IDictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="n">ITransitionHandler</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">>></span> <span class="n">map</span> <span class="p">=</span> <span class="k">new</span> <span class="n">Dictionary</span><span class="p"><</span><span class="kt">string</span><span class="p">,</span> <span class="n">ITransitionHandler</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">>>();</span>
</span><span class='line'> <span class="c1">// create a map of all available transitions and their respective transition handlers</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">"Transition_New"</span><span class="p">,</span> <span class="k">new</span> <span class="n">NewTransitionHandler</span><span class="p">());</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">"Transition_Open"</span><span class="p">,</span> <span class="k">new</span> <span class="n">OpenTransitionHandler</span><span class="p">());</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">"Transition_Close"</span><span class="p">,</span> <span class="k">new</span> <span class="n">CloseTransitionHandler</span><span class="p">());</span>
</span><span class='line'> <span class="n">map</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="s">"Transition_ReOpen"</span><span class="p">,</span> <span class="k">new</span> <span class="n">OpenTransitionHandler</span><span class="p">());</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="n">map</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="n">ICollection</span><span class="p"><</span><span class="n">ServiceTicketState</span><span class="p">></span> <span class="n">AllStates</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="n">List</span><span class="p"><</span><span class="n">ServiceTicketState</span><span class="p">></span> <span class="n">states</span> <span class="p">=</span> <span class="k">new</span> <span class="n">List</span><span class="p"><</span><span class="n">ServiceTicketState</span><span class="p">>();</span>
</span><span class='line'> <span class="c1">// create a list of all possible states</span>
</span><span class='line'> <span class="n">states</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">ServiceTicketState</span><span class="p">()</span> <span class="p">{</span> <span class="n">Code</span> <span class="p">=</span> <span class="s">"New"</span><span class="p">,</span> <span class="n">Name</span> <span class="p">=</span> <span class="s">"New Ticket"</span> <span class="p">});</span>
</span><span class='line'> <span class="n">states</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">ServiceTicketState</span><span class="p">()</span> <span class="p">{</span> <span class="n">Code</span> <span class="p">=</span> <span class="s">"Open"</span><span class="p">,</span> <span class="n">Name</span> <span class="p">=</span> <span class="s">"Ticket Open"</span> <span class="p">});</span>
</span><span class='line'> <span class="n">states</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">ServiceTicketState</span><span class="p">()</span> <span class="p">{</span> <span class="n">Code</span> <span class="p">=</span> <span class="s">"Closed"</span><span class="p">,</span> <span class="n">Name</span> <span class="p">=</span> <span class="s">"Ticket Closed"</span> <span class="p">});</span>
</span><span class='line'> <span class="n">states</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="n">ServiceTicketState</span><span class="p">()</span> <span class="p">{</span> <span class="n">Code</span> <span class="p">=</span> <span class="s">"Cancelled"</span><span class="p">,</span> <span class="n">Name</span> <span class="p">=</span> <span class="s">"Ticket Cancelled"</span> <span class="p">});</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="n">states</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now <code>ServiceTicket</code> entity can be transitioned through state machine. Create an instance of <code>StateMachine</code> as follows.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'> <span class="n">IStateMachineContext</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">></span> <span class="n">context</span> <span class="p">=</span> <span class="k">new</span> <span class="n">ExampleStateMachineContext</span><span class="p">();</span>
</span><span class='line'> <span class="n">StateMachine</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">></span> <span class="n">StateMachine</span> <span class="p">=</span> <span class="k">new</span> <span class="n">StateMachine</span><span class="p"><</span><span class="n">ServiceTicket</span><span class="p">,</span> <span class="n">ServiceTicketState</span><span class="p">>(</span><span class="n">context</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>And request a transition as shown below.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='csharp'><span class='line'> <span class="n">ServiceTicket</span> <span class="n">serviceTicket</span> <span class="p">=</span> <span class="k">new</span> <span class="n">ServiceTicket</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="n">Name</span> <span class="p">=</span> <span class="s">"An example service ticket"</span>
</span><span class='line'> <span class="p">};</span>
</span><span class='line'>
</span><span class='line'> <span class="n">StateMachine</span><span class="p">.</span><span class="n">RequestTransition</span><span class="p">(</span><span class="n">serviceTicket</span><span class="p">,</span> <span class="s">"Transition_New"</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>If you wish to contribute to the project, it is open sourced here: <a href="https://github.com/mubeenh/SSM">SSM</a></p>
<p>Feel free to contact the author of the package in case of any queries about the framework here: <a href="mailto:mubeen.haidar@gmail.com">mubeen.haidar@gmail.com</a></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Setup a Local Gitignore Without Messing Up Project]]></title>
<link href="http://gotchacode.com/blog/2014/02/15/setup-a-local-gitignore-without-messing-up-project/"/>
<updated>2014-02-15T07:51:16+05:30</updated>
<id>http://gotchacode.com/blog/2014/02/15/setup-a-local-gitignore-without-messing-up-project</id>
<content type="html"><![CDATA[<p>A lot of us use Git for Version Control. If you have used git, you must be aware of .gitignore files. It contains the list of all file and directories you want git to ignore so that it would nevet get committed. But if you work in multi person team. You might not have liberty to change the projects gitignore. What to do then?</p>
<p>Well, the solution is pretty simple. Say you are using any IDE like Pycharm or Netbeans. They always create some files to create track of your projects. Something like <code>.ropeproject</code></p>
<p>So in order to make git ignore it, Go to : <code>cd .git/info/</code></p>
<p>You see there is a file called exclude. Fill it up with the files and directories you want it to ignore, just like the gist below:</p>
<div><script src='https://gist.github.com/7597812.js'></script>
<noscript><pre><code># git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.ropeproject/*</code></pre></noscript></div>
<p>And it is done. Now you never have to worry about your editor messing up your commits.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[How to Use Facebook Page Albums as Image Source in Django]]></title>
<link href="http://gotchacode.com/blog/2014/02/14/how-to-use-facebook-page-albums-as-image-source-in-django/"/>
<updated>2014-02-14T20:39:36+05:30</updated>
<id>http://gotchacode.com/blog/2014/02/14/how-to-use-facebook-page-albums-as-image-source-in-django</id>
<content type="html"><![CDATA[<p>Lot of companies use Facebook for marketing their products. Facebook is mainly built around images. In fact the whole ecosystem is fueled by images. In order to scale for the vast user base of Facebook, they have done a really good job.</p>
<p>So what if you don’t want to use your own storage for uploading images and want to use Facebook for Images? It would be so cool, right?
There are two benefits:</p>
<ul>
<li>You don’t have to spend anytime setting up an app or service to deal with images. Believe me it is a real tough problem to solve given the size and count of images. You can’t put a bar on either of these two.</li>
<li>It gives your users a much user friendly way. They upload images just once on Facebook and it auto-magically appears on your website. Facebook almost never gets down so there is very good chance you will get a 99.9% uptime.</li>
</ul>
<p>So, In order to fix this problem last year I created a Ajax based plugins to fetch images from Facebook album. It asked user to enter album URL and name. But there was an issue with this approach. In order to get access to Facebook graph database it has to get access tokens and each access token only last two months. Plus, it collapsed when it faced IE, since there is unsolvable CORS issue with IE < 9 (our 50% client base for that project).</p>
<p>It was a tough problem to solve. But i finally found some good articles and projects on Internet. One such project was django-fbgallery. It used a really neat approach to get the Facebook images server side and renders it the page purely server side. It not only solved the IE issue, but also the quality and speed of image loading became instant.</p>
<p>But there was an issue with this app, it used URLS to render the albums and spoiled the pretty URLS that you would like for pages in Django. So I took the core part of the app ( the Facebook interaction part) and made a sweet CMS plugin out of it.</p>
<p>Here is the code to make it all work:</p>
<figure class='code'><figcaption><span>Facebook.py </span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">django.core.cache</span> <span class="kn">import</span> <span class="n">cache</span>
</span><span class='line'><span class="kn">import</span> <span class="nn">urllib2</span><span class="o">,</span> <span class="nn">urllib</span>
</span><span class='line'><span class="kn">import</span> <span class="nn">django.utils.simplejson</span> <span class="kn">as</span> <span class="nn">json</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">django.template</span> <span class="kn">import</span> <span class="n">defaultfilters</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="n">fql_url</span> <span class="o">=</span> <span class="s">'https://api.Facebook.com/method/fql.query'</span>
</span><span class='line'><span class="n">cache_expires</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="s">'CACHE_EXPIRES'</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">get_fql_result</span><span class="p">(</span><span class="n">fql</span><span class="p">):</span>
</span><span class='line'> <span class="n">cachename</span> <span class="o">=</span> <span class="s">'fbgallery_cache_'</span> <span class="o">+</span> <span class="n">defaultfilters</span><span class="o">.</span><span class="n">slugify</span><span class="p">(</span><span class="n">fql</span><span class="p">)</span>
</span><span class='line'> <span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>
</span><span class='line'> <span class="k">if</span> <span class="n">cache_expires</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
</span><span class='line'> <span class="n">data</span> <span class="o">=</span> <span class="n">cache</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cachename</span><span class="p">)</span>
</span><span class='line'> <span class="k">if</span> <span class="n">data</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
</span><span class='line'> <span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'> <span class="s">'query'</span><span class="p">:</span><span class="n">fql</span><span class="p">,</span>
</span><span class='line'> <span class="s">'format'</span><span class="p">:</span><span class="s">'json'</span><span class="p">,</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="n">f</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">urllib2</span><span class="o">.</span><span class="n">Request</span><span class="p">(</span><span class="n">fql_url</span><span class="p">,</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">(</span><span class="n">options</span><span class="p">)))</span>
</span><span class='line'> <span class="n">response</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</span><span class='line'> <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span><span class='line'> <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
</span><span class='line'> <span class="k">if</span> <span class="n">cache_expires</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
</span><span class='line'> <span class="n">cache</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">cachename</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">cache_expires</span><span class="o">*</span><span class="mi">60</span><span class="p">)</span>
</span><span class='line'> <span class="k">return</span> <span class="n">data</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">display_album</span><span class="p">(</span><span class="n">album_id</span><span class="p">):</span>
</span><span class='line'> <span class="sd">"""Display a Facebook album</span>
</span><span class='line'>
</span><span class='line'><span class="sd"> First check that the album id belongs to the page id specified</span>
</span><span class='line'><span class="sd"> """</span>
</span><span class='line'> <span class="n">fb_id</span> <span class="o">=</span> <span class="n">settings</span><span class="o">.</span><span class="n">FB_PAGE_ID</span>
</span><span class='line'> <span class="n">fql</span> <span class="o">=</span> <span class="s">"select aid, name from album where owner=</span><span class="si">%s</span><span class="s"> and aid='</span><span class="si">%s</span><span class="s">'"</span> <span class="o">%</span> <span class="p">(</span><span class="n">fb_id</span><span class="p">,</span> <span class="n">album_id</span><span class="p">)</span>
</span><span class='line'> <span class="n">valid_album</span> <span class="o">=</span> <span class="n">get_fql_result</span><span class="p">(</span><span class="n">fql</span><span class="p">)</span>
</span><span class='line'> <span class="k">if</span> <span class="n">valid_album</span><span class="p">:</span>
</span><span class='line'> <span class="n">fql</span> <span class="o">=</span> <span class="s">"select pid, src, src_small, src_big, caption from photo where aid = '</span><span class="si">%s</span><span class="s">' order by created desc"</span> <span class="o">%</span> <span class="n">album_id</span>
</span><span class='line'> <span class="n">album</span> <span class="o">=</span> <span class="n">get_fql_result</span><span class="p">(</span><span class="n">fql</span><span class="p">)</span>
</span><span class='line'> <span class="c">#album_detail = [item for item in valid_album] </span>
</span><span class='line'> <span class="k">return</span> <span class="n">album</span>
</span></code></pre></td></tr></table></div></figure>
<p>I asked user to enter the album ID and name, then rendered the album using the plugin here:</p>
<figure class='code'><figcaption><span>cms_plugins.py </span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">from</span> <span class="nn">cms.plugin_base</span> <span class="kn">import</span> <span class="n">CMSPluginBase</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">cms.plugin_pool</span> <span class="kn">import</span> <span class="n">plugin_pool</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">ugettext_lazy</span> <span class="k">as</span> <span class="n">_</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">Facebook</span> <span class="kn">import</span> <span class="n">display_album</span>
</span><span class='line'>
</span><span class='line'><span class="kn">from</span> <span class="nn">models</span> <span class="kn">import</span> <span class="n">FacebookGallery</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">FacebookGalleryPlugin</span><span class="p">(</span><span class="n">CMSPluginBase</span><span class="p">):</span>
</span><span class='line'> <span class="n">model</span> <span class="o">=</span> <span class="n">FacebookGallery</span>
</span><span class='line'> <span class="n">name</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">"Facebook Album Gallery"</span><span class="p">)</span>
</span><span class='line'> <span class="n">render_template</span> <span class="o">=</span> <span class="s">"cmsplugin_fbgallery/album.html"</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">placeholder</span><span class="p">):</span>
</span><span class='line'> <span class="n">album</span> <span class="o">=</span> <span class="n">display_album</span><span class="p">(</span><span class="n">instance</span><span class="o">.</span><span class="n">album_id</span><span class="p">)</span>
</span><span class='line'> <span class="n">context</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
</span><span class='line'> <span class="s">'object'</span><span class="p">:</span> <span class="n">instance</span><span class="p">,</span>
</span><span class='line'> <span class="s">'album'</span><span class="p">:</span> <span class="n">album</span><span class="p">,</span>
</span><span class='line'> <span class="p">})</span>
</span><span class='line'> <span class="k">return</span> <span class="n">context</span>
</span><span class='line'>
</span><span class='line'><span class="n">plugin_pool</span><span class="o">.</span><span class="n">register_plugin</span><span class="p">(</span><span class="n">FacebookGalleryPlugin</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>You could choose whatever template you want. It’s entirely upto you.</p>
<p>Here is the image of this plugin live in action:</p>
<p><a href="http://imgur.com/dmrxcXh"><img src="http://i.imgur.com/dmrxcXh.png" title="Hosted by imgur.com" /></a></p>
<p>The plugin is open sourced here: <a href="https://github.com/changer/cmsplugin-fbgallery">cmsplugin-fbgallery</a> . Feel free to contribute and ask questions.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Migrating to Octopress]]></title>
<link href="http://gotchacode.com/blog/2014/02/13/migrating-to-octopress/"/>
<updated>2014-02-13T23:07:02+05:30</updated>
<id>http://gotchacode.com/blog/2014/02/13/migrating-to-octopress</id>
<content type="html"><![CDATA[<p>Finally after much ado, I am moving Gotchacode to Octopress. There are various reasons for doing it.
I am listing some of them here:</p>
<ul>
<li>There is absolutely no good theme if you are running a technical blog.</li>
<li>Syntax highlighting is pathetic.</li>
<li>I can’t write post in my text editor.</li>
<li>There is no source control.</li>
</ul>
<p>But I will miss blogspot too. The integrated analytics was best in class and so was the SEO.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Music, Movies and Life]]></title>
<link href="http://gotchacode.com/2014/01/music-movies-and-life.html"/>
<updated>2014-01-12T08:29:00+05:30</updated>
<id>http://gotchacode.com/2014/01/music-movies-and-life</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">I love watching Movies and I love Music. They are almost inseperable part of life. I love the way they could touch and move your life more than you could imagine. I remember watching “The Social Network” almost 50 times in college. It served as a push to write more code and do awesome in life.<div><br /></div><div>Well, it might sound really strange but for last 10 years or so. I just let life flow in the natural way. I failed quite sometimes, achieved success as well. Made some long lasting friends, lost some people I felt who were my friends.</div><div><br /></div><div>The great thing is that in all these experiences, I realised that what is the true purpose of my life. They say, there are just two important days in your life.</div><div><br /></div><blockquote class="tr_bq">The day when you are born, and the day you find out why?</blockquote>I think I just found out the purpose of my life. It’s not something I would want to disclose and claim I am going to achieve. It is the way my thinking changed and the choice of life I am going to make.<br /><br />Also, I would love to thank the wonderful readers of this blog - which initially started casually just to empty my mind on topics I felt were relevant at that time. For sure there are some not so good posts as well. But again, this blog is just me writing what comes in my mind. And if some of those helps someone or guide someone. Why not?<br /><br /></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Happy New Year 2014]]></title>
<link href="http://gotchacode.com/2014/01/happy-new-year-2014.html"/>
<updated>2014-01-01T13:22:00+05:30</updated>
<id>http://gotchacode.com/2014/01/happy-new-year-2014</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">A very happy new year to all the readers of this blog. To start with, I would try to publish a post at least once a week so that it may satisfy your appetite on a regular basis. Also, I am meditating about something new on this blog. It will be revealed when the time comes. With that said, have an amazing start to the year.</div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Using HTML5 localStorage Into Your App, Check ldb.js]]></title>
<link href="http://gotchacode.com/2013/12/using-html5-localstorage-into-your-app.html"/>
<updated>2013-12-22T05:20:00+05:30</updated>
<id>http://gotchacode.com/2013/12/using-html5-localstorage-into-your-app</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Last night, I was hacking on a small utility library for use when using HTML5 localStorage. When you work with localStorage, it often gets into repetitive state when use use same command again and again. This library just abstracts the process and makes things easier for you. It would work on all modern browsers.<br /><br /><pre><code class="javascript">/**<br /> * Ldb.js<br /> * Copyright(c)2013 Vinit Kumar <vinit .kumar="" changer.nl=""><br /> * MIT Licensed<br /> */<br /><br />var Ldb = function () {};<br /><br />/**<br /> * [check Checks for localStorage support on the browsers]<br /> * @return {[String]} [status of localStorage Support]<br /> */<br />Ldb.prototype.check = function () {<br /> if (!localStorage) {<br /> return 'Please use a Modern browser, your browser does not support localStorage yet';<br /> } else {<br /> return 'Bingo, your Browsers supports localStorage, phew!';<br /> }<br />};<br /><br />/**<br /> * [get Gives the data stored in the key]<br /> * @param {[String]} key [Key to retrive the data stored in localStorage]<br /> * @return {[JSON]} [The JSON data stored | Error message saying no data stored with that key]<br /> */<br />Ldb.prototype.get = function (key) {<br /> if (localStorage.getItem(key)) {<br /> return JSON.parse(localStorage.getItem(key));<br /> } else {<br /> return 'No such key exists, Are you sure you have saved data with the key?';<br /> }<br />};<br /><br />/**<br /> * [set Saved data in the localStorage database]<br /> * @param {[String]} key []<br /> * @param {[JSON]} value [The JSON data that gets stored in the localStorage]<br /> */<br />Ldb.prototype.set = function(key, value) {<br /> if (typeof (value) === 'object') {<br /> var stringValue = JSON.stringify(value);<br /> localStorage.setItem(key, stringValue);<br /> return 'Successfully saved your data to the key' + key +' key!';<br /> }<br />};<br /><br />/**<br /> * [remove description]<br /> * @param {[String]} key [Key for the data to be deleted]<br /> * @return {[String]} [Status message for the remove operation]<br /> */<br />Ldb.prototype.remove = function(key) {<br /> if (localStorage.getItem(key)) {<br /> localStorage.removeItem(key);<br /> return 'Successfully removed data with the key'+ key +' !';<br /> } else {<br /> return 'No such key exists, nothing to remove';<br /> }<br />};<br /></vinit><br /></code><br /></pre><br />This is all code for the utility as of now. More features are going to flow in coming weeks. Also, you can just install it using ‘npm install ldb’ or ‘bower install ldb.js’. The code is Open Sourced here. https://github.com/vinitkumar/ldb.js</div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[How to Focus and Learn One Thing Perfectly?]]></title>
<link href="http://gotchacode.com/2013/12/how-to-focus-and-learn-one-thing.html"/>
<updated>2013-12-04T17:39:00+05:30</updated>
<id>http://gotchacode.com/2013/12/how-to-focus-and-learn-one-thing</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">In Software development, there are so many things to learn. Especially, if you are web developer there are so many things to learn. Should you learn Rails, Django or .NET? Or should you learn Angular, Backbone or Ember?<br /><br />It is a very tricky question and has been puzzling me for quite sometime. But some time back, it kind of dawned on me that I should just try and own one technology at one time. Say if it’s Django try and learn everything about Django. Become the best in your company at Django. The benefits are two fold:<br />- You will have a stable career and you will be happy with the quality of your work.<br />- You can use that understanding of that technology with understanding and learning other technologies really fast.<br /><br />Another problem that I sometime face is lack of motivation to learn if something gets really tough. I learned that instead of setting a super tough goal, I should rather split it up and own it one by one. First of all, it gives me a sense of achievement and confidence. Also, my whole effort would be on completing that goal with best of my abilities.<br /><br />The things I said above is not rocket science, but if you are at my stage of learning. It might be useful to you.<br /><br /><br />With that said, May the Force be with you!<br /><br /><pre><span style="color: lime;"> ____ <br /> _.' : `._ <br /> .-.'`. ; .'`.-. <br /> __ / : ___\ ; /___ ; \ __ <br /> ,'_ ""--.:__;".-.";: :".-.":__;.--"" _`,<br /> :' `.t""--.. '<@.`;_ ',@>` ..--""j.' `;<br /> `:-.._J '-.-'L__ `-- ' L_..-;' <br /> "-.__ ; .-" "-. : __.-" <br /> L ' /.------.\ ' J <br /> "-. "--" .-" <br /> __.l"-:_JL_;-";.__ <br /> .-j/'.; ;"""" / .'\"-. <br /> .' /:`. "-.: .-" .'; `. <br /> .-" / ; "-. "-..-" .-" : "-. <br /> .+"-. : : "-.__.-" ;-._ \ <br /> ; \ `.; ; : : "+. ; <br /> : ; ; ; : ; : \: <br /> ; : ; : ;: ; : <br />: \ ; : ; : ; / :: <br />; ; : ; : ; : ;: <br />: : ; : ; : : ; : ; <br />;\ : ; : ; ; ; ; <br />: `."-; : ; : ; / ; <br /> ; -: ; : ; : .-" : <br /> :\ \ : ; : \.-" : <br /> ;`. \ ; : ;.'_..-- / ; <br /> : "-. "-: ; :/." .' :<br /> \ \ : ;/ __ :<br /> \ .-`.\ /t-"" ":-+. :<br /> `. .-" `l __/ /`. : ; ; \ ;<br /> \ .-" .-"-.-" .' .'j \ / ;/ <br /> \ / .-" /. .'.' ;_:' ; <br /> :-""-.`./-.' / `.___.' <br /> \ `t ._ / bug <br /> "-.t-._:' <br /></span></pre><div><span style="color: lime;"><br /></span></div><br /><br /><br /><br /></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[What Is Information Overload and What to Do About It?]]></title>
<link href="http://gotchacode.com/2013/11/what-is-information-overload-and-what.html"/>
<updated>2013-11-30T18:13:00+05:30</updated>
<id>http://gotchacode.com/2013/11/what-is-information-overload-and-what</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Each one of us uses one Social Network or another. It was fine in the earlier days when it was connecting you to your long lost friend, colleague or someone you knew. But do we realize what it is doing to us now?<br /><div><br /></div><div>We are being subjected to information overload and that too in the worst form. There are endless stories about all the stuff that doesn’t even matter to us. We are being fed so much about our friends that we are not even interested to know about them anymore. Sharing every crap that happens in your life is a common norm and anyone who doesn’t stick to it is dated. </div><div><br /></div><div>Well, that fact is, we should just shut this information overload and take control of our life. We don’t really need to be subjected to this and become depressed and deprived people. Life has better meaning than all of it. We are born to do great things in life and not being sucked into this emotional and depressing wormhole that these Social Networks are creating.</div><div><br /></div><div>With that said, not all of the Social Networks are bad. Some of them like Twitter and Google+ gives us the option to minimise the intrusion of this excess information. So take a stand and control what kind of information gets to you. Clean up your friends and following list. Follow only those person and group you are really passionate about. Pick up some nice offline activity, meet some nice people , play some music, watch sunrise or sunset, start running etc. There are so many nice things to do. So just shut up laptop/tablets/smartphones and get some life people!</div></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Happiness Driven Development]]></title>
<link href="http://gotchacode.com/2013/11/happiness-driven-development.html"/>
<updated>2013-11-22T17:20:00+05:30</updated>
<id>http://gotchacode.com/2013/11/happiness-driven-development</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Software development could be a very tiring and demanding process. Putting 80 hour weeks running after a goal that may or maybe not be achieved and then getting into depression is not right.<br /><br />One should optimise his work and workplace for happiness. Setup small easy goals that you could really achieve and celebrate it every time. It is good to be ambitious but it is insanely stupid to make super tough goal with out some real practise.<br /><br />Start small, reach your goal and next time try to do it more efficiently. People say that ‘Failures are the pillars of success’ , I would humbly disagree. It is these small successes that are pillars of some big successes. Look around yourself. Just take chess for example: Someone doesn’t becomes a grandmaster because he had been defeated by every other grandmaster. Likewise don’t obsess with failure. Better start winning by doing something nice today however small it maybe.<br /><br />Failure is a good thing to do some self evaluation and getting better where it’s needed. Treat it as a unit test, so that you know what tests are failing and what you could do to solve them. Solve them and come out with flying colors.<br /><br />Life is way too small to waste and be sad and depressed.<br />Think about it! :)<br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://b.vimeocdn.com/ts/447/176/447176815_640.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="http://b.vimeocdn.com/ts/447/176/447176815_640.jpg" width="400" /></a></div><div><br /></div></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Seven Tips to Get Better at Writing Code]]></title>
<link href="http://gotchacode.com/2013/07/seven-tips-to-get-better-at-writing-code.html"/>
<updated>2013-07-20T14:37:00+05:30</updated>
<id>http://gotchacode.com/2013/07/seven-tips-to-get-better-at-writing-code</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Every developer dreams of getting better at writing code. He/She wants his code to be clean and pragmatic. But this doesn’t happen on its own. Here are some tips to get better at writing code.<br /><br /><ol style="text-align: left;"><li>Follow TDD: Test driven development is a great way to improve your code. It ensures that whatever functionality you have implemented is doing what it is supposed to do. One should make sure to spend some time writing tests before writing a feature. It is a difficult practise to inculcate in your developers, but believe me the amount of time and stress you will save with it is phenomenal. There are basically two types of tests that should be present with your code: unit tests and integrations tests. Both are very important. Sometimes, it might not be possible to get everything unit tested but make sure key parts have units tests and integrations tests are complete. </li><li>Write detailed commit messages: I can’t recommend this one enough. Ever since i am introduced to this practise, i could easily feel the improvement in me and my code. It prefer it to writing long comments in my code. Wherever you did something that needs to be explained or if you did a hack to resolve some particular issue, make sure you address these parts in your commit message. It really helps because whenever your codebase gets bigger.A new developers could just take a look at the code and commit message and will be more comfortable getting up to speed. Also, if you are working on an open source project or contributing to one, chances are really high that your pull request will be merged. One reason for this is that, the person merging your code will not have to dive deep into your code to make sense of that you did back there. Your ‘detailed commit message’ will serve its purpose then.</li><li>Teach yourself about writing maintainable code: Always, try to think about writing maintainable code. It might not be possible every time, since sometimes deadlines won’t allow it. But make a point to revisit that code and fix that hackery you did back there to resolve the issue. This is really important, because sooner to later, that hackery/bug will come to bite you again and things could get really ugly.</li><li>Know your editor: You should and must configure your editor for the language your code on. It must have all the required plugins to do live linting while you code. If you do python or JS, there are some pretty great plugins available for both the languages in Vim and Sublime Text2. Also, get familiar with some good snippets generating plugins for frameworks, HTML and CSS. There are pretty great plugins to beautify and minify your code as well. They really help in getting the whole code quality better.</li><li>Automate all repetitive tasks: At this time, we are pretty much equipped with the technologies such as grunt and yeoman which could automate a lot of part that you had to waste your time doing again and again. You must also learn about git hooks. For example: I made a git pre-commit hook to compile less into css and run jshint, concat and uglify operations on my javascript code any time someone changes them. This is great because my workflow prevents any bad code to enter the codebase.</li><li>Read good code, data structures and Algorithms: There is no end of learning. Teach yourself to read more and more good code. You must spend time getting better with data structures and algorithms. They might not prove useful immediately, but it will make you a better developer and will enable you to take better decisions in future.</li><li>Watch talks and presentations: Be regular to watch great talks and presentations from the various conferences round the year. They give some pretty great information about the latest trends and techniques. You could easily find them on YouTube/Vimeo and SpeakerDeck. </li></ol><div><br /></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-gXvgVkXBX4c/UeqghTlgEBI/AAAAAAAACAU/aYPFFsvrRtE/s1600/yoda.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="190" src="http://3.bp.blogspot.com/-gXvgVkXBX4c/UeqghTlgEBI/AAAAAAAACAU/aYPFFsvrRtE/s400/yoda.jpg" width="400" /></a></div><div><br /></div></div>
</div>
<div class="css-full-comments-content js-full-comments-content">
<div class="css-full-comment js-full-comment">
<div class="css-comment-user-link js-comment-user-link">
<a href="http://www.blogger.com/profile/15976191342720108781">
<div class="css-comment-name js-comment-name">
Jarrod Vaughan
</div>
</a>
<div class="css-comment-date js-comment-date">
2013-07-23T10:13:15.166Z
</div>
</div>
<div class="css-comment-content js-comment-content">
One thing which comes in my mind is to make use of less keystrokes i.e. to write less but should be understable. Even character layout works great, character displays everything in a simple way.
</div>
<br/>
</div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Json2xml: A Lightweight Python Module to Convert Json Data to Xml]]></title>
<link href="http://gotchacode.com/2013/07/json2xml-lightweight-python-module-to.html"/>
<updated>2013-07-20T13:29:00+05:30</updated>
<id>http://gotchacode.com/2013/07/json2xml-lightweight-python-module-to</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">A year before i wrote a simple python module to covert json data to xml. It is fairly straight forward and efficient to use. <div><br /></div><div>It is available at Pypi and you can install it easily using : `pip install json2xml`</div><div><br /></div><div>Also, here is the link of the project on Github: https://github.com/vinitcool76/json2xml . The project also has an example file in it. Just run it and you will understand its working.</div></div> <script src="https://gist.github.com/vinitcool76/6044989.js"></script>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Demo Post]]></title>
<link href="http://gotchacode.com/blog/2013/07/02/demo-post/"/>
<updated>2013-07-02T00:00:00+05:30</updated>
<id>http://gotchacode.com/blog/2013/07/02/demo-post</id>
<content type="html"><![CDATA[<p>This is a demo post for showing the jekyll theme. Jekyll lets you write
your blog posts on markdown. Which also has a sweet syntax highlighting.</p>
<p>This theme includes sweet Github syntax highlighting.</p>
<p>For JavaScript:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Ldb</span><span class="p">();</span>
</span><span class='line'><span class="nx">db</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">'key'</span><span class="p">,</span> <span class="nb">Object</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>For Python:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<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>
<span class='line-number'>30</span>
</pre></td><td class='code'><pre><code class='py'><span class='line'><span class="c">#! /usr/bin/env python</span>
</span><span class='line'><span class="kn">import</span> <span class="nn">time</span>
</span><span class='line'><span class="kn">import</span> <span class="nn">optparse</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">linkfetcher</span> <span class="kn">import</span> <span class="n">Linkfetcher</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">webcrawler</span> <span class="kn">import</span> <span class="n">Webcrawler</span>
</span><span class='line'>
</span><span class='line'><span class="n">Usage</span> <span class="o">=</span> <span class="s">'''</span>
</span><span class='line'><span class="s"> $ ./crawler -d5 <url></span>
</span><span class='line'><span class="s"> Here in this case it goes till depth of 5 and url is target URL to</span>
</span><span class='line'><span class="s"> start crawling.</span>
</span><span class='line'><span class="s">'''</span>
</span><span class='line'><span class="n">Version</span> <span class="o">=</span> <span class="s">'0.0.1'</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">option_parser</span><span class="p">():</span>
</span><span class='line'>
</span><span class='line'> <span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="n">Usage</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">Version</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-l"</span><span class="p">,</span> <span class="s">"--links"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">"store_true"</span><span class="p">,</span>
</span><span class='line'> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">dest</span><span class="o">=</span><span class="s">"links"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"Get links for target url only"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-d"</span><span class="p">,</span> <span class="s">"--depth"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">"store"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s">"int"</span> <span class="p">,</span>
</span><span class='line'> <span class="n">default</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">"depth"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"Maximum depth to traverse"</span><span class="p">)</span>
</span><span class='line'> <span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o"><</span> <span class="mi">1</span><span class="p">:</span>
</span><span class='line'> <span class="n">parser</span><span class="o">.</span><span class="n">print_help</span><span class="p">()</span>
</span><span class='line'> <span class="k">raise</span> <span class="ne">SystemExit</span><span class="p">,</span> <span class="mi">1</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="n">opts</span><span class="p">,</span> <span class="n">args</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Talks and Videos That Could Make You a Better Developer]]></title>
<link href="http://gotchacode.com/2013/06/talks-and-videos-that-could-make-you.html"/>
<updated>2013-06-01T19:17:00+05:30</updated>
<id>http://gotchacode.com/2013/06/talks-and-videos-that-could-make-you</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Hey fellas, sorry for not actively blogging these months. But, I have some interesting stuff for you guys.<br /><br />Development is a complex process and it requires a lot of skill, hard work and techniques to be a really good developer. Recently, I came across a lot of good stuff and things are improving for me quite positively. I wanted to share the same with you.<br /><br />These are mostly talks, videos or presentation by some really popular, successful people from our industry. The tips they give are mostly an eye opener. Hope you enjoy them.<br /><br /><script async="" class="speakerdeck-embed" data-id="505376778282a900020560da" data-ratio="1.33333333333333" src="http://gotchacode.com//speakerdeck.com/assets/embed.js"></script> Also, here is another great presentation by the same guy. <script async class="speakerdeck-embed" data-id="d3f56f007adf01307e7722000a9f0395" data-ratio="1.77777777777778" src="http://gotchacode.com//speakerdeck.com/assets/embed.js"></script><br /><br />The next talk is by Heroku co-founder Adam. This is single most awesome talk i have seen in recent times and is a must watch.<br /><br /> <iframe allowfullscreen="" frameborder="0" height="300" mozallowfullscreen="" src="http://player.vimeo.com/video/49701839" webkitallowfullscreen="" width="400"></iframe> I<br /><br /> Hope you guys enjoy ‘em and keep doing great work! </div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[JavaScript Is an Adult , See What It Can Do Now.]]></title>
<link href="http://gotchacode.com/2013/06/javascript-is-adult-now-see-what-it-can.html"/>
<updated>2013-06-01T18:48:00+05:30</updated>
<id>http://gotchacode.com/2013/06/javascript-is-adult-now-see-what-it-can</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://img.youtube.com/vi/qrf9ONmtXbM/0.jpg" height="266" width="320"><param name="movie" value="http://youtube.googleapis.com/v/qrf9ONmtXbM&source=uds" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="http://youtube.googleapis.com/v/qrf9ONmtXbM&source=uds" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div>The first version of JS was released in 10 days. Enjoy this talk by it’s founder. Enjoy it with some good coffee.<br /><br /></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Modern Development Workflow for a Team]]></title>
<link href="http://gotchacode.com/2013/03/modern-development-workflow-for-team.html"/>
<updated>2013-03-06T12:55:00+05:30</updated>
<id>http://gotchacode.com/2013/03/modern-development-workflow-for-team</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Development is a complex process and it becomes more complex when many people are pushing code on a same codebase.<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-zgWrPP9y-1Y/UTc8xKggOHI/AAAAAAAABCI/kQV7RWOI7s0/s1600/Team+Development+Right.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="254" src="http://2.bp.blogspot.com/-zgWrPP9y-1Y/UTc8xKggOHI/AAAAAAAABCI/kQV7RWOI7s0/s320/Team+Development+Right.jpg" width="320" /></a></div><br /><br /><ul style="text-align: left;"><li>Ideally a development workflow should be asynchronous, so that one does his work and fixes the issues assigned to him and doesn’t get stalled by his team member’s progress. </li><li>In order to implement this, put up you more competent programmers to pair for a dependent modules such that that doesn’t get stuck if one of the two programmer lag. </li><li>If two developers are working for different modules in a project, working on a DVCS such as Git is a great boon. Also, Github gives a great workflow with Issues and Pull Request. Issues and milestones are a great way to schedule you development such that there is no mistake in planning. You get set tag on the issues so that developer will know what is the high priority task, and plan accordingly. </li><li>Make sure your team members are competent if not experts with Git, it really helps if everyone uses git wisely. Private repos are handy as well when you are working on commercial stuff.</li><li>Using git-flow is a good choice. It truly brings sanity into the development workflow using Github and git. </li><li>Realtime chatting via Skype is also a good choice, developers could ask stuff from each other without breaking other’s flow. </li><li>Also, make sure you people plan and discuss with each other before a days work and review at the end of day. One things is for sure, following this process will have you a more effective team.</li></ul><div>Thats’s it folks. If you like the post follow me on twitter : <a href="http://twitter.com/vinitcool76" target="_blank">@vinitcool76</a></div><br /><br /></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Guide to Start With Application Development.]]></title>
<link href="http://gotchacode.com/2013/02/guide-to-start-with-application.html"/>
<updated>2013-02-26T14:30:00+05:30</updated>
<id>http://gotchacode.com/2013/02/guide-to-start-with-application</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">In my opinion the best way to learn a language is to develop applications in it once you are comfortable with the syntax.<br />It is a great learning process and teaches much more than what reading a book will teach you. Development is itself a very vast process, let me detail a very specific part of development. Web Based Application Development<br />Since it is a web based application, obviously you will have two parts, client side and server side.<br /><b>For Client Side Applications: </b>You can start with development of Chrome Extensions or Firefox Extensions. Alternatively, you can develop some Facebook or twitter Application. It will give you a great exposure to REST, plus you will get to work in the latest technologies as well.<br /><b>For Server Side Applications:</b><br />Try and develop an restful API system, such as some API for a facebook Application where the Server crunches your data and you have some meaningful information in your application. It might sound easy but its actually a quite tough thing to accomplish. Still it is a great learning experience. You might want to refer some good books in this process.<br /><br />Well, the point is you might not become a star developer of a sudden, but it will be one of the most rewarding experience in your software development process. Learning by doing, rather learning by failing in a very good process.<br /><br />So take a crazy idea and Start hacking!<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-3ePArKjFU2A/USzG-_LkJ5I/AAAAAAAABB0/4hGtwnLsTzQ/s1600/kung_fu_master_shifu_1920x1080.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="http://2.bp.blogspot.com/-3ePArKjFU2A/USzG-_LkJ5I/AAAAAAAABB0/4hGtwnLsTzQ/s400/kung_fu_master_shifu_1920x1080.jpg" width="400" /></a></div><br /><br />± May The Force Be With You! </div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[How to Setup a Mac for Web Development.]]></title>
<link href="http://gotchacode.com/2013/02/how-to-setup-mac-for-web-development.html"/>
<updated>2013-02-24T17:56:00+05:30</updated>
<id>http://gotchacode.com/2013/02/how-to-setup-mac-for-web-development</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Macs are beautiful machine. Luckily, I own a Macbook Pro that has 8GB ram and 256GB SSD. I am a Web Developer by profession so here are some tips that you could use to setup your mac.<br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-UGabibWAlr8/USpTz8VpRUI/AAAAAAAABBk/ry2cD5pt7eM/s1600/Screen+Shot+2013-02-24+at+11.22.59+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="http://3.bp.blogspot.com/-UGabibWAlr8/USpTz8VpRUI/AAAAAAAABBk/ry2cD5pt7eM/s400/Screen+Shot+2013-02-24+at+11.22.59+PM.png" width="400" /></a></div><ul style="text-align: left;"><li>Install Xcode: Install Xcode, preferably the full version, if you might like to develop for iOS or iPad. It is a free download from App Store.</li><li>Install Homebrew: This is a must and it is really satisfies the need to package manager in OSX.</li><li>Install dotfiles: Please use dotfiles, there are many good ones already shared on Github. You can use any one of them from here. <a href="http://dotfiles.github.com/" target="_blank">Install Dotfiles</a></li><li>Install z, oh-my-zsh: Oh my zsh is one of the best and feature rich shell, do use it with combination of z. Z is a directory jumping tool and it is really handy. <a href="https://github.com/rupa/z" target="_blank">Install Z</a></li><li>Install and configure a text editor: Install Sublime Text2, Vim or Emacs as your text editor. They are most extensible and powerful editors and you can configure them to satisfy all your needs. Make sure you invest sometime configuring it to your taste and needs. It will be intensely productive and satisfying experience.</li><li>Install Node and NPM: If you are web developer , you must have dealt with JavaScript. You must install both of them. Not only it extends the package manager needs, it is basis of other good package managers for web.</li><li>Install Component, Yeoman, Bower and Grunt. These are some indispensable tools that are very important for any web / web app developer.</li><li>Install Chrome Canary: If you want to get the best Developer tools available , install chrome canary. It is the latest and provide great support for various things such as sass, compass etc inbuilt.</li><li>Install Google drive and dropbox: Please keep your important stuff in cloud so that you may never loose your data again. Also, you can backup your code in Github.</li><li>Install SizeUP: It is one of most productive software on mac and provides such great arrangement of Windows that you will be amazed. Either buy it or install the trial version. <a href="http://www.irradiatedsoftware.com/" target="_blank">Install Sizeup</a></li><li>Install Git and create a account on Github, if you haven’t already. There is such a vibrant community on Github, mostly great web developers that if you are not updated with it.You will loose great deal of useful information.</li><li>Automate most of the grunt jobs you do daily. Use build tools such as Make, Cake, Jake etc. Also, learn little bit of shell scripting. It really helps in long run.</li><li>Install Python and the module install tools such a pip and easy_install. It is really a must.</li><li>Install Ruby and ROR. They have pretty good community. Just a basis google search will get you going about the install and use process.</li><li>Install VirtualBox, it is an invaluable thing if you have to use another OS such as Windows or Ubuntu.</li></ul><div>I guess these are pretty exhaustive list of TODOS if you using mac for web/web-app development. I will keep updating the post if i remember any more important thing. The baseline is that macs are great piece of hardware and a pretty decent OS, so invest sometime in setting it up. It will save you tons of time and frustation. Have a good weekend, Enjoy!</div></div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Configure Sublime Text2 for JavaScript Development.]]></title>
<link href="http://gotchacode.com/2013/02/configure-sublime-text2-for-javascript.html"/>
<updated>2013-02-24T11:19:00+05:30</updated>
<id>http://gotchacode.com/2013/02/configure-sublime-text2-for-javascript</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">I recently started using Sublime Text2 full time at work after being a vim user for more than 4 years. Vim is really good but it takes sometime to configure it properly. Well this is not a Vim vs ST2 debate. It is more of a vim user shifting to ST2 Tip.<br /><br />The first thing that you should do is to install package control, it provide really good 3rd party plugins. You can check out the link how to install it. <a href="http://wbond.net/sublime_packages/package_control/installation" target="_blank">Install Package Control</a><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-VyTJ6GhccRQ/USn4XUWXanI/AAAAAAAABBU/JM261l4WaZw/s1600/Screen+Shot+2013-02-24+at+4.52.12+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="http://4.bp.blogspot.com/-VyTJ6GhccRQ/USn4XUWXanI/AAAAAAAABBU/JM261l4WaZw/s400/Screen+Shot+2013-02-24+at+4.52.12+PM.png" width="400" /></a></div><br /><br />Once done with that open package manager and install these useful plugins<br /><br /><ul style="text-align: left;"><li>JSHint.</li><li>JSLint.</li><li>DocBlockr.</li><li>AngularJS.</li><li>Mocha & Mocha snippet </li><li>NodeJS.</li><li>Live Reload.</li><li>AMD Module Editor</li><li>Backbone.js</li><li>Pretty JSON</li><li>Require Node.js Module Helper</li></ul><div><br /></div><div>Among, these plugins mocha is the test runner and mocha snippets provides you will snippets to write the tests very fast. Also, there is good plugin for vim mode in Sublime Text2, you can use that if you don’t want to waste the muscle memory. I highly recommend the real time linting with JSHint. It will make you so much more productive and improve your code as well. It acts as the first unit test against the code you just wrote. </div><div><br /></div><div>One more important thing, you could set the indentation with tab width equals to 2 spaces. It is a very sane default while writing JavaScript code.</div><div><br /></div><div>What really struck me was that Sublime Text enabled me to do almost everything i did with Vim without going into the pain of configuration. Also, the learning curve is not at all steep so i could get productive real fast.</div></div>
</div>
<div class="css-full-comments-content js-full-comments-content">
<div class="css-full-comment js-full-comment">
<div class="css-comment-user-link js-comment-user-link">
<a href="http://www.blogger.com/profile/16586618300856804621">
<div class="css-comment-name js-comment-name">
Unknown
</div>
</a>
<div class="css-comment-date js-comment-date">
2013-02-24T16:08:16.461Z
</div>
</div>
<div class="css-comment-content js-comment-content">
2013 Wishes: Sublime Text Terminal
</div>
<br/>
</div>
<div class="css-full-comment js-full-comment">
<div class="css-comment-user-link js-comment-user-link">
<a href="http://www.blogger.com/profile/16586618300856804621">
<div class="css-comment-name js-comment-name">
Unknown
</div>
</a>
<div class="css-comment-date js-comment-date">
2013-02-24T16:08:56.069Z
</div>
</div>
<div class="css-comment-content js-comment-content">
2013 Wishes: Sublime Text Terminal
</div>
<br/>
</div>
<div class="css-full-comment js-full-comment">
<div class="css-comment-user-link js-comment-user-link">
<a href="http://www.blogger.com/profile/17194318708068141006">
<div class="css-comment-name js-comment-name">
Frank
</div>
</a>
<div class="css-comment-date js-comment-date">
2013-02-26T22:14:30.778Z
</div>
</div>
<div class="css-comment-content js-comment-content">
How do you debug javascript using the chrome debugger
</div>
<br/>
</div>
<div class="css-full-comment js-full-comment">
<div class="css-comment-user-link js-comment-user-link">
<a href="http://www.blogger.com/profile/00121175657676051962">
<div class="css-comment-name js-comment-name">
Joel
</div>
</a>
<div class="css-comment-date js-comment-date">
2013-06-30T01:57:24.119Z
</div>
</div>
<div class="css-comment-content js-comment-content">
Which mocha plugin are you referring to, the runner? or the snippet package? I'm assuming you mean the runner, but I wasn't sure at first…and in the interest of clarity for others who may also have this question, perhaps you could clarify? My experience with the rest of the plugins was smooth, however.
</div>
<br/>
</div>
</div>]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Happy New Year Readers!]]></title>
<link href="http://gotchacode.com/2013/01/happy-new-year-readers.html"/>
<updated>2013-01-15T14:01:00+05:30</updated>
<id>http://gotchacode.com/2013/01/happy-new-year-readers</id>
<content type="html"><![CDATA[<div class="css-full-post-content js-full-post-content">
<div dir="ltr" style="text-align: left;" trbidi="on">Best wishes for the New Year fellas, Last year this blog clocked more than 20k hits from all over the world.<br />Here are some stats:<br /><br />Top 3 most hits :<br />Country Wise:<br /><br /><ol style="text-align: left;"><li>USA</li><li>India</li><li>UK</li></ol><div>Operating System wise: </div><div><ol style="text-align: left;"><li>Window</li><li>OS X</li><li>Linux</li></ol><div>Browsers wise:</div></div><div><ol style="text-align: left;"><li>Chrome</li><li>Firefox</li><li>Safari</li></ol><div>With that said, recently most the posts are related to software development and programming, so this time i will try to improve the quality of posts and will be showcasing an Open Source project each week. </div></div><div><br /></div><div>Keep reading!</div></div>
</div>]]></content>
</entry>
</feed>