Embed Google Analytics code for some environments only
Google Analytics should run only in production to avoid polluting visitor statistics. Rails environment checks can gate the tracking snippet.
IIFEs in Coffeescript
Coffeescript loop variables can leak into later callbacks, causing repeated values; do and IIFEs create a fresh scope for each iteration.
AngularJS: How to force Content-Type on GET and DELETE requests
AngularJS strips Content-Type from blank-body GET and DELETE requests, which can break APIs that require it. Decorating $httpBackend can restore the header selectively.
Test redirects to an external URL with Cucumber/Capybara
External redirects are awkward to test with Cucumber and Capybara: Rack::Test ignores the host, while Selenium follows it. Controller specs or an observable redirect make the target URL verifiable.
Jasmine: Testing AJAX calls that manipulate the DOM
AJAX DOM updates are hard to test when requests are asynchronous and the target element is missing. jasmine-ajax, jasmine-fixture, and done make network mocking and DOM setup possible.
Angular: Fixing "Referencing DOM nodes in Angular expressions is disallowed"
CoffeeScript can accidentally return DOM nodes from Angular click handlers, triggering the “Referencing DOM nodes in Angular expressions is disallowed” error. An explicit return value avoids leaking a node into Angular.
How to disable auto-complete on login forms
Browser password managers ignore autocomplete=off on login forms, and disabling autocomplete weakens passwords. Hidden fields can stop saving, but not improve security.
Sticky table header with jQuery
Keep table headings visible while scrolling large tables by cloning the header and syncing widths and horizontal position with jQuery.
Run Chrome in a specific resolution or user agent with Selenium
Testing web apps at mobile-like sizes or with a custom browser identity reveals layout and behavior bugs before release.
Waiting for page loads and AJAX requests to finish with Capybara
Capybara browser tests can fail while page loads or AJAX requests are still pending; waiting for visible results reduces flickering and unreliable assertions.
How to solve Selenium focus issues
Browser focus loss makes Selenium tests flicker red and green, especially with Firefox and parallel runs. Explicit focus and blur handling and focus-independent tests improve stability.
thoughtbot/fake_stripe: A Stripe fake so that you can avoid hitting Stripe servers in tests.
fake_stripe runs a local Stripe-like server and fake Stripe.js for feature specs, letting purchase flows be tested without external HTTP requests or Stripe sandbox flakiness.
Understanding AngularJS service types
AngularJS service kinds differ in configurability, injection style, and object shape; factories are usually the default choice, while providers support configuration and decorators extend existing services.
Bookmarklet to generate a Pivotal Tracker story from Zammad Ticket
Create Pivotal Tracker stories directly from Zammad tickets with a bookmarklet for quick handoff to SWAT teams.
Bootswatch: Paper
Free Bootstrap theme with a Material Design look for Rails apps. Sass and Less files simplify integration, while the CSS-only approach keeps the theme easy to replace.
Useful tricks for logging debugging information to the browser console
Safer browser console logging makes debugging easier: %o interpolation keeps values readable, and object shorthand lets structured data expand interactively.
CSS3 Pie: Element not properly redrawn
PIE may fail to redraw nested elements when a parent class changes, leaving updated styles stale; changing the target element’s own CSS or markup works around it.
object-fit polyfill by lazysizes
IE lacks object-fit support, but lazysizes can polyfill image and video fitting with contain or cover behavior.
Switching the package manager from yarn to npm
Migrating a Rails app from yarn to npm can reduce dependency complexity and avoids upgrading to Yarn 2.0. Matching package versions helps keep installs stable.
Selenium: How to close another tab (popup)
Closing a Selenium pop-up requires switching to its window handle and then pointing the driver back to another tab to avoid broken subsequent steps.
Select2 alternatives without jQuery
jQuery-free dropdown components for advanced selects are needed when Select2 is too dependent on jQuery or missing features.
Use different CSS depending on whether elements render on the same line or multiple lines
Responsive layouts can switch styles when content wraps onto multiple lines or stays on one line, enabling different treatment for narrow screens.
Detect the current jQuery version
Read the jQuery version from $.fn.jquery to check which library release is loaded at runtime.
Why you might not need MVC with React.js
React.js uses a virtual DOM to re-render only changed parts, making full-screen updates fast enough that subviews and MVC separation may be unnecessary.