Use vscode.window.showInputBox - the returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise the returned value will be the string typed by the user or an empty string if the user did not type anything but dismissed the input box with OK.

const searchQuery = await vscode.window.showInputBox({
  placeHolder: "Search query",
  prompt: "Search my snippets on Codever",
  value: selectedText
});
if(searchQuery === ''){
  console.log(searchQuery);
  vscode.window.showErrorMessage('A search query is mandatory to execute this action');
}

if(searchQuery !== undefined){
  const searchUrl = `https://www.codever.land/search?q=${searchQuery}&sd=my-snippets`;
  vscode.env.openExternal(Uri.parse(searchUrl));
}

Reference - https://code.visualstudio.com/api/references/vscode-api#window.showInputBox

You can see it in action in the following demo:

Search from Codever Snippets VSCode Extension Demo
Search from Codever Snippets VSCode Extension Demo

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

Use update method with the multi flag set to true

db.users.update(
  { "welcomeAck": { "$exists": false } },
  { "$set": { "welcomeAck": true } },
  { "multi": true }
);

Or the equivalent shortcut with updateMany:

db.users.updateMany(
  { "welcomeAck": { "$exists": false } },
  { "$set": { "welcomeAck": true } }
);

Reference - https://docs.mongodb.com/manual/tutorial/update-documents/


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

To list services, pods and deployments resources from kubernetes namespace use the kubectl get command with --namespace=my-namespace (short -n)

# Set the "current" namespace for context
kubectl config set-context --current --namespace=my-namespace

# Get commands with basic output
kubectl get services                          # List all services in the namespace
kubectl get pods --all-namespaces             # List all pods in all namespaces
kubectl get pods -o wide                      # List all pods in the current namespace, with more details
kubectl get deployment my-dep                 # List a particular deployment
kubectl get pods                              # List all pods in the namespace
kubectl get pods  -n my-namespace             # List all pods in the "my-namespace" namespace (in namespace not set)
kubectl get pod my-pod -o yaml                # Get a pod's YAML

Reference - https://kubernetes.io/docs/reference/kubectl/cheatsheet/


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

First use the @JsonFilter jackson annotation where you define an id of the filter

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonFilter("IndividualComparisonResultsFilter")
public class ComparisonResultBulk implements Serializable {

  //other fields ignored for brevity

  @JsonProperty("max_latency_millis")
  private String maxLatencyMillis;

  @JsonProperty("individual_comparison_results")
  private List<ComparisonResult> comparisonResults;

  @JsonProperty("not_comparable_results_size")
  private Integer notComparableResultsSize;

  @JsonProperty("not_comparable_results")
  private List<ComparisonResult> notComparableResults;
}

Then create a filterProvider, for example a SimpleFilterProvider for the id where you set the filter options.

In the example below everything is serialized except two properties with the help of SimpleBeanPropertyFilter.serializeAllExcept() method (serializeAll() is also present, and the opposite SimpleBeanPropertyFilter.filterOutAllExcept("individual_comparison_results", "not_comparable_results") which would serialize only these properties). In the end set the filterProvider set to the ObjectMapper where you serialize your object:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

private ComparisonReport generateReport(ComparisonResultBulk comparisonResultBulk)
      throws JsonProcessingException {
    ComparisonReport comparisonReport = new ComparisonReport();

    ObjectMapper mapper = new ObjectMapper();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter("IndividualComparisonResultsFilter", SimpleBeanPropertyFilter.serializeAllExcept("individual_comparison_results", "not_comparable_results"));
    mapper.setFilterProvider(filterProvider);

    comparisonReport.setPayload(mapper.writeValueAsBytes(comparisonResultBulk));

    return comparisonReport;
}

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

Use case

Some code snippets I save are really long or maybe too wide, due to comments of course, to read them easily in the code text area. In this case it is very practical to view them in full screen, a feature I implemented over the passing weekend:

Toggle fullscreen for snippets
Toggle fullscreen for snippets

For the implementation I used screenfull.js1, which is a simple wrapper for cross-browser usage of the JavaScript Fullscreen API2.

Let’s see how this goes exactly.

Continue Reading ...