Recently I wrote a few posts on my personal blog with lots of pictures. To save on bandwidth and load time it’s very important to reduce the size of the images. Which until recently I did manually in Preview, MacOS. It was a rather cumbersome manual process, that I automated with the help of Node.js/ExpressJS and Jimp In this post I will presently the implementation.

The code for this nad usage instructions are open source and available on Github

Continue Reading ...

You can now export your bookmarks and snippets from Bookmarks.dev for backup or other purposes. You can do that by going to your dashboard and click Export my bookmarks button. A dialog will pop up to ask whether you want to see your bookmarks or snippets in the browser(this opens a new window) or save them as a json file:

Export my snippets

Continue Reading ...

In this post I will show how to fix the infamous Jekyll encoding exception on MacOS:

Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/main.scss':
Invalid US-ASCII character "\xE2" on line 54

Well I got inspired from the solution presented here[^1] when starting a cloud image. [^1]: https://github.com/mmistakes/minimal-mistakes/issues/1183

Instead of starting the server for local development with the usual command:

bundle exec jekyll serve

I use the following environment variables before the command:

LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8" bundle exec jekyll serve

To make the solution permanent, I added the environment variables in my .bash_profile file:

# lang variables
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"

References

The Selenium WebDriver is a popular open-source tool for web-based application automation testing. It supports a cross-operating system, cross-device and cross-browser tests. Also, it allows you to code using multiple programming languages, such as Python, Java, Ruby, PHP, Perl, and more!

PHP is a popular programming language for server-side programming. As of January 2021, research indicates that 79% of websites are developed in PHP. Did you know that PHP is used in web test automation as well?

This article discusses how you can use PHP to create web test automation. It mentions the basics around the Selenium-PHP combination. Also, it lists some popular automation testing tools that your software development company can use in their project.

Continue Reading ...

Project: codever - File: 1586782890001_add-codelets-indexes-DONE.js

Full text search is supported in Mongo by using a text index. Text indexes can include any field whose value is a string, or an array of string elements, to which you can give weights. For a text index, the weight of an indexed field denotes the significance of the field relative to the other indexed fields in terms of the text search score.

db.snippets.createIndex(
  {
    title: "text",
    tags: "text",
    "codeSnippets.comment": "text",
    "codeSnippets.code": "text",
    sourceUrl: "text"
  },
  {
    weights: {
      title: 8,
      tags: 13,
      "codeSnippets.comment": 3,
      "codeSnippets.code": 1,
      sourceUrl: 1
    },
    name: "full_text_search",
    default_language: "none",
    language_override: "none"
  }
);

For each indexed field in the document, MongoDB multiplies the number of matches by the weight and sums the results. Using this sum, MongoDB then calculates the score for the document. You then can use the $meta operator for details on returning and sorting by text scores, as in the snippet below:

let getPublicBookmarksForSearchedTerms = async function (nonSpecialSearchTerms, page, limit, sort, specialSearchFilters, searchInclude) {

  let filter = {
    public: true
  }

  if ( nonSpecialSearchTerms.length > 0 ) {
    if(searchInclude === 'any') {
      filter.$text = {$search: nonSpecialSearchTerms.join(' ')}
    } else {
      filter.$text = {$search: bookmarksSearchHelper.generateFullSearchText(nonSpecialSearchTerms)};
    }
  }

  addSpecialSearchFiltersToMongoFilter(specialSearchFilters, filter);

  let sortBy = {};
  if ( sort === 'newest' ) {
    sortBy.createdAt = -1;
  } else {
    sortBy.score = {$meta: "textScore"}
  }

  let bookmarks = await Bookmark.find(
    filter,
    {
      score: {$meta: "textScore"}
    }
  )
    .sort(sortBy)
    .skip((page - 1) * limit)
    .limit(limit)
    .lean()
    .exec();

  return bookmarks;
}

Reference - https://docs.mongodb.com/manual/core/index-text/


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