Skip to content

Instantly share code, notes, and snippets.

View scmx's full-sized avatar

Albert Arvidsson scmx

View GitHub Profile
@scmx
scmx / using-details-summary-github.md
Last active April 17, 2025 04:53
Using <details> <summary> expandable content on GitHub with Markdown #details #summary #markdown #gfm #html

How to use <details> <summary> expandable content on GitHub with Markdown

Firstly, what is <details> <summary>?

The HTML Details Element (<details>) creates a disclosure widget in which information is visible only when the widget is toggled into an "open" state. A summary or label can be provided using the <summary> element. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details.

Example

@scmx
scmx / git-commit-title-first-word.md
Last active April 15, 2025 11:04
Example list of verbs / first word to use in git commit title #git #commit #title

Example list of first words to use in a git commit title

I like writing well-formed git commits that explain the intention behind why a code change was made.

Check out Chris Beams excellent How to Write a Git Commit Message if you haven't read it.

Anyway, for a project I've been working on I've gathered up 900+ commits that hold up a pretty high quality (except for one 😁). Let's look at some trends about these commits!

Most common first words in commit titles of a project

@scmx
scmx / update-diverged-branch-with-git-checkout-B.md
Created April 7, 2017 07:01
Updating a local diverged git branch to latest remote without reset --hard. #git git checkout -B vs git reset --hard

Updating a local diverged git branch to latest remote without reset --hard

Sometimes you have a branch checked out locally that someone else owns and they do a force push. Perhaps it's during a review when they have pushed all the needed fixups and got them approved. So now they squash and force-push the branch. It's time for you to take a new look at the updated commits, so you checkout the branch and try to update it.

The situation

$ git checkout some-topic-branch
$ git pull
@scmx
scmx / docker-prompt.md
Last active January 6, 2025 22:48
How to get a fancier bash prompt PS1 inside a docker container #docker #ps1 #emoji

How to get a fancier bash prompt PS1 inside a docker container

Today I wanted to make a recording of me running some commands inside a docker-container.

❯ docker-compose run app bash
root@e9bb2af4dc11:/usr/local/go/src/example.com/dev/project#

Needless to say it looked a bit bland with no colors and a long prompt that prevents me from recording a small terminal and show the full commands I'm

@scmx
scmx / jxa-ts-applescript-typescript.md
Last active December 13, 2024 05:28
How to write AppleScript JXA JavaScript in Vim or VS Code with TypeScript types #applescript #jxa #javascript #typescript #types #vim #coc

How to write AppleScript JXA JavaScript in Vim or VS Code with TypeScript types

jxa-ts-applescript-typescript

If you have written an AppleScript before, you might have felt the same way as I did, that it was a poor experience to use the Script Editor app, it's barely better than writing the script in any text editor or in a heredoc to run using osascript.

Luckily you could try the JXA variant instead, AppleScript using Javascript. But writing such a file in the Script Editor app is not a better experience sadly.

@scmx
scmx / capybara-selenium-webdriver-slow-speed.md
Created May 5, 2018 07:46
Capybara Selenium WebDriver running at a lower speed using sleep command #capybara #selenium #rails #

Capybara Selenium WebDriver running at a lower speed using sleep command

Ever wanted to run your integration/end-to-end test suite at a lower speed so that you better could observe what's happening and perhaps make a recording of it?

Here's a a technique I've been using when writing tests with Capybara Selenium WebDriver.

Put this in test/test_helper.rb or maybe something like spec/support/capybara.rb.

@scmx
scmx / split-git-commit-with-orig-head.md
Last active October 3, 2024 16:55
How to split a Git commit and preserve message using ORIG_HEAD #git #commit #ORIG_HEAD https://twitter.com/albertarv/status/954389020758495233

How to split a Git commit and preserve message using ORIG_HEAD

A colleague told me he'd accidentally committed something. Now he wanted to remove it from the previous commit and then put in a new commit. This is called splitting a commit, and here's the best way I know of how to do it.

Solution

  1. git reset --soft HEAD~ Undo the last commit, but preserve "Changes to be committed"
  2. git reset <some/path> Exclude what you want
  3. git commit -C ORIG_HEAD Commit with the same message as before, which was stored in ORIG_HEAD

Example

@scmx
scmx / hide-idle-cursor.md
Last active July 15, 2024 14:05 — forked from josephwegner/jquery-hideIdleCursor.js
Hide your cursor on a web page when it is idle. Great if you're using a web page for some sort of TV Display and don't want the cursor messing things up. #javascript #cursor #css #idle #hide

Hide your cursor on a web page when it is idle

Great if you're using a web page for some sort of TV Display and don't want the cursor messing things up

document.addEventListener("DOMContentLoaded", () => {
  let idleMouseTimer;
  let forceMouseHide = false;

 document.body.style.cursor = "none";
@scmx
scmx / bash-prompt-git.md
Created May 9, 2018 12:32
Bash prompt with Git and autocompletion #bash #prompt #git #complete #autocomplete

Bash prompt with Git and autocompletion

First install HomeBrew and then use brew to install the bash-completion package

brew install bash-completion

After that you can open up your ~/.bashrc file and add the following:

# Load git prompt that display current branch etc
@scmx
scmx / proj-fzf-project-opener-with-tmuxinator.md
Last active December 14, 2023 15:16
proj shell script project opener using fzf with tmux and tmuxinator

proj shell script project opener using fzf with tmux and tmuxinator

proj-fzf-project-opener-tmux-nvim

First you need a script like this in your terminal. It will detect all your projects, format them with a date when last used, sort them and pass through fzf. When a project has been selected it will cd to that directory and by default run tn which is another script for creating a new tmux session from the current directory. If you run proj something it will run that instead inside that directory.

$HOME/.zshrc or similar

proj() {
  local project_cmd=("$@")