TLDR: Use for...of instead of forEach() in asynchronous code.
For legacy browsers, use for(...;...;...) or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
| import { Injectable } from '@angular/core'; | |
| import { BehaviorSubject, Observable } from 'rxjs'; | |
| export interface LoggerConfig { | |
| prefix?: string; | |
| color?: string; | |
| enabled: boolean; | |
| } | |
| @Injectable({ |
| /** | |
| * @license | |
| * Copyright (c) 2019 Jonathan Catmull. | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is | |
| * furnished to do so, subject to the following conditions: |
| upstream ws_server { | |
| server 127.0.0.1:8080; | |
| } | |
| server { | |
| listen 80; | |
| server_name 10.1.2.225; | |
| location / { | |
| proxy_pass http://ws_server/; |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent| function commarize() | |
| { | |
| // 1e6 = 1 Million, begin with number to word after 1e6. | |
| if (this >= 1e6) | |
| { | |
| var units = | |
| [ | |
| "Million", | |
| "Billion", | |
| "Trillion", |
| def factorial(n) | |
| (1..n).reduce(:*) | |
| end | |
| SECONDS_PER_STEP = 0.001 | |
| def total_seconds(n) | |
| factorial(n) * SECONDS_PER_STEP | |
| end |
| # Based on https://gist.github.com/fernandoaleman/5083680 | |
| # Start the old vagrant | |
| $ vagrant init ubuntu_saucy | |
| $ vagrant up | |
| # You should see a message like: | |
| # [default] The guest additions on this VM do not match the install version of | |
| # VirtualBox! This may cause things such as forwarded ports, shared | |
| # folders, and more to not work properly. If any of those things fail on |
| <%= simple_form_for @job, html: { class: "form-horizontal" } do |f| %> | |
| <% new_and_edit_form_fields.each do |column| %> | |
| <%= f.input *column %> | |
| <% end %> | |
| <% end %> |
Originally published in June 2008
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.