- Sep 2024
-
blog.nodejitsu.com blog.nodejitsu.com
-
Want to really annoy an open-source maintainer? Then ignore any communication channels they have setup for support.
-
- Apr 2024
-
arxiv.org arxiv.org
-
A transition s → s′ ∈ T is correct, and a computation of correct transitionsis correct.
Tags
Annotators
URL
-
- Jan 2024
-
pileofindexcards.org pileofindexcards.org
-
You can order Correct’s indexcard, dock, and Kokuyo’s fieldnote via the Service page.
Hawk Sugano apparently offered the Pile of Index Cards as a physical product offering by combining Correct's index card dock and Kokuyo's fieldnotes in late December 2006.
-
-
mongoosejs.com mongoosejs.com
-
Instance methods Instances of Models are documents. Documents have many of their own built-in instance methods. We may also define our own custom document instance methods. // define a schema const animalSchema = new Schema({ name: String, type: String }, { // Assign a function to the "methods" object of our animalSchema through schema options. // By following this approach, there is no need to create a separate TS type to define the type of the instance functions. methods: { findSimilarTypes(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); } } }); // Or, assign a function to the "methods" object of our animalSchema animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); }; Now all of our animal instances have a findSimilarTypes method available to them. const Animal = mongoose.model('Animal', animalSchema); const dog = new Animal({ type: 'dog' }); dog.findSimilarTypes((err, dogs) => { console.log(dogs); // woof }); Overwriting a default mongoose document method may lead to unpredictable results. See this for more details. The example above uses the Schema.methods object directly to save an instance method. You can also use the Schema.method() helper as described here. Do not declare methods using ES6 arrow functions (=>). Arrow functions explicitly prevent binding this, so your method will not have access to the document and the above examples will not work.
Certainly! Let's break down the provided code snippets:
1. What is it and why is it used?
In Mongoose, a schema is a blueprint for defining the structure of documents within a collection. When you define a schema, you can also attach methods to it. These methods become instance methods, meaning they are available on the individual documents (instances) created from that schema.
Instance methods are useful for encapsulating functionality related to a specific document or model instance. They allow you to define custom behavior that can be executed on a specific document. In the given example, the
findSimilarTypes
method is added to instances of theAnimal
model, making it easy to find other animals of the same type.2. Syntax:
Using
methods
object directly in the schema options:javascript const animalSchema = new Schema( { name: String, type: String }, { methods: { findSimilarTypes(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); } } } );
Using
methods
object directly in the schema:javascript animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); };
Using
Schema.method()
helper:javascript animalSchema.method('findSimilarTypes', function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); });
3. Explanation in Simple Words with Examples:
Why it's Used:
Imagine you have a collection of animals in your database, and you want to find other animals of the same type. Instead of writing the same logic repeatedly, you can define a method that can be called on each animal instance to find similar types. This helps in keeping your code DRY (Don't Repeat Yourself) and makes it easier to maintain.
Example:
```javascript const mongoose = require('mongoose'); const { Schema } = mongoose;
// Define a schema with a custom instance method const animalSchema = new Schema({ name: String, type: String });
// Add a custom instance method to find similar types animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); };
// Create the Animal model using the schema const Animal = mongoose.model('Animal', animalSchema);
// Create an instance of Animal const dog = new Animal({ type: 'dog', name: 'Buddy' });
// Use the custom method to find similar types dog.findSimilarTypes((err, similarAnimals) => { console.log(similarAnimals); }); ```
In this example,
findSimilarTypes
is a custom instance method added to theAnimal
schema. When you create an instance of theAnimal
model (e.g., a dog), you can then callfindSimilarTypes
on that instance to find other animals with the same type. The method uses thethis.type
property, which refers to the type of the current animal instance. This allows you to easily reuse the logic for finding similar types across different instances of theAnimal
model.
Tags
Annotators
URL
-
- Nov 2023
-
humanitec.com humanitec.com
-
gitlab.com gitlab.com
-
I think we are a victim of behavioural norms and so many of the apps that I use have this pattern. That's not to say it's the right behaviour, but it may be hard to break the pattern for users.
-
- Jul 2023
-
www.amazon.com www.amazon.com
-
www.flickr.com www.flickr.com
-
https://www.flickr.com/photos/hawkexpress/194730263
Hawk Sugano used a Correct Indexcard Dock (C-153DF) box for some of his index card practice.
-
- Dec 2022
-
www.rfc-editor.org www.rfc-editor.org
-
This can lead to the sending of email to the correct address but the wrong recipient.
-
-
nickjanetakis.com nickjanetakis.com
-
It’s as simple as running ngrok http 3000 to forward port 3000 (or any port) to a public ngrok address.
We're not forwarding local port 3000 to a public ngrok address — we're doing it in the opposite direction, as the previous sentence just (correctly) stated:
a secure tunnel to localhost
-
-
support.google.com support.google.com
-
Include one or both of these headers in your messages:
Actually, if you include List-Unsubscribe-Post, then you MUST include List-Unsubscribe (both).
According to https://www.rfc-editor.org/rfc/rfc8058#section-3.1,
A mail sender that wishes to enable one-click unsubscriptions places one List-Unsubscribe header field and one List-Unsubscribe-Post header field in the message. The List-Unsubscribe header field MUST contain one HTTPS URI. It MAY contain other non-HTTP/S URIs such as MAILTO:. The List-Unsubscribe-Post header MUST contain the single key/value pair "List-Unsubscribe=One-Click".
-
- Nov 2022
-
github.com github.com
-
by using symbols as keys, you will be able to use the implicit conversion of a Mash via the #to_hash method to destructure (or splat) the contents of a Mash out to a block
Eh? The example below:
symbol_mash = SymbolizedMash.new(id: 123, name: 'Rey') symbol_mash.each do |key, value| # key is :id, then :name # value is 123, then 'Rey' end
seems to imply that this is possible (and does an implicit conversion) because it defines
to_hash
. But that's simply not true, as these 2 examples below prove:``` main > symbol_mash.class_eval { undef :to_hash } => nil
main > symbol_mash.each {|k,v| p [k,v] } [:id, 123] [:name, "Rey"] => {:id=>123, :name=>Rey} ```
``` main > s = 'a' => a
main > s.class_eval do def to_hash chars.zip(chars).to_h end end => :to_hash
main > s.to_hash => {a=>a}
main > s.each Traceback (most recent call last) (filtered by backtrace_cleaner; set Pry.config.clean_backtrace = false to see all frames): 1: (pry):85:in
__pry__' NoMethodError: undefined method
each' for "a":String ```
-
- Sep 2022
-
auth0.com auth0.com
-
However, while URLs allow you to locate a resource, a URI simply identifies a resource. This means that a URI is not necessarily intended as an address to get a resource. It is meant just as an identifier.
However, while URLs allow you to locate a resource, a URI simply identifies a resource.
Very untrue/misleading! It doesn't simply (only) identify it. It includes URLs, so a URI may be a locator, a name, or both!
https://datatracker.ietf.org/doc/html/rfc3986 states it better and perfectly:
A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location").
This means that a URI is not necessarily intended as an address to get a resource. It is meant just as an identifier.
The "is not necessarily" part is correct. The "is meant" part is incorrect; shoudl be "may only be meant as".
-
- Apr 2022
-
-
Unless new evidence comes to bear that refutes the basic tenets of this analysis
that's a fun way to say this...
-
- Dec 2021
-
-
The results of the study showed that object control motor skills (such as kicking, catching, and throwing a ball), were better in the children who played interactive games.“This study was not designed to assess whether interactive gaming can actually develop children’s movement skills, but the results are still quite interesting and point to a need to further explore a possible connection,” said Dr. Lisa Barnett, lead researcher on the study.“It could be that these children have higher object control skills because they are playing interactive games that may help to develop these types of skills (for example, the under hand roll through playing the bowling game on the Wii). Playing interactive electronic games may also help eye-hand coordination.”
This is a deductive argument because the logical premise which is that video games can improve motion control skills is supported by a logical premises which is the evidence from Dr. Lisa Barnett. This premises leads to the conclusion that video games can improve motor skills.
-
- Aug 2021
-
github.com github.com
-
Please correct me if anything in there is incorrect!
-
- Jul 2021
-
twitter.com twitter.com
-
ReconfigBehSci on Twitter. (2020). Twitter. Retrieved 27 February 2021, from https://twitter.com/SciBeh/status/1339855911796543488
-
- Jun 2021
-
github.com github.com
-
In the context of git, the word "master" is not used in the same way as "master/slave". I've never known about branches referred to as "slaves" or anything similar. On existing projects, consider the global effort to change from origin/master to origin/main. The cost of being different than git convention and every book, tutorial, and blog post. Is the cost of change and being different worth it? PS. My 3 projects were using your lib and got broken thanks to the renaming. PS. PS. I'm glad I never got a master's degree in college!
-
-
www.theserverside.com www.theserverside.com
-
the benefits of GitHub renaming the master branch to main far outweigh any temporary stumbling blocks. He said the change is part of a broader internal initiative to add inclusive language to the company's systems. His team is also replacing whitelist and blacklist with allowlist and blocklist.
-
"Both Conservancy and the Git project are aware that the initial branch name, 'master,' is offensive to some people and we empathize with those hurt by the use of that term," said the Software Freedom Conservancy.
-
-
www.mutuallyhuman.com www.mutuallyhuman.com
-
I’m going to add the API Server as an actor to my first test sequence to give some granularity as to what I’m actually testing.
-
For features like websocket interactions, a single full-stack smoke test is almost essential to confirm that things are going as planned, even if the individual parts of the interaction are also covered by unit tests.
-
-
docs.gitlab.com docs.gitlab.com
-
How to test at the correct level?
-
As many things in life, deciding what to test at each level of testing is a trade-off:
-
- Apr 2021
-
stackoverflow.com stackoverflow.com
-
What's the "correct" semantic way to specify image height and width? In CSS... width:15px; or inline... <img width="15" ?
-
- Mar 2021
-
github.com github.comd3/d31
-
Microlibraries are easier to understand, develop and test. They make it easier for new people to get involved and contribute. They reduce the distinction between a “core module” and a “plugin”, and increase the pace of development in D3 features.
-
-
stackoverflow.com stackoverflow.com
-
Semantically this is wrong.
-
-
stackoverflow.com stackoverflow.com
-
Usually when people are talking about code being semantically correct, they're referring to the code that accurately describes something.
-
HTML elements have meaning. "Semantically correct" means that your elements mean what they are supposed to.
-
Semantically correct usage of elements means that you use them for what they are meant to be used for.
-
It means that you're calling something what it actually is.
-
The classic example is that if something is a table, it should contain rows and columns of data. To use that for layout is semantically incorrect - you're saying "this is a table" when it's not.
-
-
Fits the ideal behind HTML HTML stands for "HyperText Markup Language"; its purpose is to mark up, or label, your content. The more accurately you mark it up, the better. New elements are being introduced in HTML5 to more accurately label common web page parts, such as headers and footers.
Tags
- fundamental principles/paradigm of the Web
- explanation
- semantic markup
- simple explanation
- example
- calling something what it actually is (semantic labeling)
- good example
- be specific
- explicit meaning
- semantically correct
- good explanation
- use meaningful names (programming)
- definition
Annotators
URL
-
-
css-tricks.com css-tricks.com
-
You don’t need to do any tricky cursor stuff, because it’s all semantically wired up already.
-
always use real <label for="correct_input"> elements. Just that alone is a UX consideration all too many forms fail on
-
- Feb 2021
-
github.com github.com
-
now that I realize how easy it is to just manually include this in my app: <%= javascript_include_tag 'xray', nonce: true if Rails.env.development? %> I regret even wasting my time getting it to automatically look for and add a nonce to the auto-injected xray.js script
Tags
- removing feature that is more trouble than it's worth (not worth the effort to continue to maintain / fix bugs caused by keeping it)
- removing legacy/deprecated things
- regret
- wasted effort
- fix design/API mistakes as early as you can (since it will be more difficult to correct it and make a breaking change later)
- removing features to simplify implementation
Annotators
URL
-
-
www.theregister.com www.theregister.com
-
-
Allowlist, not whitelist. Blocklist, not blacklist. Goodbye, wtf. Microsoft scans Chromium code, lops off offensive words
-
a suggestion by Microsoft to “cleanup of potentially offensive terms in codebase” aims to rid the software blueprints of language such as whitelist (change to allowlist), blacklist (change to blocklist), “offensive terms using ‘wtf’ as protocol messages,” and other infelicities.
-
In May, Microsoft announced AI features in Word that, among other features, will emit “advice on more concise and inclusive language such as ‘police officer’ instead of ‘policeman.’"
-
-
trailblazer.to trailblazer.to
-
The new 2.1 version comes with a few necessary but reasonable changes in method signatures. As painful as that might sound to your Rails-spoiled ears, we preferred to fix design mistakes now before dragging them on forever.
-
The new call API is much more consistent and takes away another thing we kept explaining to new users - an indicator for a flawed API.
Tags
- if it's incorrect; fix it
- do it right/well the first time because it may be too hard to clean up/fix later if you don't
- learn from your mistakes
- pointing out gaps/downsides/cons in competition/alternatives
- better late than never
- fix design/API mistakes as early as you can (since it will be more difficult to correct it and make a breaking change later)
Annotators
URL
-
-
softwareengineering.stackexchange.com softwareengineering.stackexchange.com
-
This is not correct. Or at least, it is not entirely correct.
-
- Jan 2021
-
github.com github.com
-
The code is far simpler and easier to understand/verify
-
-
www.americanpressinstitute.org www.americanpressinstitute.org
-
The purpose of news is to inform, educate, and give us understanding and knowledge of what is going on in the world. It helps us to keep up to date with issues so we are in the know and fully aware of events taking place.
-
-
stackoverflow.com stackoverflow.com
-
text-decoration is more 'correct' because it is the 'real' CSS property meant for underlining text.
-
- Oct 2020
-
english.stackexchange.com english.stackexchange.com
-
Logistically speaking, I suppose "depender" and "dependee" would be more accurate, though neither of those are proper english words as far as I know.
-
In the context of software engineering, I've always used "dependent" and "dependee".
-
-
github.com github.com
-
virtual-dom exposes a set of objects designed for representing DOM nodes. A "Document Object Model Model" might seem like a strange term, but it is exactly that. It's a native JavaScript tree structure that represents a native DOM node tree.
-
- Sep 2020
-
www.changelogs.md www.changelogs.md
-
Move svelte into dependencies, as it was accidentally stuck in peerDependencies
"accidentally stuck in": well, not really accidentally; it's in the change log so I assume it was intentional
-
- Aug 2020
-
meta.stackexchange.com meta.stackexchange.com
-
Can't upvote this enough. It is highly irritating to see language destroyed (and we wonder why kids bastardize the language..).
Tags
- example of: using incorrect terms
- hoping/trying to convince others that your view/opinion/way is right by consistently sticking to it despite many being ignorant/mistaken/unaware/holding different opinion
- combating widespread incorrectness/misconception by consistently doing it correctly
- correctness
- even if majority makes a mistake; it doesn't make it correct
Annotators
URL
-
-
english.stackexchange.com english.stackexchange.com
-
my point is that using "into" in such a case is just as incorrect as using "inas" would be. The fact that people make mistakes doesn't change this.
"Log in" is the only correct way to spell the verb, and the only way to be consistent with 1000s of other phrasal verbs that are spelled with a space in them.
We don't need nor want an exception to the general rule just for "login" just because so many people have made that mistake.
-
- Feb 2020
-
loadimpact.com loadimpact.com
-
It is also good practice to make sure that your load testing is functionally correct. Both the performance and functional goals can be codified using thresholds and checks (like asserts).
-
- Feb 2019
-
www.literacyworldwide.org www.literacyworldwide.org
-
These discussions can be fraught with power dynamics, resulting in controversial issues appearing unbalanced as more powerful authors block alternative viewpoints.
Students need to know which information is going to be unbiased and true. There are MANY internet sources that use shock value information or biased information rather than presenting corect information.
-
- Jan 2018
-
hunabku.pbworks.com hunabku.pbworks.com
- Oct 2013
-
rhetoric.eserver.org rhetoric.eserver.org
-
The foundation of good style is correctness of language, which falls under five heads. (1) First, the proper use of connecting words, and the arrangement of them in the natural sequence which some of them require. For instance, the connective "men" (e.g. ego men) requires the correlative "de" (e.g. o de). The answering word must be brought in before the first has been forgotten, and not be widely separated from it; nor, except in the few cases where this is appropriate, is another connective to be introduced before the one required. Consider the sentence, "But as soon as he told me (for Cleon had come begging and praying), took them along and set out." In this sentence many connecting words are inserted in front of the one required to complete the sense; and if there is a long interval before "set out," the result is obscurity. One merit, then, of good style lies in the right use of connecting words. (2) The second lies in calling things by their own special names and not by vague general ones. (3) The third is to avoid ambiguities; unless, indeed, you definitely desire to be ambiguous, as those do who have nothing to say but are pretending to mean something. Such people are apt to put that sort of thing into verse.
What is really important is clarity.
Tags
Annotators
URL
-