Skip to content

Instantly share code, notes, and snippets.

View seanh's full-sized avatar

Sean Hammond seanh

View GitHub Profile
@seanh
seanh / netrw.md
Last active March 21, 2024 22:59
Netrw Cheatsheet (Vim's Built-in Directory Browser)

Netrw Cheatsheet (Vim's File Browser)

See also:

  • vinegar.vim, which makes - open netrw in the directory of the current file, with the cursor on the current file (and pressing - again goes up a directory). Vinegar also hides a bunch of junk that's normally at the top of netrw windows, changes the default order of files, and hides files that match wildignore.

    With vinegar, . in netrw opens Vim's command line with the path to the file under the cursor at the end of the command. ! does the same but also prepends ! at the start of the command. y. copies the absolute path of the file under the cursor. ~ goes to your home dir. Ctrl+6 goes back to the file (buffer) that you had open before you opened netrw.

To launch netrw:

@seanh
seanh / html_tags_you_can_use_on_github.md
Last active March 17, 2024 10:28
HTML Tags You Can Use on GitHub

HTML Tags You Can Use on GitHub

Wherever HTML is rendered on GitHub (gists, README files in repos, comments on issues and pull requests, ...) you can use any of the HTML elements that GitHub Flavored Markdown (GFM) provides syntactic sugar for. You can either use the syntactic sugar that GFM (or other GitHub-supported markup language you're using) provides or, since Markdown can contain raw HTML, you can enter the HTML tags manually.

But GitHub also allows you to use a few HTML elements beyond what Markdown provides by entering the tags manually, and some of them are styled with CSS. Most raw HTML tags get stripped before rendering the HTML. Those tags that can be generated by GFM syntactic sugar, plus a few more, are whitelisted. These aren't documented anywhere that I can find. Here's what I've discovered so far:

<details> and <summary>

A `<detai

@seanh
seanh / vimgrep.md
Last active February 20, 2024 00:00
vimgrep cheatsheet

vimgrep

  • Vimcasts on vimgrep

  • Uses native vim regexes (which are slightly different from the regexes used by grep, ack, ag, etc) so the patterns are the same as with vim's within-file search patterns.

You can do a normal within-file search first, then re-use the same pattern to

@seanh
seanh / README.md
Last active November 25, 2023 07:05
Breadcrumbs for GitHub Pages / Jekyll. Pure Liquid (no Jekyll plugin). https://seanh.github.io/posts/2020/01/01/jekyll-breadcrumbs/

Jekyll Breadcrumbs

This is a Jekyll template include that renders navigation breadcrumbs for a page or post. The breadcrumbs include the page or post's collection, categories, date and title. They look something like this:

Home > Posts > 2019 > Dec > 23 > My Blog Post

Installation

@seanh
seanh / user_stories.md
Last active November 12, 2023 15:12
My notes on user stories

User Stories

Reading list

  • [Mark Shead: Creating Good User Stories][Mark Shead]
  • [GOV.UK Service manual: Writing user stories][GOV.UK]
  • [Mike Cohn's blog posts about user stories][Mike Cohn]
  • [Mike Cohn: User Stories Applied (book)][User Stories Applied]
@seanh
seanh / README.markdown
Last active April 23, 2023 11:13
Embedding Hypothesis in a Single Page App

This is a very rough demonstration of how to embed Hypothesis in a single page app.

When you click on the "Go to page two" button it loads the second "page" of the app. This page is just loaded by JavaScript, without having the browser load a new page as it would normally do when following a link. Importantly the JavaScript code does change URL in the browser's location bar though, using history.pushState(). Before changing the URL it unloads Hypothesis from the page, and after changing the URL it reloads Hypothesis into the page. This is to work around a limitation with Hypothesis - it doesn't detect URL changes done by pushState() and reload the annotations.

@seanh
seanh / formatFilename.py
Created April 11, 2009 18:30
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
@seanh
seanh / bw-open
Last active January 20, 2023 18:29
Log in and unlock your Bitwarden vault (shell script)
#!/usr/bin/env sh
#
# Log in to and unlock Bitwarden CLI.
#
# If you save the returned session key in a BW_SESSION envvar that will unlock
# your Bitwarden vault for the current shell session. Once BW_SESSION has been
# set in one shell session it'll also be inherited by any commands or scripts
# run from that shell session.
#
# Usage (sh):
@seanh
seanh / gist:232821
Created November 12, 2009 11:11
Creating and removing files and directories with Python os module
"""This is done with the os module, which has lots of methods for handling files and dirs.
<http://docs.python.org/lib/os-file-dir.html>
Effbot's page on the os module: <http://effbot.org/librarybook/os.htm>
The shutil module is useful here also: <http://docs.python.org/lib/module-shutil.html>
"""
import os
@seanh
seanh / ConcreteObservable.java
Created March 13, 2009 19:26
Observer design pattern in java
package observer;
import java.util.Set;
import java.util.HashSet;
public class ConcreteObservable<T> implements Observable<T> {
private Set<Observer<T>> observers = new HashSet<Observer<T>>();
public void addObserver(Observer o) {