Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created August 10, 2022 04:10
Show Gist options
  • Save djanatyn/c162282f5889fce4797bd61d267f98ba to your computer and use it in GitHub Desktop.
Save djanatyn/c162282f5889fce4797bd61d267f98ba to your computer and use it in GitHub Desktop.

Simple example posting a comment to a github issue:

#+name: fend-comment
#+begin_example markdown
# hello world
this is a github comment, you can enter any markdown
#+end_example

#+begin_src sh :dir ~/repos/nixpkgs :results output :var body=fend-comment
gh pr comment -R nixos/nixpkgs 124876 -b "$body"
#+end_src

#+RESULTS:
: https://github.com/NixOS/nixpkgs/pull/124876#issuecomment-850836938

More complex example, writing Haskell inline, and then evaluating it within a nix environment, using cabal repl:

#+name: show-tweets
#+begin_example haskell
import Data.Maybe

timeline <- jadaRPGTimeline ".cred.toml"
mapM_ putStrLn $ timeline ^.. each . text
#+end_example

#+begin_src sh :var script=show-tweets :dir ~/repos/jadas-journey :results output
NIXPKGS_ALLOW_BROKEN=1 nix develop --impure .#jadas-journey -c cabal repl <<< "$script"
#+end_src

#+RESULTS:
#+begin_example
Build profile: -w ghc-8.10.3 -O1
...
Entering the world of... Jada MMORPG
,*Jada.Journey Data.Maybe> *Jada.Journey Data.Maybe> Leaving GHCi.
#+end_example

Downloading images from an inline yaml file (maybe tangle it for fun!)

* thisanimedoesnotexist.ai
** list images
#+name: images
#+begin_example yaml
---
- https://thisanimedoesnotexist.ai/results/psi-0.6/seed2269.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed1327.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed1896.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed2781.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed4098.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed7950.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed7753.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed7646.png
- https://thisanimedoesnotexist.ai/results/psi-2.0/seed6545.png
#+end_example

** download them
#+begin_src sh :results output :var data=images
mkdir -p thisanimedoesnotexist
cd thisanimedoesnotexist

echo "downloading images at $(date)"
yq -r '.[]' <<< "$data" | while read -r post; do
    curl -LO "${post}" \
        && echo "downloaded: ${post}"
done
#+end_src

#+RESULTS:
#+begin_example
downloading images at Tue Jan 19 12:59:36 PM EST 2021
downloaded: https://thisanimedoesnotexist.ai/results/psi-0.6/seed2269.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed1327.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed1896.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed2781.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed4098.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed7950.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed7753.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed7646.png
downloaded: https://thisanimedoesnotexist.ai/results/psi-2.0/seed6545.png
#+end_example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment