You're using exception_notification and want to send exception mails within a model. Here's how. The ExceptionNotifier class has a method notify_exception for that. Simply pass an...

ExceptionNotifier.notify_exception Exception.new("testfoo") => #<Mail::Message:77493640, Multipart: false, Headers: <Date: Mon, 24 Sep 2012 13:37:00 +0200>, <From: foo@example.com>, <To: ["fail@failtrain.com", "fail@failbus.org"]>, <Message-ID: <5060543b3759_212311986a0305e8@ip-10-234-82-125.mail>>, <Subject: [you...

makandra dev

...know the exact hits on your website (or whatever logfile you want) for a specific date without duplicates, here's how. "Unique" means you don't want to count hits...

...to an URL originating from the same IP twice. You can use the attached script to do so: # ./log_parser.rb 2011-10-04 27 hits on /rss.xml 36 hits on /stylesheets/fonts/slkscr-webfont.woff...

This collection of Sass mixins enables cross-browser styling (including IE with CSS3PIE) with less lines of code. This enables PIE for IE up to version 8 only (the first...

...part is not possible in Haml, so use ERB): <%= stylesheet_link_tag 'screen', :media => 'screen' %> These would be your two screen Sasses: # screen_with_pie.sass =pie behavior: url(/stylesheets/lib/PIE.htc) position: relative

You can configure a Ubuntu system as a gateway in order to share it's internet connection (maybe via WLAN or tethering) with other computers on the network.

...Enable ip traffic forwarding: Open /etc/sysctl.conf Uncomment the line net.ipv4.ip_forward=1 Reload using sudo sysctl -p /etc/sysctl.conf Reconfigure ip_tables to allow NAT: Download the attached file Replace online...

...describes a hack that lets you trace those messages in your code. Let's say you want to get rid of a console message "foobar". Copy the Undebug class below...

...that message. The console output should look like this: Message tracing is active and slowing down the application! Disable me in /home/henning/projects/notes/config/initializers/undebug.rb:34. foobar Printed 'foobar' at /home/henning/projects/notes/features/step_definitions/web_steps.rb:280:in...

makandra dev
dev.mensfeld.pl

Ruby 2.3.0 has been around since end of 2015. It brings some pretty nice new features! Make sure to read the linked post with its many examples! Hash#fetch_values...

...Similar to Hash#fetch, but for multiple values. Raises KeyError when a key is missing. attrs = User.last.attributes attrs.fetch_values :name, :email Hash#to_proc Turns a Hash into a Proc...

The basic idea is pretty simple: an element's height is accessible via the offsetHeight property, its drawn height via scrollHeight -- if they are not the same, the browser shows...

