We recently decided to put static content for HouseTrip.com to Amazon Cloudfront for a faster user experience. This happens fully automatically on deploy and is transparent in development. Together with...

...a heavy use of sprites this sped up page load time quite nicely. These are a couple of the problems you need to solve in order to do this:

If - for whatever reason - you have to render stylesheets dynamically, the following snippet might be of help. It emulates what "sprockets" would to when precompiling your assets, and give your...

...stylesheets access to all the regular bells and whistles (like asset_path, proper @imports etc): class DynamicStylesheetsController < ApplicationController def show logical_path = RELATIVE_PATH_TO_YOUR_TEMPLATE path = File.join(Rails.root...

stackoverflow.com

You're better off using debugger-ruby_core_source: gem install debugger-ruby_core_source If you can't do this, try the following. Here is how to fix the...

...for a project using Ruby 1.9.3-p448 -- adjust accordingly for your project. Fetch the source for your Ruby version, if you do not yet have it: rvm fetch ruby...

jQuery is still a useful and pragmatic library, but chances are increasingly that you’re not dependent on using it in your projects to accomplish basic tasks like selecting elements...

...styling them, animating them, and fetching data—things that jQuery was great at. With broad browser support of ES6 (over 96% at the time of writing), now is probably a...

...AWS CA file and copy it to the machine you want to connect from: http://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem As far as I could find out, you (currently) cannot access further details...

Try to connect using MySQL client % mysql -uyour_username -p -h rds_hostname_from_management_cockpit.eu-west-1.rds.amazonaws.com --ssl --ssl-ca=/path/to/mysql-ssl-ca-cert.pem Use this statement to check whether a secure connection is used:

makandra dev

...Invoked Function Expessions (or IIFEs) to prevent local variables from bleeding into an outside scope: (function() { var foo = "value"; // foo is scoped to this IIFE })(); In Coffeescript an IIFE looks...

(-> foo = "value" # foo is scoped to this IIFE )() There is also a shorthand syntax with do: do -> foo = "value" # foo is scoped to this IIFE

Whenever Firefox updates, all your Cucumber features that use Selenium break. This is annoying. In order to remedy this, version 0.5.0 of our geordi gem comes with a script that...

After installation, you can setup a separate Firefox copy for Selenium like this: setup-firefox-for-selenium Once the setup process has completed, you have two Firefoxes: One...

Be careful when stubbing out attributes on records that are defined by associations. Nothing is as it seems to be. The associated record has its own universe of things; when...

...delegating calls to it, you ca not stub methods on the associated record and expect them to be around. That is a general issue with this pattern/approach. What's happening...

...to change the locale of your Postgres cluster. A popular one is your development system's locale being used by default (which may be annoying). Here is how to do...

Beware: By following the steps below, you will drop and recreate your cluster. You will lose all data (including roles). Instructions below include a procedure for dumping and restoring...

railway.at

Create a directory .ssl in your home directory. Go there and create a self-signed certificate. It is important to enter localhost.ssl as Common Name when asked. This...

...action and :except => :some_unsafe_action as options. Boot thin thin start -p 3001 --ssl --ssl-key-file ~/.ssl/server.key --ssl-cert-file ~/.ssl/server.crt The option -p tells thin to bind...

Usage $ git diff --help Options: -M[ ], --find-renames[= ] Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the...

...file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign...

Disabling auto-complete in login forms is probably a bad idea, since it encourages weak passwords. If you are still forced to implement this (maybe due to legal or policy...

...requirements), this is how: Prevent browsers from saving the password in the first place. Disabling autocomplete does not improve security. How to prevent password saving: To prevent the browser from...

...Rails and the copied gem. This notes describes what to do. With Bundler This is super-painful. If you just copy the gem to vendor/gems, Rails will complain:

Fun fact: Our install-gems-remotely script is aware of vendored gems and will scp-copy them to the remoty server. Without Bundler Don't use gem unpack since...

end class Invitation < ActiveRecord::Base belongs_to :party belongs_to :user after_create :send_invite def send_invite other_user_names = party.users.collect(&:name) message = "You've been invited. Also...

end end When creating a party and lots of invitations, you want to send an e-mail to each user and tell them who else is coming. Unfortunately, accessing...

...dbi:ODBC:MyLegacyServer', 'my_name', 'my_password') DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect' from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect' from /usr/lib/ruby/1.8/dbi.rb:148:in `connect...

...from /usr/local/lib/site_ruby/1.8/rubygems/dependency_list.rb:14 I installed the gem ruby-odbc instead of the guide's sudo aptitude install libdbd-odbc-ruby sudo gem install ruby-odbc #Successfully installed ruby-odbc...

github.com

...an attacker might be able to use this to inject javascript code into the source code of your page. The linked github page is a collection of common markdown XSS...

...which is handy for writing tests. Producing arbitrary links: [Basic](javascript:alert('Basic')) [Local Storage](javascript:alert(JSON.stringify(localStorage))) [CaseInsensitive](JaVaScRiPt:alert('CaseInsensitive')) [URL](javascript://www.google.com%0Aalert('URL'))

When you want the table headers to always stay around (e.g. because that table is huuuge), use the code below. Style table.fixed_table_header{ position: fixed; top: 0;

...each(function(index) { $(this).css("min-width",$table.find("th").eq(index).width()+"px"); }); } function scrollFixed() { var offset = $(this).scrollTop(), tableOffsetTop = $table.offset().top, tableOffsetBottom = tableOffsetTop + $table.height() - $table.find("thead").height(); if(offset...

In theory you can take any scope and extend it with additional joins or conditions. We call this chaining scopes. In practice chaining becomes problematic when scope chains grow more...

...complex. In particular having JOINs in your scope will reduce the scope's ability to be chained with additional JOINs without crashes or side effects. This is because ActiveRecord doesn...

...to optimize powers that only check access to a given record. e.g. Power.current.post?(Post.last). See below for details. Powers that only check a given object Sometimes it is not convenient...

...to define powers as a collection. Sometimes you only want to store a method that checks whether a given object is accessible. To do so, simply define a power that...

...model inherits from others or uses many concerns / traits, it might be hard to see in the code which validators it has. But fortunately there's a method for that...

...UniquenessValidator:0x00007f55f1417e88 @attributes=[:name], @klass=UserGroup (call 'UserGroup.connection' to establish a connection), @options={:case_sensitive=>true, :scope=>:partner_id}>, #<ActiveModel::Validations::NumericalityValidator:0x00007f55f1415200 @attributes=[:user_count_limit], @options={:greater_than...

tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/. The directory where you save your Paperclip attachments should not look like this: storage/photos/1...

...storage/photos/2/... storage/photos/3/... storage/attachments/1/... storage/attachments/2/... The problem with this is that multiple environments (at least development and test) will share the same directory structure. This will cause you pain eventually. Files...

...problems installing a gem and get a error collect2: error: ld returned 1 exit status it's due to missing development headers of a library (ld is the linker).

/home/foobar/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150915-3539-1i9layj.rb extconf.rb creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling generator.c linking shared-object json/ext/generator.so /usr/bin/ld: cannot find -lgmp collect2: error: ld returned 1 exit status

There are several gems that make it easy to read and process xlsx files. Parsing the entire file at once however is error-prone since each cell is transformed to...

...formatted but empty cells. As of today, I found two promising alternatives that provide a stream-based access to spradsheet rows: Roo supports multiple spreadsheet types like ODS or CSV...

If you want a widget for awesome that runs a command regularly (every X seconds) and puts the output into your awesome panel, this is for you.

...below into your ~/.config/awesome/rc.lua. It supplies two methods: execute_command will run a command and return its output. Multiple lines will be joined into one line. The code is from...