---
type: collection
section: snippets
generated_at: 2026-04-11T07:09:56+02:00
total_entries: 12
---

# Snippets

## Remove Duplicate Homebrew Apache launchd Service

---
type: snippet
id: qbidnuc15pn3jbjs
title: >
  Remove Duplicate Homebrew Apache launchd
  Service
url: >
  https://www.jakubpelak.com/snippets/duplicate-homebrew-apache-service
section: snippets
tags:
  - Homebrew
  - macOS
  - Apache
  - launchd
  - CLI
published_at: 2026-02-19
---

If `brew services start httpd` succeeds but `brew services list` shows an error with `root` as the user, you likely have a leftover system LaunchDaemon from a previous `sudo brew services` invocation alongside the user LaunchAgent. Remove the system daemon to resolve the conflict.

```bash
brew services stop httpd || true
sudo brew services stop httpd || true
sudo launchctl bootout system /Library/LaunchDaemons/homebrew.mxcl.httpd.plist 2>/dev/null || true
sudo rm -f /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
brew services cleanup
brew services start httpd
```

After this, `brew services list` should show httpd as started under your user.

## Delete Local Git Branches Whose Remote Was Deleted

---
type: snippet
id: le540vfe3hsou4yo
title: >
  Delete Local Git Branches Whose Remote
  Was Deleted
url: >
  https://www.jakubpelak.com/snippets/git-branches-remote-deleted
section: snippets
tags:
  - Git
  - Cleanup
  - Automation
  - CLI
published_at: 2026-01-31
---

When working with feature branches, it’s easy for your local repository to accumulate branches that were already deleted on the remote. This snippet safely removes all local branches whose remote tracking branch no longer exists.

```sh
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -d
````

If you want to remove them regardless of merge status, replace `-d` with `-D`.

## Responsive Auto-Fill Grid with Tailwind Utility

---
type: snippet
id: l0pxg6oh1lu9fc1c
title: >
  Responsive Auto-Fill Grid with Tailwind
  Utility
url: >
  https://www.jakubpelak.com/snippets/responsive-auto-fill-grid-with-tailwind-utility
section: snippets
tags:
  - CSS
  - Grid
  - Tailwind
published_at: 2025-08-23
---

This custom Tailwind utility creates a responsive grid that automatically fills the available space with as many columns as possible. The minimum column width is controlled by the number you pass after `grid-cols-fill-`. Perfect for card layouts, galleries, or product grids without hardcoding breakpoints.

```postcss
@utility grid-cols-fill-* {
  grid-template-columns: repeat(
    auto-fill,
    minmax(min(calc(var(--spacing) * --value(integer)), 100%), 1fr)
  );
}
```

### Usage Example

```html
<div class="grid grid-cols-fill-48 gap-4">
  <div class="bg-gray-200 p-4">Item 1</div>
  <div class="bg-gray-200 p-4">Item 2</div>
  <div class="bg-gray-200 p-4">Item 3</div>
  <div class="bg-gray-200 p-4">Item 4</div>
</div>
```

This will create as many columns as fit in the container, each at least `calc(var(--spacing) * 48)` wide, expanding to fill remaining space.

## Find Dirty Git Repositories

---
type: snippet
id: yqeihixirgfk24gh
title: Find Dirty Git Repositories
url: >
  https://www.jakubpelak.com/snippets/find-dirty-git-repositories
section: snippets
tags:
  - Git
  - Automation
  - CLI
  - Script
published_at: 2025-08-08
---

A tiny shell script that recursively scans a directory for Git repositories with uncommitted changes, nicknamed `dirgit`—a play on words combining "directory", "dirty", and "git".

```bash
#!/bin/bash

# Use current directory or first argument
ROOT="${1:-$(pwd)}"

# Find all Git repositories and check for dirty state
find "$ROOT" -type d -name ".git" 2>/dev/null | while read -r gitdir; do
    repo="$(dirname "$gitdir")"
    cd "$repo" || continue
    if [[ -n $(git status --porcelain) ]]; then
        echo "$repo"
    fi
done
````

Save it as `dirgit` (or any name you prefer), make it executable (`chmod +x dirgit`), and place it in `/usr/local/bin` or `~/bin` to use it globally.

### Usage

```bash
dirgit         # scan current directory
dirgit ~/code  # scan a specific directory
```

## How to Reset a Single File in Git

---
type: snippet
id: g4togielbs9vkxus
title: How to Reset a Single File in Git
url: >
  https://www.jakubpelak.com/snippets/how-to-reset-single-file-in-git
section: snippets
tags:
  - Git
  - CLI
published_at: 2025-07-15
---

If you've made changes to a file and want to discard them, you can use `git checkout` to restore it to the version from the last commit. This is useful when you want to undo changes that haven't been staged yet.

```sh
git checkout -- <file>
```

To restore a file from a different branch, you can use:

```sh
git checkout <branch> -- <file>
```

## Delete All Local Branches Except main

---
type: snippet
id: RYVuj6j1rJ49DePN
title: Delete All Local Branches Except main
url: >
  https://www.jakubpelak.com/snippets/delete-all-local-branches-except-main