var hasScrollbars = element.scrollHeight != element.offsetHeight; So, in order to say something like... Then the element "#dialog_content" should not have scrollbars ... you can use this step (only for Selenium scenarios...

There are two ways within systemd to manage the fact that you need the gluster service active before mounting the mountpoint. Thus in the past the mount triggered before the...

...gluster service was running and didn't mount again. /etc/fstab You can use the x-systemd.autmount feature which mounts the mountpoint as soon as it's accessed localhost:/shared /gluster/shared glusterfs...

A snippet of the carrierwave documentation You might come to a situation where you want to retroactively change a version or add a new one. You can use the recreate...

...base file. This uses a naive approach which will re-upload and process the specified version or all versions, if none is passed as an argument. Call recreate_versions! on...

...the remote branch to check out, but when using more than one remote, it seems like it no longer can do that. Even if the branch is the same on...

...both remotes, you need to specify the branch to check out from explicitly, like that: $ git checkout -b my-branch origin/my-branch Branch my-branch set up to track remote branch...

makandra dev

Using OpenSSL it's very easy to seriously encrypt files. Use the script below. Input / Output are self explanatory. Put a long passphrase into PASSWORD_FILENAME. It is the key...

...m 60 > /tmp/openssl_encryption_password Remember to at least delete the input file afterwards. Better use shred to wipe files on Linux as used in the script below. #!/bin/sh PASSWORD_FILENAME=/opt/backup/openssl_encryption_password...

The migration DSL now supports adding and removing foreign keys. They are dumped to schema.rb as well. At this time, only the mysql, mysql2 and postgresql adapters support foreign keys...

...exclude things like default, 'not null' and foreign key constraints in the database. ActiveRecord supports most of them. comment = Comment.build(title: 'Bikini Bottom', content: 'Burgers for free', user_id...

When updating WebMock, be prepared that your specs may send real requests into the depths of the internet unless you update Curb as well.\ WebMock will not complain about those...

...requests not being stubbed. One of the commits that made it into 1.8.0 actually breaks Curb versions below 0.7.16 while fixing it for that version (and above, hopefully).\

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

Upgrading from Ruby 1.8.7 to 2.1.2 took me an hour for a medium-sized application. It involved hardly any changes except removing the occasional monkey patch where I had backported...

...longer in the load path by default) replacing the old debugger with byebug removing sytem_timer from Gemfile (see this SO thread for details) If you get LoadError: cannot load...

makandra dev
curl.haxx.se

When making requests using curl, no cookies are sent or stored by default. However, you can tell curl to re-use cookies received earlier (or forge your own cookies).

...are 2 command line switches you need to use: -c will write cookies to a given file -b will read cookies from a given file Example The remote server sets...

If you open a pop-up window [1] in your Selenium tests and you want to close it, you can do this: # Find our target window handle = page.driver.find_window("My...

# Close it page.driver.browser.switch_to.window(handle) page.driver.browser.close # Have the Selenium driver point to another window last_handle = page.driver.browser.window_handles.last page.driver.browser.switch_to.window(last_handle) Mind these: find_window returns a window handle, which...

Sometimes you need a file of some size (possibly for testing purposes). On Linux, you can use dd to create one. Let's say you want a 23 MB file...

dd if=/dev/zero of=test.file bs=1048576 count=23 The block size (bs) is set to 1 MB (1024^2 bytes) here, writing 23 such chunks makes...

makandra dev

...its tables and their data, under a new name. Make a dump of your source database: mysqldump -uroot -p my_project -r my_project.sql Or, if you only want to dump...

...the database's table structure (schema) without any contents: mysqldump -uroot -p my_project -r my_project.sql --no-data Open up a MySQL shell: mysql -uroot -p From the MySQL shell...

...css? matcher has a couple of options you might find useful. Check that a selector appears a given number of times Use the :count option like this: Then /^I should...

...see (\d+) users?$/ do |count| page.should have_css('ul#users li', :count => count.to_i) end Check that a selector has a given text content Use the :text option like this...

dev.opera.com

Since version 11.10 Opera provides support for linear gradients using -o-linear-gradient. The syntax is pretty similar to Mozilla's -moz-linear-gradient. This will create a vertical gradient...

...image: -o-linear-gradient(top, #ff0, #f00); The first parameter defines where the gradient starts and which direction it will go. \ You can use top/left/bottom/right (and combinations of those) but...

This snippet makes links that refer to an anchor (like "...

...") scroll softly to it.\ In this example we only do it for links that also own a data-animate attribute...

...var hash = $(this).attr('href'); var offset = $(hash).offset(); if (offset) { $('html, body').animate({ scrollTop: offset.top }, 'slow'); location.hash = hash; return false; } }); Note that this could basically work for any element...

Similar to our snippet that runs all Cucumber features matching a given string, the following will run all modified or new Cucumber features by looking at your git status:

...status --short | grep -v '^ D ' | grep '.feature' | sed 's/.. //' | tr '\n' ' ' | xargs geordi cucumber If you want to know what each of the above commands does, see explainshell.

...To fix this error upgrade your project's ruby version or install the last supported version of Bundler for Ruby < 2.3: gem install bundler -v '~>1' You will also see...