setTimeout() executes a function after some time. What does the following print in 1 second? Why? setTimeout(student.sayHello, 1000) What does the following print in 1 second? Why?

...function() { student.sayHello() }, 1000) What does the following print in 1 second? Why? setTimeout(student.sayHello.bind(student), 1000) Now we use another object: var student = { name: 'Anna', sayHello: function() { console.log("Hello, my...

makandra dev
github.com

...used for the same effect. Relation#to_sql # Rails 2 scope Post.scoped(:conditions => { :id => [1, 2] }).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" ^ # Rails 3 relation...

...Post.where(:id => [1, 2]).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" Implementation note: Rails 3+ implements #to_sql. Relation#to_id_query Site.joins(:user).where(:users...

regular-expressions.info

...A-Za-z0-9]+> is easier to write but matches invalid tags such as <1>. Use \b[1-9][0-9]{3}\b to match a number between 1000 and...

...Use \b[1-9][0-9]{2,4}\b matches a number between 100 and 99999. Modes: Greedy, Lazy and Possessive Example string: This test is a first test string...

# for which the block evaluates to true, # the second containing the rest. (1..6).partition { |v| n.even? } #=> [[2, 4, 6], [1, 3, 5]] Works well with destructuring assignment...

even, odd = (1..6).partition { |n| n.even? } even #=> [2, 4, 6]

...to use our own daho.im service. All daho.im subdomains resolve to your local IP (127.0.0.1). That means you can use a different hostname for different apps, and you will stay...

...logged in in each app: http://foo-app.daho.im:3000 => 127.0.0.1 http://bar-app.daho.im:3000 => 127.0.0.1 http://bam-app.daho.im:3000 => 127.0.0.1 Caution It's safe to use daho.im since it's our own domain. Don't use...

end describe '#age' do it { is_expected.to validate_inclusion_of(:age).in_range(1..100) } end end See the shoulda-matchers README for a full list of matchers provided...

docs.ruby-lang.org

The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...

...different data types to be formatted, such as %f for floats: sprintf('%f', 1) # => 1.000000 Example: This is quite useful to replace long strings such as API endpoints which might...

github.com

...are three ways to define your own RSpec matchers, with increasing complexibility and options: 1) Use RSpec::Matchers.define RSpec::Matchers.define :be_a_multiple_of do |expected| match do |actual|

block expectations If you want to use a block expectation like expect { rand(100) }.to produce_different_results, you have to use this syntax and call supports_block_expectations...

developer.chrome.com

} entries.sort((a, b) => { if (a.kind === b.kind) { return a.name.localeCompare(b.name) } return a.kind === 'directory' ? -1 : 1 }) for (const entry of entries) { const connector = '├─' const childPrefix = prefix + '│ ' if (entry.kind === 'file') { const file...

...explains some options to make browsers wrap inside a long word like "Donaudampfschifffahrt". Option 1: hyphens CSS property (preferred) Modern browsers can hyphenate natively. Use the hyphens CSS property:

The hyphens property has good browser support. If you need to support Safari < 17, you may need to also set -webkit-hyphen. If a browser lacks the dictionary for...

...has_many :users end Here activity 42 has four users: activity = Activity.find(42) activity.users.ids # => [1, 2, 3, 4] Let's say we want to do the same on all activities...

By reloading the object, its full list of associated users is restored: activity.reload.users.ids # => [1, 2, 3, 4] Reset the association cache Or you can reset the association cache: activity.users.reset...

Unfiltered: `User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "secret-token"], ["LIMIT", 1]]` After the filter is applied:

...ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "[FILTERED]"], ["LIMIT", 1]]` Unfortunately, this mechanism is not always applied, because of code dependencies. Some are written by...

...MembershipJob.perform_later(membership) second_blocked_job = MembershipJob.perform_later(membership) # Verify blocking behavior assert_equal(1, SolidQueue::ReadyExecution.count) assert_equal(1, SolidQueue::BlockedExecution.count) blocked = SolidQueue::BlockedExecution.last assert_equal(second_blocked_job.provider_job_id...

...die Web Security 🇩🇪 provides essentials for the topic of this card. Read following chapters: (1) Security Principles (3.3) Sessions and Cookies (3.5) Same-Origin-Policy (4.2) Angriffsfläche / Attack Surface...

...Kryptographische Grundlagen (7) Authentifikation (8) Authorization (9) Session Management Ohne (9.4) JSON Web Tokens (10) Federation / Single-Sign on (11) Serverseitige Angriffe (12) Clientseitige Angriffe (13) Clientseitige Schutzmaßnahmen

...a running JVM process you can use jcmd. List the running processes: $ jcmd -l 1 /app.jar 140 jdk.jcmd/sun.tools.jcmd.JCmd -l The first column shows the PID of the process.

...system configuration with the PID: $ jcmd 1 VM.system_properties 1: #Thu Jan 26 10:34:20 UTC 2023 java.specification.version=17 sun.jnu.encoding=UTF-8 java.class.path=/app.jar java.vm.vendor=Eclipse Adoptium sun.arch.data.model...

...with Rails 6 and below, or when the inverse scope may contain NULL values. [1] There are two different ways of "inverting a scope": As an example, consider the following...

...role" IN ('admin', 'superuser')) That also works with range conditions like where(created_at: 1.week.ago..), but does not work for missing (because its join statement is lost). So, sadly this...

...class that includes your module, and no longer exists after your test has finished. 1. Defining the class and assigning to a constant (preferred) describe Notifier do before do

masilotti.com

...quite manageable. Let’s dive into how this works. Only few fixture per model (1-2 is enough in most cases) You should only have a minimal amount of fixtures...

...User.count == 3 end Good example: test "user can be created" do assert_difference "User.count", 1 do post users_path, params: { first_name: "Foo", last_name: "Bar" } end end Conclusion

...and straightforward) Enable caching for individual test Enable caching for individual test (file cache) 1. Leave the default configuration 2. Add a caching helper which gives you a unique file...

...some_key')).to be(true) end end Enable caching for individual test (memory store) 1. Leave the default configuration 2. Now stub the Rails cache and clear it before each...

makandra dev

...within the diff. Colors The value for color configuration variables is a list of 1-2 colors and 0-1 attributes, separated by spaces. Colors: normal, black, red, green, yellow...

...Read the following chapters from The Pragmatic Programmer, anniversary edition (in our library): Chapter 1, Topic 3: Software Entropy Chapter 2, Topic 9: The Evils of Duplication Chapter 2, Topic...

...10: Orthogonality Chapter 5, Topic 28: Decoupling (and the Law of Demeter) Read the following chapters from Clean Code (in our library): Chapter 1: Clean Code Chapter 2: Meaningful Names...

Why nouns from the client domain do not always map to Ruby models 1:1. E.g. although an "address book contact" and a "user" are both human beings, it...

An example would be an AngularJS application where the following HTML actually works. [1] Hello Capybara will fail to find that link, even though looking it up via the...

...and click_link work, simply add href="#" to your element: Hello >> find_link("Hello") => # [1] Note that while it does work in your application (links are usually styled correctly, and...

...to the db you can list your keyspaces/databases with: # Show info about all databases 127.0.0.1:6379> INFO keyspace # Keyspace db0:keys=2674,expires=2663,avg_ttl=99821491105

...expires=466,avg_ttl=33842000297 db2:keys=12,expires=6,avg_ttl=23445951871 In this example you can see that we have 3 DBs. If you are unsure which DB...