– we create awesome web applications

Boris recently purchased iA Writer to edit Markdown, which is our primary format used internally for readmes, proposal documents, contracts etc.

iA Writer looks very nice indeed. The typography is beautiful, and I especially like how it outdents headings and lists:

Ai Writer Formatting Example

Still, I can't help but find it impossible to do any serious text editing without the full Vim power by my side.

So I decided to try to at least approximate the experience of using iA Writer with Vim.

It turned out you can make the text look pretty decent by using a good font and bigger linespace. The "outdent" is out of the question of course (if anyone knows how to accomplish it I'd be very glad to hear that), but the rest is actually pretty good, with some extra formatting for lists, links etc.

I don't like the 'focus mode' in iA Writer, so I didn't try to replicate any of this, and not sure if its possible. Instead I use a different background color for the current line. Here is the result:

Vim Formatting Example

As you can see its not bad ;), and its Vim!

I've put the config into ~/.vim/writer.vim file that I can ':source ~/.vim/writer.vim' when I'm working with Markdown:

set background=light
set nonu
set laststatus=0
colorscheme default
hi FoldColumn guibg=white
set foldcolumn=12
set linespace=8
set guifont=Source\ Code\ Pro\ Light:h20
set tw=80
hi Normal guibg=gray95
hi NonText guifg=gray95
hi FoldColumn guibg=gray95
hi CursorLine guibg=gray90
hi Title gui=bold guifg=gray25
hi MarkdownHeadingDelimiter gui=bold guifg=gray25
hi htmlSpecialChar guifg=black
hi markdownBold gui=bold guifg=gray25
hi markdownItalic guifg=gray25 gui=underline
hi markdownUrl guifg=#2fb3a6
hi markdownAutomaticLink guifg=#2fb3a6
hi markdownLinkText guifg=#317849
hi markdownUrlTitle guifg=#317849
hi markdownBlockquote guifg=#317849 gui=bold
hi markdownId guifg=#2fb3a6
hi markdownIdDeclaration guifg=#317849 gui=bold
hi markdownListMarker guifg=#317849
highlight Cursor guibg=#15abdd

Stop using strftime. Seriously. At least if you are using Rails that is.

Rails, or rather, its I18N dependency, has a much better alternative I18n.l. The great thing about it is that you provide the name/kind of the format that you want separately of the format itself, so that you can, for example, change it completely for the whole application, or for a different locale.

The usage is quite simple. Instead of

Time.now.strftime('%Y-%m-%d %H:%M:%S')

You can do instead:

I18n.l Time.now, format: :myformat

with the myformat format defined in a locale file, say config/locale/time_formats.en.yml:

en:
  time:
    formats:
      myformat: '%Y-%m-%d %H:%M;%s'

The format string supports all the same format options as strftime, so conversion of your existing strftime code should be completely trivial.

It is important to pass a Symbol to the :format option of I18n.l, or it will try to interpret it as the format itself, and not its 'name' in the localization file.

Note: I18n.l has an alias I18n.localize, feel free to use it if you like to type.

When you are inside of a Rails view, you have another shortcut:

= l Time.now, format: :myformat

This is not all, yet...

It works for dates to:

I18n.l Date.today, format: :myformat

Event though it uses the same format name, it will use a different localisation key:

en:
  date:
    formats:
      myformat: '%Y-%m-%d'

Of course myformat is not such a great name for a format name ;). In a real application I would use something like compact, full, connfig, etc.

A couple of formats,:short, and :long are already provided, but I wouldn't rely on them and I suggest you define by yourself any time/date format that you intend to use inside of your application.

Lately, my prefered Postgres distribution of choice for OSX is Postgres.app.

Its very easy to download and install (just drag-n-drrop, like most other OSX Apps), no need to wait for it to compile, and it comes with a nice menubar icon for control.

In its default configuration it only listens on a port, but not on a unix socket. The problem is, Rails recipes with postgres create a config/database.yml file that assumes a socket presence.

Of example:

✗ rails new test1 -d postgresql
      create
      create  README.rdoc
      ...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
✗ cd test1
✗ rake db:create
could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

This problem was bothering me for a while as I tried to use rails_apps_composer to bootstrap new applications and it was failing on those database errors.

