-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
530 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ out/ | |
|
||
.env* | ||
!.env.example | ||
|
||
# DB | ||
prisma/*.db* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
title: Controlling Browsers With AppleScript | ||
tags: [cli] | ||
--- | ||
|
||
I recently came across a [Raycast](https://www.raycast.com) extension that | ||
allows you to play/pause music from YouTube music while it's running in your | ||
browser. After exploring how it worked internally given I was a bit astonished | ||
it is even possible, I found that it's all just using AppleScript. | ||
|
||
So, a bit of bash code later and I had a working implementation of a new `js` | ||
command to allow running JavaScript either the active browser tab or in all | ||
windows with a given URL. | ||
|
||
```bash showLineNumbers js | ||
#!/usr/bin/env bash | ||
|
||
# Default values | ||
browser="Arc" | ||
url="" | ||
code="" | ||
|
||
# Parse the command line args | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
-b | --browser) | ||
browser="$2" | ||
shift 2 | ||
;; | ||
-u | --url) | ||
url="$2" | ||
shift 2 | ||
;; | ||
*) | ||
code="$1" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
_wrap() { | ||
if [[ -n "$url" ]]; then | ||
printf "repeat with w in (every window)\n" | ||
printf "repeat with t in (every tab whose URL contains \"$url\") of w\n" | ||
printf "tell t\n" | ||
else | ||
printf "tell front window\n" | ||
printf "tell active tab\n" | ||
fi | ||
|
||
# Run the JS | ||
printf "$1\n" | ||
printf "end tell\n" | ||
|
||
if [[ -n "$url" ]]; then | ||
printf "end repeat\n" | ||
printf "end repeat\n" | ||
else | ||
printf "end tell\n" | ||
fi | ||
} | ||
|
||
osascript -e " | ||
tell application \"$browser\" | ||
$(_wrap "execute javascript \"$code\"") | ||
end tell | ||
" >/dev/null | ||
``` | ||
|
||
Here's the command that will play music from YouTube music like what the Raycast | ||
extension was doing. But this now can be a terminal command! | ||
|
||
```bash play | ||
js --url music.youtube.com "document.querySelector('#play-pause-button[aria-label=Play]').click()" | ||
``` | ||
|
||
Definitely planning on using this more for other areas where I have simple | ||
JavaScript I want to execute, such as clicking something after a hot reload, | ||
etc. | ||
|
||
## Chromium security | ||
|
||
In Chromium based browsers (e.g. Chrome, Arc), you need to enable a developer | ||
flag in order for this to work properly. You can find it in the menu: | ||
|
||
``` | ||
View -> Developer -> Allow JavaScript from Apple Events | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Better Shell Aliases | ||
tags: [fish, cli] | ||
--- | ||
|
||
I use shell aliases quite heavily to simplify common CLI commands. However, one | ||
of my biggest pain points when using them is they didn't work as well in certain | ||
complex commands. | ||
|
||
For example, suppose I have the following alias in my Fish config that assigns | ||
the `task` command to an alias `t`: | ||
|
||
```bash | ||
alias t="task" | ||
``` | ||
|
||
Now I can run commands like this: | ||
|
||
```bash | ||
t add New task | ||
``` | ||
|
||
But with a complex command like this, it doesn't work: | ||
|
||
```fish | ||
seq 10 | xargs -I {} t add Testing {} | ||
``` | ||
|
||
I found that a simple solution was to simple create a binary in addition to the | ||
alias. For the `t` alias, this would look like this: | ||
|
||
```bash | ||
#!/usr/bin/env bash | ||
|
||
task "$@" | ||
``` | ||
|
||
Now, you could just create the binary and remove the alias, but the alias | ||
ensures fish can provide autocompletion properly, so I find that the combination | ||
of both gives the best of both worlds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Using Git Hooks When Creating Worktrees | ||
tags: [git] | ||
--- | ||
|
||
I've started to use `git worktree`s more lately but one of the pain points I had | ||
was that they don't copied ignored files such as `.env` files. I found I was | ||
able to improve this workflow by adding a `post-checkout` hook. | ||
|
||
In a nutshell, the hook will check if we are checking out a new worktree (that's | ||
what the `"$1" == "0000..."` is all about). If we are, then we can run some code | ||
to copy over whatever files we need to. | ||
|
||
```bash showLineNumbers .git/hooks/post-checkout | ||
#!/bin/bash | ||
|
||
if [[ "$1" == "0000000000000000000000000000000000000000" ]]; then | ||
basePath="$HOME/dev/repo" | ||
paths=(.env) | ||
|
||
for path in "${paths[@]}"; do | ||
cp "$basePath/$path" "$(pwd)/$path" | ||
done | ||
fi | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fuse: | ||
dir: "/litefs" | ||
|
||
data: | ||
dir: "/var/lib/litefs" | ||
|
||
exit-on-error: false | ||
|
||
proxy: | ||
addr: ":8080" | ||
target: "127.0.0.1:3000" | ||
db: "prod.db" | ||
|
||
exec: | ||
- cmd: "npx prisma migrate deploy" | ||
if-candidate: true | ||
|
||
- cmd: "node server.js" | ||
|
||
lease: | ||
type: "static" | ||
advertise-url: "http://${FLY_ALLOC_ID}.vm.${FLY_APP_NAME}.internal:20202" | ||
candidate: ${FLY_REGION == PRIMARY_REGION} | ||
promote: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.