<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title>Vladimir Penkin</title>
 <link href="http://penkin.co.uk/atom.xml" rel="self"/>
 <updated>2012-01-26T23:11:39+04:00</updated>
 <id>http://penkin.co.uk/</id>
 <author>
   <name>Vladimir Penkin</name>
   <email>penkinv@gmail.com</email>
 </author>
 
 <entry>
   <id>http://penkin.co.uk/sinatra-template</id>
   <link href="http://penkin.co.uk/sinatra-template"/>
   <title>Sinatra template</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='sinatra_template'&gt;Sinatra template&lt;/h1&gt;

&lt;p&gt;Recently I found myself doing a couple of very simple services for my cliens with Sinatra. Just some basic authentication, &lt;code&gt;active_record&lt;/code&gt; and &lt;code&gt;mysql2&lt;/code&gt; database, few forms, rails view helpers. There is a lot of guides and tutorials around internet. But it seems that there is no good Sinatra template with testing coverate, basic files structure, etc. So I made one. &lt;a href='https://github.com/shell/sinatra-template'&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2 id='features'&gt;Features&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;* HTTP basic authentication 
* ActiveRecord orm
* Sqlite3 for development, Mysql2 for production
* 2 very basic but associated models
* HAML, blueprint, jquery
* User and Admin interfaces
* Scroller with products
* Full rake tasks for db management(hacked sinatra-activerecord gem)
* Testing suite out of the box(RSpec)
* Some essential Rails helpers 
* Ready for deploy with passenger(config/setup_load_paths.rb)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Some prefer to extract controllers, models and helpers in corresponding folders and split them over files. It is a matter of taste, bit hey! If you have that much code, consider using Rails instead.&lt;/p&gt;

&lt;p&gt;Enjoy&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/code-reading-retrospectiva</id>
   <link href="http://penkin.co.uk/code-reading-retrospectiva"/>
   <title>Code reading Retrospectiva</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h3 id='remark'&gt;Remark&lt;/h3&gt;

&lt;p&gt;With this article I want to start a series of &amp;#8216;code reading&amp;#8217; posts. I love to read source code, especialy good one. And I think it is important for you as a programmer to read others code. You can pick up some tricks or find a better way to structure code or even find new constructions you weren&amp;#8217;t aware of. Also checkout code reading series: &lt;a href='http://www.arailsdemo.com/posts'&gt;ARailsDemo&lt;/a&gt;, &lt;a href='http://rubysource.com/?s=Code+Safari'&gt;Code Safari&lt;/a&gt;&lt;/p&gt;

&lt;h1 id='code_reading_retrospectiva'&gt;Code Reading: Retrospectiva&lt;/h1&gt;

&lt;h2 id='what_is_it'&gt;What is it?&lt;/h2&gt;

&lt;p&gt;&lt;a href='http://retrospectiva.org/overview'&gt;Retrospectiva&lt;/a&gt; as it says on the site &amp;#8220;open-source project management tool, intended to assist the collaborative aspect of work carried out by agile software development teams&amp;#8221; by &lt;a href='https://github.com/dim'&gt;Dimitrij Denissenko&lt;/a&gt;. It came under my radar a long time ago and just recently I had opportunity to read across project.&lt;/p&gt;

&lt;p&gt;I like a structure of the code and especially extension bindings. It&amp;#8217;s very rails 2.x-ish and very clean. Everything has it&amp;#8217;s own place.&lt;/p&gt;

&lt;h2 id='gems_rake_task'&gt;$gems_rake_task&lt;/h2&gt;

&lt;p&gt;As a good rails app, Retrospectiva have it&amp;#8217;s core functionality under &lt;code&gt;/lib&lt;/code&gt; directory. The interesting thing in &lt;code&gt;environment.rb&lt;/code&gt; is how it get activated:&lt;/p&gt;

&lt;p&gt;Core doesn&amp;#8217;t get loaded if rails environment is called via rake task. Appears that there is 2 global variables that allow you do define whether you are in rake or rails environment in your code &lt;code&gt;$gems_rake_task&lt;/code&gt;, &lt;code&gt;$rails_rake_task&lt;/code&gt;!&lt;/p&gt;

