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

Capistrano automatically logs each (successful) deployment into a file on your application servers. It is located at the root of your server's project folder, i.e. the parent of releases...

...and current, like so: /var/www/your-project$ ls current log releases repo revisions.log <--- here shared Each line in that file contains the deployed branch, commit, release ID, and username (was read from...

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

makandra dev

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

joshmcarthur.com

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

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

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

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

stackoverflow.com

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

makandra dev

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

api.jquery.com

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

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

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

stefanjudis.com

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.

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

github.com

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

makandra dev
medium.com

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

makandra dev

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

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

...like invoices/generated?number=123. This could be your (very careless) controller method: def generated send_file File.join(Rails.root, 'shared', 'invoices', params[:number]) end This allows your users not only to...

...files but also any files your application can read, like this: invoices/generated?number=../../../../../etc/passwd # => send_file '/etc/passwd' You do not want this. In most cases you should prefer a show...

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

makandra dev

...your remote database, you might not want it to dump each time you deploy (say, you're experimenting with staging and don't want ten dumps an hour). How to...

...skip dump creation: Capistrano 2 In your Capistrano file: before 'deploy:update_code', 'db:dump' unless fetch(:skip_dump, false) The second parameter of fetch sets a default value if...

makandra dev

...of control”. A function that accepts a callback instead of a return value is saying, “Don’t call me, I’ll call you.”. Promises un-invert the inversion, cleanly separating...

...the input arguments from control flow arguments. This simplifies the use and creation of APIs, particularly variadic, REST and spread arguments. Note that promises are not a drop-in replacement...