Skip to content

Instantly share code, notes, and snippets.

Avatar

Albert Arvidsson scmx

View GitHub Profile
@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
View locales-find-ruby-on-rails-script.md

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
View locales-compare-ruby-on-rails.md

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
View git-allcommits.md

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
View vscode-settings-typescript-tsdk-double-backslash-windows-workaround-nextjs.md

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
View equential-paste-recording.md

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
View nodejs-detect-inconsistent-filepaths-in-smallburg-character-asset-pack.md

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

Smallburg Base Pack (Smallburg Village 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
View jxa-ts-applescript-typescript.md

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 / iterm-dynamic-profile-dark-mode.md
Created April 9, 2021 18:44
How to switch between dark mode and light mode in iTerm using dynamic profiles #iterm #dark-mode #light-mode #node
View iterm-dynamic-profile-dark-mode.md
@scmx
scmx / git-commit-title-first-word.md
Last active February 27, 2023 02:20
Example list of verbs / first word to use in git commit title #git #commit #title
View git-commit-title-first-word.md

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 / extract-objects-from-rails-models-and-controllers.md
Last active February 17, 2023 11:28
7 Patterns to Refactor Rails Models 7 years later #rails #model #refactor #valueobject #serviceobject #formobject #queryobject #viewobject #policyobject #decorator
View extract-objects-from-rails-models-and-controllers.md

7 Patterns to Refactor Rails Models 7 years later

You may have read the following excellent blogpost by Brian Helmkamp of CodeClimate. It nicely describes 7 types of objects that can be extracted from models and controllers in a Rails-app.

7 Patterns to Refactor Fat ActiveRecord Models https://codeclimate.com/blog/7-ways-to-decompose-fat-activerecord-models/ Brian Helmkamp on Oct 17, 2012.

Here are my thoughts on it, reading it as an experienced rails developer, 7 years later 😅 👴