&lt;h2 id='seedsrb'&gt;seeds.rb&lt;/h2&gt;

&lt;p&gt;How are yours &lt;code&gt;db/seeds.rb&lt;/code&gt; file looks like? Usually I used to put ordinary Rails code there.&lt;/p&gt;

&lt;p&gt;Althouth it can and need to be represented as a module! Remember &lt;a href='http://www.catonmat.net/'&gt;Good coders code, great reuse&lt;/a&gt;. Retrospectiva does follow this rule in &lt;code&gt;db/seeds.rb&lt;/code&gt;:&lt;/p&gt;

&lt;h2 id='changelogrb'&gt;changelog.rb&lt;/h2&gt;

&lt;p&gt;It is great to have CHANGELOG file in your project, but it&amp;#8217;s usually a pain to see what changed recently from the last version. Why don&amp;#8217;t let &lt;b&gt;ruby&lt;/b&gt; and &lt;b&gt;git&lt;/b&gt; do this job for you? &lt;a href='https://github.com/dim/retrospectiva/blob/master/script/changelog.rb'&gt;script/changelog.rb&lt;/a&gt; contain a ruby script that does the trick. You just need to write a good commit messages.&lt;/p&gt;

&lt;h2 id='retrospectiva_installerrb'&gt;retrospectiva_installer.rb&lt;/h2&gt;

&lt;p&gt;Another great script for app installation &lt;a href='https://github.com/dim/retrospectiva/blob/master/script/remote/retrospectiva_installer.rb'&gt;script/remove/retrospectiva_installer.rb&lt;/a&gt;&lt;/p&gt;

&lt;h2 id='tiny_gitrb'&gt;tiny_git.rb&lt;/h2&gt;

&lt;p&gt;For integration with git, Retrospectiva using self written module that you could easily pick up at &lt;code&gt;vendor/plugins/tiny-git&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='it_should_behave_like'&gt;it_should_behave_like&lt;/h2&gt;

&lt;p&gt;I wan&amp;#8217;t aware of this feature of RSpec before. With &lt;code&gt;share_as&lt;/code&gt; and &lt;code&gt;it_should_behave_like&lt;/code&gt; you can describe general behaviour of an object and then mix it to your current spec. It&amp;#8217;s like module/include/extend for specs.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://relishapp.com/rspec/rspec-core/v/2-0/docs/example-groups/shared-example-group'&gt;Shared example group(RSpec docs)&lt;/a&gt; &lt;br /&gt; &lt;a href='http://blog.davidchelimsky.net/2010/11/07/specifying-mixins-with-shared-example-groups-in-rspec-2/'&gt;Specifying mixins with shared example groups in RSpec-2&lt;/a&gt;&lt;/p&gt;

&lt;h2 id='flashkeep'&gt;flash.keep&lt;/h2&gt;

&lt;p&gt;Keeps either the entire current flash or a specific flash entry available for the next action. &lt;a href='http://apidock.com/rails/ActionDispatch/Flash/FlashHash/keep'&gt;ApiDock&lt;/a&gt;&lt;/p&gt;

&lt;h2 id='tips'&gt;Tips&lt;/h2&gt;

&lt;p&gt;A trick for 99% of your projects&lt;/p&gt;

&lt;p&gt;Well thats all for today.&lt;/p&gt;</content>
   <updated>2011-09-09T00:00:00+04:00</updated>
   <category scheme="http://penkin.co.uk/tags/" term="code reading" label="code reading" />
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/tips</id>
   <link href="http://penkin.co.uk/tips"/>
   <title>tips</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h2 id='tips'&gt;tips&lt;/h2&gt;
&lt;hr /&gt;
&lt;p&gt;Always trust projects &lt;code&gt;.rvmrc&lt;/code&gt; file&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;A trick for 99% of your projects&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Array#to_proc&lt;/p&gt;
&lt;hr /&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/code-reading</id>
   <link href="http://penkin.co.uk/code-reading"/>
   <title>Code reading</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;p&gt;Importance of code reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;teambox&lt;/li&gt;

&lt;li&gt;locomotive_cms&lt;/li&gt;

&lt;li&gt;hamster&lt;/li&gt;

