Ruby On Rails

UnQLite - Embeddable NoSQL database engine. LicenseFinder - Help your lawyers figure out how your gems are licensed. This stuff is, by the way, an utter mess in the ruby community. "Confident Ruby" now in Beta! - New ebook from Avdi Gr...
UnQLite - Embeddable NoSQL database engine. LicenseFinder - Help your lawyers figure out how your gems are licensed. This stuff is, by the way, an utter mess in the ruby community. "Confident Ruby" now in Beta! - New ebook from Avdi Grimm. ish. - Responsive HTML design tool that throws random viewports at your code so you can see how it copes (or doesn't).
33 minutes ago
This article is heavily styled and is best viewed at PeepCode! Written by Geoffrey Grosenbach · Design by Paula Lavalle The only thing more difficult than learning something new is tea...
This article is heavily styled and is best viewed at PeepCode! Written by Geoffrey Grosenbach · Design by Paula Lavalle The only thing more difficult than learning something new is teaching it. At PeepCode, we put a lot of time into creating great explanations of difficult concepts. We won’t publish a video until we’re confident that it explains the topic better than anything else out there. And feedback from people who have viewed our videos on Ember.js, Ruby on Rails, JavaScript and other topics show that we’re doing just that. Summary Here’s some of what we’ve learned about explaining technical topics to developers. Teach one thing at a time Tell a story Use appropriate terminology Know your audience The Goal The goal of any tutorial is to get back into the mind of someone who doesn’t understand the topic. If an explanation only makes sense to people who already know what you know, then it’s not a very good explanation. But that insight alone doesn’t tell you how to explain well. Instead, it might help to think about how developers go wrong when trying to explain a concept. They try to teach too many things at once. This overwhelms the student. They are disorganized. Teaching things out of order makes the student do too much work to sort it out in their mind. They use the wrong words. Throwing an unknown term into an explanation can intimidate a student or even cause fear. They don’t know who they are speaking to. I don’t know of any single explanation that works for all people at all levels of learning. When developers are unclear about their audience, they risk delivering ideas that will confuse everyone listening. Here are four solutions to these problems. Teach one thing at a time This is the biggest problem I see, and it’s the first strategy you should use to improve your explanations. Decide what you’re trying to teach, and only talk about that. You’ll have to intentionally block out the 10 other things you want to communicate. If a concept is important enough, dedicate a separate chapter, slide, or day to it. Then focus on the one thing you’re trying to teach right now. This is extremely difficult for developers. We love details. We love to debate some tiny nuance of a program before it even runs. We like discovering edge cases that no one else has thought about. And we’re afraid. We’re afraid that when we conclude a presentation, one person in the audience will be able to say “Hah! You forgot to mention X!” Or “You were wrong on this one point!” To teach well, you need to get over these fears. You need to allow yourself to say something that’s 99% true, even if you know someone will correct you for the 1%. Because mentioning that 1% in your explanation will probably hinder you from sticking to teaching just one thing at a time. To teach well, you need to abandon your insurance policy of saying “We’ll cover this other thing later.” That disclaimer is only there to comfort you, not to help the student. Teach the one thing you’re trying to teach now, then teach one other thing later when you’ve finished teaching the one thing you’re teaching now. In fact, leaving out an important concept or saying something that’s only 99% true can be used to your advantage. It can help you tell a story. Tell a story with problems and solutions Stories are great because they hold our attention. The story could go anywhere, but we also have a hunch about what will happen next. That anticipation keeps our interest: “Will it turn out like I think it will, or will something unexpected happen?” Malcolm Gladwell is a great
about 12 hours ago
When you develop a program in a group of programmers, it is really important to have some standards. Especially helpful are standards of naming things and formatting code. If all team members format the code in the same way and use consi...
When you develop a program in a group of programmers, it is really important to have some standards. Especially helpful are standards of naming things and formatting code. If all team members format the code in the same way and use consistent names, then it is much easier to read the code. This also means that the team works faster. The same rules apply when you develop software in Python. For Python there is a document which describes some of the most desirable style features for Python code Style Guide for Python Code. However there are some problems with that, as even the standard Python library has some libraries which are not consistent. This shouldn’t be an excuse for your team to be inconsistent as well. Ensuring that the code is nice and readable is worth working for a moment on that. In Python there are two tools which I use for writing code in Python – Python style guide checker and Python code static checker. pep8 Program pep8 is a simple tool checking Python code against some of the style conventions in PEP 8 document. Installation You can install it within your virtual environment with simple: pip install pep8 Usage Let’s test the pep8 command on such an ugly Python file named test.py: "this is a very long comment line this is a very long comment line this is a very long comment line" def sth ( a ): return "x"+a def sth1 ( a,b,c): a+b+c The basic usage of the program is: pep8 test.py The above command prints: test.py:1:80: E501 line too long (100 > 79 characters) test.py:2:1: E302 expected 2 blank lines, found 0 test.py:2:11: E201 whitespace after '(' test.py:2:14: E202 whitespace before ')' test.py:2:8: E211 whitespace before '(' test.py:3:16: E225 missing whitespace around operator test.py:4:1: E302 expected 2 blank lines, found 0 test.py:4:11: E201 whitespace after '(' test.py:4:13: E231 missing whitespace after ',' test.py:4:15: E231 missing whitespace after ',' test.py:4:9: E211 whitespace before '(' test.py:5:6: E225 missing whitespace around operator test.py:5:8: E225 missing whitespace around operator test.py:6:1: W391 blank line at end of file Configuration Pep8 is highly configurable. The most important options allow to choose which errors should be ignored. For this there is an argument --ignore. There is also one thing in PEP8 document, which I don’t agree with. This document states that the length of the line shouldn’t be bigger than 80 characters. Usually terminals and editors I use are much wider and having 100 characters doesn’t make your program unreadable. You can set the allowed length of your line with --max-line-length. So if I want to ignore the errors about empty lines at the end of file and set maximum line length to 100, then the whole customized command is: pep8 --ignore=W391 --max-line-length=100 test.py The output is different now: test.py:2:1: E302 expected 2 blank lines, found 0 test.py:2:11: E201 whitespace after '(' test.py:2:14: E202 whitespace before ')' test.py:2:8: E211 whitespace before '(' test.py:3:16: E225 missing whitespace around operator test.py:4:1: E302 expected 2 blank lines, found 0 test.py:4:11: E201 whitespace after '(' test.py:4:13: E231 missing whitespace after ',' test.py:4:15: E231 missing whitespace after ',' test.py:4:9: E211 whitespace before '(' test.py:5:6: E225 missing whitespace around operator test.py:5:8: E225 missing whitespace around operator Config file The same effect can be achieved using a config file. PEP8 searches for this file at the project level, the file must be named .pep8 or setup.cfg. If such a file is not found, then it looks for a file ~/.config/pep8. Only the first file is taken into consideration. After finding a file, it looks for a pep8 section in, if there is no such section, then no custom settings are used. To have the same settings as in the above example, you can create a file .pep8 in the project directory with the following content: [pep8] ignore = W391 max-line-length = 100 T
about 21 hours ago
Searchlight - Searching gem that minimizes magic. Comes with ActiveRecord integration module. Open Source Report Card - Analyze a GitHub user's activity for interesting patterns. Fargo - Online outliner that stores its files in your Dr...
Searchlight - Searching gem that minimizes magic. Comes with ActiveRecord integration module. Open Source Report Card - Analyze a GitHub user's activity for interesting patterns. Fargo - Online outliner that stores its files in your Dropbox.
1 day ago
Easier rules for class structure, ProMotion for RubyMotion, JSON APIs in Rails 4, concurrency with Futuroscope, ActiveRecord help via Searchlight, and internationalization with haml-i18n-extractor. Listen to this episode on Ruby5 This...
Easier rules for class structure, ProMotion for RubyMotion, JSON APIs in Rails 4, concurrency with Futuroscope, ActiveRecord help via Searchlight, and internationalization with haml-i18n-extractor. Listen to this episode on Ruby5 This episode is sponsored by Heroku Build better apps, faster. Spend your time building applications, not managing the servers that run them. Heroku is a Platform as a Service that adds simplicity to deploying, scaling and managing the infrastructure that runs applications. It removes barriers that slow the software development process, freeing you to put 100 percent of your energy into creating quality software. Sandi Metz's Rules for Developers Sandi Metz, author of Practical Object-Oriented Design in Ruby, has put together some simple rules of thumb regarding class and method composition. Caleb Thompson wrote up a blog article about them over at the Thoughtbot blog. ProMotion To make it even easier to build iOS apps in Ruby, Jamon Holmgren created ProMotion, a RubyMotion framework for abstracting the screen and navigation handling in a Ruby-like way. It makes it easy to work with things like UINavigationControllers, UITabBarControllers, and UIViewControllers. JSON APIs with Rails 4 Emil Soman wrote up a blog article on how to write a tested, documented and versioned JSON API Using Rails 4. Futuroscope Josep Jaume Rey of Codegram wrote in to let us know about Futuroscope. It's their implementation of "futures", which let you easily handle processes in the background. You just wrap your long-running code in a block, and retrieve the result when you need it. Searchlight The Searchlight gem, which simplifies complex method chains. It works with ActiveRecord and ActionView out of the box. It also lets you set defaults and offers other shortcuts for interacting with Rails forms. haml-i18n-extractor This week Shai Rosenfeld released the haml-i18n-extractor gem, which is a command line tool that looks for certain strings in your haml templates that are likely to be internationalized. It replaces those strings with calls to the translate ("t") method, then it creates the proper yaml locale files for you.
1 day ago
Here's another shoulda backport I added recently. If you're still stuck using a legacy Rails system, this backport will let you use "in_array" in the "ensures_inclusion_of" Matcher. Save it into something like: config/initializers/sho...
Here's another shoulda backport I added recently. If you're still stuck using a legacy Rails system, this backport will let you use "in_array" in the "ensures_inclusion_of" Matcher. Save it into something like: config/initializers/shoulda_monkeypatches.rb, then use it like this: should ensure_inclusion_of(:widget_status).in_array(Widget::VALID_STATUSES).allow_blank.with_message(:is_invalid).use_integer_test_value # backport the "in_array" method for the ensure_inclusion_of matcher # While we're at it, add allow_blank and allow_nil too module Shoulda # :nodoc: module ActiveRecord # :nodoc: module Matchers class EnsureInclusionOfMatcher ARBITRARY_OUTSIDE_STRING = 'shouldamatchersteststring' ARBITRARY_OUTSIDE_INT = -999999999 # to initialize the options def initialize(attribute) super(attribute) @options = {} end # add the method we want to allow us to pass in arrays instead of # just ranges def in_array(array) @array = array self end # might as well also add the allow_blank and allow_nil methods too def allow_blank(allow_blank = true) @options[:allow_blank] = allow_blank self end def allow_nil(allow_nil = true) @options[:allow_nil] = allow_nil self end # This is a method of my own addition to point out that the # test-value must be an Int, not a String... because a string can # evaluate to 0 which is a valid Int... which will make the test # pass where it shouldn't :P def use_integer_test_value(only_integer = true) @options[:use_integer_test_value] = only_integer self end # override description so it doesn't just try to inspect the range def description "ensure inclusion of #{@attribute} in #{inspect_message}" end # override the matches method to allow arrays as well as ranges def matches?(subject) super(subject) if @range @low_message ||= :inclusion @high_message ||= :inclusion disallows_lower_value && allows_minimum_value && disallows_higher_value && allows_maximum_value elsif @array if allows_all_values_in_array? && allows_blank_value? && allows_nil_value? && disallows_value_outside_of_array? true else @failure_message_for_should = "#{@array} doesn't match array in validation" false end end end private # provide the message-inspect method to use either array or range def inspect_message @range.nil? ? @array.inspect : @range.inspect end # array helper methods def allows_all_values_in_array? @array.all? do |value| allows_value_of(value, @low_message) end end def disallows_value_outside_of_array? disallows_value_of(value_outside_of_array) end def value_outside_of_array test_val = @options[:use_integer_test_value] ? ARBITRARY_OUTSIDE_INT : ARBITRARY_OUTSIDE_STRING if @array.include?(test_val) raise CouldNotDetermineValueOutsideOfArray else test_val end end # blank and nil helper methods def allows_blank_value? if @options.key?(:allow_blank) blank_values = ['', ' ', "\n", "\r", "\t", "\f"] @options[:allow_blank] == blank_values.all? { |value|
1 day ago
Week of May 13 - May 19, 2013 The master code is, as one would expect, in upheaval again. This week featured a big rewrite of callback internals, though I haven't sussed out whether it changes any features in that area. 3073c531 adds...
Week of May 13 - May 19, 2013 The master code is, as one would expect, in upheaval again. This week featured a big rewrite of callback internals, though I haven't sussed out whether it changes any features in that area. 3073c531 adds Minitest 5 compatibility to Rails 4.
2 days ago
migrating from iPhoto to Dropbox, from feature rich to future proof - I'm starting to think it's time to get off of OS/X. Walled gardens do not attract me. New gem released: Futuroscope! - Run selected operations on background threads w...
migrating from iPhoto to Dropbox, from feature rich to future proof - I'm starting to think it's time to get off of OS/X. Walled gardens do not attract me. New gem released: Futuroscope! - Run selected operations on background threads with very little change to your code.
2 days ago
I was asked to develop a prototype app for one of our clients lately. The basis for this app was an old Rails app:Rails 3.2.8 RailsAdmin MySQL rbenv + ruby-build I wanted to upgrade the stack to work with latest toys all cool kids are so...
I was asked to develop a prototype app for one of our clients lately. The basis for this app was an old Rails app:Rails 3.2.8 RailsAdmin MySQL rbenv + ruby-build I wanted to upgrade the stack to work with latest toys all cool kids are so thrilled about. I also didn’t have Rails console facility at my disposal since the Ruby version installed on the development machine hadn’t been compiled against libreadline.Not having root or sudo access on the machine I embarked on a sligthly hacky journey to make myself a better working environment.Ruby 2.0After reading Mike Farmer’s blog post about Ruby 2.0 and tons of other material about it on the Internet, I wanted to get a feeling of how faster & greater the new Ruby is. It’s always great also to stay up-to-date with latest technologies. It’s great for me as a developer, and more importantly - it’s great for our clients.Importance of libreadline in development with RubyTo be productive developing any Rails-based application, we have to have Rails-console available at any moment. It serves a multitude of purposes. It’s also a great scratch-pad when developing methods.While you don’t need your Ruby to support libreadline for basic uses of irb, you need it when using with Rails.Installing Ruby 2.0.0 with rbenv (ruby-build)If you’ve installed ruby-build some time ago, chances are that you need to update it in order to be able to install latest build of Ruby 2.0.0To do it:cd ~/.rbenv/plugins/ruby-build git pull And you should be able now to have available latest Ruby build to install:rbenv install 2.0.0-p195 If you want to install Ruby compiled with support for libreadline, you have to have it installed in your system before compiling the build with rbenv install.If you have access to root or sudo on your system, the easiest way is to e. g:on Debian-related Linuxes:apt-get install libreadline-dev or on Fedora:yum install readline-devel Installing libreadline from sourcesIn my case - I had to download sources and compile them myself. Luckily the system had all needed essential packages installed for building it.wget "ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz" tar xvf readline-6.2.tar.gz cd readline-6.2 ./configure --prefix=/home/kamil/libs make make install I had to specify –prefix option pointing at the path where I wanted the libreadline library to be installed after compilation.Then, I was able to actually build Ruby with readline support “on”:CONFIGURE_OPTS="--with-readline-dir=/home/kamil/libs" rbenv install 2.0.0-p195 Notice: I was making myself a development environment and compiling from sources was my last resort. It is not a good practice for production environments. Last thing I needed to do was to get rb-readline working with the project I was working on.It turnes out that latest rb-readline doesn’t play well with latest Ruby. Also, when using Ruby 2.0.0 one have to explicitely specify it in the Gemfile, or else it won’t be loaded for the console.Gemfile:gem 'rb-readline', '~> 0.4.2' This still isn’t perfectWhile this setup works, it won’t let you use arrow keys. The irb process crashes quickly after even first try to navigate through the text.For some reason, after upgrading Ruby, the RailsAdmin stylesheets stopped working. I noticed that they are being served with comments which should be replaced by other stylesheets like:/* ... *= require_self *= require_tree . */ I had to update Rails version in the Gemfile to have my admin back:Gemfile:gem 'rails', '3.2.13' Console:bundle Last thing I wanted to do, was to try if I could upgrade Rails even further and have a working Rails4 setup. This was impossible unfortunately since RailsAdmin isn’t yet compatible with it as stated here.I conclude that latest Ruby is quite usable right now. If you don't mind the quirks with the readline - you're pretty safe to upgrade. This assumes though that your app doesn't use any incompatibl
5 days ago
I spent this week with the team of engineers who made Riak on Engine Yard Cloud possible, attending RICON East: all Distributed Systems, all the time. Later in the week we took advantage of being in New York City to visit local customers...
I spent this week with the team of engineers who made Riak on Engine Yard Cloud possible, attending RICON East: all Distributed Systems, all the time. Later in the week we took advantage of being in New York City to visit local customers and discuss the various features we’re working on and field any technical, product, and data questions. Both our engineering and product teams love incorporating customer feedback into our direction. Speaking of which -- if you’re in San Francisco, I’m organizing customer UX feedback sessions! Hit me up :) --Tasha Drew, Product Manager Engineering Updates PHP is now GA on Engine Yard Cloud! Per Product Manager Noah Slater: “PHP has been an important part of Engine Yard’s growing family since the acquisition of Orchestra in 2011. And now, PHP on Engine Yard Cloud represents the culmination of our efforts to deliver the industry’s best Platform as a Service for PHP developers. The result of this work is a unified service offering for PHP, Node.js, and Ruby applications.” Read all about the GA launch announced by Davey Shafik at php[tek] in Chicago this week! Data Data Data Riak and Clusters are live! See our blogpost for more info - https://blog.engineyard.com/2013/riak-is-ga-engine-yard A cluster is a new way to organize and manage instances that share a specific function.  Clusters take much of the functionality that was once placed at the environment level, and moves it down to the cluster level. One environment can have many clusters, and each cluster can run different cookbooks and be in different regions. We drove the cluster model hand in hand with our productization of Riak on Cloud because the distributed model of Riak paired perfectly with where we wanted to drive the future of our platform. We can now take this underlying work and begin to re-productize other offerings to take advantage of its flexibility in many ways. Social Calendar (Come say hi!) Tuesday May 20th: Engine Yard Dublin hosts the PHP meetup where Eugene Kenny, Adverts.ie discusses his "Developer Toolbox", and then Matthew Weier O'Phinney of Zend Framework & Nate Abele of Lithium go head to head on the subject of Frameworks. Wednesday May 21st: Engine Yard’s San Francisco HQ will be hosting the monthly Riak meetup! Lead data engineer and fan favorite Ines Sombra will be presenting about Riak on Engine Yard Cloud, followed by Basho’s Mark Phillips discussing Riak CS. Wednesday May 21st: Our PDX office will be hosting Coder Dojo for students K-12 to learn about software! Grab a ticket and bring your parents for some software fun. Thursday May 22nd: Engine Yard Dublin plays host to Open Data Ireland, “Give us our health data!” Friday May 23rd: In which I talk about myself in the 3rd person? Tasha Drew will be speaking at Cloud East in Cambridge, UK, about deployments in the cloud, including various strategies we at Engine Yard see for environments of different sizes -- and concluding with sharing our own deployment strategy. Articles of Interest  Lightweight screenshot and annotation tool http://glui.me/ has gained some fans in our office! Engine Yard friend Daragh Curran, Head of Product Engineering, Intercom shared an awesome blog here. “Shipping brings life to your team, to your product, and to your customers. Shipping is your company’s heartbeat.”
5 days ago