38 Matching Annotations
  1. Jan 2024
    1. 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 the Animal 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 the Animal schema. When you create an instance of the Animal model (e.g., a dog), you can then call findSimilarTypes on that instance to find other animals with the same type. The method uses the this.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 the Animal model.

      Certainly! Let's go through each part and explain it in simple terms: ### 1. `this` in Mongoose: - **What is `this`?** In JavaScript, `this` refers to the current context or object. In Mongoose, particularly within methods and middleware functions, `this` represents the instance (document) the function is currently operating on. - **Why is it used?** `this` is used to access and modify the properties of the current document. For example, in a Mongoose method, `this` allows you to refer to the fields of the specific document the method is called on. ### 2. Example: Let's use the `userSchema.pre("save", ...)`, which is a Mongoose middleware, as an example: ```javascript userSchema.pre("save", async function (next) { if (!this.isModified("password")) { next(); } else { this.password = await bcrypt.hash(this.password, 10); next(); } }); ``` - **Explanation in Simple Words:** - Imagine you have a system where users can sign up and set their password. - Before saving a new user to the database, you want to ensure that the password is securely encrypted (hashed) using a library like `bcrypt`. - The `userSchema.pre("save", ...)` is a special function that runs automatically before saving a user to the database. - In this function: - `this.isModified("password")`: Checks if the password field of the current user has been changed. - If the password is not modified, it means the user is not updating their password, so it just moves on to the next operation (saving the user). - If the password is modified, it means a new password is set or the existing one is changed. In this case, it uses `bcrypt.hash` to encrypt (hash) the password before saving it to the database. - The use of `this` here is crucial because it allows you to refer to the specific user document that's being saved. It ensures that the correct password is hashed for the current user being processed. In summary, `this` in Mongoose is a way to refer to the current document or instance, and it's commonly used to access and modify the properties of that document, especially in middleware functions like the one demonstrated here for password encryption before saving to the database.

    Tags

    Annotators

    URL

  2. May 2023
  3. Mar 2023
    1. If we assume students want to learn - and I do - we should show our interest in their learning, rather than their performance.
    2. Value the process, rather than the product.

      Good writing is often about practices and process to arrive at an end product and not just the end product itself.

      Writing is a means to an end, but most don't have the means to begin with.

      Writing with a card index, zettelkasten, commonplace book or other related tools can dramatically help almost any writer because it provides them with a means from the start rather than facing a blank page and having to produce whole cloth in bulk.

    1. The process began much earlier.
      • Comment
      • Means lumps the entire European academic tradition as complicit in promoting the wrong worldview laying the ground for my modernity's destruction of nature and civilization
        • Isaac Newton
        • Rene Descartes
        • John Locke
        • Adam Smith
        • Georg Hegel
        • Karl Marx
      • Title

        • Revolution and American Indians: “Marxism is as Alien to My Culture as Capitalism"
      • Author

        • Russell Means
      • Context

        • The following speech was given by Russell Means in July 1980, before several thousand people who had assembled from all over the world for the Black Hills International Survival Gathering, in the Black Hills of South Dakota.
        • It was Russell Means's most famous speech.
  4. Jan 2023
    1. https://www.youtube.com/watch?v=NPqjgN-pNDw


      When did the switch in commonplace book framing did the idea of "second brain" hit? (This may be the first time I've seen it personally. Does it appear in other places?) Sift through r/commonplace books to see if there are mentions there.


      By keeping one's commonplace in an analog form, it forces a greater level of intentionality because it's harder to excerpt material by hand. Doing this requires greater work than arbitrarily excerpting almost everything digitally. Manual provides a higher bar of value and edits out the lower value material.

  5. Oct 2022
    1. Asset limits (or savings penalties) are designed sothat only the most vulnerable can access public benefit programs. However, in practice,they discourage low-income households from having a checking or savings account andbuilding a savings cushion. Relaxed asset limits increase low-income household savingsand mainstream financial market participation.

      Is there evidence for this? Other confounding factors that prevent people from opening accounts?

    Tags

    Annotators

  6. Sep 2022
    1. means-tested program—Medicaid, Supplemental Nutrition AssistanceProgram (SNAP), Supplemental Security Income (SSI), Temporary Assistancefor Needy Families (TANF), and/or General Assistance (GA)
    2. means- tested welfare program (e.g., Supplemental Nutrition AssistanceProgram [SNAP], Medicaid

      What does the full list of available means-tested programs look like?

    3. Welfare programs are generally considered those in whichan individual has to be below a certain income and asset level and fall into aparticular population group in order to be eligible. These are also known asmeans- tested programs, with individuals only able to participate if their incomeand assets are low enough to qualify.7
  7. Jul 2022
  8. Jun 2022
    1. Short-lived victories, however, came at a long-term cost. Evangelical leaders set something in motion decades ago that pastors today can no longer control. Not only were Christians conditioned to understand their struggle as one against flesh and blood, fixated on earthly concerns, a fight for a kingdom of this world—all of which runs directly counter to the commands of scripture—they were indoctrinated with a belief that because the stakes were getting so high, any means was justified.
    1. Had their colonies not allowed European countries totranscend their territorial limits, it would have been necessary to findthese sources of supply elsewhere.

      Colonial exploitation between 1500 and 1800 allowed European countries to dramatically expand beyond their own dwindling natural resources and territorial limits. Had they been trapped in a closed system, the world would have seen a very different arc of history.

  9. Feb 2022
  10. openlab.citytech.cuny.edu openlab.citytech.cuny.edu
    1. But it isn’t. This is because over such a long period a message can easily be distorted or altered without this being in any way intended. (This distortion or alteration in the meaning or method of transmission of a message, whether intended or not, is called “noise.”) Languages, both written and spoken, always change. The meanings of symbols are often lost in the passage of time. In fact, most messages are bound so closely to a particular period and place that even a short time later they cannot be understood. Therefore, ensuring that a message created now can be decoded by future generations is highly problematic.

      Can symbol that represents one thing change over a long period of time to mean something different?

    2. ea. It is only because there is already a well-established connection in our minds between the appearance of an apple and the idea of temptation that this fruit is used in the picture. It is this connection that makes the picture successful in terms of communicatio

      Why was the apple chosen as the representation of temptation?

    3. semiotician,

      A Theory of signs and symbols that deals especially with there function in both artificially constructed and natural languages.

  11. Nov 2021
    1. In your Svelte component, you can then use your store with the special $ prefix syntax, to access the value of the store ('cause the temperature variable is a reference to the store itself, it's just a mean to our end, the result we need is the value):
  12. Apr 2021
    1. @7:40:

      We're aware that some students might actually revel in the gymnastics of a sophiscated writing and retrieval system like this. Now, we don't want to subordinate the material to the system, nor is the system merely being used to provide an alternative to a classroom experience. What we are striving for is to make a flexible system with lots of interesting material so that we may serve the needs of a genuinely contemporary student.

  13. Feb 2021
    1. bird counts across the United States have fallen a staggering 29 percent in the last 50 years

      29% in 50 years? That means in the next 50 years half of the bird population could decrease!

    1. The Quest for Truth

      The quest for Truth is everywhere and not limited to the economic topics linked here. This is just a topic that started a thought process where I had access to a convenient tool (Hypothesis) to bookmark my thoughts and research.

      Primary thought is: The Quest for Truth. Subcategories would provide a structured topic for the thought. In this case the subcategory would be: US Economy, Inflation

      The TRUTH is a concept comprised of inconsistencies and targets that frequently move.

      Targets (data, methods, people, time, semantics, agenda, demographic, motive, means, media, money, status) hold a position in time long enough to fulfill a purpose or agenda. Sometimes they don't consciously change, but history over time shines light and opens cracks in original narrative that leads to new truth's, real or imagined.

      Verifying and validating certain Truth is very difficult. Why is That?
  14. Jun 2020
    1. Some large tech behemoths could hypothetically shoulder the enormous financial burden of handling hundreds of new lawsuits if they suddenly became responsible for the random things their users say, but it would not be possible for a small nonprofit like Signal to continue to operate within the United States. Tech companies and organizations may be forced to relocate, and new startups may choose to begin in other countries instead.
  15. May 2020
    1. a person or thing through which power is exerted or an end is achieved : instrumentality

      Would this be proxy agency? Or is it different?

      On the one hand, I think it's different. instrumentality seems to have a subtly different meaning from proxy agency.

      But looking at their example sentence,

      communicated through the agency of the ambassador , it is striking how similar these ideas/words/meanings are: the ambassador acted on behalf of his country (proxy agency: acted => agency; "on behalf of" => proxy); the communication occurred through his actions (= he was the means, he was instrumental in causing that communication to take place)

      https://en.wikipedia.org/wiki/Agency_(sociology):

      proxy agency is when an individual acts on behalf of someone else

    2. communicated through the agency of the ambassador
    1. of, relating to, or being a grammatical case or form expressing means or agency

      I really need an example of this!

      It seems unusual that they specifically mention "a grammatical case or form". I've never seen a definition before that is anything like this one.

      How is this different from definition 1?

    2. serving as a crucial means, agent, or tool
  16. Apr 2020
  17. Mar 2020
  18. May 2019
  19. Feb 2019
    1. it is necessary first to consider their use and end:

      Is language seen as a means to an end?

    2. Locke believes that there b a real external world and that knowledge of it is pos!-iblc. hul only ii' we underst:md the processes by which we come lo ~uch knowledge.

      Knowledge is the goal, the end, but the process by which knowledge is discovered, the means, is also important to Locke.

  20. Jan 2019
    1. n otherwords, even if rhetoric is the art of never finally answering the question, "Whatis rhetoric?" this art would necessarily include all attempts to finally answer thatquestion.

      Based on this statement, could it be inferred that Muckelbauer places importance on not only the answer to the question (end) but also the process by which that answer is sought (means)? If so, how might the process of discovery be as important as the discovery itself?

  21. Jul 2018
  22. Sep 2017
    1. The point of political protest is to change the world. And yet the process matters, too.
    2. To live in the present is not to avoid hard work or strife. Alongside the projects that occupy you in your profession, or in your political life, the telic activities that matter to you, is the atelic process of protesting injustice or doing your job. To value the process is not to flee from work or political engagement. That is why living in the present is not an abdication of ethical responsibility or a recipe for detachment.
    3. To live in the present is not to deny the value of telic activities, of making a difference in the world. That would be a terrible mistake. Nor can we avoid engaging in such activities. But if projects are all we value, our lives become self-subversive, aimed at extinguishing the sources of meaning within them. To live in the present is to refuse the excessive investment in projects, in achievements and results, that sees no inherent value in the process.
    4. “If you are learning, you have not at the same time learned.” When you care about telic activities, projects such as writing a report, getting married or making dinner, satisfaction is always in the future or the past. It is yet to be achieved and then it is gone. Telic activities are exhaustible; in fact, they aim at their own exhaustion. They thus exhibit a peculiar self-subversion. In valuing and so pursuing these activities, we aim to complete them, and so to expel them from our lives.