Skip to content

Instantly share code, notes, and snippets.

View scmx's full-sized avatar

Albert Arvidsson scmx

View GitHub Profile
@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 / git-commit-title-first-word.md
Last active June 27, 2024 12:21
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 / using-details-summary-github.md
Last active June 24, 2024 16:56
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 / 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 / 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 19, 2024 21:36
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 / split-git-commit-with-orig-head.md
Last active January 9, 2024 09:37
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 / 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=("$@")
@scmx
scmx / generate-qrcode-quick-action.md
Last active November 21, 2023 15:09
Generate QR code macOS quick action open in Preview.app #qrencode #automator

Generate QR code macOS quick action open in Preview.app

#qrencode #automator

A little automator script for adding a right click menu Services -> "Generate QR Code and open in Preview"

brew install qrencode cli for creating QR code. (brew info qrencode)

Open Automator.app -> Add a new Quick Action (service) -> Add "Run Shell Script"

@scmx
scmx / obfuscate-sentence.md
Created October 2, 2023 11:53
Obfuscate sentence by scrambling letters except first and last #ruby #shell

Obfuscate sentence by scrambling letters except first and last

#ruby #shell

obfuscate-sentence

#!/usr/bin/env ruby

ARGF.read.split("\n").each do |line|
  puts line
    .split(' ')