Improvement on a shell one-liner
objdump -d /usr/bin/* | cut -f3 | ja '~.{%/^[a-z]+/}{`1}'
cabal list --simple | ja '~.$1'
(one can download all packages from Hackage with:)
cabal list --simple | ja '~.$1' | xargs cabal get
This is simpler than:
cabal list --simple | cut -d' ' -f1 | sort -u
cabal info splitmix \
| ja -R '\n[^:\n]*:' -b -F'\s*,\s*' '[x ~* 1 /(\d+(\.\d+)*)/]:?{%/Versions available:/}{[y]|>`$}'
git branch --contains | ja '{%/^[^\*]/}{`0}' | xargs git branch -d
ja --csv "{ix=1}{sprintf'CREATE TABLE c (%s);'([x+', '+y]|>[sprintf '%s TEXT' x]¨\`$)}" -i data.csv
CREATE TABLE c (Series_reference TEXT, Period TEXT, Data_value TEXT, STATUS TEXT, UNITS TEXT);
cdeps pyc/apple.c | ja "[x+' '+y]|> ~.{|subs /[^\/]+\/\.\.\// '' \`0}"
This is not entirely rigorous since dir1/dir2/../file
is not always dir1/../file
.
cdeps pyc/apple.c | xargs realpath | ja "[x+' '+y]|> ~.\$0"
Extract Fixity Declarations for HLint
{%/infix(r|l)?\s+\d+/}{sprintf '- fixity: %s' `0}
Equivalently:
[sprintf '- fixity: %s' x]¨(~/infix(r|l)?\s+\d+/)#.$0
This is equivalent to hlint --find src/FILE.hs | rg '^- fixity:'
, except it
works on Happy, Alex, etc. preprocessor files.
echo 'https://soundcloud.com/shitzulover07/ayesha-erotica-vacation-bible-school?utm_medium=text&utm_campaign=social_sharing' \
| ja '.?{|`1 ~* 1 /([^\?]*)/}'
yields
https://soundcloud.com/shitzulover07/ayesha-erotica-vacation-bible-school
Download a video using yt-dlp, trimming tracking information from the URL:
yt-dlp "$(pbpaste | ja '.?{|`1 ~* 1 /([^\?]*)/}')"
Modification of a StackExchange one-liner using Awk.
ps -aux | rg "$(ps -p $$ -o ppid=)" | ja '{ix=1}{`*}'
cabal -v0 build |& ja -R'\n\n' -F':' "{\`1='src/Ty.hs'}{\`0}"
fd '\.hs$' . -x ja '.?{|`0 ~* 1 /LANGUAGE\s*([a-zA-Z]*)\s*#-/}' -i | ja '~.$0'
This is not entirely rigorous; it does not account for {-# LANGUAGE Xxx,Yyy #-}
.
This could be used to populate the other-extensions
field in a .cabal
file.
curl -sL https://raw.githubusercontent.com/nychealth/coronavirus-data/master/latest/now-weekly-breakthrough.csv | \
ja ',[1.0-x%y] {ix>1}{`5:} {ix>1}{`17:}' -F,
ja -F= '{%/let\s*[[:lower:]][[:alnum:]]*/}{(⍳.`1)}' -i lib.dhall
curl https://www.stats.govt.nz/assets/Uploads/Food-price-index/Food-price-index-September-2023/Download-data/food-price-index-september-2023-weighted-average-prices.csv -o food-prices.csv
ja --csv '(%)\. {%/Apple/}{`3:}' -i food-prices.csv
printenv | ja -F= '{%/^PATH/}{`2}'
nm -D $(which pandoc) \
| sed 's/\([^z]\)zi/\1./g ;s/\([^z]\)zm/\1-/g; s/\([^z]\)zd/\1$/g; s/ZC/:/g; s/zz/z/g' \
| ja '~..?{`2 ~ /^(T|t)$/}{`3 ~* 1 /([A-Za-z][A-Za-z0-9\-]*\-\d+(\.\d+)*)\-[0-9a-f]{4}/}'
@include'lib/string.jac'
unlines¨{% /-lHS/}{captures `0 1 /-lHS([A-Aa-z][A-Za-z0-9\-]*\d+(\.\d+)*)/}
readelf -p '.debug-ghc-link-info' $(which pandoc) | ja -R, '.?{|`0 ~* 1 /-lHS([A-Aa-z][A-Za-z0-9\-]*\d+(\.\d+)*)/}'
readelf -p '.debug-ghc-link-info' $(which pandoc) | tr ',' '\n' | rg '\-lHS([A-Aa-z][A-Za-z0-9\-]*\d+(\.\d+)*)' -o -r'$1'
readelf -d $(which vim) | ja '.?{%/Shared library/}{`5 ~* 1 /\[(.*)\]/}'
otool -l $(locate libpng.dylib | tail -n1) | ja -R'Load command' '{%/LC_LOAD_DYLIB/}{`7}'
otool -l $(locate libapple.dylib | tail -n1) | ja -R 'Load command' '{%/LC_RPATH/}{`7}'
readelf -d libapple.so | \
ja '.?{%/RUNPATH/}{`5 ~* 1 /\[(.*)\]/}' | \
tr ':' '\n'
readelf -h $(locate libpng.so | tail -n1) | ja -F':\s*' '{%/Machine/}{`2}'
Use the following to create a git tag by extracting the current version number
from the .cabal
file:
git tag "$(ja -F'\s*:\s*' '{%/^\s*version/}{`2}' -i jacinda.cabal)"
To kill all running GHC processes:
kill $(ps u | ja '{%/ghc/}{`2}')
fd '\.hs$' $(ja -F'\s*:\s*' '{%/hs-source-dirs/}{`2}' -i jacinda.cabal) -x stylish-haskell -i
fd '\.(c|h)$' -x wc -l | ja '(+)|0 $1:'
Count nonblank lines:
(+)|0 {%/./}{1}
Count blank lines:
(+)|0 {%/^$/}{1}
(+)|0 {%/Bloom/}{1}
max|_1 #¨$0
All lines >110 bytes:
{#`0>110}{`0}'
[#x>110] #. $0
Find all Haskell code >80 bytes wide
fd '\.hs$' -x ja '[#x>80] #. $0' -i
Is there a line >110 bytes?
(||)|#f {#`0>110}{#t}
(max|_1 #¨$0) > 110
One could write
sum := [(+)|0 x]
product := [(*)|1 x]
or := [(||)|#f x]
and := [(&)|#t x]
count := [(+)|0 [:1"x]
maximum := [max|_1 x]
(+)^0 [:1"$0
{|⍳}
futhark defs lib/github.com/vmchale/img-fut/img.fut | \
ja -F'[\s+:]' "{|sprintf '%s\t%s\tcall cursor(%s,%s)' (\`2.\`3.\`4.(splitc \`5 '-').1)}"
@include 'prelude/fn.jac'
fn dirname(x) :=
x ~* 1 /([^\/]*\/)*(.*)/;
fn src(d) :=
d ~* 1 /^\s*#include\s*"([^"]*)"/;
let
val dir := fromMaybe '.' (dirname fp) + '/'
in [(dir +)"src x]:?$0 end
One would invoke like so (zsh):
for d in $(ja run cdeps.jac -i src/frame.c); do realpath $d; done
This could be used for better dependency tracking in a Makefile, viz.
C_SRC := $(shell for d in $$(ja run cdeps.jac -i src/main.c); do realpath $$d; done | ja "[x+' '+y]|> \$$0")
src/main.c: $(C_SRC)
% python3 -m site | ja ".?{|\`1 ~* 1 /([^']*site-packages)/}"
/Users/vanessa/Library/Python/3.13/lib/python/site-packages
/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages
We could use this to pass flags to a C compiler like so:
% python3 -m site | ja "[x+' '+y]|>(sprintf'-L%s')¨.?{|\`1 ~* 1 /([^']*site-packages)/}"
-L/Users/vanessa/Library/Python/3.13/lib/python/site-packages -L/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages
rg 'traverse' -c | ja -F: '(+)|>$2:i'