&lt;li&gt;facets&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/rails3_before_render-plugin</id>
   <link href="http://penkin.co.uk/rails3_before_render-plugin"/>
   <title>rails3_before_render plugin</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='rails3_before_render_plugin'&gt;rails3_before_render plugin&lt;/h1&gt;

&lt;p&gt;I&amp;#8217;ve just released small plugin &lt;a href='https://github.com/shell/rails3_before_render'&gt;rails3_before_render&lt;/a&gt;. It adds a hook like &lt;code&gt;before_filter&lt;/code&gt; to your controllers that gets executed between when your action is completed and the template is rendered. It can really DRY up loading some data.&lt;/p&gt;

&lt;p&gt;Please be carefull using that. Regular &lt;code&gt;before/after/around&lt;/code&gt; filters is enough for &lt;strong&gt;most&lt;/strong&gt; of the tasks that you can imagine. If not you always call method directly, that will increase readability of your code. Use &lt;code&gt;before_render&lt;/code&gt; in exceptional cases.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://blog.davidchelimsky.net/wp-content/uploads/2010/11/duplication.pdf'&gt;Here&lt;/a&gt; is good presentation by David Chelimsky about code duplication and DRY concept.&lt;/p&gt;

&lt;h2 id='use_case'&gt;Use case&lt;/h2&gt;

&lt;p&gt;Mostly I&amp;#8217;ve needed that plugin for my &lt;code&gt;mugen&lt;/code&gt; gem.&lt;/p&gt;

&lt;p&gt;There is error check after each api request that populate &lt;code&gt;Mugen.errors&lt;/code&gt; variable with messages. Every action of controller after all requests has been sent need to check that variable and populate flash messages with that. Without having plugin I used wrapper function like this:&lt;/p&gt;

&lt;p&gt;After 5-th action code duplication seems unreasonable. Regular filters like &lt;code&gt;before_filter&lt;/code&gt; and &lt;code&gt;after_filter&lt;/code&gt; didn&amp;#8217;t fit here. Errors parsing clearly needs to be executed right before rendering.&lt;/p&gt;

&lt;p&gt;With that I could remove &lt;code&gt;mygengo_request&lt;/code&gt; method along with wrapping each action in controller.&lt;/p&gt;

&lt;h2 id='before_render'&gt;before_render&lt;/h2&gt;

&lt;p&gt;Before writing this plugin I have found &lt;a href='https://github.com/xtoddx/before_render'&gt;before_render&lt;/a&gt; plugin by Todd Willey. Sadly it worked for rails 2.x only. Rails 3 brought us completely new architecture of ActionPack and as I have found even ActiveSupport had major changes. Callbacks module is now more efficient that is was before.&lt;/p&gt;

&lt;p&gt;New &lt;code&gt;ActiveSupport::Callbacks&lt;/code&gt; methods were used, in analogy with ActionDispatch. That allowed me to escape reimplementing callback filter chains.&lt;/p&gt;</content>
   <updated>2011-03-11T00:00:00+03:00</updated>
   <category scheme="http://penkin.co.uk/tags/" term="rails plugin" label="rails plugin" />
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/textmate-project-drawer-enhanced</id>
   <link href="http://penkin.co.uk/textmate-project-drawer-enhanced"/>
   <title>TextMate Project Drawer Enhanced</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='textmate_missing_sidebar_enhanced'&gt;TextMate Missing Sidebar Enhanced&lt;/h1&gt;

&lt;p&gt;&lt;a href='https://github.com/jezdez/textmate-missingdrawer'&gt;Missing Drawer&lt;/a&gt; is a better sidebar for Textmate project.&lt;/p&gt;

&lt;p&gt;First thing to notice, is when you hiding project drawer it automatically resizes text window, so you can enjoy full screen without more actions.&lt;/p&gt;

