Having a unique selector for an element is useful to later select it from JavaScript or to update a fragment with an Unpoly. Haml lets you use square brackets ([]) to...
...with ActiveRecord instances, which have a persisted #id and will hence generate the same selector over multiple renderings of the same view. Example - @users.each do |user| .row[user] = user.name
...message like this, rubygems.org might have issues with their ipv6 connectivity: $ bundle install Fetching source index from https://rubygems.org/ Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch...
...specs from https://rubygems.org/ due to underlying error <timed out (https://rubygems.org/specs.4.8.gz)> The (a little bit dirty) possible solution If that's actually the case, then you can try...
What are the advantages of a gem like memoized over the @variable ||= syntax? Why can it be dangerous to memoize class methods? Why is it often fine to...
...memoize instance methods? Resources Speeding up Rails with Memoization 4 Simple Memoization Patterns in Ruby (And One Gem) Don't use the || operator to set defaults Exercise
...the transcluded content before adding it to the DOM. # Directive template: """ """ transclude: true link: (scope, element, attributes, _controller, transclude) -> transclude (content) -> # Do custom stuff element.find('.wrapper').append(content)
...much more you can do with the transclusion function. For an in-depth introduction, see this Guide to Angular Transclusion. Also read the Angular docs on this...
You can use JavaScript to get or set cookie values on the client. Using the vanilla JavaScript API In JavaScript, document.cookie is an accessor to all cookies on the current...
...site. It looks like a String, but its setter is actually more powerful. When setting cookies this way, remember to set the path=/ option. Reading cookies A result may look...
...Use Before and After to avoid that. Details Consider this Cucumber feature file: Feature: Something that needs to be tested Background: Given a user And I sign in Scenario: Sign...
When I sign out Then I should see "Signed out" Scenario: Something else # ... Now, assume you have these step definitions: Around do puts "** Around: before yield" yield puts "** Around...
...to those fields that is case-insensitive. The model looked like this: create_table :shop_locations do |t| t.string :street t.string :house_number t.string :zip_code t.string :city t.belongs_to...
end But how to solve the uniqueness problem? Another day, another undocumented Rails feature! This time, it’s that ActiveRecord::Base.connection.add_index supports an undocumented option to pass a...
Ruby's regular expressions can be represented differently. When serializing them, you probably want to use inspect instead of to_s. For the examples below, consider the following Regexp object...
>> regexp.to_s => "(?mi-x:^f(o+)!)" inspect As the Ruby docs say: Perhaps surprisingly, #inspect actually produces the more natural version of the string than #to_s...
...IDENTIFIED BY 'some_password'; GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%'; Adjust MySQL configuration : Edit /etc/mysql/my.cnf: server-id = 1 log_bin = /var/log/mysql/mysql-bin.log replicate-do-db = some_project_production replicate-do-db...
...other_project_production replicate-ignore-db = mysql server-id needs to be unique among all connected master and slave servers. When replicate-do-db is provided only the chosen databases...
# the value from the form field's ngModel (which means it's not sent to the # server, and old values would not be overwritten). # # This directive makes sure that...
...form fields with an invalid value return an # empty string instead of undefined. for elementType in ['input', 'textarea', 'select'] @app.directive elementType, -> priority: 1 restrict: 'E' require: '?ngModel' link: (scope, element...
...an array, neither JavaScript/ES6+ nor libraries like LoDash offet that natively. Here is a simple function instead that modifies the input array in place. function moveArrayElement(array, element, offset) {
...It was what I needed, but you could easily adjust that. Check the linked StackOverflow post for more information and other implementations...
...Basic.encode_credentials for that, and put its result into the Authorization request header. Request specs For request specs, use the :header option. it 'requires authentication' do get '/' expect(response.status).to...
...username, password) get '/', header: { Authorization: encoded_credentials } expect(response.status).to eq(200) end Controller specs In controller specs, you can put then into request.env['Authorization']. it 'requires authentication' do
...unwrap(). Here is how. Consider the following example element. $container = $(' Hello World ') Let's say we want to discard any tags, but keep their contents. Simply find them, then dive...
When using state_machine you sometimes need to know whether an object may execute a certain transition. Let's take an arbitrary object such as a blog article as an...
...example that has those states: A -> B -> C -> D Additionally, you have transitions between the states as shown above. Let's call the transition between 'A' and 'B' transition_ab...
jQuery offers many different methods to move a selection through the DOM tree. These are the most important: $element.find(selector) Get the descendants of each element in the current set...
...of matched elements, filtered by a selector. Does not find the current element, even it matches. If you wanted to do that, you need to write $element.find(selector).addBack(selector...
The Interactive Advertising Bureau (IAB) is a European marketing association which has introduced a standard how advertising can be served to users in line with the General Data Protection Regulation...
...GDPR). This standard is called the TCF 2.0 (Transparency and Consent Framework). If you want to integrate any kind of advertising into a website, chances are the advertising network will...
When using Sidekiq in your application, you must write thread-safe code. This wiki page also lists gems that are known to be unsafe on threaded applications.
...gem that will also be used by a Sidekiq worker, make sure to confirm it's thread-safe...
Suppose you want to implement a publish/subscribe pattern in your Frontend application to react to data changes and events. First, you might be looking for an event emitter library.
If you're trying to start a cloud-init based Ubuntu VM with KVM you will suffer long boot times and confusing output on the terminal. If you want to...
...to remove cloud-init. wait until the VM boots login echo 'datasource_list: [ None ]' | sudo -s tee /etc/cloud/cloud.cfg.d/90_dpkg.cfg sudo apt-get purge cloud-init sudo rm -rf /etc/cloud/; sudo rm...
Note: Making a reverse proxy with nginx is much more straightforward. A reverse proxy is a "man in the middle" server that tunnels requests to another server. You can use...
...makes sure that it can fetch from HTTPS internally. You've basically built your custom SSL-stripping MITM attack server. If your proxy server should be accessible over HTTPS, use...
...relaying information to input variables it's happening via environment variables. Depending on the size of the content of the variable it might exceed your OS limits. This is independent...
A possible workaround is to use a generated file to load the input instead of the env variable, e.g. # WORKAROUND # the variable my_huge_input cannot be...
...why it’s important to find a way to order and maintain your routes. See: Clean your Rails routes: grouping Sometimes the routes.rb grows very fast and each line adds...
...confusion to it. Maybe it is time for a new approach. The quoted article suggests to split up your routes.rb into small partials to keep it clean. For example you...
Besides their default styling properties, HTML elements have a semantic meaning. For example, an h1 tag is usually styled with a larger font and bold, while it denotes "the single...
...single main content of a page nav for sets of navigation links article for independent, self-contained content section for sections like chapters, typically with a heading aside for content...
This is how you regain disk space from OpenStack instances if you are using kvm and qcow. If your instance used up all configured disk space once the disk file...
...remains big. You can end up in a situation where for example the instance use only 20GB disk space but the disk file on the server has 100GB (or even...