<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/styles/rss-style.xsl" type="text/xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>eunoia :: snippets</title><description>small code snippets, usually just scripts or fun stuff to put in your .bashrc.</description><link>https://eunoia.sayitditto.net/</link><item><title>aesthetic imagemagick-edited photos</title><link>https://eunoia.sayitditto.net/snippets/aesimg/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/aesimg/</guid><description>distort an image to look super aesthetic!</description><content:encoded>&lt;p&gt;&lt;a href=&quot;https://imagemagick.org/&quot;&gt;imagemagick&lt;/a&gt; is &lt;em&gt;crazy&lt;/em&gt; powerful! seriously, you can do so much cool shit with it, all from your terminal. to be honest i did rip most of the flags in this from various forum threads but the script automates the process of making an image like below, ok? &lt;span&gt;:P&lt;/span&gt;&lt;/p&gt;

	example output from the script below
&lt;pre&gt;&lt;code&gt;&amp;lt;img src=&quot;/images/ruru/ruru-aesimg.jpg&quot; alt=&quot;edited photo of dambara ruru performing on stage with the hand microphone held up to her mouth as she sings. the image has been distorted and transformed using image magick to make it black &amp;amp; white, dither it, and add half tones&quot; width=&quot;50%&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env bash
#
# usage: aesimg image_file_name

orig=&quot;$1_orig&quot;

cp $1 $orig

magick $1 -level 0x70% -set option:distort:viewport &apos;%wx%h+0+0&apos; -colorspace CMYK -separate null: \( -size 2x2 xc: \( +clone -negate \) +append \( +clone -negate \) -append \) -virtual-pixel tile -filter gaussian \( +clone -distort SRT 60 \) +swap \( +clone -distort SRT 30 \) +swap \( +clone -distort SRT 45 \) +swap \( +clone -distort SRT 0 \)  +swap +delete -compose Overlay -layers composite -set colorspace CMYK -combine -colorspace RGB &quot;$1_ver1&quot;

magick &quot;$1_ver1&quot; -colorspace gray &quot;$1_ver2&quot;

magick &quot;$1_ver2&quot; -ordered-dither h16x16o &quot;$1&quot;

rm -rf &quot;$1_ver1&quot; &quot;$1_ver2&quot;
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>copy all magnet links on a page</title><link>https://eunoia.sayitditto.net/snippets/copymagnetlinks/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/copymagnetlinks/</guid><description>bookmarklet to grab every magnet link on a page</description><content:encoded>&lt;p&gt;i am an avid torrenter, and so sometimes in my torrenting adventures, i&apos;ll do a search for something i want/need, and find that there is no batch for it; instead, there are only haphazard pieces of a would-be batch. and sometimes there can be a &lt;em&gt;lot&lt;/em&gt; of these links!&lt;/p&gt;
&lt;p&gt;&lt;a&gt;copy all magnet links&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;the code is below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;!function(a) {
	var b = document.createElement(&quot;textarea&quot;),
	c = document.getSelection();
	b.textContent = a, document.body.appendChild(b), c.removeAllRanges(), b.select(), document.execCommand(&quot;copy&quot;), c.removeAllRanges(), document.body.removeChild(b)
}

