...your HTTP request with curl, you can use the -w (--write-out) option: curl --silent -o /dev/null -w "%{time_connect};%{time_starttransfer};%{time_total};%{time_appconnect};%{time_pretransfer}\n...
...With -w you can make curl display informations for your HTTP request. As seen in the example above you can e.g. output this in a CSV format for further analysis...
RubyMine offers you to exclude directories from search, meaning faster search results and less "noise" in the list of result. Right-click a folder in your project tree and click...
...and other directories that you don't need to access during development and whose search results are irrelevant. They won't be deleted but simply ignored when searching across a...
...check checkboxes. But there's one problem, if you want to test a custom styled checkbox, which hides its -Tag: The methods cannot (un)check checkboxes without an visible .
...error message will be something like: Unable to find visible checkbox "Some label" that is not disabled Solution 1 Use the keyword argument allow_label_click: true within the method...
Sometimes, the rails dev server doesn't terminate properly. This can for example happen when the dev server runs in a RubyMine terminal. When this happens, the old dev server...
...blocks port 3000, so when you try to start a new server, you get the error: Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)
...filled out at the same time, there is no built-in validation. I've seen different solutions in the wild, each with different downsides: Private method referenced via validate: works...
...name, :nickname, xor_presence: true end Validator Here is the validator class; put it somewhere in your project. class XorPresenceValidator < ActiveModel::Validator def initialize(options) @attributes = Array.wrap(options[:attributes]).freeze...
Angular directives with isolate scopes have three different variable binding strategies, of which one is =. Example: # HTML # Coffeescript @app.directive 'panel', -> scope: evaluated: '=value' bound: '=twoway' link: -> scope.evaluated # = false scope.bound = 'foo...
...bound with = (value, twoway) have their value evaluated as Angular expression in the parent scope's context and have the result assigned to the corresponding scope variable (evaluated, bound). It...
...have multiple exported resources that are identical. There are nodes that provide the same services for failover reasons. It is likely to have duplicate resources, when exporting nagios_check from...
...everything is fine. But when it comes to realizing the resources on the monitoring server, the puppetrun will fail due to the duplicate addresses. So how to mitigate this issue...
A datetime in MySQL does not have a zone. It just stores the literal string "2010-05-01 12:00:00". That means that Rails must make...
...mode Rails assumes that your application lives in the same time zone as your server's local zone settings. In this mode ActiveRecord will not try to convert times coming...
It's not possible to change the bwlimit of Proxmox storages via the Web-UI (at least in Proxmox 7.x). To change the bwlimit you need to use the...
...pvesm command and specify the limit for the desired category. For example to increase the bwlimit for migrations: pvesm set $NAME_OF_STORAGE --bwlimit migration=$INTEGER_LIMIT # example
If others on a call (Skype, SIP, ...) can not hear you loud enough, your volume levels are probably too low. Also, Skype may be changing your mixer levels.
...proper recording volume Open your mixer software (run pavucontrol). Switch to input devices. If you have more than one recording device, find the correct one. Make a test call to...
If you want to to create maps within SASS/SCSS-files, it normally works like this: $some-map: (key1: value1, key2: value2) However, some maps can get big really fast, if they...
...since 2011 and it hasn't been resolved since then. Writing a map likes this: $some-map: ( key1: value1, key2: value2 ) confuses the SASS-parser and you will get an...
...is pretty useful, but manipulating values of arrays can be awkward because of its syntax. Consider the following users table which each example below will start from: name topics
Bob {llamas} (PostgreSQL uses curly braces to represent arrays, true story.) Adding values Use the array_cat function, or the || operator. These calls will add the values "cats...
Sometimes it is useful to define a named scope by implementing a static method with the scope's name on the scoped class. For instance, when a method should decide...
...which existing scope should be the next link in the scope chain. Take this class for example: class Meal < ActiveRecord::Base named_scope :for_date, lambda { |date| :conditions => { :date => date...
Stringex is a gem that offers some extensions to Ruby's String class. Ruby 1.9 compatible, and knows its way around unicode and fancy characters...
...Examples for stringex's String#to_url method: # A simple prelude "simple English".to_url => "simple-english" "it's nothing at all".to_url => "its-nothing-at-all"
Today I needed to execute a ruby gem executable with sudo. But, surprisingly, bash would tell me command not found for the gem that ran lovely without sudo.
...are installed to /var/lib/gems/1.8/bin, which is not in sudo’s PATH. Unfortunately, you can’t change the path, since sudo for Ubuntu is compiled with the --with-secure-path option...
SVG files are often much larger than necessary, containing comments, metadata, hidden elements etc. Optimize them with this tool. Web UI: https://jakearchibald.github.io/svgomg/ Binary: https://github.com/svg/svgo
...for a properly scaling SVG, you need to keep the viewBox attribute. There's an option --disable=removeViewBox for this...
When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app: app/assets/fonts app/assets/images app/assets/javascripts app/assets/stylesheets With the asset pipeline, you can use the...
When you deploy, Rails runs assets:precompile which precompiles all assets into static files that live in public/assets. This way you have all the performance of static files...
Ruby's standard library includes a class for creating temporary directories. Similar to Tempfile it creates a unique directory name. Note: You need to use a block or take care...
...of the cleanup manually You can create a prefix and suffix e.g. Dir.mktmpdir(['foo', 'bar']) => /tmp/foo20220912-14561-3g93n1bar You can choose a different base directory than Dir.tmpdir e.g. Dir.mktmpdir('foo', Rails.root.join('tmp...
ActiveRecord provides the ids method to pluck ids from a scope, but what if you need to pluck Global IDs? While you could just call map(&:to_global_id) on...
...your scope, this approach would instantiate each record just to do that. When you have many records, this will at the very least be slow. Here is a method that...
ActiveRecord offers an explain method similar to using EXPLAIN SQL statements on the database. However, this approach will explain all queries for the given scope which may include joins or...
Output will resemble your database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users` WHERE...
...is edited by WSYIWYG-Editor but want some length checking nevertheless, you need to strip all tags and then the special characters: def hard_sanitize(text) ActionController::Base.helpers.strip_tags(text...
...gsub(/[^[:word:]]+/, " ") end :001 > hard_sanitize("This is beautiful markup ") => "This is beautiful markup" If you allready have nokogiri on board, you can use that as well, though it has...
...when you work for clients from Europe or the US, there are two dominantish standards you should know about. Each of these has subtle differences. ISO 8601 This is adhered...
...to by most European countries. Weeks start on Monday and end on Sunday. To get the number of the weekday in Ruby as defined by ISO 8601, use Date#cwday...
...we use pagination Exercises Create 7500 movies in MovieDB (hint: Doing it in a single transaction is much faster). Load the movies index and measure how long it renders.
...the movies index render now? Inspect the HTML generated by will_paginate. Customize the style so it matches the look of your MovieDB. tail -f log/development.log and see which queries...
Delegating methods to other objects is often helpful but the syntax of both def_delegators and def_delegator is a complete mess that makes your code hard to read.
...ActiveRecord::Base belongs_to :topic def_delegators :topic, :title, :category end Here, we can say Post.new.title and actually read title from the Post's Topic object. Because of what we...