...frozen, tainted and singleton methods are ignored (like dup) Behavior depends on implementation Hash: returns a deep copy, i.e. referenced objects/values will be deep_duped as well Array: returns a...
Timecop is a great gem to set the current time in tests. However, it is easy to introduce flakyness to...
...the following three possible values: critical, medium, low. Sorting with Issue.all.order(criticality: :desc) will return the following order: The 'medium' issue The 'low' issue The 'critical' issue This happens because...
...TYPE criticality AS ENUM ('low', 'medium', 'critical'); Sorting with Issue.all.order(criticality: :desc) will now return the following order: The 'critical' issue The 'medium' issue The 'low' isse
...falls back to a COUNT query count If a counter cache is set up, returns the cached value Issues a COUNT query else Caveats If you trigger a COUNT query...
...assertion. Using .size avoids this problem. length Loads all records from the database, then returns the number of elements
const path = require('path') const hq = require('alias-hq') function escapeStringRegexp(string) { return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') .replace(/-/g, '\\x2d') } const mapAliasedPath = hq.get(({ rootUrl, baseUrl, paths }) => { return (importPath) => {
...importPath.includes('@')) { return importPath } const basePath = path.join(rootUrl, baseUrl) for (const [aliasedPath, replacements] of Object.entries(paths)) { const regexp = new RegExp('(^|.*/)' + escapeStringRegexp(aliasedPath).replace('\\*', '(.*)')) importPath = importPath.replace(regexp, path.join(basePath, replacements[0]).replace...
}).observe({ type: 'largest-contentful-paint', buffered: true }) // Helpers ///////////////////////////////////////////////////////////////////// function dedupe(arr, key) { return [...new Map(arr.map((item) => [item[key], item])).values()] } function getActivationStart() { const navEntry = getNavigationEntry() return (navEntry...
...getNavigationEntry() { const navigationEntry = self.performance && performance.getEntriesByType && performance.getEntriesByType('navigation')[0] if ( navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now() ) { return navigationEntry } } When optimizing LCP, these extra steps may be helpful: # media_performance_steps.rb Then(/^the image "(.*)" should...
...hour format, @: same, but in 12-hour am/pm format \n: newline \r: carriage return \\: backslash Colors & Styles colors have to be escaped (see General), color codes should be followed by...
...30m\]>\[\033[00m\] ' => ✔ mycomputer ~/projects/platforms master > _ # Arne's epic timestamped prompt with return status indicator and status-colored (green if fresh, or red if unstaged, or yellow if staged) git...
Let's say we want Peter to respond to a method age that returns his age. On the other hand, Alice should not respond to this method as you...
...is empty, it's just discarded. Careful: In peter's case peter.class does not return his eigenclass now. It still returns User. This means the klass reference in the C...
...probably looks "nothing special", which is good. export async function deleteComment({ uuid }: { uuid: string }) { return withAuthorizedUser(async ({ accessibleBy }) => { const prisma = await prismaClient() const comment = await prisma.comment.findUnique({ where: { uuid }, include: { file...
}) if (!comment) { return notFound() } await prisma.comment.delete({ where: { uuid, AND: accessibleBy('delete').Comment, }, }) revalidatePath(`/backend/files/${comment.file.directoryUuid}`, 'layout') return 'ok' }) } Set up prettier First, add the prettier npm package.
...scrollable element for the main viewport. On Chrome, Firefox and modern Safari, document.scrollingElement will return the element. The behavior varies on legacy browsers that we no longer support:
...versions, document.scrollingElement will return the element. On the legacy Edge engine (EdgeHTML), document.scrollingElement will return the element. IE11 does not support document.scrollingElement, but you can assume its . Setting overflow-y...
...it considers your connection to be offline. async function isOnline({ path, timeout } = {}) { if (!navigator.onLine) return false path ||= document.querySelector('link[rel*=icon]')?.href || '/favicon.ico' timeout ||= 6000 const controller = new AbortController()
...timeoutTimer = setTimeout(() => controller.abort(), timeout); try { await fetch(path, { cache: 'no-store', signal: controller.signal }) return true } catch(error) { return false } finally { clearTimeout(timeoutTimer) } } Limitations of built-in navigator.onLine
...Makes a color less saturated. grayscale($color) Converts a color to grayscale. complement($color) Returns the complement of a color. invert($color) Returns the inverse of a color...
...the File System Access API. Please try a modern browser like Chrome or Edge.') return } const processDirectory = async (dirHandle, pathPrefix, prefix = '') => { const entries = [] for await (const entry of dirHandle.values()) { entries.push...
} 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...
...binary cannot run at all, but won't raise an error if the binary returns an exit code > 0. This will instead be reflected in status. stdout_str, error_str...
...str = stderr.read # read stderr to string status = wait_thr.value # will block until the command finishes; returns status that responds to .success? etc end This form is useful for long running commands...
...e.g. Article#name becomes Article#name_de and Article#name_en and Article#name returns the variant in the current locale. You also need a migration strategy to fill those...
...You can set it up to store timestamps as UTC in the database, but return magic, zone-aware values when accessing ActiveRecord time or date attributes. In practice this solution...
...this object. Here are some tools to do so: Relevant methods @object.methods - Object.instance_methods returns a list of methods excluding methods inherited from Object. This makes the methods list drastically...
...filters the list of method names with a regular expression. Instance variables @object.instance_variables returns all instance variables defined on the object. Access them with @object.instance_variable_get :@varname, modify...
...probably only care about seconds. This means that two consecutive calls of Time.now probably return two inequal values. Consider freezing time in your tests so it is not dependent on...
Rails extends Time with a method #end_of_day which returns the latest possible Time on the same day. The exact value for this is...
...record, as well as to query the record for registered errors. This object is returned when calling .errors: errors = @user.errors # => # Here are some helpful messages of its API: [ ]
...error message from the locale files. get( ) (Almost) an alias of []. Calls messages[ ] and returns an array of error messages for that attribute. include?( ) Returns whether there is an error...
...method to detect the end of the scrolling animation. Methods like scrollTo() don't return a promise. We may eventually get a scrollend event, but that is still some time...
Until then I'm using the following awaitScrollEnd() function as a workaround. It returns a promise that resolves when the given Document or Element does not receive a scroll...
...can, don't permit! everything but permit only known good keys. Use request.path_parameters returns a Hash with all parameters relevant for building a path with e.g. url_for (excluding...
...and similar). Note that it does not include query parameters. Use params.to_unsafe_h returns a HashWithIndifferentAccess with everything from params. If none of the above was enough for you...
def __init__(self): GObject.Object.__init__(self) def get_background_items(self, window, file): """Returns the menu items to display when no file/folder is selected (i.e. when right-clicking the...
...file.is_directory() and file.get_uri_scheme() == "file": if os.path.exists(TERMINAL_PATH): items += [self._create_terminal_item(file)] return items def _setup_gettext(self): """Initializes gettext to localize strings.""" try: # prevent a possible exception...
...an array with a block that is called with each element. The block must return a [key, value] tuple. This is useful if both the hash key and value can...
...a block. The block is called for each element in the array and should return a 2-tuple where the first element is the key and the second element is...
...attached files to config/initializers. It gives your strings a method #to_sort_atoms that returns an object that compares as expected. You can now say: ["Schwertner", "Schöler"].sort_by(&:to...
...of #to_sort_atoms: describe String do describe '#to_sort_atoms' do it 'should return an object that correctly compares German umlauts' do expect('Äa'.to_sort_atoms <=> 'Az'.to...
...Version uploader and original uploader can be distinguished by checking #version_name: version uploaders return the version name, whereas the original uploader instance returns nil Version instances do not have...