...to be defined ahead of your before block and can be different for individual sections. It works just like that: describe User do describe '#locked?' do before :each do subject.should...
...receive(:current_plan).and_return plan end context 'when expiring today' do let(:plan) { stub(:expiry => Date.today) } it 'should be false' do subject.should_not be_locked end end context 'when...
Use Socket.gethostname. So for a machine whose hostname is "happycat", it will look like this: >> Socket.gethostname => "happycat" That should work right away for your Rails application. For plain Ruby, you...
...first need to do: require 'socket' If you don't want to use Socket for some reason, you can still just use the hostname command, at least on non-Windows...
When you regularly make use of Cucumber's "show me the page" step (or let pages pop up as errors occur), the capybara-20120326132013.html files will clutter up your Rails root...
To tell Capybara where it should save those files instead, put this into features/support/env.rb: Capybara.save_and_open_page_path = 'tmp/capybara...
...to an open redirect vulnerability. Your application's generated route methods with a _url suffix are also affected because they use url_for unter the hood. The problem
...use links with your application's hostname, cause a redirect to evil.tld and present a sign-in form which looks like yours. Users will enter their login credentials and submit...
The will_paginate gem will show a default of 30 records per page. If you want to test pagination in a Cucumber feature, you don't want to create...
...records just for that. Instead, you probably want to modify the number of items shown, by saying something like this: Given we paginate after 2 users Using the following step...
Forms in PDF documents follow the AcroForm definition. Prawn has no native support for it, but you can build form fields through plain PDF objects. The card is only about...
...fields, since I have only used those. Text fields Here is how to add a single-line text field, e.g. in a Prawn::View class. Note that ref! and state...
To find a hash key by it's value, i.e. reverse lookup, one can use Hash#key. It's available...
Sometimes you want git to ignore certain files that appear on your machine. You can do this in 3 ways: Per project, in the project's .gitignore file
Downsides of per-project .gitignore entries While it might be tempting to set it per project (other devs might benefit from it), you need to do it each...
...consider processing your images with libvips instead of ImageMagick. Reasons for libvips There are several upsides to using libvips over ImageMagick: libvips is considerably faster and uses less memory.
...has a large attack surface that has repeatedly caused security incidents in the past (compare ImageMagick CVEs with libvips CVEs). Ubuntu is sometimes slow to fix the numerous ImageMagick vulnerabilities...
...be answered with an empty response if the underlying content hasn't changed. This saves CPU time and reduces the bandwidth cost for a request/response exchange to about 1 KB...
...can be considered secure. Random masking of CSRF tokens was introduced to mitigate BREACH, a side-channel attack against HTTPS that was published in 2013. BREACH is pretty hard to...
Jasmine specs for the frontend often need some DOM elements to work with. Because creating them is such a common task, we should have an efficient way to do it...
...Let's say I need this HTML structure: item 1 item 2 This card compares various approaches to fabricating DOM elements for testing. Constructing individual elements While you can use...
Migrating data from a legacy into a new system can be a surprisingly large undertaking. We have done this a few times. While there are significant differences from project to...
...project, we do have a list of general suggestions. Before you start, talk to someone who has done it before, and read the following hints: Understand the old system
When you repeat a subpattern with a *, + or {...} operator, you may choose between greedy, lazy and possessive modes. Switching modes may affect the result and performance of your regular expressions...
...In the worst case, an ill-suited mode may make your regular expression so slow that it can DoS your application (Examples are the ActiveRecord's PostgreSQL CVE...
To open a terminal quickly navigate to System → Preferences → Keyboard Shortcuts. There, click the "Run a terminal" row (It should be in the "Desktop" section) and press the keyboard shortcut...
...for Ubuntu's default terminal is gnome-terminal. Be aware that many programs use shortcuts of their own and you would not want to clash with those (like Ctrl+T...
Rails has configurable time zones, while Ruby is always in the server's time zone Thus, using Ruby's time API will give you wrong results for...
...zones, because their existence is a fact. You can, however, tell Rails the only single time zone you'll need is the server's. config.time_zone = "Berlin" # Local time zone...
You can make both mobile Chrome and mobile Safari display a native app install banner. The banner suggests that the user installs an app that is related to the current...
...page. It is shown in the phone's native UI. See attached animation. There is some fineprint you need to read to make this work (see below). References Android: Increasing...
Observed on Rails 2.3 and machinist 1.0.6 Like the title says, when you define the method empty? like in the following example, you may not longer use collection.make.
The flip-flop operator is a hotly contested feature of Ruby. It's still struggling to find an idiomatic use case, except for a few very rarely needed things. It...
...s not something you'll likely reach for on a daily, weekly or even monthly basis. The only thing you really need to know about it is what it does...
...Claude Code, Codex, and Cursor can work on multiple tasks in parallel by creating separate Git worktrees. Each worktree has its own working directory, but Rails will normally use the...
...across all worktrees. This can cause conflicts when agents run tests, change the database schema, or modify test data simultaneously. This card shows a harness-agnostic technique to give every...
TL;DR: Pannellum is a small (~56 kB, own WebGL renderer, no three.js) equirectangular panorama viewer. The npm package has no ES module export - importing it runs an IIFE that...
...assigns the API to window.pannellum. Bundle it statically, make sure the viewer's container gets a definite size, and allow blob: in your img-src CSP. Considered Photo Sphere Viewer...
...you have files in your .gitignore they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file system...
...While a regular git clean will ignore them as well, passing the -x switch changes that: git clean -x If you want to see what would happen first, make sure...
...toggle an outlining of HTML elements quickly. This helps greatly when you want to see the actual dimensions of elements, e.g. for floating elements inside containers, instead of opening up...
...shortcut (Shift+G for the 9.2-compatible layout or for the default layout with enabled "single-key shortcuts") and select "Outline" from the View → Style menu (needs to be done...
The program 'foo' can be found in the following packages: * foobar * barfoo Try: sudo apt-get install -bash: foo: command not found But you can customize this with the...
...connected with ssh. Because I'm using $@ I can also use options like a custom ssh-port...
Angular's location provider stalls links to the current URL, i.e. window.location. As soon as the $location service is activated in an Angular app, it will intercept links. The click...
...your interaction with the browser history (i.e. you're just using Angular as JS sugar on your page), Angular will create the above issue as soon as you use anything...