section: snippets
tags:
  - Git
  - Automation
  - CLI
published_at: 2025-06-26
---

A handy one-liner to clean up all your local Git branches except `main`. It uses `-D` to **force-delete** each branch, even if it hasn’t been merged—so be careful. If you want a safer version, replace `-D` with `-d` to only delete branches that have been merged.

```sh
git branch | grep -v "main" | xargs git branch -D
```

Credit: (link: https://coderwall.com/p/x3jmig/remove-all-your-local-git-branches-but-keep-master)

## Convert Image to WebP

---
type: snippet
id: CzfLwMhehVwtbw4R
title: Convert Image to WebP
url: >
  https://www.jakubpelak.com/snippets/convert-image-to-webp
section: snippets
tags:
  - Image
  - WebP
  - CLI
published_at: 2025-06-06
---

Quickly convert a PNG image to the modern WebP format using the `cwebp` CLI tool. This command sets the output quality to 80%, striking a good balance between file size and visual clarity—perfect for optimizing images for the web.

```bash
cwebp -q 80 image.png -o image.webp
```

## Switch remote HTTPS to SSH in Git

---
type: snippet
id: f4NDATop1pkniG9P
title: Switch remote HTTPS to SSH in Git
url: >
  https://www.jakubpelak.com/snippets/switch-remote-https-to-ssh-in-git
section: snippets
tags:
  - Git
  - SSH
  - HTTPS
  - CLI
published_at: 2025-05-25
---

Quick snippet to switch a Git remote URL from HTTPS to SSH for easier authentication with SSH keys.

```sh
git remote -v
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
```

Credit: (link: https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories)

## Merge Video and Audio with FFmpeg

---
type: snippet
id: 3y8oc2ShoNLSpS9R
title: Merge Video and Audio with FFmpeg
url: >
  https://www.jakubpelak.com/snippets/merge-video-and-audio-with-ffmpeg
section: snippets
tags:
  - Video
  - FFmpeg
  - Audio
  - CLI
published_at: 2025-03-13
---

This simple FFmpeg command merges a video file `video.mp4` and an audio file `audio.mp4` without re-encoding. It copies both streams as they are, ensuring fast processing and no quality loss.  

```sh
ffmpeg -i video.mp4 -i audio.mp4 -c:v copy -c:a copy output.mp4
```

## Rename PNG Files to Random UUIDs

---
type: snippet
id: kOwznHLJJRGeQ9R2
title: Rename PNG Files to Random UUIDs
url: >
  https://www.jakubpelak.com/snippets/rename-png-files-to-random-uuids
section: snippets
tags:
  - Automation
  - CLI
  - UUID
  - Script
published_at: 2025-03-09
---

A simple Bash script that renames all `.png` files in the current directory using randomly generated lowercase UUIDs. It ensures `uuidgen` is installed before execution and skips renaming if no PNG files are found.

```bash
#!/bin/bash

# Check if 'uuidgen' command is available
if ! command -v uuidgen &> /dev/null; then
  echo "uuidgen command not found. Please install it first."
  exit 1
fi

# Loop through all .png files in the current directory
for file in *.png; do
  # Skip if no PNG files found
  if [ ! -e "$file" ]; then
    echo "No PNG files found in the current directory."
    exit 0
  fi

  # Generate a random UUID v4 and convert to lowercase
  uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')

  # Rename the file
  mv "$file" "${uuid}.png"
done

echo "All PNG files have been renamed to random lowercase UUIDs."
```

## Adjust Color Opacity

---
type: snippet
id: jKV0rmGhPI0PdyWV
title: Adjust Color Opacity
url: >
  https://www.jakubpelak.com/snippets/adjust-color-opacity
section: snippets
tags:
  - CSS
  - Color
published_at: 2025-03-08
---

Easily create a semi-transparent version of any color using `color-mix()`. This CSS function blends two colors in a specified ratio. In this example, `currentColor` is mixed with `transparent` at 50%, creating a softer, partially transparent effect that adapts to the element’s text or border color.

```css
.something {
  color: color-mix(in srgb, currentColor, transparent 50%);
}
```

Credit: (link: https://una.im/color-mix-opacity/)

## Build a Search Query String in JavaScript

---
type: snippet
id: yreym9gqpwzlxr8o
title: >
  Build a Search Query String in
  JavaScript
url: >
  https://www.jakubpelak.com/snippets/javascript-build-search-query
section: snippets
tags:
  - JavaScript
  - Webdev
  - URL
published_at: 2024-05-30
---

PHP has (link: https://www.php.net/manual/en/function.http-build-query.php text: `http_build_query` target: _blank rel: external noopener) and I never forget it. JavaScript's (link: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams text: `URLSearchParams` target: _blank rel: external noopener) does the same thing but doesn't filter empty values or prepend `?`. This helper wraps it into something you can actually use directly:

```javascript
function buildSearch(params) {
  const query = new URLSearchParams(
    Object.entries(params).filter(([, x]) => x != null && x !== "")
  ).toString()
  return query && "?" + query
}
```

Credit: (link: https://stackoverflow.com/questions/316781/how-to-build-query-string-with-javascript text: Stack Overflow rel: external noopener)