I didn't want to mess with Postgres.app configs, as I suspected they'd be overwriten on each version upgrade, so at first I tried to somehow trick it to stop and let me replace the config/database.yml file in time. The solution turned out to be much simpler though.

The Rails Postgres driver recognizes standard Postgres environment variables, one of which is PGHOST. When set to localhost Rails will go for the port instead of the Unix socket, even if there is no host: localhost setting in the YAML file.

✗ PGHOST=localhost rake db:create
✗ _

So just add export PGHOST=localhost to your shell start file, e.g. ~/.zshrc and you are set.

Im actually went further with it, and now I have shell aliases to reset postgres env config, configure it for localhost, or read current application Heroku configs and pre-set Postgres environment for a direct access to Heroku db, but that is a topic for another blog post.

I recently had an interesting bug that I want to share.

We had an age method in the User model, that was implemented like this:

def age
  return unless birthday
  now = Time.now.utc.to_date
  now.year - birthday.year - (birthday.to_date.change(year: now.year) > now ? 1 : 0)
end

And the following test for it:

describe :age do
  it 'should calculate age on exact date' do
    user = record(birthday: '2000-10-10')
    Timecop.freeze(Date.parse('2010-10-10')) do
      user.age.should == 10
    end
  end

  it 'should calculate age on next date' do
    user = record(birthday: '2000-10-10')
    Timecop.freeze(Date.parse('2010-10-11')) do
      user.age.should == 10
    end
  end

  it 'should calculate age on prev date' do
    user = record(birthday: '2000-10-10')
    Timecop.freeze(Date.parse('2010-10-9')) do
      user.age.should == 9
    end
  end
end

Suddenly, on 2013-07-14, I received a Circleci email that my last commit broke the specs. While investigating I found out that it failed in a place completely unrelated to my latest changes. It failed with an ArgumentError: invalid date. WTF?!

Investigating I found that we had a typo in one of our fixtures, that went like this:

triton:
  name: Triton
  birthday: <%= 501.days.ago %>
  ...

Notice the days instead of years that were ment to be used. And 501 days before 2013-07-14 is 2012-02-29, a leap year extra day, oops ;)

The age implementation tried to do .change(year: 1) to 2012-02-29 which produced an invalid date 2013-02-29. Apparently Date#change wasn't smart enough to take care of that:

> d = Date.parse('2012-02-29')
=> Wed, 29 Feb 2012
> d.change(year: 1)
ArgumentError: invalid date

I changed tirton's age to 501 years, and added the following test:

it 'should not fail when birthdate is on feb-29' do
  user = record(birthday: '2012-02-29')
  Timecop.freeze(Date.parse('2013-05-01')) do
    user.age.should == 1
  end
end

and fixed the implementation to be like so:

def age
  return unless birthday
  now = Time.now.utc.to_date
  diff = now.year - birthday.year
  diff - (diff.years.since(birthday) > now ? 1 : 0)
end

ActiveSupport's Date#since is smarter then #change and handles invalid dates properly:

> d = Date.parse('2012-02-29')
=> Wed, 29 Feb 2012
> 1.year.since(d)
=> Thu, 28 Feb 2013

Also note that there will be no problem with user fixtures on Feb-29 of the next leap year 2016-02-29. The x.years.ago that is used for birthdays will work just fine.

Astrails, the oldest, most renown, experienced and just plain awesomest Rails development studio in Tel Aviv is looking for an experienced, nay, fuck experienced, passionate web developer.

We work with Rails since 2005, done more than a hundred projects for startups from all over the world and work with the newest and most interesting technologies around. We constantly speak at conferences and literally wrote a book about Rails.

We are 7 industry veterans, have shitloads of knowledge accumulated and happy to share it. We routinely do code reviews, pair programming and automatic testing. We work with best tools money can buy and have unlimited educational budget for everyone.

Long story short, if you want to learn and advance as a developer, there is no better place to be, period.

We're looking for a web developer that loves the craft. If you can loudly argue about advantages of client vs server side rendering, NoSQL vs relational DB, Ruby vs Python, do apply, you'll find who to argue with here :)

