-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
365 lines (231 loc) · 11.3 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Railstic]]></title>
<link href="http://emrekutlu.github.com/atom.xml" rel="self"/>
<link href="http://emrekutlu.github.com/"/>
<updated>2012-08-21T14:26:11+03:00</updated>
<id>http://emrekutlu.github.com/</id>
<author>
<name><![CDATA[İ. Emre Kutlu]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Check Existence of DelayedJob Records]]></title>
<link href="http://emrekutlu.github.com/2011/08/check-existence-of-delayedjob-records/"/>
<updated>2011-08-29T03:23:19+03:00</updated>
<id>http://emrekutlu.github.com/2011/08/check-existence-of-delayedjob-records</id>
<content type="html"><![CDATA[<p>I’m using the collectiveidea fork of <a href="http://github.com/collectiveidea/delayed_job" target="_blank">DelayedJob</a>. There are two ways to create a DelayedJob record. First you can use the <code>delay</code> method.</p>
<script src="https://gist.github.com/1177431.js?file=dj_delay.rb"></script>
<p>Second way to create DelayedJob records is custom jobs.</p>
<script src="https://gist.github.com/1177431.js?file=dj_custom_job.rb"></script>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Dynamically Defining Methods with define_method]]></title>
<link href="http://emrekutlu.github.com/2011/06/dynamically-defining-methods-with-define_method/"/>
<updated>2011-06-11T02:08:08+03:00</updated>
<id>http://emrekutlu.github.com/2011/06/dynamically-defining-methods-with-define_method</id>
<content type="html"><![CDATA[<p>If you have been hacking ruby for a while you should have heard that “Everything is an object”. To understand this concept knowing what a <strong>singleton class</strong> is important. <a href="http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/" target="_blank">Yehuda Katz’s post</a> is a good source for it.</p>
<p>My ruby version 1.9.2.</p>
<script src="https://gist.github.com/1009449.js?file=ruby_version.bash"></script>
<p>First I’m going to show you how to add methods to instances by using <code><strong>define_method</strong></code>.</p>
<script src="https://gist.github.com/1009449.js?file=add_instance_methods.rb"></script>
<p>You can also write an instance method to create instance methods. <code><strong>send</strong></code> must be used because <code><strong>define_method</strong></code> is private.</p>
<script src="https://gist.github.com/1009449.js?file=add_instance_methods_by_instance_method.rb"></script>
<p>Write a singleton method to create instance methods.</p>
<script src="https://gist.github.com/1009449.js?file=add_instance_methods_by_singleton_method.rb"></script>
<p>Now it is time to add singleton methods. When we call <code><strong>define_method</strong></code>, it creates an instance method. What we have to do is call <code><strong>define_method</strong></code> on class’ singleton class.</p>
<p>Getting singleton class of a class:</p>
<script src="https://gist.github.com/1009449.js?file=get_singleton_class.rb"></script>
<p>First defining singleton method to create singleton methods.</p>
<script src="https://gist.github.com/1009449.js?file=add_singleton_methods_by_singleton_method.rb"></script>
<p>Then defining instance method to create singleton methods.</p>
<script src="https://gist.github.com/1009449.js?file=add_singleton_methods_by_instance_method.rb"></script>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Nested Object Forms with has_one Relation]]></title>
<link href="http://emrekutlu.github.com/2009/06/nested-object-forms-with-has_one-relation/"/>
<updated>2009-06-15T15:40:30+03:00</updated>
<id>http://emrekutlu.github.com/2009/06/nested-object-forms-with-has_one-relation</id>
<content type="html"><![CDATA[<p>Rails 2.3 has a good solution for multi model forms. But there is not much examples of how to use<code> <strong>accepts_nested_attributes_for</strong></code> with <code><strong>has_one</strong></code> relation.</p>
<p>Assume that we have a Book model which has one Author.</p>
<script src="http://snipt.net/embed/821f03288846297c2cf43c34766a38f7" type="text/javascript"><!--mce:0--></script>
<br />
<script src="http://snipt.net/embed/02bd92faa38aaa6cc0ea75e59937a1ef" type="text/javascript"><!--mce:1--></script>
<br />
<p>Controller :<script src="http://snipt.net/embed/f0ef6bf2d1b0bc59796999ff717bf149" type="text/javascript"><!--mce:2--></script></p>
<br />
<p>View:</p>
<script src="http://snipt.net/embed/2b2d98bcfa219f53623aa6c1f1301a01" type="text/javascript"><!--mce:3--></script>
<br />
<p>No special action is needed for <strong><code>create</code></strong> method of BooksController, <strong>attr_accessible</strong> is not necessary for Book model. Just don’t forget to add the second parameter (<strong><code>@book</code></strong>) of <strong><code>form_for</code></strong> and build your nested object (@book.build_author).</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Tidbit: Converting Strings with Line Feed to Array]]></title>
<link href="http://emrekutlu.github.com/2009/01/tidbit-converting-strings-with-line-feed-to-array/"/>
<updated>2009-01-21T10:08:02+02:00</updated>
<id>http://emrekutlu.github.com/2009/01/tidbit-converting-strings-with-line-feed-to-array</id>
<content type="html"><![CDATA[<p>If you have trouble when converting string to array, check if your string includes any line feed (\n). Check how <code>Array("string")</code> behaves:</p>
<pre lang="bash">irb(main):001:0> Array("izzet emre \nkutlu")
=> ["izzet emre \n", "kutlu"]
</pre>
<p>This output is not what most of the people expected. Be careful!</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Rails 2.2 & Inflector]]></title>
<link href="http://emrekutlu.github.com/2008/12/rails-22-inflector/"/>
<updated>2008-12-14T22:14:52+02:00</updated>
<id>http://emrekutlu.github.com/2008/12/rails-22-inflector</id>
<content type="html"><![CDATA[<p>If you have recently updated to Rails 2.2.2, you may encounter this error when you want to start your application:</p>
<pre lang="bash">/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in
`load_missing_constant': uninitialized constant Inflector (NameError)</pre>
<p>As I learned from <a href="http://paulsturgess.co.uk/articles/show/76-load_missing_constant-uninitialized-constant-inflector-when-upgrading-to-ruby-on-rails-222" target="_blank">Paul’s post</a> usage of <code>Inflector</code> class is changed a bit. You can see the difference when you compare the inflections.rb files. Path of the file is <em>yourApp/config/initializers/inflections.rb</em></p>
<p>inflections.rb (Rails 2.1.0)</p>
<pre lang="ruby"> Inflector.inflections do |inflect|
.
.
.
end</pre>
<p>inflections.rb (Rails 2.2.2)</p>
<pre lang="ruby"> ActiveSupport::Inflector.inflections do |inflect|
.
.
.
end</pre>
<p>In my situation changing <code>Inflector</code> to <code>ActiveSupport::Inflector</code> was enough to solve the problem.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Updating RubyGems to 1.2 (Manually)]]></title>
<link href="http://emrekutlu.github.com/2008/08/updating-rubygems-to-12-manually/"/>
<updated>2008-08-27T12:34:50+03:00</updated>
<id>http://emrekutlu.github.com/2008/08/updating-rubygems-to-12-manually</id>
<content type="html"><![CDATA[<br />
<p>This is what happened when I want to install rmagick gem.</p>
<br />
<pre lang="bash" colla="+">
username@username-desktop:~$ sudo gem install rmagick
Bulk updating Gem source index for: http://gems.rubyforge.org/
ERROR: could not find rmagick locally or in a repository
</pre>
<br />
<p>What the hell…
After some googling I found that RubGems 1.1.x is buggy and and update to RubyGems 1.2 is necessary.
To learn your RubyGems version:</p>
<br />
<pre lang="bash" colla="+">
username@username-desktop:~$ gem -v
1.1.0
</pre>
<!--more-->
<p> I try to update RubyGems :</p>
<br />
<pre lang="bash" colla="+">
username@username-desktop:~$ sudo gem update --system
Updating RubyGems
Bulk updating Gem source index for: http://gems.rubyforge.org/
Nothing to update
</pre>
<br />
<p>After this failed attempt, I realized that RubyGems 1.1.x is really buggy. So I must go on manually to update RubyGems.</p>
<br />
<p><strong>Now the solution:</strong></p>
<br />
<ol>
<li>
Download <a href="http://rubyforge.org/frs/download.php/38844/rubygems-update-1.2.0.gem">rubygems-update-1.2.0.gem</a>
</li>
<li>
Change your directory where your downloaded gem is. In these example my gem is at Desktop.
Now you must install <em>rubygems-update-1.2.0.gem</em>.
<pre lang="bash" colla="+">
username@username-desktop:~$ cd Desktop/
username@username-desktop:~/Desktop$ sudo gem install rubygems-update-1.2.0.gem
</pre>
</li>
<li>
<pre lang="bash" colla="+">
username@username-desktop:~$sudo update_rubygems
</pre>
</li>
</ol>
<br />
<p>To check if our process is successful :</p>
<br />
<pre lang="bash" colla="+">
username@username-desktop:~$gem -v
1.2.0
</pre>
<br />
<p>If you see <em>1.2.0</em>, you did it.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Recursive methods with block in Ruby]]></title>
<link href="http://emrekutlu.github.com/2008/08/recursive-methods-with-block/"/>
<updated>2008-08-26T10:46:17+03:00</updated>
<id>http://emrekutlu.github.com/2008/08/recursive-methods-with-block</id>
<content type="html"><![CDATA[<br />
<pre lang="ruby" colla="+">
def comic(cast)
cast.each do |character|
unless character.is_a?(Array)
yield(character)
else
comic(character) {|x| yield x}
end
end
end
</pre>
<br />
<p>This method takes an array as argument and checks each element if it is an <em>Array</em>.
If the element is not an <em>Array</em> then the block is called.
If the element is an <em>Array</em> then the same method is called with that element as an argument and with the same block.</p>
<br />
<p>Now let’s look how we can call this method.</p>
<pre lang="ruby" colla="+">
names = ['lucky luke', 'jolly jumper', 'rin tin tin', ['joe', 'william','jack', 'averell']]
comic(names) {|c| puts c}
</pre>
<br />
<p><strong>Output :</strong></p>
<pre lang="bash">
lucky luke
jolly jumper
rin tin tin
joe
william
jack
averell
</pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[How to check if a div exists in rjs?]]></title>
<link href="http://emrekutlu.github.com/2008/08/how-to-check-if-a-div-exists-in-rjs/"/>
<updated>2008-08-24T17:52:36+03:00</updated>
<id>http://emrekutlu.github.com/2008/08/how-to-check-if-a-div-exists-in-rjs</id>
<content type="html"><![CDATA[<br />
<pre lang="html4strict" colla="+">
<body>
<div id='main'>
Main Div
</div>
</body>
</pre>
<br />
<pre lang="ruby" colla="+">
render :update do |page|
page << "if ($('main')){"
page.replace_html 'main', :inline => 'Here it is'
page << "}"
end
</pre>
<p>This ruby code checks if there is a DOM object that its id = “main”.
If there is then changes its content to “Here it is”, if there is not do nothing.</p>
]]></content>
</entry>
</feed>