View

CSS: Emulate borders with inset box shadows

When is this useful?

  • When both parent and child elements have borders, with this technique you don't get two borders (which looks ugly). This is because child elements are rendered over inset box shadows, not inside inset box shadows.
  • You want more than one border on the same element. You can have as many inset box shadows on the same element as you like, e.g. allowing you to make a picture-frame-like border.

Examples

Remember the attribute list of box-shadow is x-offset, y-offset, blur radius, shadow r…

External content

7 Ways to Decompose Fat ActiveRecord Models - Code Climate Blog

“Fat models” cause maintenance issues in large apps. Only incrementally better than cluttering controllers with domain logic, they usually represent a failure to apply the Single Responsibility Principle (SRP). “Anything related to what a user does” is not a single responsibility.

Early on, SRP is easier to apply. ActiveRecord classes handle persistence, associations and not much else. But bit-by-bit, they grow. Objects that are inherently responsible for persistence become the de facto owner of all business logic as well. And a year or tw…

External contentUnfinished

CSS-Style

Richard Powell presents a collection of CSS styling advice that's mainly taken from SMACSS. Here's my favorites.

#Do not use ID's in CSS Selectors
It is never safe to assume there will only ever be one of something on a page so do not use ID's for CSS. Id's are much better used as javascript hooks so use them for this instead.

.list {…} instead of #list {…}

#Animate an interface using classes not inline styles
Inline styles added by javascript are harder to update and maintain, prefer to add classes using ja…

External content

rails/turbolinks

Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head.

This is similar to pjax, but instead of worrying about what element on the page to replace, and tailoring the server-side response to fit, we replace the entire body. This means that you get the bulk of the speed benefits from pjax (no recompiling of the JavaScript or CSS) without having to tail…

External content

Creating a Grid for Product View for a eCommerce Site

Randy Hoyt is presenting a way to display something (e.g. products) in a grid. It's responsive, too!

External content

An easy demonstration of what Twitter Bootstrap does

Holly Schinsky from Adobe shows some of Bootstrap's capabilities. The combination of explanation, screenshots and source code makes it easy to understand

Automatically strip all string fields of an ActiveRecord

If your application has forms to edit string fields, you probably want to strip the entered values (remove whitespace from beginning and end). The reason is that your users will copy + paste values from unholy places (websites, Microsoft Office) and end up having trailing whitespace in most of their records.

Because browsers ignore whitespace, no one will usually notice this until you get the weirdest bug reports (e.g. two seemingly equal records are not, or multiple records for "unique" values).

Use the attached trait in your model to hav…

RSpec: Change the type of a spec regardless of the folder it lives in

In a Rails application, *_spec.rb files get special treatment depending on the file's directory. E.g. when you put a spec in spec/controllers your examples will have some magic context like controller, post or get that appears out of nowhere.

If you want that magic context for a spec in another folder, use the :type option:

describe CakesController, :type => :controller do
  ...
end
External content

mattheworiordan/capybara-screenshot

Takes a screenshot when you call it, or when a test fails.

Literally 101 Ruby tricks

The linked slidedeck holds many tips, of which I list the most interesting to me below

DATA and END

The __END__ keyword tells Ruby where a file ends – but you don't have to stop there. Any text you add after it is accessible via the DATA object.

Running the attached example file data.rb prints:

DATA is a File object to everything in the current file after "__END__"

No braces needed for 'special variables'

@instance, @@class, $global = [ 'instance', 'class', 'global' ]
puts "#@instance, #@@class, #$global" ...

Rspec_spinner or cucumber_spinner get into an infinite loop

Chances are, something in your project uses the mathn library, which is known to cause infinite loops when rendering the progress bar. If so, this will probably fix it.

External content

A jQuery plugin pattern every jQuery plugin should use

Many jQuery plugins suffer from a good plugin architecture. When you write jQuery plugins you should use the plugin pattern described in this article which makes your plugin highly customizable and extensible.

Related article with patterns for namespaced jquery plugins (more detailed)

External content

floere/phony

The (admittedly crazy) goal of this Gem is to be able to format/split all phone numbers in the world.

External content

jsTimezoneDetect

Makes a robust determination of a user's timezone through Javascript.

Fixing errors with state_machine when excluding states

This is for you if you get the following strange error from the state_machine gem:

undefined method `-' for #<StateMachine::BlacklistMatcher:0x124769b0>

You probably did something like this in your state_machine ... do block:

def self.final_states
  [ :foo, :bar ]
end
   
transition (all - machine.final_states - [:baz]) => :target_state

Instead, define the source states like this:

def self.final_states
  [ :foo, :bar ]
end
   
transition (all - (mach...

How Ruby lets you keep script and data in *one* file

The __END__ keyword tells Ruby where a file ends – but you don't have to stop there. Any text you add after it is accessible via the DATA object.

The attached example file data.rb looks like this:
```
puts DATA.read

END
DATA is a File object to everything in the current file after "END"
```
Running it with ruby data.rb prints:

DATA is a File object to everything in the current file after "__END__"

Workaround for broken integer division after requiring the mathn library

Ruby's mathn library changes Fixnum division to work with exact Rationals, so

2 / 3 => 0
2 / 3 * 3  => 0

require 'mathn'
2 / 3 => Rational(2,3)
2 / 3 * 3 => 2

While this might sometimes be quite neat, it's a nightmare if this gets required by some gem that suddenly redefines integer division across your whole project. Known culprits are the otherwise excellent distribution and [GetText](https://g…

Get rid of WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.8

Rebuilt the gem with the newer library

gem install --no-rdoc --no-ri nokogiri -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib

If you still get the error, try to uninstall all nokogiri versions with

gem uninstall nokogiri

and install nokogiri again.

View
3222 cards