If your idea of a job is punching a card and being done with it, go to Microsoft or something, it will not work out here. But if you're enthusiastic about technology, spend your time reading dev news, come talk to us, we speak the same language.

What you get:

  • You will work with cutting edge technologies and people that care about them
  • You'll get to know a lot of emerging startups, the world startup scene and never get bored
  • You get a Macbook Air, 27" kick ass Apple Cinema Display and an Apple keyboard and mouse to go with it
  • You will work in a cool office with a fridge full of good stuff and the best coffee we can find

What we want:

  • some 2-3 years of web development experience, if it was Ruby or Python - big fat plus
  • strong understanding of front end development, JS, jQuery, Backbone.js, HTML5, CSS3 should be something you can tell us about
  • we will strongly prefer someone who has github account, contributes to some open source project, did some pet projects at home, runs a blog about development, tweets about related stuff, you get the idea.

Sounds like your cup of beer? we@astrails.com

A while back Vitaly wrote a post about LaunchBar. One of the feedbacks we got was to try out Alfred.

After checking it out we switched.

Alfred is an app launcher and then some for OSX. In the version 2 released not that long ago they added brilliant feature - possibility to create your own workflows using nice and simple UI and share them with everyone.

The one workflow I find particularly useful is the Alfred Github Workflow.

The June 2013 DevCon event took place on June 20. We sponsored the event, as we always do. Also Vitaly gave an overview talk on RubyMotion.

Check out the talk

Lean Startup Machine is coming to Tel Aviv this summer. Signup for a chance to win a free ticket.

Lean Startup is the hot new "thing". Its a practice that lets entrepreneurs build successfull startups in the most efficient way.

New version - 0.3.1 - of astrails-safe released.

New stuff:

  • Internally switched from jeweler to bundler. Should not matter for users, but be sure to report any strange behaviour.
  • Plain FTP support, before that we only supported SFTP - contributed by seroy
  • mongodump support - contributed by Matt Berther

Thanks guys for your contributions.

The are multiple ways of configuring your Rails application for different environments (e.g. staging, production, etc). One of the popular ones is through environment variables. For example Heroku uses this type of configuration extensively.

We extracted a small gem that will allow you to manage it effectively.

The Rails 4 Way on Leanpub.com

We are proud to announce that our own Vitaly Kushner co-authored the new edition of 'The Rails 4 Way' together with Rails legend Obie Fernandes of Hashrocket fame.

'The Rails 4 Way' is the latest edition of the most comprehensive, authoritative guide to delivering production-quality code with Rails 4.

Pow is great. The single thing that bothered me was problems with using debugger while pow'ing away.

Did you ever put a debugger into your controller, connected with rdebug, hit refresh but it didn't stop?

The problem is most probably with POW_WORKERS setting. You see, by default, pow will start 2 ruby processes per application.

About half a year ago Vitaly posted a post about how simple it is today to use ruby patches bundled with rvm installation to dramatically reduce big rails app loading times and make your dev environment a much happier place.

Since then Ruby advanced with new patchlevels and there are new patches to use, so let's go over this once again.

Back in February we sponsored a great technical event - Reversim Summit 2013

Now the organizers uploaded videos from all talks to youtube, so go check out a lots of quality technical content

My personal favorite - How To Fuckup, by Yosi Taguri

I was frustrated by ⌘Q and ⌘W proximity for a long time. Long, long time. Seriously, long time.

It hits me the most with browsers since I usually open and close quite a lot of tabs during the day. And I tend to do it from keyboard, so sometimes I just hit ⌘Q when I only intended ⌘W.

It just happened again.

But this time I suddenly realized that I can easily remap it. I was using this OSX feature for other things, like remapping useless since the typewriter days Caps Lock key, but somehow missed that I can fix this annoying problem too.

If not universally then at least in Chrome (or any other application if needed).

This is really easy:

Rails Conference 2012, first time in Israel, was a great deal of fun. Lot's of presenters both local and from all over the world, well, more like from all over the world of Rails. There were talks from Github, Heroku, Engine Yard, Gogobot, Get Taxi and lots and lots of others. Solid organization from Raphael Fogel People and Computers guys. Hordes of interesting people to talk to, nice and abundant food and coffee, lots of great content from the speakers and to sign off the day Github guys invited everyone to an open bar drinkup event.