&lt;p&gt;Also it adds &amp;#8220;Open Terminal Here&amp;#8221; button. Handy! Because you never need &lt;code&gt;cd&lt;/code&gt; to working directory anymore.&lt;/p&gt;
&lt;img alt='Screenshot' class='post-img' src='https://github.com/downloads/jezdez/textmate-missingdrawer/Screen%20shot%202010-08-20.png' /&gt;
&lt;p&gt;Although, there was a bug when you use it with iTerm 2. It always open new window instead of new tab. &lt;em&gt;fixed&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Also added nice enhancement that save me couple of seconds every day - &lt;code&gt;GitX&lt;/code&gt; button.&lt;/p&gt;
&lt;img alt='textmate-drawer' class='post-img' src='/images/textmate-missing-drawer.png' /&gt;
&lt;p&gt;While my &lt;a href='https://github.com/jezdez/textmate-missingdrawer/pull/32'&gt;pull request&lt;/a&gt; awaiting for a merge into master branch, why not try it out right now?&lt;/p&gt;
&lt;a href='/downloads/MissingDrawer.tmplugin.zip'&gt;plugin&lt;/a&gt;</content>
   <updated>2011-03-03T00:00:00+03:00</updated>
   <category scheme="http://penkin.co.uk/tags/" term="textmate" label="textmate" />
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/mygengo-contest</id>
   <link href="http://penkin.co.uk/mygengo-contest"/>
   <title>myGengo Api Labs Contest</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='mygengo_api_labs_contest'&gt;myGengo Api Labs Contest&lt;/h1&gt;

&lt;p&gt;Starting from a new years holidays I have participated in &lt;a href='http://mygengo.com/services/api/lab/'&gt;myGengo Api Labs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3 Things I have developed so far:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mugen&lt;/strong&gt; - ruby wrapper for myGengo API, based on &lt;code&gt;httparty&lt;/code&gt;. Also include generators of nested rails app that provides basic interface. I have took a look on existing wrapper provided by myGengo Team, which was not very clear and rubyish way. Also it&amp;#8217;s been a while since I wanted to try &lt;code&gt;httparty&lt;/code&gt; gem by John Nunemaker. &lt;a href='https://github.com/shell/mugen'&gt;GitHub&lt;/a&gt; &lt;a href='http://mygengo.com/services/api/plugins/details/ruby-on-rails/'&gt;Mygengo Plugin page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install it now by :&lt;/p&gt;
&lt;br /&gt;&lt;img alt='mugen' class='post-img' src='/images/screen-mugen.png' /&gt;
&lt;p&gt;&lt;strong&gt;Radiant-cms extension&lt;/strong&gt; - Is also using &lt;code&gt;mugen&lt;/code&gt; to talk to myGengo servers. This extension integrates to your administration interface to set up jobs for translation. Translations can easily be stored in your database and inserted in your content. &lt;a href='http://ext.radiantcms.org/extensions/260-mygengo'&gt;Extension page&lt;/a&gt;, &lt;a href='https://github.com/shell/radiant-mygengo-extension'&gt;GitHub&lt;/a&gt; &lt;a href='http://mygengo.com/services/api/plugins/details/radiant/'&gt;Mygengo Plugin page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Radiant installation:&lt;/p&gt;
&lt;br /&gt;&lt;img alt='mugen' class='post-img' src='/images/screen-radiant-extension.png' /&gt;
&lt;p&gt;&lt;strong&gt;Zend Framework plugin&lt;/strong&gt; - it took 2 days of hardcore digging in ZF documentation and coding all that classes in PHP. But I nailed it. Installation instructions for existing zf apps as well as quickstart guide available in &lt;a href='https://github.com/shell/zf-mygengo/blob/master/README.md'&gt;readme&lt;/a&gt;. &lt;a href='https://github.com/shell/zf-mygengo'&gt;GitHub&lt;/a&gt; &lt;a href='http://mygengo.com/services/api/plugins/details/zend-framework/'&gt;Mygengo Plugin page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out &lt;a href='http://mygengo.com/services/api/lab/winners/'&gt;Winners page&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/my-footprint-on-the-mras</id>
   <link href="http://penkin.co.uk/my-footprint-on-the-mras"/>
   <title>My footprint on the Mars</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='my_footprint_on_the_mars'&gt;My footprint on the Mars&lt;/h1&gt;

&lt;p&gt;I have never been on the Moon, on the Mars and at RailsConf. Although I had a chance to left my footprint on the RailsConf&amp;#8217;10.&lt;/p&gt;
&lt;img alt='Mars!' class='post-img rounded' src='/images/footprint.jpg' /&gt;
&lt;p&gt;p.s. Mars - you&amp;#8217;re next!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/forklift-open-in-terminal-for-iterm</id>
   <link href="http://penkin.co.uk/forklift-open-in-terminal-for-iterm"/>
   <title>Switching ForkLift to use iTerm by default</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='switching_forklift_to_use_iterm_by_default'&gt;Switching ForkLift to use iTerm by default&lt;/h1&gt;

