Sean's Blog

心之所向,身之所往。

How To Get A List Of Sheet Names In Google Sheets With Script?

There’s no built-in formula to do this, and we have to write our own script with Google’s Apps Script to achieve the function.

  1. First, go to the Extensions → Apps Script.

  2. Second, write our own method getSheetsName in the Apps Script console, and save.

Code snippets:

function getSheetsName() {
var sheetNames = new Array()
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length ; i++) {
sheetNames.push( [ sheets[i].getName() ] )
}
return sheetNames
}

Then go back to your sheet, and type the formula with the function name we just created in the Apps Script.


[Elasticsearch] Function score query

By reading the official document of the Function score query, I still couldn’t get a sense of how to use it correctly. After reading through more articles written by others, here’s how I interpret it with the formula of the newly computed score:

function_score = min(score_mode(f1_score, f2_score, ...), max_boost)
_score = boost_mode(boost*query_score, function_score)

Example 1:

{
  "query": {
      "function_score": {
        "query": { "match_all": {} },
        "boost": "5",
        "random_score": {}, 
        "boost_mode": "multiply"
      }
   }
}

Score:


[Prometheus] What is the difference between rate and irate

Here are the definitions from the official document for rate() and irate(). But if you still don’t quite understand, check the examples below.

In this example, I select all the values I have recorded within the last 1 minute for all time series that have the metric name prometheus_http_requests_total and a handler label set to /metrics:

prometheus_http_requests_total{handler=”/metrics”}[1m]

Output from the Prometheus UI:

# Element
prometheus_http_requests_total{code="200",handler="/metrics",instance="localhost:9090",job="prometheus"}
# ValueHere are the definitions from the official document for rate() and irate(). But if you still don’t quite understand, check the examples below.

In this example, I select all the values I have recorded within the last 1 minute for all time series that have the metric name prometheus_http_requests_total and a handler label set to /metrics:


Useful commands for zsh

Moving the cursor

  • Ctrl+A: To move to the beginning of the current line.
  • Ctrl+E: To move to the end of the current line.

Manipulating your typing

  • Ctrl+W: To delete the word in front of the cursor.
  • Ctrl+U: To clear the entire line.
  • Ctrl+K: To clear the characters on the line after the current cursor position.

How to cherry-pick a commit from another git repository?

# Adding (as "other") the repo from we want to cherry-pick
$ git remote add other git://github.com/username/repo.git

# Fetch the "other" branch
$ git fetch other

# Cherry-pick the commit we need
$ git cherry-pick 0549522