<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>scriptonia</title><generator>Tumblr (3.0; @oivoodoo)</generator><link>http://oivoodoo.tumblr.com/</link><item><title>blog.izs.me: Everyone has a Price</title><description>&lt;a href="http://blog.izs.me/post/45196990126/everyone-has-a-price"&gt;blog.izs.me: Everyone has a Price&lt;/a&gt;: &lt;p&gt;&lt;a class="tumblr_blog" href="http://blog.izs.me/post/45196990126/everyone-has-a-price"&gt;izs&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Got this email this morning:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;From: Andrew
To: i@izs.me
Subject: Have a minute to talk about npmjs.org? Hello, We have a client interested in npmjs.org. Would you
consider selling the site? Please let me know a day, time and phone number
you could speak about this possibility and we'll try
to...&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;</description><link>http://oivoodoo.tumblr.com/post/45257045274</link><guid>http://oivoodoo.tumblr.com/post/45257045274</guid><pubDate>Wed, 13 Mar 2013 10:08:56 +0200</pubDate></item><item><title>Set tabname in iterm2</title><description>&lt;p&gt;&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/oivoodoo/4154463"&gt;https://gist.github.com/oivoodoo/4154463&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/44703824381</link><guid>http://oivoodoo.tumblr.com/post/44703824381</guid><pubDate>Wed, 06 Mar 2013 15:23:17 +0200</pubDate><category>terminal</category><category>iterm2</category></item><item><title>Print grape routes using rake task.</title><description>&lt;p&gt;&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/oivoodoo/5089237"&gt;https://gist.github.com/oivoodoo/5089237&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/44703785352</link><guid>http://oivoodoo.tumblr.com/post/44703785352</guid><pubDate>Wed, 06 Mar 2013 15:22:06 +0200</pubDate><category>grape</category><category>rails</category><category>rake</category></item><item><title>Use http_basic with grape API layer.</title><description>&lt;p&gt;&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/oivoodoo/5098963"&gt;https://gist.github.com/oivoodoo/5098963&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/44702072160</link><guid>http://oivoodoo.tumblr.com/post/44702072160</guid><pubDate>Wed, 06 Mar 2013 14:27:00 +0200</pubDate><category>rails</category><category>grape</category><category>api</category><category>rspec</category></item><item><title>Track your time.</title><description>&lt;p&gt;Today I&amp;#8217;ve decided to install widget of the cashboardapp.com. it&amp;#8217;s definitely save my time in the future for making invoices to the clients. Also I have already started to create the stories based on the pivotaltracker and then just click log time.&lt;/p&gt;
&lt;p&gt;I will see result at the end of the month.&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/43563015627</link><guid>http://oivoodoo.tumblr.com/post/43563015627</guid><pubDate>Wed, 20 Feb 2013 15:17:20 +0200</pubDate></item><item><title>Migrating s3 data to the new account</title><description>&lt;p&gt;Few days ago I needed to migrate s3 data from one account to another account. I&amp;#8217;ve decided to use as background worker heroku server. And wrote this code below:&lt;/p&gt;
&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/oivoodoo/5099330"&gt;https://gist.github.com/oivoodoo/5099330&lt;/a&gt;&lt;/div&gt;</description><link>http://oivoodoo.tumblr.com/post/43120780608</link><guid>http://oivoodoo.tumblr.com/post/43120780608</guid><pubDate>Fri, 15 Feb 2013 04:52:00 +0200</pubDate><category>ruby</category><category>ruby-on-rails</category><category>rails</category><category>rails3</category><category>amazon</category><category>s3</category></item><item><title>devise masquerade gem</title><description>&lt;p&gt;Yesterday I published the simple gem for devise. Now it is easy to add &amp;#8216;Login As&amp;#8217; functionality to your admin pages.&lt;/p&gt;
&lt;p&gt;1. Add gem &amp;#8216;devise_masquerade&amp;#8217; to your Gemfile.&lt;/p&gt;
&lt;p&gt;2. Add before_filter :masquerade_user! to the application_controller.rb&lt;/p&gt;
&lt;p&gt;3. Add link_to &amp;#8216;Login As&amp;#8217;, masquerade_path(user) to your table with users.&lt;/p&gt;
&lt;p&gt;4. Use it :)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/oivoodoo/devise_masquerade" title="More"&gt;More&lt;/a&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/36131182829</link><guid>http://oivoodoo.tumblr.com/post/36131182829</guid><pubDate>Tue, 20 Nov 2012 11:57:33 +0200</pubDate><category>rails</category><category>gem</category><category>ruby</category><category>devise</category><category>ruby on rails</category></item><item><title>deploy branch to the heroku</title><description>&lt;p&gt;&lt;pre&gt;git push heroku branch-name:master
&lt;/pre&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/34154483688</link><guid>http://oivoodoo.tumblr.com/post/34154483688</guid><pubDate>Tue, 23 Oct 2012 10:08:11 +0300</pubDate><category>heroku</category><category>rails</category></item><item><title>parallel each for array with the same size</title><description>&lt;p&gt;&lt;pre&gt;[[1,2,3], [4,5,6]].transpose.map do |data| 
  v1 = data[0]
  v2 = data[1]
  puts "#{v1} - #{v2}"
