-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
502 lines (303 loc) · 22.1 KB
/
index.html
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
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Indyarocks</title>
<meta name="author" content="Chandan Kumar">
<meta name="description" content="Today I explored Rack, an awesome API connecting web servers and web frameworks by Christian Neukirchen. Here is an introduction article by Christian …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://indyarocks.github.io">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="Indyarocks" type="application/atom+xml">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-41641165-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Indyarocks</a></h1>
<h2>Happy Hacking!</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss email">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
<li><a href="[email protected]" rel="subscribe-email" title="subscribe via email">Email</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:indyarocks.github.io" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/blog/2013/10/13/rack-basics/">Rack Basics</a></h1>
<p class="meta">
<time datetime="2013-10-13T20:04:00+05:30" pubdate data-updated="true">Oct 13<span>th</span>, 2013</time>
| <a href="/blog/2013/10/13/rack-basics/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>Today I explored Rack, an awesome API connecting web servers and web frameworks by Christian Neukirchen. Here is an <a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html" target="_blank">introduction article</a> by Christian Neukirchen.</p>
<p><a href="http://rack.github.io/" target="_blank">Rack</a> was insipired from python’s <a href="http://wsgi.readthedocs.org/en/latest/">WSGI</a>.</p>
<h3>What is Rack?</h3>
<p>To put in the words of Christian,</br></p>
<p style="font-style:italic;margin:1.5em;">Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.</p>
<p>Instead of going deeper in documentation, I’ll walk through what exactly Rack is, and how it fits in different web-frameworks in Ruby. I’ve put the references at the end of the post, which helped me understand Rack.</p>
</div>
<footer>
<a rel="full-article" href="/blog/2013/10/13/rack-basics/">Read on →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2013/10/12/activerecord-logger-in-rails-console/">ActiveRecord Logger in Rails Console</a></h1>
<p class="meta">
<time datetime="2013-10-12T14:51:00+05:30" pubdate data-updated="true">Oct 12<span>th</span>, 2013</time>
| <a href="/blog/2013/10/12/activerecord-logger-in-rails-console/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>This came to my surprise, as I was going through ‘The Rails 4 Way’ by Obie Fernandez, that we can have our own logger instances in Rails.</p>
<p>Watch, what ActiveRecord is doing with your query in console itself. :)</p>
<div><script src='https://gist.github.com/indyarocks/6947792.js'></script>
<noscript><pre><code>> rails c
Loading development environment (Rails 4.0.0)
2.0.0p247 :001 > ActiveRecord::Base.logger = Logger.new(STDOUT)
=> #<Logger:0x007f816e1c35a8 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f816e1c3580 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x007f816e1c3530 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x007f816e1c3508 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007f816e1c34b8>>>>
2.0.0p247 :002 > user = User.first
D, [2013-10-12T14:46:23.337060 #25919] DEBUG -- : User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 1, name: "Chandan Kumar", email: "[email protected]", created_at: "2013-09-16 20:01:15", updated_at: "2013-09-16 20:34:20", password_digest: "$2a$10$qoNP6rM.89XSOJEXIsXig.9LKM2jcvY0Y4bFhCECCJ4X...", remember_token: "66302290bbc685a193b5d2ab5c8d3fc67e56318e", admin: true>
2.0.0p247 :003 > user.microposts
D, [2013-10-12T14:46:28.886696 #25919] DEBUG -- : Micropost Load (36.8ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY created_at DESC [["user_id", 1]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Micropost id: 301, content: "Cool\r\n", user_id: 1, created_at: "2013-10-06 15:27:10", updated_at: "2013-10-06 15:27:10">, #<Micropost id: 295, content: "Eligendi ducimus aut incidunt vel vitae accusamus.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 289, content: "Dolores blanditiis aut omnis corrupti et unde.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 283, content: "Quia iste et consequatur et id illo voluptas.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 277, content: "Excepturi voluptatem adipisci nesciunt praesentium ...", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 271, content: "Deserunt et labore explicabo est id voluptatibus vo...", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 265, content: "Aut perspiciatis sapiente aspernatur maiores.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 259, content: "Labore illo accusantium atque asperiores voluptas.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 253, content: "Laborum tempora eum ipsa dolores.", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, #<Micropost id: 247, content: "Excepturi commodi quibusdam velit deserunt nulla om...", user_id: 1, created_at: "2013-09-16 20:01:23", updated_at: "2013-09-16 20:01:23">, ...]></code></pre></noscript></div>
<p>I came across blog of Jamis Buck, and he had given on more interesting piece of hack to see the log in console. In your config/environment.rb define following method:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">log_to</span><span class="p">(</span><span class="n">stream</span><span class="p">)</span>
</span><span class='line'> <span class="ss">ActiveRecord</span><span class="p">:</span><span class="ss">:Base</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="no">Logger</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">stream</span><span class="p">)</span>
</span><span class='line'> <span class="ss">ActiveRecrod</span><span class="p">:</span><span class="ss">:Base</span><span class="o">.</span><span class="n">clear_active_connections!</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now you can buffer your logs in a local variable.</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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="o">></span> <span class="n">log_to</span> <span class="no">STDOUT</span>
</span><span class='line'><span class="o">=></span> <span class="o">.</span><span class="n">.</span>
</span><span class='line'><span class="o">></span> <span class="no">Post</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="ss">:first</span><span class="p">)</span>
</span><span class='line'> <span class="no">Post</span> <span class="no">Load</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="mo">00013</span><span class="mi">8</span><span class="p">)</span> <span class="no">SELECT</span> <span class="o">*</span> <span class="no">FROM</span> <span class="n">posts</span> <span class="no">LIMIT</span> <span class="mi">1</span>
</span><span class='line'><span class="o">=></span> <span class="c1">#<Post:0x1234 ...></span>
</span><span class='line'><span class="o">></span> <span class="n">buffer</span> <span class="o">=</span> <span class="no">StringIO</span><span class="o">.</span><span class="n">new</span>
</span><span class='line'><span class="o">=></span> <span class="o">.</span><span class="n">.</span>
</span><span class='line'><span class="o">></span> <span class="n">log_to</span> <span class="n">buffer</span>
</span><span class='line'><span class="o">=></span> <span class="o">.</span><span class="n">.</span>
</span><span class='line'><span class="no">User</span><span class="o">.</span><span class="n">first</span><span class="p">(</span><span class="ss">:first</span><span class="p">)</span>
</span><span class='line'><span class="o">=></span> <span class="c1">#<User:0x1234...></span>
</span><span class='line'><span class="o">></span> <span class="nb">p</span> <span class="n">buffer</span><span class="o">.</span><span class="n">string</span>
</span><span class='line'><span class="o">=></span> <span class="s2">"</span><span class="se">\e</span><span class="s2">...."</span> <span class="c1"># Logs here</span>
</span></code></pre></td></tr></table></div></figure>
<p>This can be found useful at many place you want to check the behavior of certain queries in console.</p>
<p>Thanks Jamis/Obie :)</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2013/10/10/using-ruby-gsub-with-a-hash/">Using Ruby Gsub With a Hash</a></h1>
<p class="meta">
<time datetime="2013-10-10T22:47:00+05:30" pubdate data-updated="true">Oct 10<span>th</span>, 2013</time>
| <a href="/blog/2013/10/10/using-ruby-gsub-with-a-hash/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><strong> Gsub with Hash </strong>
We all have used gsub for global substitution of a pattern in string. The cool thing I came across today is, you can use hash to define the replacement.</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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">cool_gsub_with_hash</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
</span><span class='line'> <span class="n">str</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/[aeiou]/</span><span class="p">,</span> <span class="s1">'a'</span> <span class="o">=></span> <span class="s1">'1'</span><span class="p">,</span> <span class="s1">'e'</span> <span class="o">=></span> <span class="s1">'2'</span><span class="p">,</span> <span class="s1">'i'</span> <span class="o">=></span> <span class="s1">'3'</span><span class="p">,</span> <span class="s1">'o'</span> <span class="o">=></span> <span class="s1">'4'</span><span class="p">,</span> <span class="s1">'u'</span> <span class="o">=></span> <span class="s1">'5'</span><span class="p">)</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="o">></span> <span class="n">cool_gsub_with_hash</span><span class="p">(</span><span class="s2">"We all have used gsub for global substitution of a pattern in string. "</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="o">=></span> <span class="s2">"W2 1ll h1v2 5s2d gs5b f4r gl4b1l s5bst3t5t34n 4f 1 p1tt2rn 3n str3ng. "</span>
</span><span class='line'>
</span><span class='line'><span class="o">></span> <span class="n">cool_gsub_with_hash</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="o">=></span> <span class="s2">"h2ll4"</span>
</span></code></pre></td></tr></table></div></figure>
<p>Here we are not restricted with single character replacements:</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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">gsub_word_with_hash</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
</span><span class='line'> <span class="n">str</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/H(ello)?i?/</span><span class="p">,</span> <span class="s1">'Hi'</span> <span class="o">=></span> <span class="s2">"Namaste"</span><span class="p">,</span> <span class="s2">"Hello"</span> <span class="o">=></span> <span class="s2">"Wannakam"</span><span class="p">)</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="o">></span> <span class="n">gsub_word_with_hash</span><span class="p">(</span><span class="s2">"Hello Chandan"</span><span class="p">)</span>
</span><span class='line'> <span class="o">=></span> <span class="s2">"Wannakam Chandan"</span>
</span><span class='line'><span class="o">></span> <span class="n">gsub_word_with_hash</span><span class="p">(</span><span class="s2">"Hi Chandan"</span><span class="p">)</span>
</span><span class='line'> <span class="o">=></span> <span class="s2">"Namaste Chandan"</span>
</span></code></pre></td></tr></table></div></figure>
<p>I found it quite interesting. Courtesy: Bozahidar</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2013/06/11/forked-octopress/">Forked Octopress</a></h1>
<p class="meta">
<time datetime="2013-06-11T23:23:00+05:30" pubdate data-updated="true">Jun 11<span>th</span>, 2013</time>
| <a href="/blog/2013/06/11/forked-octopress/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content">
</div>
</article>
<div class="pagination">
<a href="/blog/archives">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/2013/10/13/rack-basics/">Rack Basics</a>
</li>
<li class="post">
<a href="/blog/2013/10/12/activerecord-logger-in-rails-console/">ActiveRecord Logger in Rails Console</a>
</li>
<li class="post">
<a href="/blog/2013/10/10/using-ruby-gsub-with-a-hash/">Using Ruby Gsub With a Hash</a>
</li>
<li class="post">
<a href="/blog/2013/06/11/forked-octopress/">Forked Octopress</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating…</li>
</ul>
<a href="https://github.com/indyarocks">@indyarocks</a> on GitHub
<script type="text/javascript">
$(document).ready(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'indyarocks',
count: 0,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
<section>
<h1>On Delicious</h1>
<div id="delicious"></div>
<script type="text/javascript" src="http://feeds.delicious.com/v2/json/indyarocks?count=3&sort=date&callback=renderDeliciousLinks"></script>
<p><a href="http://delicious.com/indyarocks">My Delicious Bookmarks »</a></p>
</section>
<section class="googleplus">
<h1>
<a href="https://plus.google.com/chandan.jhun?rel=author">
<img src="http://www.google.com/images/icons/ui/gprofile_button-32.png" width="32" height="32">
Google+
</a>
</h1>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - Chandan Kumar -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'indyarocks';
var disqus_script = 'count.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js#appId=212934732101925&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>