Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and code from gems might use one or the other.

Your life will be easier if your application does not need to support time zones. Disable them like this: config.time_zone = 'Berlin' # Your local time zone config.active_record.default_timezone...

Webmocks hash_including is similar to RSpec::Mocks::ArgumentMatchers#hash_including. Be aware that hash_including (webmock v3.0.1) doesn't parse integer values to String. Without hash including you would...

uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: {foo: 1, bar: 2}) Net::HTTP.get(uri) # ===> Success If you only want to check if foo is present...

The git doc states on the difference of these two commands: git-restore[1] is about restoring files in the working tree from either the index or another commit. This...

...The command can also be used to restore the content in the index with --staged, or restore both the working tree and the index with --staged --worktree. By default, if...

Embedding videos on a website is very easy, add a tag to your source code and it just works. Most of the time. The thing is: Both the operating...

...an 0.x version and has quite some development dependencies. It has the Apache license. streamio-ffmpeg seems to be perfect, but had its last release in 2016. It offers...

businesswire.com

...previously announced it would not charge royalties for such video through December 31, 2015 (see http://www.mpegla.com/Lists/MPEG%20LA%20News%20List/Attachments/226/n-10-02-02.pdf), and today’s announcement makes clear that royalties will continue not to...

...be charged for such video beyond that time. Products and services other than Internet Broadcast AVC Video continue to be royalty-bearing...

...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...

Shoulda Matchers don't provide canditional validations (validations with if: option). Here is how to write tests for the condition: Class: class Employee < ActiveRecored::Base validates :office, presence: true, if...

describe Employee do describe '#office' do context 'is a manager' do before { allow(subject).to receive(:manager?).and_return(true) } it { is_expected.to validate_presence_of(:office) } end context 'is...

...the same child table, declare a has_many association per condition with its own scope and dependent: :restrict_with_error, then declare the plain dependent: :destroy association last.

...The example below uses two scoped associations to keep things readable, but the same approach works with one, three, or any number of independent restrictions. class Account < ApplicationRecord

RAG is often equated with vector databases, embeddings, and semantic search. But RAG ("Retrieval-Augmented Generation") really is just 'put relevant data in the prompt' — the retrieval mechanism is up...

...to you. If your app already has any working search functionality, you can build a useful RAG pipeline with it. Semantic search can still be included later on, if really...

If you're on Ubuntu: sudo apt-get install ruby-dev On other platforms: Look for a package containing ruby header files. On Red Hat that's "ruby-devel" likely...

To force a check on your next reboot (here for your root partition), simply: touch /forcefsck To manually do this, here is how to do it for the first partition...

...on sda, when you are using ext4: fsck.ext4 -fn /dev/sda1 -f forces the check, even if everything seems okay. -n is a "read only" check, where nothing is changed and...

Most forms have a single submit button that will save the record when pressed. Sometimes a form needs additional submit buttons like "accept" or "reject". Such buttons usually attempt...

...a state transition while updating the record. To process a form with multiple buttons, your server-side code will need to know which button was pressed. To do so you...

...warning after upgrading to rails >= 2.3.10 DEPRECATION WARNING: The :overwrite_params option is deprecated. Specify all the necessary parameters instead. that is for example caused by url_for( :overwrite_params...

...link_to uses url_for internally, so you can can use params.merge {...

...} as the second parameter of link_to...

thegnar.com

View specs are a powerful tool to test several rendering paths by their cases instead of using a more costing feature spec. This is especially useful because they become quite...

...used with Capybara::Node::Finders and Capybara::RSpecMatchers. This allows to wirte view unit specs as you can isolate specific parts of the rendered view and then use readable and...

api.rubyonrails.org

...However, you need to be aware of the overall transaction nesting constellation, because creating proper sub-transactions can lead to unwanted or too early triggering of after_commit callbacks:

...project> Country.first.name # => "Afghanistan will not change" Wait. What happened to the rollback in the after_save-callback? From the Rails docs: Transaction calls can be nested. By default, this makes...

Slides for Henning's talk on Sep 21st 2017. Understanding sync vs. async control flow Talking to synchronous (or "blocking") API print('script start') html = get('/foo') print(html)

Script outputs 'script start', (long delay), '...

...', 'script end'. Talking to asynchronous (or "evented") API print('script start') get('foo', done: function(html) { print(html) }) print('script end')

Stop MySQL: sudo service mysql stop Move (or copy) your mysql directory. If you want /mnt/mysql to be the new directory, do it like this:

.../var/lib/mysql /mnt/ Open your MySQL configuration (sudo vim /etc/mysql/my.cnf) and change the datadir value to your new path (e.g. /mnt/mysql) Modify your AppArmor configuration: sudo vim /etc/apparmor.d/usr.sbin.mysqld Change/copy the lines...

httpd.apache.org

...you are done and all is well: remember to remove those entries again, or set the log level to 0, to switch off rewrite logging...

Any form fields where users enter numbers should be an . Numeric inputs have several benefits over : On mobile or tablet devices, number fields show a special virtual keyboard that shows...

...mostly digit buttons. Decimal values will be formatted using the user's language settings. For example, German users will see 1,23 for . Values in the JavaScript API or when...

This step will pass if the specified select is sorted. Then /^the "(.*?)" select should be sorted$/ do |label, negate| select = find_field(label) options = select.all('option').reject { |o| o.value.nil? } options.collect...

...this custom matcher, the each_cons block can be replaced with: options.should be_naturally_sorted Usage Then the "Organizations" select should be sorted Depends on Capybara. This step is now...

Note: Consider using MATE instead of Gnome 3 on newer system Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi...

Improve your font-rendering Copy /etc/xdg/awesome/rc.lua to ~/.config/awesome/rc.lua. Take a look, it's pretty self-explanatory. You can instantly apply changes by reloading Awesome with Meta-Ctrl-R.

PostgreSQL supports the SQL OVERLAPS operator. You can use it to test if two date ranges overlap: => SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS...

overlaps -------- true An important caveat is that the date ranges are defined as start <= time < end. As such the later date is not included in the range:

Sometimes, due to git or other "accidents", important files get deleted or overwritten. At a state when even Ctrl+Z doesn't work anymore, you maybe can rescue your files...

...that file in the editor Go to RubyMine and click on VCS -> Local History -> Show History In the now open window, you should see all greater changes made to the...

makandra dev

Never use raise_error without specifying the Error you expect. expect { do_a_lot_of_complicated_stuff }.to raise_error will be green if you make any error in programming...

...E.g. a simple typo would make the test above green. The block will catch the Spec:: exception and the test will be happy. Be sure to always have custom errors...