atlassian.com

By file Only commits that introduced changes to a specific file git log -- foo.rb bar.rb Note In case the file was renamed or moved the --follow option can be...

git log --follow -- foo.rb By content If you want to know when a specific line of code was added in the project git log -S"def function_name"

...sets the value to the specified query parameter more Example const params = new URLSearchParams('foo=bar') params.append('baz', 'baq') params.toString() // 'foo=bar&baz=baq' params.delete('baz') params.toString() // 'foo=bar'

params.has('foo') // true params.set('foo', 'baz') params.toString() // 'foo=baz' Working with URLs You can also easily use the URLSearchParams API if you have an URL or an URL...

CONCAT('foo', 'bar', NULL) = NULL the NULL always wins in MySQL. If you would rather treat NULL as an empty string, use CONCAT_WS (concatenation with separator) instead...

...CONCAT_WS('', 'foo', 'bar', NULL) = 'foobar' PostgreSQL In PostgreSQL the NULL is not viral in CONCAT: CONCAT('foo', 'bar', NULL) = 'foobar...

it { should allow_value("email@addresse.foo").for(:sender) } it { should_not allow_value("foo").for(:sender) } # Rspec 3 expect syntax it { is_expected.to allow_value("email@addresse.foo").for(:sender) } it { is_expected.not...

...to allow_value("foo").for(:sender) } end Errors that may occur if you do use should validate_format_of(...): NoMethodError: private method `gsub' called for /\A[a-z0-9\-_]+\z...

Typhoeus has a different way of representing array params in a get request than RestClient. Typhoeus: http://example.com/?foo[0]=1&foo[1]=2&foo[2]=3

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

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

github.com

...for sidekiq works as expected and the retries total duration fits. # Example: TestWorker.perform_async('foo', 'bar') class TestWorker include Sidekiq::Worker def perform(*args) raise 'This is a test error...

...to remove blank values from collections (e.g. arrays). Remove nil values from an array ['foo', nil].compact # => ['foo'] # You can use the splat operator to ignore nil values when constructing...

['foo', *nil] # => ['foo'] Remove blank values from collections Array array = [1, "", nil, 2, " ", [], {}, false, true] # Any Rails version array.reject(&:blank?) # => [1, 2, true] # Since Rails 6.1+ array.compact_blank...

thoughtbot.github.io

...share some attributes and traits: FactoryBot.define do factory :user do screen_name 'john' email 'foo@bar.de' trait :with_profile do age 18 description 'lorem ipsum' end end factory :client do

...name 'John Doe' email 'foo@bar.de' trait :with_profile do age 18 description 'lorem ipsum' end end end You can re-use the shared fields by defining a trait outside the...

...Date and Time to that list, but other classes could also make sense. data = {foo: 'bar'}.to_yaml ::YAML.safe_load(data) Psych::DisallowedClass: Tried to load unspecified class: Symbol

...load(data, [Symbol]) => {:foo=>"bar"} Pitfall 2: Psych::BadAlias Psych#dump will create aliases if you reference the same object more than one time. By default this is disabled by...

Check if an object (or its prototype) has a property CoffeeScript var hasFoo = 'foo' of object JavaScript var hasFoo = 'foo' in object; Iterate through all properties of an object...

makandra dev

...you can also render a partial within a helper. #_mobile_navigation.html.haml .mobile_navigation .htmlclass .htmlclass .foo links.each do |link| = link_to(link) module SomeHelper def render_mobile_navigation links = build_links...

def long_message puts(<<-EOT) Here goes a very long message... Sincerely, foobear EOT end <<-EOT will be somewhat of a placeholder: anything you write in the line...

...the example above will be " Here goes a very long message...\n Sincerely,\n foobear\n". Depending on where you use it, this may or may not be a problem...

makandra dev
ruby-doc.org

...When you compare two objects in ruby, you most often see the use of foo == bar. By default the == operator inherits from Object and is implemented as object identity (see...

makandra dev

...files to access their full history. Given a file "bar" that was previously named "foo": touch foo git add foo git commit -m "Add foo" mv foo bar

git commit -m "Rename foo to bar" git log bar commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow) Author: Michael Leimstaedtner <makmic@makandra.de> Date: Wed May 12 08:49:37 2021 +0200

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

The reason is that each_with_index yields 2 elements to the block, and you need to deconstruct the first element (a tuple of key and value) explicitly...

github.com

...scope to pluck all the ids of the relation: # Modern Rails User.where("users.name LIKE 'Foo Bar'").ids # Rails 3.2+ equivalent User.where("users.name LIKE 'Foo Bar'").pluck(:id) # Edge rider equivalent...

User.where("users.name LIKE 'Foo Bar'").collect_ids

makandra dev

...will comment code so it will not be sent to the client: -# = link_to 'foo' 99% of the time you'll be adding notes for other developers, or disabling code...

...background-image: url('../images/foo.png') won't work any longer, because there is no public/assets/images. foo.png now lives directly in public/assets. Example app/assets/fonts app/assets/fonts/fonts_root.css app/assets/fonts/fonts_root.js app/assets/fonts/fonts_root.png app/assets/fonts/fonts_root.ttf app/assets/fonts/subfolder app/assets/fonts/subfolder/fonts_subfolder.css app/assets/fonts/subfolder/fonts_subfolder.js app/assets/fonts/subfolder/fonts_subfolder.png...

...in the first place. Simply use the SASS helper: .tile background-image: image-url('foo.png') Managing 3rd party assets You don't want to manually fix references in external libraries...

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

makandra dev

...or IIFEs) to prevent local variables from bleeding into an outside scope: (function() { var foo = "value"; // foo is scoped to this IIFE })(); In Coffeescript an IIFE looks like this: (->

...value" # foo is scoped to this IIFE )() There is also a shorthand syntax with do: do -> foo = "value" # foo is scoped to this IIFE You can also use do with...

makandracards.com

options = { settings: { number_of_replicas: NUMBER_OF_REPLICAS}, } searchick **options ... end Class Foo < ActiveRecord::Base include DoesSearch ... Our operations team used to patch the number_of_replicas setting...

...an element "the container's width minus 20px on each side"? Here you go: .foo { width: calc(100% - (20px * 2)); } When using Sass, you need to interpolate Sass expressions:

.foo width: calc(100% - #{$margin}) Supported by all modern browsers and IE9...

...speed a like query that has a wildcard on the right side: SELECT * FROM foo WHERE field LIKE "bar%" # will be faster with an index It can not speed up...

...a query that has a variable left side: SELECT * FROM foo WHERE field LIKE "%bar%" # will not be faster with an index That also means if you use the ancestry...