Skip to content

Instantly share code, notes, and snippets.

Avatar

Albert Arvidsson scmx

View GitHub Profile
@scmx
scmx / equential-paste-recording.md
Created Jan 23, 2023
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 Oct 4, 2022
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 Jun 2, 2022
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 Apr 9, 2021
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 Jan 29, 2023
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 Jan 19, 2023
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 😅 👴

@scmx
scmx / hide-idle-cursor.md
Last active Dec 17, 2022 — 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
View hide-idle-cursor.md

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-vim-mac-os-bash.md
Last active Apr 24, 2022
Simple git + vim setup on Mac OS with bash #git #vim #macos #bash
View git-vim-mac-os-bash.md

Simple git + vim setup on Mac OS with bash

Nice defaults

git config --global commit.verbose true
git config --global push.default current

Load up ~/.bashrc on Mac OS bash ~/.bash_profile

@scmx
scmx / marbles.ex
Last active Dec 9, 2018
Elixir circular data structure marbles for solving Advent of Code 2018 day 9
View marbles.ex
defmodule Marbles do
def new do
%{size: 0, current: 0, counter: 0}
end
def to_list(state) do
[]
|> do_to_list(state, state.current, state.current)
|> Enum.reverse
end
@scmx
scmx / how-to-abbrev-long-tech-words.md
Created Oct 1, 2018
How to abbreviate long tech words nicely #abbreviate #tech #i18n #l10n #k8s
View how-to-abbrev-long-tech-words.md

How to abbreviate long tech words nicely :trollface:

Just for fun, I do not recommend using this

Ever heard of I18n? Probably. But do you know what it stands for? Internationalization. There's a few other common ones as well

  • l10n localization
  • k8s kubernetes