We gave 2 talks, Vitaly's "Performance - When, What and How" and Boris' "Rails Missing Features". Check out slides and videos of those talks.

nanoScroller.js - jQuery plugin to implement OSX Lion-styled scrollbars for your website.

strong_parameters gem allows you to "test drive" the new way that Rails 4 is going to treat parameters security. attr_accessible and friends are being deprecated.

celluloid.io interesting approach to multithreaded programming for Ruby.

Letters - new take on debugging logging library for Ruby.

showcase of 40 pricing tables and signup pages can help with with some inspiration for your pricing page.

lenticular.js - Tilt controlled images.

Repo.js - light-weight jQuery Plugin that lets you easily embed a Github repo onto your site.

FullCalendar is a jQuery plugin that provides a full-sized, drag & drop calendar with events etc.

tl;dr Legal - easy summaries of open source licenses.

CCMenu - OS X menu bar application to pull build status of your projects. Support many different CI backends.

UPDATE [30 Apr 2013]: The new, updated and faster version of this blog post covering Ruby 1.9.3 patchelevel 392 and railsexpress patch set.

I knew that there are various Ruby patches available but I've never tried them as I didn't want to waste time for something that I thought I don't really need.

Then I found out that rvm comes bundled with patches ready to be applied, so I'm just a simple command line away from having a patched Ruby. Don't know how I missed that before.

Finally, there is a Rails Conference here in Israel. Long overdue. We're sponsoring it and giving one keynote and one lecture.

I recently switched to ruby 1.9.3 as my deafult ruby verison, and suddenly some of my scripts started to fail in some funny ways.

One of the latest ones was the script that was supposed to change 'updated' timestamp in a YAML formatted file. Instead of the current date it started to spit out binary strings.

The problem is quite complext but the fix is simple...

I did an overview presentation about the current state of real time web and server-push technologies at the Israely DevCon 2012 conference.

Below is the transcript of the talk (actually more like a talk plan ;)

There is also a [pdf version for download][pdf].

It is in English as this is the way I usually write down my presentations, although the actual talk was delivered in Hebrew.

Check out the video of the talk on YouTube or embedded here. And if you more of a reader then viewer you can check out the slides with sort of transcript below.

Given that module Foo is defined elsewhere what is the difference between this snippet:

class Foo::Bar
  ...
end

and this:

module Foo
  class Bar
    ...
  end
end

Answer inside ;)

LaunchBar is one of the tools I can't live without.

Basically, it's an application launcher, but besides actually launching an application it has lots and lots of features that help me complete tasks on my laptop while staying in the flow.

Ever since I installed it on my MacBook my workflow changed quite dramatically to the better.

My Vim-fu improved a lot in the last couple of years.

Part of the reason is that working on [dotvim][dotvim] forced me to dive deeper into it, but thats not the whole story.

I think a much bigger reason is that I decided to systematically work on improving it.

One of the tricks I use is to have a list of Vim tricks and shortcuts that I'm learning right now on my OSX dashboard.

It's alive. Again ;)

This blog was dead for a while. It was running on an old Mephisto system and it's admin interface just broke one day, throwing some cryptic exception.

It was probably not that hard to fix, but every time I thought to write a blog post it was like "oh, I have to dig into this antient codebase to figure out how to fix it before I actually get to write anything. I'll pass..."

So days become weeks, and weeks become months, pretty fast its a year that passed by with no blog posts whatsoever.

Meanwhile I was scribing my thoughts on future blogposts in markdown files on my harddrive.

Not long ago we finally decided to do something about it.

I had a lot of things to do last Thursday, Feb-17. I met a friend from abroad 3am at Ben Gurion Airport and spent several hours talking before we went to sleep, signed a contract for developing killer web app at 1:30am, and finally gave a presentation at The Junction at 4:30pm.

Vitaly gave an interesting presentation about MongoDB at Database 2011 Conference.

MongoDB. NoSQL for SQL addicts.

Slides are here.

We presented on IGTCloud Ruby On Rails Day today.

