Skip to content

Instantly share code, notes, and snippets.

View scmx's full-sized avatar

Albert Arvidsson scmx

View GitHub Profile
@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(' ')
@scmx
scmx / locales-find-ruby-on-rails-script.md
Created March 15, 2023 13:44
Ruby on Rails locales-find script for fuzzy searching through locales yaml files using full dot notation part #rails #locales #fzf #fuzzy #compare

Ruby on Rails locales-find script for fuzzy searching through locales yaml files using full dot notation part

Hacked together a quick ruby script for fuzzy searching for locale keys with their full dot notation part. It loads all yaml files in config/locales, flattenes all the key paths like sv.foo.bar.baz and prints the value and filename after. The result is passed through fzf for fuzzy filtering.

bin/locales-find | fzf --ansi -e

or maybe: docker-compose run --rm web bin/locales-find 2>/dev/null | fzf --ansi -e

@scmx
scmx / locales-compare-ruby-on-rails.md
Created March 15, 2023 13:29
Ruby on Rails compare yaml locales by key for each language #rails #locales #yml #compare #ruby #script

Ruby on Rails compare yaml locales by key for each language

Comparison tool for rails locales.

Pass in dotation paths for interesting yaml parts and this tool will travsere through all locales looking for matches, printing the found value for each locale if a match is found.

Example usage

@scmx
scmx / git-allcommits.md
Last active February 23, 2023 20:58
git-allcommits List all commits made by you in all repositories in the last month #git #commits #multirepo

git-allcommits List all commits made by you in all repositories in the last month

#!/usr/bin/env bash

# List all commits made by you in all repositories in the last month

set -euo pipefail

commits=()
@scmx
scmx / vscode-settings-typescript-tsdk-double-backslash-windows-workaround-nextjs.md
Last active February 22, 2023 16:08
VSCode settings.json typescript.tsdk double backslash windows workaround Next.js

VSCode settings.json typescript.tsdk double backslash windows workaround Next.js

VSCode does not provide a way to have OS specific .vscode/settings.json for a project. microsoft/vscode#5595

Next.js adds property to it with a value that needs to be different for windows:

  • macOS/Linux "typescript.tsdk": "node_modules/typescript/lib"
  • Windows "typescript.tsdk": "node_modules\\typescript\\lib"

This is problematic when you want the file to be shared and tracked by version control.

@scmx
scmx / equential-paste-recording.md
Created January 23, 2023 10:48
macOS Sequential Copy Paste pbcopy pbpaste shell script. Start it and copy some things. Press Ctrl+c and you get the list all things you copied. #macos #clipboard #sequential #paste #pbpaste #pbcopy #bash #shell

macOS Sequential Copy Paste pbcopy pbpaste shell script

Start it and copy some things, then press Ctrl+c and you get a list of all things you copied.

~/.bin/sequential-paste-recording

#!/usr/bin/env bash

list=()
last=""
@scmx
scmx / nodejs-detect-inconsistent-filepaths-in-smallburg-character-asset-pack.md
Last active October 4, 2022 12:20
Node.js script for detecting inconsistent character images in small-burg-towns-pack Smallburg base pack

Node.js script for detecting inconsistent character images in small-burg-towns-pack Smallburg base pack

is a really cool pixel art pack by almostApixel that you can find on itch.io.

I was playing around with the folder of images and started building a little demo that generates a random character in a random state, with random skin, random hair etc.

But then I noticed that some images didn't load. The file paths I were relying on weren't consistent. If I for example randomized an adult character with a dark brown ponytail, then the image wouldn't work

@scmx
scmx / jxa-ts-applescript-typescript.md
Last active June 2, 2022 09:53
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.