end
&lt;/pre&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/34089573672</link><guid>http://oivoodoo.tumblr.com/post/34089573672</guid><pubDate>Mon, 22 Oct 2012 11:14:46 +0300</pubDate><category>ruby</category></item><item><title>print sql queries in the console while debugging</title><description>&lt;p&gt;rails code:&lt;/p&gt;
&lt;pre&gt;   class Post &amp;lt; ActiveRecord::Base
     def method1
       require 'ruby-debug'
       debugger
       ...
     end
   end
&lt;/pre&gt;
&lt;p&gt;In the debug session you should run the next following code:&lt;/p&gt;
&lt;pre&gt;  ActiveRecord::Base.logger = Logger.new($stdout)
&lt;/pre&gt;
&lt;p&gt;My ~/.rdebugrc&lt;/p&gt;
&lt;pre&gt;set autolist
set autoeval
set autoreload
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/33827511101</link><guid>http://oivoodoo.tumblr.com/post/33827511101</guid><pubDate>Thu, 18 Oct 2012 11:07:41 +0300</pubDate><category>rails</category><category>debug</category><category>ruby</category></item><item><title>postgres selection with cases</title><description>&lt;p&gt;Hi everyone!&lt;/p&gt;
&lt;p&gt;Not a long time ago I found that I can use when/case conditions in the aggregation functions in the postgres.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;SELECT SUM(CASE WHEN one_column IS NULL then another_column else one_column) as total FROM table_name
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/32862572686</link><guid>http://oivoodoo.tumblr.com/post/32862572686</guid><pubDate>Thu, 04 Oct 2012 10:13:15 +0300</pubDate></item><item><title>ActiveRecord aggregation functions a quick trick.</title><description>&lt;p&gt;Today I found a very interesting trick connection with aggregation functions in the ActiveRecord.&lt;/p&gt;
&lt;p&gt;For example you have a Stat(clicks:integer(default: 0), key:string) model. And you need to find sum of the clicks for the specific key.&lt;/p&gt;
&lt;pre&gt;Stat.where(:key =&amp;gt; 'your key').all(:select =&amp;gt; "sum(clicks) as clicks")
&lt;/pre&gt;
&lt;p&gt;Lets imagine you have the stats with key. And as result of expression you will get stat object with clicks.&lt;/p&gt;
&lt;pre&gt;[#&amp;lt;Stat clicks: 102&amp;gt;] 
&lt;/pre&gt;
&lt;p&gt;But if you have no the stats with key:&lt;/p&gt;
&lt;pre&gt;Stat.where(:key =&amp;gt; 'your key').count =&amp;gt; 0
&lt;/pre&gt;
&lt;p&gt;Lets the same expression for finding summary of the clicks:&lt;/p&gt;
&lt;p&gt;Stat.where(:key =&amp;gt; &amp;#8216;your key&amp;#8217;).all(:select =&amp;gt; &amp;#8220;sum(clicks) as clicks&amp;#8221;)&lt;/p&gt;
&lt;pre&gt;[#&amp;lt;Stat clicks: nil&amp;gt;] 
&lt;/pre&gt;
&lt;p&gt;As I wrote above clicks should have default value as 0. And you are making something like report page, you don&amp;#8217;t want to add to_i for nil objects to the different expressions.&lt;/p&gt;
&lt;p&gt;I wrote a small patch for this behavior:&lt;/p&gt;
&lt;pre&gt;module Extensions
  module DefaultAttributeValue
    def self.included(base)
      base.send :extend, ClassMethods
    end

    module ClassMethods
      def default_attribute_value(key, value)
        self.class_eval %Q{
          def #{key}
            value = read_attribute(:#{key})

            value || #{value}
          end
        }
      end
    end
  end
end


# specs

require 'spec_helper'

class TestClass
  include Extensions::DefaultAttributeValue

  attr_accessor :key

  default_attribute_value :key, 0

  def read_attribute(key)
    instance_variable_get("@#{key}")
  end
end

describe Extensions::DefaultAttributeValue do
  let(:object) { TestClass.new }

  it { object.key.should == 0 }

  context 'when key assigned' do
    before { object.key = 1 }

    it { object.key.should == 1 }
  end
end

# example

class Stat #&amp;lt; ActiveRecord::Base
  include Extensions::DefaultAttributeValue

  default_attribute_value :clicks, 0
end

&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/3774620"&gt;Gist&lt;/a&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/32186391561</link><guid>http://oivoodoo.tumblr.com/post/32186391561</guid><pubDate>Mon, 24 Sep 2012 09:37:00 +0300</pubDate><category>rails</category><category>activerecord</category><category>gist</category><category>extension</category></item><item><title>Setup the default app for heroku</title><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If you are using multiple applications for the heroku project.&lt;/p&gt;
&lt;p&gt;For examle you have staging, production, demo environments but mostly you are using the staging in the development. You could use the next following command for setup the default app for your environment:&lt;/p&gt;
&lt;pre&gt;git config heroku.remote staging
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/31802725252</link><guid>http://oivoodoo.tumblr.com/post/31802725252</guid><pubDate>Tue, 18 Sep 2012 20:23:24 +0300</pubDate><category>heroku</category><category>snippet</category></item><item><title>Go App is my the first test application using Go lang</title><description>&lt;p&gt;&lt;a href="https://github.com/oivoodoo/go-page"&gt;Go page sources&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;package app

import (
    "github.com/garyburd/twister/server"
    "github.com/garyburd/twister/web"
    "text/template"
)

var (
  page *template.Template
)

func index(request *web.Request) {
  page.Execute(
    request.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8"),
    request.URL.Host)
}

func main() {
  page = template.Must(template.New("index").Parse(body))

  server.Run(":8080",
    web.NewRouter().
      Register("/", "GET", index))
}

const body = `
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Developed using Go :)&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;I made this page using Go language&amp;lt;/h1&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt; `
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/31479198765</link><guid>http://oivoodoo.tumblr.com/post/31479198765</guid><pubDate>Fri, 14 Sep 2012 00:06:00 +0300</pubDate><category>go</category><category>programming</category><category>web</category><category>server</category></item><item><title>Using multiple accounts on the heroku.</title><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;p&gt;If now someone is using heroku for hosting applications you could meet a problem with multiple accounts in the heroku. For example on the work you could have your company account like your_name@your_company.com but at home you are using your_name@gmail.com&lt;/p&gt;
&lt;p&gt;1. Generate to different ssh-keys&lt;/p&gt;
&lt;pre&gt;ssh-keygen -t rsa # your_name@your_company
&lt;/pre&gt;
&lt;pre&gt;ssh-keygen -t rsa your_name@gmail
&lt;/pre&gt;
&lt;p&gt;2. Login to the heroku using the company account and add your key to the heroku.&lt;/p&gt;
&lt;pre&gt;heroku login:auth
heroku keys:add
&lt;/pre&gt;
&lt;p&gt;3. Login to the heroku using your home account and add your key to the heroku&lt;/p&gt;
&lt;p&gt;OK, now if you want to start working with a company account you should do the next following steps:&lt;/p&gt;
&lt;pre&gt;ssh-add -D
ssh-add ~/.ssh/your_name@your_company
heroku auth:logout # if you need it
heroku login:auth
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/31456348622</link><guid>http://oivoodoo.tumblr.com/post/31456348622</guid><pubDate>Thu, 13 Sep 2012 14:02:00 +0300</pubDate><category>heroku</category><category>hosting</category><category>rails</category><category>terminal</category><category>ssh</category></item><item><title>Easy deploy to the heroku using .git/config remote sections</title><description>&lt;p&gt;Open .git/config in your project and add the next following sections for the different environments.&lt;/p&gt;
&lt;pre&gt;[remote "production"]
  url = git@heroku.com:your_project.git
  fetch = +refs/heads/*:refs/remotes/production/*
[remote "staging"]
  url = git@heroku.com:staging-your_project.git
  fetch = +refs/heads/*:refs/remotes/staging/*
&lt;/pre&gt;
&lt;p&gt;And now you can easy deploy to the different envs to the heroku.&lt;/p&gt;
&lt;pre&gt;git push production deploy
git push staging deploy
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/31394302298</link><guid>http://oivoodoo.tumblr.com/post/31394302298</guid><pubDate>Wed, 12 Sep 2012 14:04:19 +0300</pubDate><category>rails</category><category>heroku</category><category>rails3</category><category>configuration</category><category>git</category><category>git-core</category></item><item><title>Iterate by days in the Rails 3</title><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I have just found a very nice snippet how to iterate by days in the Rails 3.&lt;/p&gt;
&lt;pre&gt;start_date = 1.day.from_now.to_date
end_date = 5.days.from_now.to_date

start_date.upto(end_date) do |day|
  puts day
end
&lt;/pre&gt;</description><link>http://oivoodoo.tumblr.com/post/31391915022</link><guid>http://oivoodoo.tumblr.com/post/31391915022</guid><pubDate>Wed, 12 Sep 2012 12:10:39 +0300</pubDate><category>ruby</category><category>rails</category><category>rails3</category><category>snippet</category></item><item><title>Testris, today I've published my game to the heroku hosting.</title><description>&lt;a href="http://tetris-app.herokuapp.com/"&gt;Testris, today I've published my game to the heroku hosting.&lt;/a&gt;: &lt;p&gt;Chrome WebStore version - &lt;a href="https://chrome.google.com/webstore/detail/eeehcmbhicglclggakomjhhlmemhjbde"&gt;https://chrome.google.com/webstore/detail/eeehcmbhicglclggakomjhhlmemhjbde&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I hope soon I will publish the galaxy invaders game based using html5 rendering.&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/31050149104</link><guid>http://oivoodoo.tumblr.com/post/31050149104</guid><pubDate>Fri, 07 Sep 2012 12:58:00 +0300</pubDate><category>chrome</category><category>game</category><category>html5</category><category>javascript</category><category>web</category><category>website</category><category>dev</category><category>gamedev</category></item><item><title>How to developer the feed items dashboard element for the different kinds of models in your application.</title><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;p&gt;In my current application we have the dashboard page with custom gadgets for the different kind of aspects of the application. Today I will try to describe how to develop the feed items gadget for your dashboard. Obviously, it&amp;#8217;s an audit information that&amp;#8217;s caused by a user interaction with the system.&lt;/p&gt;
&lt;p&gt;For example a user posted a new post for the new category. That means you will see two different items on the dashboard (one for the &amp;#8216;new category&amp;#8217; action and the &amp;#8216;new post&amp;#8217;).&lt;/p&gt;
&lt;p&gt;User&amp;#8217;s post could have the author information, the posted at, the short description but the category could have only the name and link to the page with the full information of the category. As you can it&amp;#8217;s a different templates for each of feed item.&lt;/p&gt;
&lt;p&gt;For this kind of situations I prefer to create separate classes, let&amp;#8217;s call it like delegators. And post and category should know how to create delegator.&lt;/p&gt;
&lt;p&gt;I am not writing here tests because it&amp;#8217;s out of this article. I hope everyone could describe it at first using tests :)&lt;/p&gt;
&lt;p&gt;Imagine, we have the dashboard controller that&amp;#8217;s collecting the feed items from the db.&lt;/p&gt;
&lt;pre&gt;class DashboardController &amp;lt; ApplicationController
  def index
    @feed_items = FeedItem.all
  end
end
&lt;/pre&gt;
&lt;p&gt;FeedItem operates using a polymorphic connection between post or category.&lt;/p&gt;
&lt;pre&gt;class FeedItem &amp;lt; ActiveRecord::Base
  belongs_to :subject, :polymorphic =&amp;gt; true
  
  def delegator
    @delegator ||= Feeds::const_get("#{event_time.classify}Delegator").new(self.subject)
  end
end
&lt;/pre&gt;
&lt;p&gt;As you can see in the delegator method I am creating instance of the delegator class(that&amp;#8217;s representing the access layer to the original item of the feed item(post or category).&lt;/p&gt;
&lt;p&gt;OK, now we can create try to implement our dashboard page.&lt;/p&gt;
&lt;p&gt;# dashboard/index.html.haml&lt;/p&gt;
&lt;pre&gt;#feed-items
  = render :partial =&amp;gt; "item", :collection =&amp;gt; @feed_items
&lt;/pre&gt;
&lt;p&gt;#dashboard/_item.html.haml&lt;/p&gt;
&lt;pre&gt;= render :partial =&amp;gt; "dashboard/feeds/#{item.event_type}", :object =&amp;gt; item.delegator,  :as =&amp;gt; :item
&lt;/pre&gt;
&lt;p&gt;#dashboard/feeds/_post.html.haml&lt;/p&gt;
&lt;pre&gt;= item.author
= item.body
= item.title
&lt;/pre&gt;
&lt;p&gt;#dashboard/feeds/_category.html.haml&lt;/p&gt;
&lt;pre&gt;= link_to item.name, item.object
&lt;/pre&gt;
&lt;p&gt;As you can it&amp;#8217;s a quite simple,  we are rendering a partial by an event type information from the feed item. Every feed item will instantiate a delegator by an event type as well.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s describe the delegators for our post and category models.&lt;/p&gt;
&lt;pre&gt;require 'forwardable'

module Feeds ; end

class Feeds::PostDelegator
  extend Forwardable
  
  attr_reader :object
  
  def initialize(post)
    @object = post
  end

  def_delegators :@object, :author, :title, :body
end

class Feeds::CategoryDelegator
  extend Forwardable
  
  attr_reader :object
  
  def initialize(category)
    @object = category
  end

  def_delegators :@object, :name
end
&lt;/pre&gt;
&lt;p&gt;When and how to create feed items you could decide yourself but you will need to specify event_type and pass a subject as post or category.&lt;/p&gt;
&lt;p&gt;I prefer to use for autogeneration on callbacks &lt;a href="https://github.com/jamesgolick/timeline_fu" title="https://github.com/jamesgolick/timeline_fu"&gt;timeline_fu&lt;/a&gt; gem.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s it.&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/30859689790</link><guid>http://oivoodoo.tumblr.com/post/30859689790</guid><pubDate>Tue, 04 Sep 2012 11:05:00 +0300</pubDate><category>design</category><category>rails</category><category>ruby</category><category>patterns</category></item><item><title>My wife made a very nice photo.</title><description>&lt;p&gt;&lt;a href="http://500px.com/photo/12768611"&gt; &lt;img alt="Parisian lady by Anna Korsak (AnnaKorsak) on 500px.com" border="0" height="280" src="http://pcdn.500px.net/12768611/593040f347698130a44589e70d405122a8b853ad/3.jpg" width="280"/&gt;&lt;/a&gt; &lt;br/&gt;&lt;a href="http://500px.com/photo/12768611"&gt;Parisian lady&lt;/a&gt; by &lt;a href="http://500px.com/AnnaKorsak"&gt;Anna Korsak&lt;/a&gt;&lt;/p&gt;</description><link>http://oivoodoo.tumblr.com/post/30516829674</link><guid>http://oivoodoo.tumblr.com/post/30516829674</guid><pubDate>Thu, 30 Aug 2012 15:22:22 +0300</pubDate></item></channel></rss>
