makandra dev

There are multiple ways to redirect URLs to a different URL in Rails, and they differ in small but important...

stackoverflow.com

...newIndex > -1 && newIndex < array.length) { // Remove the element from the array const removedElement = array.splice(index, 1)[0] // At "newIndex", remove 0 elements and insert the removed element array.splice(newIndex, 0, removedElement...

...negative to move towards the beginning): const list = [object1, object2, object3] moveArrayElement(list, object2, 1) // list => [object1, object3, object2] moveArrayElement(list, object2, -2) // list => [object2, object1, object3]

...Power.new(build(:user)) Power.with_power(power) do expect(power).to receive(:buildings).at_least(1).time.and_return [building, other_building] expect(build(:unit)).to allow_association_values(building, other_building...

...assignable_values generates: ... Power.with_power(power) do expect(power).to receive(:buildings).at_least(1).time.and_return [building, other_building] unit = build(:unit) expect(unit.assignable_buildings).to contain_exactly(building...

...with Selenium and Capybara despite these issues. Both have different advantages and drawbacks. Method 1: Inspecting the file without navigation There are ways to download and inspect a file without...

features/support/download_helpers.rb # This is an adapted approach from # https://collectiveidea.com/blog/archives/2012/01/27/testing-file-downloads-with-capybara-and-chromedriver module DownloadHelpers TIMEOUT = 10 module_function def download_path download_path = Rails.root.join("tmp/test_downloads#{ENV['TEST_ENV_NUMBER']}") FileUtils.mkdir_p...

makandra dev

...have a reference to their parent uploader class DemoUploader < CarrierWave::Uploader::Base process :resize # 1 before :cache, :do_something # 3 version :thumb do # 2 process :crop end private

index = 0 User.find_each do |user| printf("Progress: %.2f%%\r", index.to_f / count * 100) user.update!(role: 'member') index += 1 end

Ubuntu 18.04 uses systemd to manage services. There are basically two commands for listing all services and manipulating the state of a certain service: service and systemctl: service manages System...

...overrides LSB defaults (2 3 4 5). insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `bluetooth' overrides LSB defaults (0 1 6).

...mx), but set config.not_rfc_mx_lookup_flow = true. Validation methods explained Regex validation (1) is pretty straight-forward and basically "free" since you're not making and network connections...

...all known emails from a production application with a very "typo-heavy" user base (108k+ emails with 5.2k+ unique domains) and found no false positives. So I suggest you...

...you will only synchronize changes from hour 6-29, but forget changes from hour 1-4. Instead your cronjob should remember the last time a sync was performed successfully, and...

...the mocked property is a simple value, it will not work: const x = { foo: 1 } console.log(x.foo) // 1 spyOnProperty(x, 'foo').and.returnValue(2) // Throws: Error: : Property foo does not have...

...can be mocked with Jasmine. You can use it like this: const x = { foo: 1 } console.log(x.foo) // 1 spyOnValueProperty(x, 'foo').and.returnValue(2) expect(x.foo).toBe(2)

...hello', 'universe'].each_with_index do |value, index| puts "#{index}: #{value}" end # 0: hello # 1: universe This also works on hashes. However, mind the required syntax: { hello: 'universe', foo: 'bar...

...with_index do |(key, value), index| puts "#{index}: #{key} => #{value}" end # 0: hello => universe # 1: foo => bar The reason is that each_with_index yields 2 elements to the block...

...Enumerator for chaining with other methods: Person.find_each.with_index do |person, index| person.award_trophy(index + 1) end Ruby's map with index Similarly, you may need an index when using other...

...Here is an example for map: people.map.with_index do |person, index| person.at_rank(index + 1)

...effect that you can not configure Psych#dump to only write safe data. Pitfall 1: Psych::DisallowedClass Psych#safe_load only whitelists the following classes: TrueClass, FalseClass, NilClass, Numeric, String...

...optimize the result. time = Time.now data = {foo: time, bar: time}.to_yaml => => "---\n:foo: &1 2019-11-08 11:28:34.834180510 +01:00\n:bar: *1\n" ::YAML.safe_load(data...

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

...environment. Depending on your CSS framework you also need to adjust the z-index: 1. [data-environment=test] input

...might want to validate the MIME type in addition to the name extension. Solution 1 The solution you will see most often is that the model that has a Carrierwave...

makandra dev

...Advanced configuration It is helpful to set the global git config git config status.submodulesummary 1. This will add a short summary of the commits in the git submodules. Example:

...config status.submodulesummary 1 $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed...

raise ArgumentError, "Unknown type #{type}" end end end pretty_print_redis(Redis.new(host: "10.0.1.1", port: 6380, db: 15...

...Ruby 2.7 introduced a method for this exact purpose: filter_map. So instead of >> [1, 2, 3, 4, 5, 6].map { |i| i * 2 if i.even? }.compact

>> [1, 2, 3, 4, 5, 6].select(&:even?).map { |i| i * 2 } => [4, 8, 12] you can just do >> [1, 2, 3, 4, 5, 6].filter_map { |i| i...

uri = URI.parse(path) if allow_fuzzy_expiry expires_at = expires_at.end_of_hour + 1 end timestamp = expires_at.localtime.strftime('%Y%m%d%H%M%S') # this is similar to an hmac...

stackoverflow.com

...Explicit conversion Explicit conversion happens when requesting it, e.g. with the splat operator: args = [1,2,3] some_method(*args) # Ruby calls args.to_a here Implicit conversion Implicit conversion happens...

manpages.ubuntu.com

...run-this-one is exactly like run-one, except that it will use pgrep(1) and kill(1) to find and kill any running processes owned by the user

makandra dev

...log --oneline | fzf --prompt 'Select the first commit you want to move' | awk '{print $1}') branch=$(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | fzf --prompt 'Select the...

...branch to rebase onto' | awk '{print $1}') test_command="git rebase -i --onto $branch $commit~" read -p "Execute command '$test_command' (Y/n)? " choice case "$choice" in n|N ) echo "aborted...

Cookies without an expiration timestamp are called "session cookies". [1] They should only be kept until the end of the browsing session. However, when Chrome or Firefox are configured to...

...for quite a while now and it seems they won't change their mind. [1] We are not talking about the the Rails session cookie here, though it often is...

...a dependency of cucumber-rails), which will break all your tests. The fix Bundler >= 1.14 has a --conservative flag. Using the conservative flag allows bundle update GEM to update the...

The options below might be relevant if you're stuck with Bundler < 1.14: Option 1 This will work if all dependencies for the update are already satisfied.