- Jul 2024
-
tmurphy.physics.ucsd.edu tmurphy.physics.ucsd.edu
-
Given that assumptions of quantitativegrowth are pervasive in our society andhave been present for many generations,it is perhaps not surprising that growth isnot widely understood to be a transientphenomenon. Early thinkers on the physicaleconomy, such as Adam Smith, ThomasMalthus, David Ricardo and John Stuart Millsaw the growth phase as just that: a phase9
for - quote - economic growth - pioneering economists saw growth not as permanent, but as just a temporary phase
quote - economic growth - pioneering economists saw growth not as permanent, but as just a temporary phase - (see below) - Given that - assumptions of quantitative growth are pervasive in our society and - have been present for many generations, - it is perhaps not surprising that growth is not widely understood to be a transient phenomenon. - Early thinkers on the physical economy, such as - Adam Smith, <br /> - Thomas Malthus, - David Ricardo and - John Stuart Mill - saw the growth phase as just that: a phase
-
- Jun 2024
-
www.dalailama.com www.dalailama.com
-
it’s important to know that it is the perfection of wisdom rather than the perfection of meditation that is stressed as the key to attaining enlightenment.
for - quote - HH Dalai Lama - attaining enlightenment through wisdom, not just meditation
quote - HH Dalai Lama - attaining enlightenment through wisdom, not just meditation - (see below) - Even today I meet Buddhists in Japan for example - who tell me that Buddhahood can be attained through non-conceptual meditation, - but there seems little room for wisdom. - I feel it’s important to know that - it is the perfection of wisdom rather than - the perfection of meditation - that is stressed as the key to attaining enlightenment
-
- Jan 2024
-
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
-
-
gitlab.com gitlab.com
-
I feel that the current design area should be a key part of the workflow on any work item, not just type of designs. As a PM I don't schedule designs independently. It's odd to open and close a design issue when it doesn't deliver value to the customer.
-
- Jun 2023
-
stackoverflow.com stackoverflow.com
-
If it's dangerous, note it in the class/method Javadocs, don't just blindly slam the door shut.
-
- Mar 2023
-
stackoverflow.com stackoverflow.com
-
Just because the code is described as part of the WebDAV spec doesn't mean it's WebDAV-specific! Status codes are supposed to be generic.
-
- Oct 2022
-
stackoverflow.com stackoverflow.com
-
The problem is that the caller may write yield instead of block.call. The code I have given is possible caller's code. Extended method definition in my library can be simplified to my code above. Client provides block passed to define_method (body of a method), so he/she can write there anything. Especially yield. I can write in documentation that yield simply does not work, but I am trying to avoid that, and make my library 100% compatible with Ruby (alow to use any language syntax, not only a subset).
An understandable concern/desire: compatibility
Added new tag for this: allowing full syntax to be used, not just subset
-
- Aug 2022
-
-
I'm building a Rails API with a separate web frontend app as "just another API client" (various smartphone apps to follow as well). In the previous "monolithic" version of the service, where all the server side was rolled into one Rails app
-
- Sep 2021
-
blog.johnnyreilly.com blog.johnnyreilly.com
-
Let's not get over-excited. Actually, we're only part-way there; you can compile this code with the TypeScript compiler.... But is that enough?I bundle my TypeScript with ts-loader and webpack. If I try and use my new exciting import statement above with my build system then disappointment is in my future. webpack will be all like "import whuuuuuuuut?"You see, webpack doesn't know what we told the TypeScript compiler in the tsconfig.json.
-
- Jun 2021
-
docs.gitlab.com docs.gitlab.com
-
When mocking is deemed profitable:
-
-
www.postgresql.org www.postgresql.org
-
The field/element/path extraction operators return NULL, rather than failing, if the JSON input does not have the right structure to match the request; for example if no such key or array element exists.
-
- Mar 2021
-
blog.izs.me blog.izs.me
-
Those sorts of complaints are like saying that someone is not a buddhist unless they speak Pali.
-
- Feb 2021
-
en.wikipedia.org en.wikipedia.org
-
which entails computer programming (process of writing and maintaining the source code), but also encompasses a planned and structured process from the conception of the desired software to its final manifestation
-
-
stackoverflow.com stackoverflow.com
-
If you teach your users to trust that URL bar is supposed to not change when they click links (e.g. your site uses a big iframe with all the actual content), then the users will not notice anything in the future either in case of actual security vulnerability.
-
-
medium.com medium.com
-
The point is, just because you don’t see it, doesn’t mean it’s not happening. It’s been more than two years and as far as I know, no one has ever noticed one of my requests. Maybe it’s been in your site this whole time
-
- Jan 2021
-
discourse.ubuntu.com discourse.ubuntu.com
-
Most users frankly don’t care how software is packaged. They don’t understand the difference between deb / rpm / flatpak / snap. They just want a button that installs Spotify so they can listen to their music.
-
What’s the use of ie. snap libreoffice if it can’t access documents on a samba server in my workplace ? Should I really re-organize years of storage and work in my office for being able to use snap ? A too high price to pay, for the moment.
-
- Nov 2020
-
github.com github.com
-
This is Sass based, and therefore doesn't require Svelte components
Just because we could make Svelte wrapper components for each Material typography [thing], doesn't mean we should.
Compare:
material-ui [react] did make wrapper components for typography.
- But why did they? Is there a technical reason why they couldn't just do what svelte-material-ui did (as in, something technical that Svelte empowers/allows?), or did they just not consider it?
svelte-material-ui did not.
- And they were probably wise to not do so. Just reuse the existing work from the Material team so that there's less work for you to keep in sync and less chance of divergence.
-
- Oct 2020
-
-
hyperscript is much simpler to refactor and DRY up your code than with JSX, because, being vanilla javascript, its easier to work with variable assignment, loops and conditionals.
Tags
- making it easy for later refactoring
- it's just _
- template language: bad: by not reusing existing language constructs; forced to reinvent equivalents which are inferior and unfamiliar
- javascript
- hyperscript
- JSX
- template language vs. reusing existing language constructs
- reuse existing language constructs
- comparison with:
Annotators
URL
-
-
dylanvann.com dylanvann.com
-
Disclaimer: I’m new to Svelte so this isn’t so much a recommendation as it is a “I guess this is a way to do it 🤷♂️”
-
-
online.mines.edu online.mines.edu
-
Class participation vs. attending class.The quantity andquality of online class participation replaces on-siteattendance
The flexibility is nice!
-
-
github.com github.com
-
I created a pull request to have the if (node.parentNode) conditional added to detach. It was not applied due to the desire to find the root cause of the <meta> tag manifestation of this issue.
-
- Sep 2020
-
-
Why not just do something like this?
-
This can and should be done with other components, IMHO.
-
- Apr 2020
-
www.iubenda.com www.iubenda.com
-
Please note that at the moment the Cookie Solution is optimized to comply with very strict Italian implementation regulations (this can only improve compliance in other jurisdictions).
-
-
lnakamur.files.wordpress.com lnakamur.files.wordpress.com
-
Surely all Uber drivers were submitted to the same labor regime, but those who had to endure it as a means to survive were predominantly people of color.
This is also true of companies like Instacart, GrubHub,etc.
-
- Jul 2019
-
en.wikipedia.org en.wikipedia.org
-
ports many programming languages and markup languages, and functions can be added by users with plugins, typically community-built a
test annot
-
- Apr 2017
-
static1.squarespace.com static1.squarespace.com
-
Wild tongues can't be tamed, they can only be cut out.
“When you tear out a man's tongue, you are not proving him a liar, you're only telling the world that you fear what he might say.”
George R. R. Martin (through Tyrion Lannister)
-