(Array.from(document.querySelectorAll(&apos;a[href*=&quot;magnet:?&quot;]&apos;)).join(&quot;\n\n&quot;));
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>terminal notifications</title><link>https://eunoia.sayitditto.net/snippets/notif/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/notif/</guid><description>(audible!) notifications after a long command</description><content:encoded>&lt;p&gt;i usually chain this one after commands like &lt;code&gt;dig&lt;/code&gt;, combined with &lt;code&gt;watch&lt;/code&gt;. for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;watch -g &quot;dig sayitditto.net +short&quot; &amp;amp;&amp;amp; notif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this makes it so that, when the &lt;code&gt;watch&lt;/code&gt; command detects a change, it exits, and then triggers the &lt;code&gt;notif&lt;/code&gt; function. it&apos;s &lt;em&gt;extremely&lt;/em&gt; convenient.&lt;/p&gt;
&lt;p&gt;the function triggers a sound with &lt;code&gt;aplay&lt;/code&gt; OR &lt;code&gt;paplay&lt;/code&gt; (depends on your audio setup), but you can change the path to any audio file you&apos;d like.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# to get quick notifs
# after long commands
notif() {
	notify-send &quot;done!&quot;
	paplay /usr/share/sounds/sound-icons/start
	spd-say -t female3 -r +25 &quot;done!&quot;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>alphanumeric password generator</title><link>https://eunoia.sayitditto.net/snippets/passgen/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/passgen/</guid><description>quick password generation for CLI nerds</description><content:encoded>&lt;p&gt;with the power of &lt;a href=&quot;https://github.com/charmbracelet/gum&quot;&gt;gum&lt;/a&gt;, this function accepts a number input and then uses it as the length for a randomly generated alphanumeric string.&lt;/p&gt;
&lt;p&gt;this is kind of jank but if, like me, you find yourself in need of a quick password or something and are too lazy to hit the &lt;i&gt;generate password&lt;/i&gt; button on your graphical password manager (please don&apos;t tell me you&apos;re not using one)... well, it&apos;s just &lt;kbd&gt;CTRL&lt;/kbd&gt; + &lt;kbd&gt;ALT&lt;/kbd&gt; + &lt;kbd&gt;T&lt;/kbd&gt; and you&apos;re off.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# password generator. takes input for password length by number
passgen() {
	PASSLENGTH=$(gum input --placeholder &quot;type a number&quot;)
	date +%s | sha256sum | base64 | head -c $PASSLENGTH ; echo
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>random network port</title><link>https://eunoia.sayitditto.net/snippets/portfree/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/portfree/</guid><description>get a random port number!</description><content:encoded>&lt;p&gt;as a sysadmin, i usually need new ports fast. my past method was to just keysmash a bit on the number pad till i found something that resembled an unused port, but then i read online about functions like this one, and wrote my own &lt;span&gt;:)&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# get a random free port. this is useful for my
# insane sysadmin website woman adventures
portfree() {
	while
		port=$(shuf -n 1 -i 49152-65535)
		netstat -atun | grep -q &quot;$port&quot;
	do
		continue
	done
	echo &quot;$port&quot;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>share files to server</title><link>https://eunoia.sayitditto.net/snippets/share/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/share/</guid><description>quickly send files to a server for sharing</description><content:encoded>&lt;p&gt;sometimes i need a quick link to a file, be it an image, video, text file, anything. and sometimes i don&apos;t want to wait to upload it somewhere, when all i need is a quick URL!&lt;/p&gt;
&lt;p&gt;the next best thing? send the file to your server (with a UUID before the original filename, so it can&apos;t be easily guessed), using SCP and SSH config shortcuts.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/env bash
#
# quickly share files

if [ $# -eq 0 ]; then
	echo &quot;Usage: share [FILENAME]&quot;
	exit 1
fi

FN_TEMP=$(uuidgen)_$(basename &quot;$1&quot;)

scp -q &quot;$1&quot; mac:/var/www/stash/pics/dump/&quot;$FN_TEMP&quot;

echo &quot;https://stash.4-walls.net/pics/dump/$FN_TEMP&quot; | lolcat
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>social media clips</title><link>https://eunoia.sayitditto.net/snippets/snsclip/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/snsclip/</guid><description>share your idol fancams to the masses</description><content:encoded>&lt;p&gt;i love my idol fancams and clips so i decided to save maybe half a second in sharing my idol clips with this script. it&apos;s a simple &lt;code&gt;yt-dlp&lt;/code&gt; wrapper, where the first argument is the youtube link, and the second is your desired filename (minus the extension; it&apos;ll always be an MP4 file).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/env bash
#
# yt-dlp wrapper for quickly making clips
# to share on social media

URL=&quot;$1&quot;
FILE_OUT_NAME=&quot;$2&quot;

if [ $# -eq 0 ]; then
	echo &quot;Usage: snsclip [URL] [FILENAME]&quot;
	exit 1
fi

yt-dlp -f &quot;ba+bv*[height&amp;lt;=1080p]&quot; -o &quot;$FILE_OUT_NAME&quot; &quot;$URL&quot; --merge-output-format mp4
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>fahrenheit and celsius conversion</title><link>https://eunoia.sayitditto.net/snippets/temperature/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/temperature/</guid><description>convert to/from celsius and Burger Units</description><content:encoded>&lt;p&gt;i write this as my region is in the midst of a record breaking, &lt;a href=&quot;https://medium.com/@ian.hunt27/coldest-summer-of-the-rest-of-our-lives-bd04812b40f8&quot;&gt;coldest summer of our lives&lt;/a&gt; kinda heat wave. thus, to accurately convey to your friends in different areas how hot it is, this script may be handy!&lt;/p&gt;
&lt;p&gt;this script relies on the wonderful &lt;a href=&quot;https://github.com/charmbracelet/gum&quot;&gt;gum&lt;/a&gt; by &lt;a href=&quot;https://charm.sh/&quot;&gt;charm CLI&lt;/a&gt; — check it out to make your scripts cute AF!&lt;/p&gt;
&lt;p&gt;(inspired by &lt;a href=&quot;https://www.youtube.com/@BreadOnPenguins&quot;&gt;bread on penguins&lt;/a&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/env bash

f_to_c() {
	fah=&quot;$(gum input --placeholder &apos;enter temp in fahrenheit&apos;)&quot;
	cel=$(bc &amp;lt;&amp;lt;&amp;lt; &quot;scale=2; ($fah - 32) * 5/9&quot;)
	result=&quot;$fah°F is equal to $cel°C&quot;
	notify-send &quot;$result&quot; &amp;amp;&amp;amp; echo &quot;$result&quot;
}

c_to_f() {
	cel=&quot;$(gum input --placeholder &apos;enter temp in celsius&apos;)&quot;
	fah=$(bc &amp;lt;&amp;lt;&amp;lt; &quot;scale=2; ($cel * 9/5) + 32&quot;)
	result=&quot;$cel°C is equal to $fah°F&quot;
	notify-send &quot;$result&quot; &amp;amp;&amp;amp; echo &quot;$result&quot;
}

choice() {
	choose=$(gum choose &quot;fahrenheit to celsius&quot; &quot;celsius to fahrenheit&quot;)
	case &quot;$choose&quot; in
		*celsius) f_to_c ;;
		*fahrenheit) c_to_f ;;
		*) exit;;
	esac
}

choice
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>webcam camera. webcamera lol</title><link>https://eunoia.sayitditto.net/snippets/webcam_img/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/webcam_img/</guid><description>take a few pics with your webcam on demand</description><content:encoded>&lt;p&gt;this one is basically a one-liner for taking two quick pics with your webcam. it uses &lt;code&gt;ffmpeg&lt;/code&gt;, obviously.&lt;/p&gt;
&lt;p&gt;change &lt;code&gt;$PICPATH&lt;/code&gt; to wherever you want to store these pictures. you might have to tweak the input device for &lt;code&gt;ffmpeg&lt;/code&gt;, too. and if you don&apos;t want any terminal logging, you can take out all references to &lt;code&gt;gum&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/bash

PICPATH=&quot;/home/kat/Pictures/Camera/webcam&quot;

echo &quot;taking pictures!&quot; | gum style --foreground &quot;#f4b8e4&quot; --border none

ffmpeg -f video4linux2 -i /dev/video0 -vframes 2 -video_size 1920x1080 &quot;$PICPATH/webcam_pic_$(date &apos;+%a__%b%d__%H_%M_%S&apos;)%3d.jpeg&quot; -hide_banner -loglevel error

echo &quot;done!&quot; | gum style --foreground &quot;#f4b8e4&quot; --border none
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>device IP addresses</title><link>https://eunoia.sayitditto.net/snippets/whatip/</link><guid isPermaLink="true">https://eunoia.sayitditto.net/snippets/whatip/</guid><description>determine your device&apos;s IP addresses</description><content:encoded>&lt;p&gt;my PC changes its internal address frequently, which can cause problems when interacting with my servers. this function also prints the external address, because if i&apos;m checking my IP then i might as well see if that&apos;s changed again too.&lt;/p&gt;
&lt;p&gt;the text is piped to &lt;code&gt;&lt;a href=&quot;https://github.com/busyloop/lolcat&quot;&gt;lolcat&lt;/a&gt;&lt;/code&gt; because i like rainbows and cute things. you can take that out if you want.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# print internal &amp;amp; external IPs
whatip() {
	echo -n &quot;internal IP: &quot; | lolcat -p 0.7; hostname -I | awk &apos;{print $1}&apos;
	echo -n &quot;external IP: &quot; | lolcat -p 0.7; curl -4 icanhazip.com
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item></channel></rss>