Agenda was a bit different this time, not only technical presentations but also a few words about modern approach of building web applications.

Find the slides below.

I was working on tests for blender when I came upon a need to mock or stub a back-tick operator e.g.:

`shell command`

Apparently this is just a shortcut for calling Kernel method :`.

The OPEN 2010 conference was very well organized and had many interesting talks.

We are giving 4 out of 20 sessions at Open 2010, an Israeli open source conference.

I just recently reinstalled my MacBook Pro, this time with Snow Leopard.

So I'm again going through various installation problems I already forgot about from few years back when I installed Leopard.

Anyway, just had to hunt down a problem with mysql gem installation on Snow Leopard.

A few days ago I gave a presentation about Ruby for Sayeret Lambda discussion group.

The title was "Ruby is an acceptable lisp" but the message is better served by "Ruby is Better then Lisp ... sometimes" :)

http://markupslicer.com

Supports ERB and HAML for now, vote on site for more formats.

Beautifully crafted, totally free and it's kinda fun.

About a week ago about 15 people were gathered in People and Computers offices thanks to Raphael Fogel.

There is a new (0.2.7) version of Astrails-Safe.

I've just read "Do You Believe In Magic?" and the following quote resonated particularly well:

"It's not magic. There is no magic involved. It's just, if you never learnt Lisp, then you never learned to program, and Ruby's power is exposing a deficiency in your skills."

The opportunity

120 happy dreamers cooking for 54 hours of pure startup joy, well-fed and ready to work. Of course, I’m talking here about Startup Weekend Israel.

The challenge

Come up with an idea that can be implemented in a couple of days, yet is so cool, so innovative, and so useful that I could attract the best of the best.

Read the rest at blogtheblog.jobthejob.com

P.S Now we have some pictures too there, you should check it out

If you follow us on twitter (@astrails if you wondering) you already know that we are at the Startup Weekend Israel right now.

Which is going amazing by the way, thanks for asking, lots and lots of nice people, very creative and energetic atmosphere, food and beer.

Turns out our idea attracted a great team of developers, designers and business developers.

We just started a project for a client that involves Cassandra.

If you've been living under a rock and don't know what Cassandra is let me tell you :)

Cassandra is a "second-generation distributed database" that was built for web scale.

Its is one of the many distributed nosql databases that appear everywhere lately like mushrooms after a heavy rain :).

What sets Cassandra apart is that it comes from a recognizable entity - Facebook.

But I digress.

This is not meant to be a Cassandra introduction, there are enough of those on the net. I Just created a new nosql section on this blog where I'm going to post various tidbits of information about cassandra (and probably others) as I learn them while working on this new project.

Here is the first one: Cassandra gem is just an installer

Yeah, I know, MVC is the "Only True Way™". But sometimes, just sometimes, you need your link_to or html helpers working in the model.

For example, sometimes the cleanest way to implement something is to have to_html in the model (widgets anyone?).

Doing this will most probably require generating some urls, and you need a controller for that. Usually I solved this by passing controller to the to_html function, but it always felt wrong.

Just released a new 0.2.5 version of astrails-safe.

astrails-safe is our very simple to use backup script for mysql, postgres, filesystem, and subversion. It can store your backups locally, on Amazon s3 or on a remote SFTP server. Optional GnuPG enctyption completes the picture.

Since Github stopped to build gems we are moving to the gemcutter.

Damn, I just found this unpublished article in the blog admin...

How come it evaded my attention for 3 months??!!

Anyway, releasing it now thought this is all quite old news, going to announce 0.2.4 in a moment :)

I just did something pretty stupid. I edited /etc/sudoers file directly from within my non-root user account.

This is going to be the first part of a blog post series about javascript widgets.

First type I'm going to cover is Popup Widget. Sometimes it's called Popin Widget because there is no actually new window that pops up, instead the content is shown IN-side a current page. The idea is quite simple: you provide some html/js snippet to other sites. They put it into relevant place, and you have some functionality of your site running there.

Clicktale is a service that allows you to record and later playback behavior of your users while they are using your site. And Rails is Rails, you know.

And those two are getting along just fine, until the user logs in. After that clicktale service is cut out of the html pages this user gets and can't record the session. But it just started to get interesting...

I just pushed new version 0.1.9 of astrails-safe to github.

The main difference is a fix to an embarrassing bug in the S3 backup rotation code.

Thanks to Thuvarakan Tharmalingam for reporting.

Again, the reason it escaped was the fact that we don't yet have full test coverage.

We are getting there though....

It looks like our astrails-safe gem is quite popular :). People started to contribute new features:

Mephisto commenting system is... how do i put it ... outdated :)

And we wanted something more engaging for our blog. Looking around the web we found that Disqus was used all over the place, so we decided to integrate it into our blog instead of the native comments system.

Wouldn't it be cool if you could just require "http://my-host/my-lib.rb" in ruby?

Now You Can! Using our "http_require" gem! :-)

Everyone needs a backup, right? Unfortunately almost no one does though. Why?!

We needed something for ourselves and our customers. Something simple, free, configure-and-forget. Most of the time there is no need for something fancy, a simple tar + mysqldump can do the job for many small/medium sites.

RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings.

Let's run it with Ruby on Leopard.

sudo port install rrdtool

Default ports installation comes without ruby bindings.

Thanks a lot to Amit Hurvitz for providing a file of Virtual Disk Image (VDI) of VirtualBox, containing an up and running JRuby on Rails on Glassfish with Mysql. Image also contains some examples (actually solutions to the code camp exercises), all running on top of an OpenSolaris guest OS (can be run on many host systems).

Grab the image ~1.5GB archive.

Grab the exercises ~9.7MB archive.

We recently moved our DNS to dnsmadeeasy.com from godaddy.com name servers.

After the transfer some internal CNAME records had a problem. So after fixing the problem and checking in the terminal that the changes propagated to the DNS server (host xxx.astrails.com) I tried to type the address in the browser, but it kept giving me the "can't find host" error.

We participated in JRuby on Rails with GlassFish Code Camp hosted by Sun Microsystems Inc. I was speaking about the framework in general trying to infect Java developers with Ruby On Rails. Slides are available.

Amit Hurvitz gave exciting presentation about GlassFish and short introduction into DTrace. Find out more details about the Code Camp.

I was the last person in our company working with ERB to render templates. While all the rest switched to HAML. At the beginning it was quite hard for me to read HAML comparing to ERB. HAML looked for me like some completely alien thing with weird percent marks all over the place and the significant whitespace never did it for me. On the other hand ERB felt like warm home after years we spent together.

Until I did the switch.

2008 was the year when we finally switched to full time consulting. And like all consulters we faced the problem of correct pricing. There are two well-known ways to charge a customer: per-hour rate and fixed bid quote, and several combinations of them.

Recently we looked for video transcoding/hosting solution to use in one of our client's projects.

The best thing we've found is Panda. It runs on Amazon stack of services including ec2, s3, and simpledb.

Using amazon has many advantages. no contracts, pay as you go, easy and fast scaling in case your site explodes :)

Unfortunately the image that is refered in the Getting Started (ami-05d7336c) is not safe for production - it has openssh version with a serious security bug, but don't worry, we will explain how to fix it.

This blog-post is mostly targeted at non-Rails developers. Rails devs should know all this by heart :) Many times we need to explain to our customers what is 'proper deployment' and why their current one sucks :) Now we'll be able to just point them to this post...

Blog moved to Mephisto. So we have comments now.

In the process of installing Mephisto I've got a problem with image_science gem.

It installed OK but when trying to require it the was a problem with RubyInline compilation:

We really like Debian and we usually use the current "stable" distribution for our production servers.

It all works great with one little problem: if you need very current soft it is probably not in the 'stable' yet.

The current Debian stable ("etch") includes rubygems 0.9.0-5 which is way too old.

We needed to upgrade to at least 1.2.

We just incorporated our own Ltd. company.

It was coming for a while now but we finally got to it when we started to hire people :)

Once again I’ve hit a problem of installing gems on a machine with very little memory.

On one of our projects we needed to do some caching for an action with an expensive db query. Fragment caching took care of the rendering but we needed a way to skip the db if we have a cache hit. And checking for an existence of the fragment file in the controller just didn’t seem right.