&lt;p&gt;To open current selected folder in iTerm instead of default Terminal.app from ForkLift, in &lt;code&gt;ForkLift.app/Resources/OpenInTerminal.applescript&lt;/code&gt; file put following:&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <id>http://penkin.co.uk/pre-and-post-hooks-with-method_alias</id>
   <link href="http://penkin.co.uk/pre-and-post-hooks-with-method_alias"/>
   <title>Pre and post hooks for external libraries</title>
   <author>
     <name>Vladimir Penkin</name>
     <email>penkinv@gmail.com</email>
   </author>
   <content type="html">&lt;h1 id='pre_and_post_hooks_for_external_libraries_with_alias_method'&gt;Pre and post hooks for external libraries with alias_method&lt;/h1&gt;

&lt;p&gt;Ever missing hooks in your favorite libraries? &lt;code&gt;before_filter&lt;/code&gt; and &lt;code&gt;after_fileter&lt;/code&gt; is not working outside rails? Thanks to ruby awesomness it&amp;#8217;s never been an issue for programmers who know how to use &lt;code&gt;alias&lt;/code&gt; or &lt;code&gt;alias_method&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='problem'&gt;Problem&lt;/h2&gt;

&lt;p&gt;Here I am, sitting in front of laptop, writing yet another API wrapper. As I get tired of ruby native &lt;a href='http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html'&gt;NET::HTTP&lt;/a&gt; requests and wanted to try something more explicit and gave a shot to &lt;a href='http://github.com/jnunemaker/httparty'&gt;HTTParty&lt;/a&gt; by John Nunemaker. Syntax is very simple and I came with following code:&lt;/p&gt;

&lt;p&gt;But apparently interaction is not so easy as it seems. All authenticated calls must be signed. The process of signing include arguments that was passed to current method. So in every method that called, it needs sign data before sending:&lt;/p&gt;

&lt;p&gt;Seems like unnecessary code duplication. Isn&amp;#8217;t this kind of thing that pre-hook is made for? To solve this problem you diffinetly &lt;a href='http://railstips.org/blog/archives/2010/10/14/stop-googling/'&gt;shouldn&amp;#8217;t google&lt;/a&gt; for that.&lt;/p&gt;

&lt;p&gt;After digging httparty source code I haven&amp;#8217;t found some pre- or post- hooks. Seems like we need to do it ourselves.&lt;/p&gt;

&lt;h2 id='cooking_hooks_with_alias_methiod'&gt;Cooking hooks with alias_methiod&lt;/h2&gt;

&lt;p&gt;Thanks to greatness of ruby, I can open and modify native or external classes:&lt;/p&gt;

&lt;p&gt;Ok now we have self-cooked &lt;code&gt;before_get&lt;/code&gt; method that will be called before original HTTParty.get and will do the work:&lt;/p&gt;

&lt;p&gt;Remember to put &lt;code&gt;original_get&lt;/code&gt; arguments back with last line&lt;/p&gt;

&lt;h2 id='things_to_watch_out'&gt;Things to watch out&lt;/h2&gt;

&lt;p&gt;Be aware &lt;code&gt;alias&lt;/code&gt; is keyword so there is no comma after name of new method. But &lt;code&gt;alias_method&lt;/code&gt; is method version of alias.&lt;/p&gt;

&lt;p&gt;Also do not crush others code. If I put &lt;code&gt;Mugen.set_params&lt;/code&gt; in &lt;strong&gt;&lt;code&gt;httparty_extensions.rb&lt;/code&gt;&lt;/strong&gt; this can easily break other code that rely on HTTParty.&lt;/p&gt;
&lt;!-- Discovering new tricks in ruby is always fun. --&gt;</content>
   <updated>2011-02-02T00:00:00+03:00</updated>
   <category scheme="http://penkin.co.uk/tags/" term="ruby" label="ruby" />
 </entry>
 
</feed>
