...GitHub repository is a bit like our "dev" cards deck, but groomed from a single person (Josh Branchaud). It includes an extensive list of over 900 TILs on many topics...
...TILs that were new to me. I encourage you to take your time to skim over the original list as well! Assoc For Hashes Hash#assoc can be used to...
tl;dr: Do not use merge! for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session...
...is empty when you start (same effect when there is data): # In our example, we're in a Rack middleware request = Rack::Request.new(env) request.session.merge! :hello => 'Universe' request.session => {} Wat?
Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL...
...release_roles|...) :some_role do Resources Very helpful, leads you 90% of the upgrade: https://semaphoreci.com/blog/2013/11/26/capistrano-3-upgrade-guide.html Official documentation Many examples of SSHKit...
To update your Rubygems to the latest available version, type the following: gem update --system Note that you have a separate Rubygems installation for each Ruby version in your RVM...
...or rbenv setup. Updating one does not update the others. Ruby 1.8.7 If you are using Ruby 1.8.7 you cannot use the latest version of Rubygems. Type the following to...
...lambdas in Ruby work, check out the code at the attached link. Here the summary: ^ ---------------------------- Section 6: Summary ---------------------------- So, what's the final verdict on those 7 closure-like entities...
...method Y closure yes The things within each of these groups are all semantically identical -- that is, they're different syntaxes for the same thing: 1. block (called with yield...
...messages should include the ID of the issue your code belongs to. Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users...
Fresh Chrome installations now show a "Choose your search engine" popup in Europe. This might make your Cucumber tests fail. Fortunately there is a flag to disable the popup. Add...
...the following option to your chromedriver setup code: options.add_argument('--disable-search-engine-choice-screen') I found this flag in Peter Beverloo's list. Background: This was experienced locally with...
...Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts/) and finds out that you are defining ActiveRecord classes inside it, it...
...the whole file. Here is how to avoid that. What's happening? Let's say you have the following script which is only run once, manually, via script/runner: # lib/scripts/doomsday.rb
Sometimes you want to write a test for a business rule that's based on multiple variables. In your goal to cover the rule thoroughly, you start writing tests for...
...each permutation of all variables. Quickly it blows up into something unsustainable. With n variables for the business rule, you get 2n permutations/test cases. This is manageable with 2 variables...
jQuery's deferred objects behave somewhat like standard promises, but not really. One of many subtle differences is that there are two ways to chain callbacks to an async functions...
...is done, which only exists in jQuery: $.ajax('/foo').done(function(html) { console.debug("The server responded with %s", html); }); There is also then, which all promise libraries have:
...use Solr by calling Article.search { fulltext(title) paginate(:per_page => limit) } Now look at http://sunspot.github.com/docs/ to learn about all the possibilities of Sunspot. Overwrite Sunspots' search method
...your SysOp team that you'll need Solr on staging and production, on Ubuntu the solr-common will provide what you need. First of all you should provide Solr with...
...with modern CSS features In the past, you might have resorted to bulky JavaScript solutions or CSS hacks like transitioning between max-height: 0 and max-height: 9999px. All of...
...them were awkward and/or have several edge cases. With modern CSS, there is actually a way to do it properly: Just use a display: grid container which transitions its grid...
...need to use XPath, you can have Nokogiri help you out on creating it. Simply use Nokogiri's xpath_for: Nokogiri::CSS.xpath_for('#foo') # => ["//*[@id = 'foo']"] Nokogiri::CSS.xpath_for('#foo...
...bar:nth-of-type(2)') # => ["//*[@id = 'foo']//*[contains(concat(' ', @class, ' '), ' bar ') and position() = 2]"] Since XPath is more powerful you may still need to do some hardcore XPath hacking eventually...
If you have ... an object that defines to_hash (may well be a simple Hash instance) and pass it to a method with optional arguments and keyword arguments
...it is not set as the first optional argument. Instead, Ruby calls to_hash on the object and tries to match the result to keyword arguments. If the hash contains...
Just found out about a great feature in Rails that seems to be around since Rails 2. Start a console with the --sandbox (or -s) parameter: rails console --sandbox
...database will be rolled back on exit. Warning Changes beyond the database (deleting files, sending emails, etc) cannot be rolled back...
...take the content-box for the element's shape, i.e. without margin, padding and border. shape-outside: content-box Set the margin where you want it, e.g. 10px left and...
Set the shape-margin to the same size as the margin. Note that the shape-margin can never exceed the (rectangular) margin-box of an element! --margin: 10px;
If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database...
SET GLOBAL query_cache_type=OFF; and restart your rails server. You can also disable the cache on a per query basis by saying SELECT SQL_NO_CACHE...
Sometimes you may want to print files from the command line, especially when you have lots of them. You can use lp for that. To print a single example.pdf file...
...on your default printer, simply say: lp example.pdf lp accepts multiple filenames, so to print all PDF files in the current directory: lp *.pdf You can specify a printer via...
...you can install the official Java JRE: sudo apt-get update sudo apt-get install sun-java6-jre You can now check your default JVM with java -version. It should...
...versions below 10.10. If it does, please update this note. sudo add-apt-repository ppa:sun-java-community-team/sun-java6 You probably want to get rid of OpenJDK (which is...
The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...
...this example we are using %s identifier to replace strings. class Fetcher FIND_URI = 'https://someapi.com/3/search/record?query=% s&include_many=% s&language=en-US&page=1' # some public methods
See the attached link for a useful overview of modern (and classic) DOM API methods, like matches, contains, append, cssText, etc. You will still need to look up some documentation...
...e.g. on how to modify a ClassList, but it's still better than browsing interfaces and superclasses of Element on MDN without knowing what to look for. When coming from...
If you have an html_safe string, you won't be able to call gsub with a block and match reference variables like $1. They will be nil inside the...
...with rails_xss) as well as Rails 3 applications. Here is a fix to SafeBuffer#gsub. Note that it will only fix the $1 behavior, not give you a safe...
Chromedriver (or selenium-webdriver?) will not reliably scroll elements into view before clicking them, and actually not click the element because of that. We've seen this happen for elements...
...a 40px button). Our assumption is that the element is considered visible (i.e. Capybara::Selenium::ChromeNode#visible? returns true for such elements) but the Selenium driver wants to actually click...
This card shows you how to format a card's content using Markdown. We use the Commonmarker interpreter, so here are examples for its dialect. Formatting **Bold** Bold _Italics_
Add a new line for a paragraph. Headlines Underline headlines with an equals sign or dash -- or start a line with a hash symbol: Hello World ----------- Lorem ipsum...