Skip to content

Instantly share code, notes, and snippets.

View richkuz's full-sized avatar

Rich Kuzsma richkuz

View GitHub Profile
@richkuz
richkuz / scrape-github-issues.js
Last active April 20, 2020 14:06
JS to scrape issue text from GitHub results
// Run this script against the issues results at:
// https://github.com/search?p=1&q=is%3Aissue+is%3Aopen+label%3A%22tech+debt%22+repo%3Aelastic%2Fenterprise-search-team+repo%3Aelastic%2Fapp-search-team+repo%3Aelastic%2Fsite-search
// We're not using GitHub API because not everyone's personal access tokens are granted access to the elastic org.
function scrapeIssues() {
document.getElementsByXPath = function(sValue){ var aResult = new Array();var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for ( var i = 0 ; i < a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));}return aResult;};
var issues = document.getElementsByXPath("//div[contains(@class, 'issue-list-item')]/div/div[2]/a");
issuesList = [];
issuesMap = {};
for (var i = 0; i < issues.length; i++) {
@richkuz
richkuz / scrape-github-closed-issues.js
Created April 20, 2020 14:09
JS to scrape closed issues from GitHub UI
// Run this script against the issues results at:
// https://github.com/search?p=1&q=is%3Aissue+is%3Aclosed+label%3A%22tech+debt%22+repo%3Aelastic%2Fenterprise-search-team+repo%3Aelastic%2Fapp-search-team+repo%3Aelastic%2Fsite-search
// We're not using GitHub API because not everyone's personal access tokens are granted access to the elastic org.
function scrapeClosedIssues() {
document.getElementsByXPath = function(sValue){ var aResult = new Array();var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for ( var i = 0 ; i < a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));}return aResult;};
var issues = document.getElementsByXPath("//div[contains(@class, 'issue-list-item')]/div/div[2]/a");
issuesList = [];
for (var i = 0; i < issues.length; i++) {
var id = issues[i].href.substring(issues[i].href.lastIndexOf('/') + 1);
issuesList.push(id);
@richkuz
richkuz / insert-date-mac-osx.md
Created June 12, 2020 15:35
Insert ISO-8601 formatted date yyyy-mm-dd on Mac OSX using a keyboard shortcut

Recently, I converted to using ISO-8601 formatted dates as much as possible, e.g. 2020-06-12. As a meme, I hope this catches on. Dates written this way are internationally recognizable, no confusion over mm/dd/yy or dd/mm/yy. They are sortable. And, when used consistently, they are easy to search; no worries about case sensitivity, or Jun/June spellings. Don’t take my word for it, though. Randall Munroe agrees. So does GitLab.

Here's how to create a keyboard shortcut to insert the current date formatted as ISO-8601.

  1. Launch Automator, and create a new Service.

  2. This particular service receives no input.

  3. Drag in Run AppleScript to the service.

@richkuz
richkuz / gist:b8f92969d1a99ebb43c7c490e10c8df5
Created October 8, 2020 21:01
Inject a GitHub gist JS file into Charles proxy

You can inject an arbitrary JS file from a GitHub gist in place of another JS file on a web page using Charles proxy.

Map the remote path to the gist raw content path:

Tools -> Map Remote

image

Then update the Content-Type header from plain text to text/javascript so you don't get CORB errors.

@richkuz
richkuz / intragrams.md
Last active April 1, 2021 18:27
Elastic App Search intragram matching

App Search < 7.12 performs fuzzy matches in part by using an "intragram" analyzer.

Intragram is an internal name given to an Elasticsearch ngram tokenizer configured with some filtering to handle mixed case letters, non-ASCII Basic Latin characters, and normalize width differences in Chinese, Japanese, and Korean characters.

An intragram analyzer looks like this in pure Elasticsearch terms:

PUT my-intragrams
{
 "settings": {
@richkuz
richkuz / resize-ent-search-nodes.md
Last active February 24, 2021 15:11
Resizing Enterprise Search nodes on Elastic Cloud via API

You can increase or decrease how many Enterprise Search nodes you have running on Elastic Cloud using the ECE API.

For example, if your website traffic follows a predictable pattern and you know you'll experience increased load at specific times during the day, you can run a cron job to predictably size up and size down your cluster.

Resizing a cluster via API using curl follows this general pattern:

export DEPLOYMENT_ID=bf4d13dcdc9340f5ac...  # Your Cloud deployment ID from the Cloud Deployments page
export ECE_API_KEY=VlU4MDFIY0JxVld3M...     # Generate an API key under Cloud, Features, API Keys
@richkuz
richkuz / 5-minutes-by-the-clock.md
Last active April 13, 2021 13:49
Rationality trick: 5 minutes by the clock

5 minutes, by the clock

Here's a cheap trick for increasing creativity and continuous improvement, especially when you're stuck on a problem.

Pull up a blank text editor and think about the problem for 5 minutes by the clock. An actual physical clock is recommended. Begin writing down ideas, thoughts, solutions, anything relevant or irrelevant. Especially lean into any thoughts your mind is subconsciously avoiding.

This exercise has to be for an actual 5 minutes, though. You can't just blink and say "Yeah, thought about it, I've got nothing." Set a timer and stick by it.

@richkuz
richkuz / fix-mac-calendar-app.md
Last active April 19, 2021 15:22
Mac OSX CalDav calendar app and Next Meeting app not updating from Google Calendar

I use Next Meeting on my Macbook Pro to show me my next Google Calendar meeting in the OSX system menu bar.

Sometimes, the menu gets out of sync with my Google Calendar events.

Next Meeting uses Apple's own calendar APIs to fetch calendar info. The native Calendar app itself also was not showing me the latest Google Calendar events.

To resolve

  • Open the native Mac Calendar app
  • Go to Calendar, Preferences, Accounts and set your Google Calendar CalDav account to Refresh Calendars: Manually.
  • Click View, Refresh Calendars
@richkuz
richkuz / docker-compose-app-search-7.6.0.yml
Created April 19, 2021 22:56
docker-compose file for running Elastic App Search 7.6.0
# A docker-compose to make it easier to run Elastic App Search
# docker-compose --file docker-compose-app-search-7.6.0.yml up -d
version: "2"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.0
environment:
- "discovery.type=single-node"
@richkuz
richkuz / docker-compose-ent-search-7.10.0.yml
Created April 19, 2021 22:57
docker-compose file for running Elastic Enterprise Search 7.10.0
# A docker-compose to make it easier to run Elastic Enterprise Search
# docker-compose --file docker-compose-enterprise-search-7.10.0.yml up -d
# A docker-compose to make it easier to run PHP integration tests locally with different PHP versions.
version: "2"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
environment: