Skip to content

Instantly share code, notes, and snippets.

@jacekkopecky
jacekkopecky / new-tab-page.md
Last active September 27, 2017 17:22
Custom new tab page in Chrome

Issue

Chrome v61 broke the New Tab Redirect extension slightly:

  • Before v61, a new tab would redirect to the desired page, put cursor in the address bar, and select the whole URL (screenshot 1). You start typing, the selection is replaced, only what you typed remains, plus any autocomplete suggestions (screenshot 2). Normally, I just need to type n, chrome knows I mean Netflix, suggests that, and I can press Enter.
  • With v61, a new tab redirects to the desired page, the cursor is in the address bar, but the whole URL is not selected (screenshot 3). If you start typing, what you type gets prepended to the URI (screenshot 4). I type n, I have nfile:///home/jacek/start.html with the cursor after n. The extra keystrokes to get rid of the URL are annoying.

Workaround

Until Chrome is fixed (if it ever is), here's my workaround: put start.html into my own extension.

@jacekkopecky
jacekkopecky / google-drive-tree-saver.js
Last active July 23, 2019 18:38
Google Drive: remember which folders were open
/*
Google Drive Folder Tree State Saver
(c) 2019 Jacek Kopecky <jacek@jacek.cz>
License: Creative Commons Attribution-ShareAlike
This script can be added as custom JS in drive.google.com so the browser remembers which folders you had open.
Tested in Google Chrome with the extension "Custom JavaScript for Websites 2" (id ddbjnfjiigjmcpcpkmhogomapikjbjdk)
analysis of how Drive the webpage works (in case they change it):
@jacekkopecky
jacekkopecky / postgres-create-host-user
Last active September 18, 2019 12:58
create postgres user and database based on hostname – used in OneServerPerStudent at Uni of Portsmouth
#!/bin/sh
echo creating PostgreSQL user and database for the main user of this machine
# wait for postgres to start
while ! su -c "echo testing postgres connection; psql -c '\\c'" postgres
do
echo waiting for postgres to start
sleep 10
done
# check hostname again in case it wasn't ready when the script started
@jacekkopecky
jacekkopecky / index.js
Created October 17, 2019 22:33
javascript hello world
console.log('Hello world!');
@jacekkopecky
jacekkopecky / index.js
Created May 20, 2021 16:47
Custom javascript for github.com projects: In GitHub project boards, double click on a card, or select a card and press 'e' to edit it.
// double click on a card, or select a card and press e, to edit it
document.addEventListener('keyup', (e) => {
if (e.key === 'e' && document.activeElement?.classList.contains('project-card')) {
const buttons = document.activeElement.querySelectorAll('details button[role=menuitem]');
for (const btn of buttons) {
if (btn.textContent === 'Edit note') btn.click();
}
}
});
@jacekkopecky
jacekkopecky / gnu-terry-pratchett.js
Created June 5, 2021 21:43
Code for sending GNU Terry Pratchett with Express.JS servers
// "A man is not dead while his name is still spoken."
// - Going Postal, Chapter 4 prologue
app.use((req, res, next) => {
res.set('X-Clacks-Overhead', 'GNU Terry Pratchett');
next();
});
@jacekkopecky
jacekkopecky / hex-grid.js
Created September 7, 2022 15:05
Hex grid, with code to pick the right hex based on normal coordinates (quick and dirty)
const cos30 = Math.sqrt(3)/2;
/**
* A grid of hexagons with flat faces top and bottom, and points left and right.
*/
export class HexGrid {
constructor(height) {
this.h = height;
this.w = height * cos30; // small width - x distance between centers
this.W = height / cos30; // big width - from left point to right point