<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>code-fu.pl</title>
 <link href="http://code-fu.pl/atom.xml" rel="self"/>
 <link href="http://code-fu.pl/"/>
 <updated>2011-07-27T00:24:12+02:00</updated>
 <id>http://code-fu.pl/</id>
 <author>
   <name>Grzesiek Kolodziejczyk</name>
   <email>gk@code-fu.pl</email>
 </author>
 
 
 <entry>
   <title>Running PDFKit on Heroku</title>
   <link href="http://code-fu.pl/blog/2011/05/17/pdfkit-heroku"/>
   <updated>2011-05-17T00:00:00+02:00</updated>
   <id>http://code-fu.pl/blog/2011/05/17/pdfkit-heroku</id>
   <content type="html">&lt;p&gt;If you try to run &lt;a href='https://github.com/jdpace/PDFKit/'&gt;PDFKit&lt;/a&gt; on Heroku you will run into a problem with starting a request to the stylesheets from within a request - thin can&amp;#8217;t handle that.&lt;/p&gt;

&lt;p&gt;Instead of running the PDFKit middleware, you&amp;#8217;ll need to add a pdf format in your &lt;code&gt;respond_to&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;First, register PDF as a mime-type in &lt;code&gt;config/initializers/mime_types.rb&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='no'&gt;Mime&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Type&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;register&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;application/pdf&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:pdf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, create the responder. The trick is to render the view you want to use to a string, create a PDFKit object from that, and add stylesheet paths instead of loading them through the problematic separate request.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;format&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;pdf&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
  &lt;span class='n'&gt;kit&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;PDFKit&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;render_to_string&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:template&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;controller/view.html&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                                    &lt;span class='ss'&gt;:layout&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;layout.html&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
  &lt;span class='c1'&gt;# stylesheets in tmp because I&amp;#39;m using compass&lt;/span&gt;
  &lt;span class='n'&gt;kit&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;stylesheets&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;Rails&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;root&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;tmp&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;stylesheets&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;style.css&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;to_s&lt;/span&gt;
  &lt;span class='n'&gt;render&lt;/span&gt; &lt;span class='ss'&gt;:text&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;kit&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;to_pdf&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, you need to make sure that all partials are called as&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;render&lt;/span&gt; &lt;span class='ss'&gt;:partial&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;partial.html&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;since &lt;code&gt;render_to_string&lt;/code&gt; doesn&amp;#8217;t know the proper format then.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GitHub repos in jekyll</title>
   <link href="http://code-fu.pl/blog/2011/05/07/github-repos-in-jekyll"/>
   <updated>2011-05-07T00:00:00+02:00</updated>
   <id>http://code-fu.pl/blog/2011/05/07/github-repos-in-jekyll</id>
   <content type="html">&lt;p&gt;I created a plugin for &lt;a href='https://github.com/mojombo/jekyll'&gt;jekyll&lt;/a&gt; to present a list of public Github repositories. Usage is simple: put the &lt;code&gt;github_projects.rb&lt;/code&gt; file in the &lt;code&gt;plugins/&lt;/code&gt; directory, and the &lt;code&gt;projects.html&lt;/code&gt; layout into &lt;code&gt;_layouts/&lt;/code&gt;. Also, you need to add &lt;code&gt;octokit&lt;/code&gt; to your &lt;code&gt;Gemfile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Edit the projects layout to specify which repositories you want to show, and customise the display. &lt;code&gt;project&lt;/code&gt; is a hash (converted to &lt;code&gt;Hashie::Rash&lt;/code&gt;) returned by &lt;code&gt;Octokit.repo(&amp;quot;user/repo&amp;quot;&lt;/code&gt;, which gives a nice Ruby-styled wrapper for the &lt;a href='http://develop.github.com/p/repo.html'&gt;Github API response&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As ususal, comments and suggestions welcome at the bottom of the page.&lt;/p&gt;

&lt;p&gt;If you want to play with it, here&amp;#8217;s the code: &lt;script src='https://gist.github.com/960394.js'&gt; &lt;/script&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Rails + MongoDB resources</title>
   <link href="http://code-fu.pl/blog/2010/01/17/rails-mongodb-resources"/>
   <updated>2010-01-17T00:00:00+01:00</updated>
   <id>http://code-fu.pl/blog/2010/01/17/rails-mongodb-resources</id>
   <content type="html">&lt;p&gt;Here is a work-in-progress list of useful resources for starting out a Rails project with MongoDB and MongoMapper:&lt;/p&gt;

&lt;h2 id='railstips_articles_about_mongomapper'&gt;RailsTips articles about MongoMapper&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://railstips.org/blog/archives/2009/12/23/getting-a-grip-on-gridfs/'&gt;Getting A Grip on GridFS&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://railstips.org/blog/archives/2009/12/18/why-i-think-mongo-is-to-databases-what-rails-was-to-frameworks/'&gt;Why I think Mongo is to Databases what Rails was to Frameworks&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://railstips.org/blog/archives/2009/10/09/more-mongomapper-awesomeness/'&gt;More MongoMapper Awesomeness&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='getting_started'&gt;Getting started&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://www.shiftcommathree.com/articles/how-to-install-mongodb-on-os-x'&gt;How to install MogoDB on OS X&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://railscasts.com/episodes/194-mongodb-and-mongomapper'&gt;MongoDB and MongoMapper&lt;/a&gt; Railscast&lt;/li&gt;

&lt;li&gt;&lt;a href='http://blog.bitzesty.com/mongodb-with-mongomapper-and-ruby-on-rails'&gt;MongoDB with MongoMapper and Ruby on Rails&lt;/a&gt; with nice initializer example&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.mongodb.org/display/DOCS/Rails+-+Getting+Started'&gt;Rails - Getting Started&lt;/a&gt; from mongoDB docs&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails'&gt;MongoDB Data Modeling and Rails&lt;/a&gt; really good read on how to approach modeling of your data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='mongodb_usage'&gt;MongoDB usage&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://kylebanker.com/blog/2009/11/mongodb-count-group/'&gt;Counting and grouping&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://kylebanker.com/blog/2009/11/mongodb-advanced-grouping/'&gt;Advanced grouping&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://kylebanker.com/blog/2009/12/mongodb-map-reduce-basics/'&gt;Map-reduce basics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='authentication'&gt;Authentication&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://github.com/plataformatec/devise'&gt;Devise&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/theshortcut/devise_mongomapper_example/'&gt;Devise MongoMapper Example&lt;/a&gt; at github&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='useful_additions'&gt;Useful additions&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://github.com/ramdiv/mongo_mapper_acts_as_tree/'&gt;Acts as tree&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/mepatterson/acts_as_mongo_rateable'&gt;ActsAsMongoRateable&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/mepatterson/acts_as_mongo_taggable'&gt;ActsAsMongoTaggable&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/collectiveidea/delayed_job/tree/backends'&gt;DelayedJob&lt;/a&gt; branch with non-AR backend support&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/jnicklas/carrierwave'&gt;CarrierWave&lt;/a&gt; - replacement for Paperclip (could use &lt;a href='http://github.com/mdirolf/nginx-gridfs'&gt;nginx-gridfs&lt;/a&gt; for serving the files)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='testing'&gt;Testing&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://boldr.net/test-mongomapper/'&gt;Easy Testing MongoMapper models&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/nmerouze/machinist_mongo'&gt;Machinist Mongo&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/nmerouze/remarkable_mongo'&gt;Remarkable Mongo&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='open_source_apps_using_rails_and_mongomapper'&gt;Open source apps using Rails and MongoMapper&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://github.com/banker/newsmonger'&gt;Newsmonger&lt;/a&gt; - &amp;#8220;A simple social news application demonstrating MongoDB and Rails.&amp;#8221;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/Papipo/congo-cms/'&gt;Congo CMS&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://github.com/shingara/oupsnow/'&gt;opusnow&lt;/a&gt; - a bugtracker&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you know any other useful articles, please point them out in the comments.&lt;/p&gt;</content>
 </entry>
 
 
</feed>

