March 2011
1 post
3 tags
Clear your logs automatically in development when...
# config/initializers/clear_logs.rb # This snippet simply clears your logs when they are too large. # Large logs mean looooong search in TextMate. You know it :) # Every time you run rails server or rails console it checks log sizes # and clears the logs for you if necessary. if Rails.env.development? MAX_LOG_SIZE = 2.megabytes logs = File.join(Rails.root, 'log', '*.log') if...
Mar 24th
3 notes
February 2011
1 post
2 tags
Interesting commits #1
Devise. [dd721f] Use secure compare as well. # constant-time comparison algorithm to prevent timing attacks def self.secure_compare(a, b) return false unless a.present? && b.present? return false unless a.bytesize == b.bytesize l = a.unpack "C#{a.bytesize}" res = 0 b.each_byte { |byte| res |= byte ^ l.shift } res == 0 end In short, a timing attack uses statistical analysis of...
Feb 21st
16 notes
October 2010
1 post
3 tags
git was compiled without libcurl support.
If you get error “git was compiled without libcurl support” when deploying it probably means that you’ve added a git submodule using http protocol. git submodule add http://github.com/[repo].git Open your .gitmodules file and replace http://github.com/[repo].git with git://github.com/[repo].git Next time you add a submodule use command like this: git submodule add...
Oct 2nd
August 2010
2 posts
3 tags
APIDock from command line
milandobrota: Ruby on Rails developers spend a lot of time in console. function api() { google-chrome "http://apidock.com/$1/search?query=$2" ;} added to your .bashrc file will allow you to search Ruby/Ruby on Rails/Rspec documentation on APIDock directly from the console. Usage: api [ruby|rails|rspec] method_name Example: api rails link_to A better way is to search by default in rails and...
Aug 30th
27 notes
2 tags
Radiant: No such file or directory - db/schema.rb
If you clone a repository with Radiant and while running rake db:bootstrap you get an error like this rake aborted! No such file or directory - /path-to-you-project/db/schema.rb Just create a db/ folder inside your application
Aug 12th
June 2010
1 post
3 tags
How to disable Adobe Reader Safari plugin
On Mac OSX, the default thing that happens when you click a PDF link in Safari is that it is displayed, quickly and efficiently, with the “Preview” tool. Unfortunately, if you download and install Adobe’s own “Reader” software, it changes Safari’s behaviour to use the crap slow-loading slow-displaying Adobe tool instead. Granted, it can do some other things...
Jun 14th
4 notes
April 2010
1 post
4 tags
How a little comma in ruby code can be a pain in...
Let assume that you transform a hash { :a => 1, :b => 2 } into local variables somewhere in your code and forget to remove a little comma after one line a = 1, b = 2 You still have a valid ruby code but it produces something unexpected! a # => [1,2] b # => 2 Why? Because of the comma ruby uses multiple assignment operator to assign values. Let write the code into one line to...
Apr 11th
3 notes
March 2010
30 posts
1 tag
Pure RSpec →
RT @kpumuk: Wow, so many new things about RSpec http://pure-rspec-scotruby.heroku.com/ P.S. Use arrows to navigate through the presentation
Mar 31st
1 note
2 tags
Let Hoptoad know about your failed rake tasks
If you use Hoptoad and run rake tasks from cron you won’t receive any error messages until you call Hoptoad notifier explicitly. The correct way to do that is to call: HoptoadNotifier.notify(e) task :taskname do begin # ... rescue Exception => e HoptoadNotifier.notify(e) raise # to show error in console end end
Mar 26th
1 note
3 tags
How to display .gitignore files in Textmate →
RT @kpumuk How to display .gitignore files in Textmate http://skitch.com/kpumuk/n5s9j/display-.gitignore-file-in-textmate #tmtricks
Mar 25th
1 note
3 tags
Rails, Redis, Resque and Cucumber
If you have a cucumber feature which depends on a resque worker make sure that the resque worker is running in “cucumber” environment transactions are turned off for the feature by @no-txn tag
Mar 24th
2 tags
Cucumber - undefined method `fork='
$ rake cucumber undefined method `fork=' for #<Cucumber::Rake::Task:0x3521fa4> If updating rspec, rspec-rails and cucumber gems doesn’t help. Probably you have an old cucumber gem installed Try to remove it [sudo] gem uninstall aslakhellesoy-cucumber
Mar 23rd
2 tags
WatchWatch
Outside-In Development with Cucumber at Mountain West RubyConf 2009 (Ben Mabey)
Mar 22nd
3 tags
Hoptoad and rescue_from →
I’m using rescue_from in my controller, but now I don’t see the exceptions in Hoptoad. Whazzup with that? Hoptoad uses alias_method_chain to hook into the rescue_action_in_public method. # Overrides the rescue_action method in ActionController::Base, # but does not inhibit any custom processing that is defined # with Rails 2's exception helpers. def...
Mar 22nd
1 note
4 tags
IRHG - Integrated Ruby Hacker's Guide →
The RHG is a book that explains how the ruby interpreter (the official C implementation of the Ruby language) works internally. It is partially translated from Japanese. Official RHG contains only 4 chapters. The IRHG Project has been significantly improved by the integration of the Ruby Forge Translation Documents. The two projects have been merged and have provided a improved format,...
Mar 17th
2 tags
YQL Geo Library (pure JavaScript) →
geolocation, reverse geocoding, content analysis UPD Other Open-Source Geocoders
Mar 17th
2 tags
Javascript charting libraries →
Open Source Bluff : Ruby’s Gruff ported to JS. Looks pretty straightforward. gRaphael : built on the awesome Raphael JS vector graphics library. Limited functionality, but that’ll change. Canvas3D : super cool, but not sure if it’s ready for a production site… jqPlot : charting for jQuery. I’m neither pro- nor con-jQuery, so I’m not sure that I’d pick a jQuery-centric...
Mar 13th
1 tag
Shadow Art →
Mar 13th
2 tags
Rails "Good Touch"/"Bad Touch" →
Did you know that useful little method ActiveRecord::Base#touch will fire all of your after_save callbacks? 
Mar 13th
2 tags
Credit Card Test Cases (Google Checkout XML API) →
All of the credit card numbers below are randomly generated numbers. In addition, none of the credit card numbers has the same last four digits as any other credit card number. This ensures that when you select a credit card to complete an order, you can easily associate a test credit card with a particular test
Mar 12th
1 note
2 tags
Replace a div.fieldWithErrors with a span in Rails →
Replace the stupid fieldWithErrors <div> with a <span>. YES, I know you can make DIVs inline by applying a “display: inline” style; the real problem is that you can’t simply use DIVs anywhere. Most significantly, you can’t use DIVs inside a P, which would be invalid HTML and in fact confuses some browsers more than you’d...
Mar 10th
1 note
1 tag
Google Analytics. Asynchronous Tracking. Multiple... →
Multiple Tracker Objects As mentioned above, the creation of tracker objects is implied. They are created the first time you use them. The examples above only show how to used the default tracker object. If you need more tracker objects, you must prepend a unique name to the method name of each command array you push for non-default trackers. For example, the following code sets the account and...
Mar 9th
3 tags
Ruby Best Practices Chapter #6 →
This chapter on what to do “When Things Go Wrong” turned out to be one of the most enjoyable ones to write. Having a strong ability to troubleshoot and debug code is a powerful skill to have, and I do my best to share all my secrets here. Go ahead and download Chapter 6 now
Mar 8th
3 tags
Иконки многих платёжных систем →
Очень мне хотелось собрать все иконки платёжных систем в одном стиле. Отрисовал все, которые смог найти […] Иконки очень не любят чёрный/тёмный фон. На любые светлые тона ложатся отлично. Возможность скачать архив с png.
Mar 8th
1 tag
Top 20 Nginx WebServer Best Security Practices →
Mar 6th
1 tag
The Git Community Book →
Mar 6th
2 tags
Absolute Center (Vertical & Horizontal) an Image →
Mar 6th
1 tag
WatchWatch
Daniel Kahneman reveals how our “experiencing selves” and our “remembering selves” perceive happiness differently.
Mar 6th
1 tag
Input fields as blanks within sentences →
A while ago, I came across a unique registration form built by Jeremy Keith for his audio sharing site, Huffduffer […] I was curious how it would perform against a traditional form. Would people be more inclined to complete it because of the narrative format? Or would the unfamiliar presentation format confuse people? […] I now have some early answers. […] Mad Libs style forms...
Mar 5th
2 tags
If exim has too long message queue and ls returns...
cd /var/spool/exim/ find ./msglog/ -name "*"|xargs /bin/rm find ./input/ -name "*"|xargs /bin/rm
Mar 4th
1 note
1 tag
Functional Programming Meditation →
Mar 3rd
1 note
3 tags
@augustl: Good arguments against Ruby 1.9 encoding →
For me, I absolutely hate all this encoding stuff in ruby 1.9, and I’ll try to explain why here. In ruby 1.8, if I write an expression like “s3 = s1 + s2”, where s1 and s2 are strings, this is easy because it’s a one-dimensional space. As long as s1 and s2 are strings, then I know that s3 will be a string, consisting of the bytes from s1 followed by the bytes from s2....
Mar 3rd
1 tag
Rails Indexes plugin →
Rails indexes is a small package of 2 rake tasks that scan your application models and displays a list of columns that probably should be indexed. Display a migration for adding/removing all necessary indexes based on associations: rake db:show_me_a_migration UPD: Another similar plugin ambitious_query_indexer Ambitious Query Indexer is a Rails plugin to identify database indexes that are...
Mar 2nd
1 tag
“Microsoft рекомендует не нажимать кнопку F1 когда вы пользуетесь браузером IE...”
– bondbig, Хабр
Mar 2nd
2 tags
Recursive Lambdas in Ruby
Recursive Lambdas in Ruby Recursive Lambdas in Ruby using Object#tap A Really Simple Recursive Combinator Fun With the Y Combinator in Ruby
Mar 2nd
2 tags
How jQuery is Killing Flash + jQuery Tutorials &... →
Mar 2nd
2 notes
2 tags
Writing Good Factories →
I really wanted to remember what Pratik had to say about writing good factories in his Rails Summit talk so I’m putting it up here as a reference. Should be able to loop 10.times { Factory(:user) } No associations in the base Factory Factory(:user) and Factory(:user_with_items) Should pass validations
Mar 1st
February 2010
22 posts
2 tags
O’Reilly Ruby Best Practices →
Because we value our craft, its important to know the difference between code that is agile, and code that is fragile. Chapter 1 - Driving Code Through Tests Chapter 2 - Designing Beautiful APIs Chapter 3 - Mastering the Dynamic Toolkit Chapter 4 - Text Processing and File Management Chapter 5 - Functional Programming Techniques Code examples from Ruby Best Practices
Feb 28th
1 note
1 tag
Functional Javascript →
Functional is a library for functional programming in JavaScript. It defines the standard higher-order functions such as map, reduce (aka foldl), and select (aka filter). It also defines functions such as curry, rcurry, and partial for partial function application; and compose, guard, and until for function-level programming. And all these functions accept strings, such as 'x -> x+1', 'x+1',...
Feb 28th
2 tags
Сколько секунд было в 2008 году?
С одной стороны 3600*24*366+1=31622401 т.к. 31 декабря была введена очередная секунда координации. Но подвох тут - в географии. Дополнительная секунда координации вводится в полночь по гринвичу (UTC time). Соответственно в восточном полушарии это был уже 2009 год, а в западном еще 2008. Итак, полный ответ в 2008 году - 31622401 секунд в западном полушарии, и 31622400 в восточном. По...
Feb 27th
2 tags
EventMachine Protocol Implementations →
Feb 25th
1 note
3 tags
Ruby Quicktips: Conditional Validation using... →
When you have a model that requires additional information, if a certain condition is met and you need to validate this attribute, this little trick can help. Say we have a user model that needs to validate the truck_serial attribute if the user has the role of driver: class User <...
Feb 25th
97 notes
1 tag
Hg Init: a Mercurial tutorial →
Пособие по Mercurial от Joel Spolsky
Feb 25th
3 tags
SyncEnumerator in ruby
SyncEnumerator creates an Enumerable object from multiple Enumerable objects and enumerates them synchronously Example require 'generator' s = SyncEnumerator.new([1,2,3], ['a', 'b', 'c']) # Yields [1, 'a'], [2, 'b'], and [3,'c'] s.each { |row| puts row.join(', ') } ruby-doc
Feb 24th
1 note
1 tag
Трекинг заказных писем по СНГ →
Россия, Украина, Казахстан, Узбекистан
Feb 23rd
1 tag
Python Tips, Tricks, and Hacks →
Переводы статьи на Хабре Python: советы, уловки, хаки (часть 1) Python Tips, Tricks, and Hacks (часть 2) Python Tips, Tricks, and Hacks (часть 3)
Feb 23rd
1 tag
Материалы продвинутого уровня по Питону →
Feb 15th
2 tags
Interesting refactoring #1
A code that lets you define a date by using syntax like Feb[28][2010]. require 'date' FancyDate = Hash.new do |hash, month| Hash.new do |hash, day| Hash.new do |hash, year| Date.new(year, month, day) end end end Date::ABBR_MONTHNAMES[1..-1].each_with_index do |name,index| Object.const_set(name, FancyDate[index+1]) end refactor my code
Feb 14th
2 notes
3 tags
Offline rss reader
Идея сервиса навеяна статьей на хабре Создать утилиту/сайт, которая(ый) бы на основе Google Reade’a генерил новостной pdf/fb2/txt  и синхронизировался с ридером/нетбуком/коммуникатором. В генерируем документе не должно ката, все что под катом должно вытягиваться автоматически и вставляться в документ в том или ином виде. Основа корректной синхронизации, генерируемые скрытые файлы на...
Feb 14th
2 tags
Linkdump #1
Срез от developers.org.ua Современная версия “RU.PROGRAMMING FAQ” на reddit, reddit.com: FAQ — Must-read programming books? 220+ comments (best comment: “Yes, you must.”) JavaScript на сервере, CommonJS/JSGI: The Emerging JavaScript Application Server Platform Учебник по JavaScript, Contents — Eloquent JavaScript Большая подборка тулов для веб-разработки под Firefox, IE, Opera, Codefusion Lab:...
Feb 12th