77 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. Nov 2023
  3. Oct 2023
  4. Jul 2023
    1. I feel insanely chuffed at recognizing scarce and desirable works that have been overlooked or underpriced. I once paid $5 for an inscribed first edition of Zora Neale Hurston’s “Tell My Horse” in a very good dust jacket. Try to find a like copy today.

      It's particularly difficult to find inscribed or rare books with odd quirks in an online marketplace where one can't hold a book and browse through it in person.

    2. Books aren’t commoditiesAdvertisementI despise — viscerally, perhaps irrationally — the people one sometimes sees at used book stores scanning every title with a handheld device to check its online price. They regard books strictly as products and usually don’t know anything about them, only caring about what they can buy low and sell high on Amazon or eBay.
  5. Jun 2023
  6. May 2023
    1. Grading guidelines New. Item is brand new, unused and unmarked, in flawless condition. Protective wrapping should be intact. No blemishes on the outside cover. Stickers/marks indicating it may be “bargain” or “remainder” should not be considered new. Used: Like New. Item has very few defects and looks as good as new. Some minor blemishes and/or remainder marks are acceptable for this condition.   Dust cover/outside case (if applicable) should be intact.   Pages: No marking or highlighting of any kind. Shrink wrap: May be opened or missing for standard bound items. Loose leafs should be shrink wrapped to ensure all pages are present. Supplemental materials: (e.g.) CDs, DVDs, access codes should be unused. Used: Very Good. Items may have some minor defects such as marks, wear, bends, spine and page creases. Dust covers/outside case may be missing. Supplemental materials: May be missing. Water/stains: No water damage or stains of any kind acceptable in this condition. Pages: Very minor writing or highlighting (a few pages) OK. Personalization: No library labels acceptable in this condition. Name written inside OK. Binding/covers: Minimal blemishes and slight defects acceptable. No missing or loose pages. Loose leafs should be wrapped or rubber banded together and all pages must be present. Used: Good. Items with moderate wear and tear. Binding and pages should be intact. Covers: Can have curl and small creases. Moderate scuff marks or small cut OK. Corners: Can have some damage, light (1-2 inches) peeling OK, some (25%) bend OK. Pages: Minor highlighting (~20%) OK. Dog ear folds on page corners OK. Water/Stains: No visible water/spill damage. Minimal stains OK. Supplements: Can be missing/opened, unless the ISBN is a stand alone access card or a bundle edition (book with access code). Personalization: Name written inside or library labels OK. Binding: Moderate wear is OK, no loose pages. Loose leafs should be wrapped or rubber banded together and all pages must be present. Used: Acceptable. Items with more than moderate wear and tear. Binding and pages should be intact. Pages: Should be readable. Moderate highlighting and writing OK (more than ~20%). Water/Stains: Minor water/spill damage OK. Binding: Heavy wear OK, must still be intact, no loose or missing pages. Used: Unacceptable. Cover: Cover not intact. Cuts going through the cover into multiple pages. Page damage: Lines unreadable from highlighting. Page completely torn (part of page is missing) or major partial tear (high probability that normal wear and tear during next usage will result in part or all of page falling out). Water damage: Pages swollen, major wrinkling, excessive stains, major discoloration or moldy (foxing). Mismatch ISBN: Submitted ISBN does not match ISBN of what was received. Stickers or Tape: Used deliberately to hide markings specific to instructor, international, and sample editions, which are all deemed unacceptable. Rebound items. Binding: Pages are separating from binding or have been fixed with tape.
  7. Oct 2022
    1. 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

  8. Sep 2022
    1. I took along my son, who had never had any fresh water up his nose and who had seen lily pads only from train windows. On the journey over to the lake I began to wonder what it would be like. I wondered how time would have marred this unique, this holy spot--the coves and streams, the hills that the sun set behind, the camps and the paths behind the camps. I was sure that the tarred road would have found it out and I wondered in what other ways it would be desolated. It is strange how much you can remember about places like that once you allow your mind to return into the grooves which lead back. You remember one thing, and that suddenly reminds you of another thing. I guess I remembered clearest of all the early mornings, when the lake was cool and motionless, remembered how the bedroom smelled of the lumber it was made of and of the wet woods whose scent entered through the screen. The partitions in the camp were thin and did not extend clear to the top of the rooms, and as I was always the first up I would dress softly so as not to wake the others, and sneak out into the sweet outdoors and start out in the canoe, keeping close along the shore in the long shadows of the pines. I remembered being very careful never to rub my paddle against the gunwale for fear of disturbing the stillness of the cathedral.

  9. Aug 2022
    1. fragments_shored · 1 hr. agoI don't have a specific edition to offer, but you asked "why don't publishers publish more books with scholar's margins?" and the answer is because it's expensive. More white space means more paper and binding material, longer time for the print run, more customization on the press, heavier and therefore more costly to ship. Book publishing operates on a very thin margin so it's not cost-effective, especially when most consumers don't care about the extra margin space and/or aren't willing to absorb the costs in the purchase price.What can consumers do to encourage publishers to change these practices? Be willing to spend the $80 for the scholar's margins instead of expecting to pay the normal $5 to $10.

      The razor thin margins argument only works from the bookseller's perspective, and this is primarily due to excessive competition from Amazon. Beyond this, sure the product would be slightly more expensive, but (pun intended) only marginally so. Revenue margins on classics written before 1924 (which most of this class of books is) are also significantly higher because they're public domain and the company isn't paying royalties on them. Additionally, at scale, a company with a series like Penguin Classics has a pretty solid understanding of print runs and demand to more easily allow them to innovate like this. Take the Penguin Classics copy of Thucydides' The History of the Peloponnesian War which lists for $20 in paperback and sells for $12.00 on Amazon. (You'll notice that Amazon is essentially giving away their entire discount (aka margin, usually a 40% discount on the list price) here. At a 10,000 copy print run, the cost of the print/paper/print run is in the $2.00 per copy range or lower. Amazon is taking a razor margin for the sale, but Penguin is pocketing almost $10 in pure profit as I'm sure their marketing budget is very near zero here.<br /> They could easily still do very close to this with either larger book margins or even the same text printed on 6 x 9" instead of 5 x 8.25 (or even smaller pulp sizes) so they don't have to reset the entire book for pennies on the dollar at the publisher level. Given that the majority of this market is targeted at students, who could directly use these affordances (and often do but in more cramped space) for the small mark up (particularly in comparison to the $80 copies, which still don't fit the bill, when they exist), I would attribute their non-existence to laziness and lack of imagination on the part of the publishers. Perhaps a smaller publishers like Dover might take on such a project as a means of cheaply, but profitably improving their position in the market? Those making the argument for not marking up these sorts of copies to keep the book pristine for the next reader are missing the point. I also suspect that they haven't recently purchased these sorts of used copies that often go for under $4 on the used market. Even when treated well and not heavily annotated by the first reader, these books are not in good shape and really aren't designed to be read by more than three people. It's also the reason that most libraries don't purchase them. I might buy their argument for the more expensive hardcover collector's market, but not for the pulp mass market books which hold almost no value on the secondary market. Additionally the secondary market for this class of books doesn't usually reflect large value differences between heavily annotated/highlighted texts and those that aren't. Whether they mark them up or not, the first owner is responsible for the largest proportion of depreciated value. Tangentially, I find myself lamenting the cultural practices of prior generations who valued sharing annotated copies of texts with friends and lovers as tokens of their friendship and love. I'm guessing those who vitiate against annotation have never known these practices existed.

  10. Jul 2022
  11. Mar 2022
    1. Each highlighted statement expresses political talking points aligned to induce trump-like support.

      Trump introduced new marketing and strategy, formulated using concepts and metrics mastered by Reality TV and Hollywood and then paired with advertising propaganda and "selling" techniques to create a "Brand". This is after-all Donald Trump, this is what he does, has done and is the only way he has found to make money. Trump built the "brand" (just barely) while teetering on self destruction.

      His charismatic persona became "the glue" that allowed creative narratives to stick to certain types of people in-spite of risk. Trump learned OTJ how to capture a specific type of audience.

      The mistake people make about Trump is assuming his audience to be "Joe Six-Pack", redneck's with limited education! This assumption does not have merit on its own.<br /> * There is a common "follower" theme among his audience that is exploited by those who: * Bought the "licensing rights" to the master-class Trump "how-to" course.

  12. Nov 2021
    1. How people use to write was on Papyrus which was made out of hands and other natural things you find in nature. People also wrote with black and red ink. And they would make those into scrolls. What is papyrus?

  13. Sep 2021
  14. Aug 2021
    1. In April 1863, Carleton gave orders to Colonel Kit Carson to round up the entire Navajo population and escort them to Bosque Redondo. Those who resisted would be shot. Thus began a period of Navajo history called the Long Walk, which remains deeply important to Navajo people today

      Important

  15. Jul 2021
    1. sinful

      This is another word that Miss Clack used a lots in her narrative.

    2. devout

      The word "devout" came out a few thing from Miss Clack's narrative. I assume she is a devout Christian?

    3. alas!

      This is one of words that Miss Clack will use, but Betteredge won't use. However, this word also reveals some personality of Miss Clack, by definition, alas means: "an expression of grief, pity, or concern." By this we can assume Miss Clack might be a sentimental person

  16. Jun 2021
  17. Apr 2021
    1. We are are continuing our commitment to creating our games that are free and widely accessible anyone that is curious by making our game files available under Creative Commons license BY–NC–SA 4.0. That means we will continue offering a full, free print-and-play kit for Pax Pamir, and later this campaign, John Company! Anyone can use, remix, and share the game, so long as they do not use it for commercial purposes. 
    1. A generic trademark, also known as a genericized trademark or proprietary eponym, is a trademark or brand name that, because of its popularity or significance, has become the generic term for, or synonymous with, a general class of products or services, usually against the intentions of the trademark's owner.
  18. Mar 2021
    1. Software that is not currently being used gradually becomes unusable as the remainder of the application changes.
    2. Infrequently used portions of code, such as document filters or interfaces designed to be used by other programs, may contain bugs that go unnoticed. With changes in user requirements and other external factors, this code may be executed later, thereby exposing the bugs and making the software appear less functional.
    1. Another important MicroJS attribute is independence. Ember, Backbone—even Bootstrap to a degree–have hard dependencies on other libraries. For example, all three rely on jQuery. A good MicroJS library stands by itself with no dependencies. There are exceptions to the rule, but in general, any dependency is another small MicrojJS library.
    1. In production, you will never trigger one specific callback or a particular validation, only. Your application will run all code required to create a Song object, for instance. In Trailblazer, this means running the Song::Create operation, and testing that very operation with all its side-effects.
    2. There’s no need to test controllers, models, service objects, etc. in isolation
    3. Run the complete unit with a certain input set, and test the side-effects. This differs to the Rails Way™ testing style, where smaller units of code, such as a specific validation or a callback, are tested in complete isolation. While that might look tempting and clean, it will create a test environment that is not identical to what happens in production.
  19. Feb 2021
    1. found that using only the Pascal-provided control structures, the correct solution was given by only 20% of the subjects, while no subject wrote incorrect code for this problem if allowed to write a return from the middle of a loop.
    1. Operations don't know about HTTP or the environment. You could use an operation in Rails, Hanami, or Roda, it wouldn't know.
  20. Dec 2020
  21. Nov 2020
    1. Many linguists believe that the natural language a person speaks affects how they think. Does the same concept apply to computer languages?
  22. Oct 2020
    1. All validators can be used independently. Inspried by functional programming paradigm, all built in validators are just functions.

      I'm glad you can use it independently like:

      FormValidation.validators.creditCard().validate({
      

      because sometimes you don't have a formElement available like in their "main" (?) API examples:

      FormValidation.formValidation(formElement
      
    1. that does not mean that I am advocating the other extreme–i.e., a templating language that allows a lot of logic. I find such templating languages, especially those that allow the host programming languages to be used inside the template, to be hard to read, hard to maintain, and simply a bad choice.
  23. Sep 2020
    1. Passing the class prop to the root dom element is already a wide spread practice
    2. It's a convention in Svelte to export { className as class } inspired from docs, but it's certainly not required by the compiler, so I don't think the class:directive can/should be assumed here.
    3. On the one hand, it's an unofficial but widely-used practice to do let classNames=''; export { classNames as class }; in components and then apply that class on the top-level DOM element in the component. On the other hand, there are plenty of components out there that don't use this idiom
    1. For a non-monorepo package you can simply point directly to the Github repo. This case is similar, but you want to scope it just to a single package within the repo. For those that make monorepos they don't necessarily need this feature. It's for those that use projects that use monorepos. Telling them to not organize their projects into monorepos doesn't help people who make use of these projects.
    2. If npm installs a git repo, it assumes that the git repo is the package. I don't really know how we could specify a sub-path easily, since all parts of the git url are already used for other things.
    1. This is more a rhetoric question as this seems to be quite hard ;-) There is a long discussion about installing a subfolder of a repository and monorepos in general at the NPM Github issues (yarn misses this feature, too). The thing is that this makes it quite hard to report issues of your project as one can't test the current master easily. Do you recommend a way how to use the latest Github version?
  24. Jul 2020
  25. Mar 2020
    1. Used By

      I like how they have indexed their core code base so they can show in both directions:

      • which other core functions a function uses
      • which other core functions use this function (references)
  26. Dec 2019
  27. Nov 2019
    1. You want to write maintainable tests for your React components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
    2. We try to only expose methods and utilities that encourage you to write tests that closely resemble how your web pages are used.
    3. The more your tests resemble the way your software is used, the more confidence they can give you.
    4. Most of the damaging features have to do with encouraging testing implementation details. Primarily, these are shallow rendering, APIs which allow selecting rendered elements by component constructors, and APIs which allow you to get and interact with component instances (and their state/properties) (most of enzyme's wrapper APIs allow this).
  28. Aug 2019
  29. May 2019
    1. homebrewing

      Very grass roots/home brew friendly organization; appeals to sense of independence and optimism; "home grown"

  30. Sep 2018
    1. Snapchat says it reaches 28.5 to 30 million 18-24 year old users in the U.S. According to a recent survey of Instagram users, approximately 32 percent of its 1 billion-strong user base is 18-24.

      Snapchat reaches around 30 million 18-24 year old users; important ages that are more recently able to vote and take political action. Instagram and snapchat are most popular amongst younger users.

  31. Oct 2016
  32. Aug 2015