Skip to content

Instantly share code, notes, and snippets.

trait Handler<Args> {
fn call(self) -> Result<(), ()>;
}
macro_rules! impl_for_tuple {
($($tys:ident),*) => {
impl<F, $($tys,)*> Handler<($($tys,)*)> for F
where
F: FnMut($($tys),*) -> (),
$($tys: std::str::FromStr,)*
@ayosec
ayosec / parallel-thumbnails.sh
Created April 12, 2020 16:39
Directory thumbnails. Avoid memory limits in ImageMagick using subprocesses.
#!/bin/bash
set -eu -o pipefail
CMD="$(mktemp)"
for DIR in "$@"
do
echo "set -xe; montage \\" > "$CMD"
@ayosec
ayosec / aws-sdk with gem2deb.sh
Last active February 22, 2020 18:22
aws-sdk with gem2deb
set -xue -o pipefail
cd "$(mktemp -d)"
make-pkg sid gem2deb
dpkg -i debs/gem2deb*deb
gem2deb aws-eventstream
gem2deb aws-partitions
gem2deb jmespath
#!/usr/bin/wish
package require json
# Data from current window
set window [
json::json2dict [
exec i3-msg -t get_tree \
| jq ".. | (.nodes? // empty)\[] | select(.focused == true)"
@ayosec
ayosec / query-athena
Created January 29, 2020 17:25
Script to send queries to AWS Athena
#!/bin/bash
#
# This program sends a query to Athena, and download the results in CSV when
# the execution is completed. It expects the database name and the query as
# arguments:
#
# $ query-athena -d mydb 'select ...'
#
# The CSV file is downloaded in /tmp/QUERYID.csv by default. To use a different
# file, use -w:
#!/bin/bash
role="$1"
aws iam list-role-policies --role-name "$role" \
| jq -r '.PolicyNames[]' \
| sort \
| xargs -l1 aws iam get-role-policy --role-name "$role" --policy-name
#!/usr/bin/env ruby
#
# Launch pastel commands using GST syntax.
#
# Example
#
# $ pastel random ! mix green ! lighten 0.2 ! format
#
# https://github.com/sharkdp/pastel is expected to be in
# /usr/local/bin/pastel. Change the PROGRAM constant if
@ayosec
ayosec / color-picker.md
Last active August 27, 2019 01:53
Color picker

Pick a color with gpick and copy it to the clipboard:

gpick --pick --single --output --no-newline | xsel -b

To use with xbindkeys:

"(gpick --pick --single --output --no-newline | xsel -b -i) &amp;"