Skip to content

Instantly share code, notes, and snippets.

View RomainGehrig's full-sized avatar

Romain Gehrig RomainGehrig

View GitHub Profile
@RomainGehrig
RomainGehrig / orgql-open.sh
Last active August 25, 2022 07:24
Query org-files, select entry and open emacs
# Put the lines below in your .bashrc
# Usage: orgql-open '(todo "TODO")'
# See sexp query format here: https://github.com/alphapapa/org-ql#non-sexp-query-syntax
function orgql-open() {
QUERY=$@
emacsclient -e "(json-encode (org-ql-query :select '(list (cons \"header\" (substring-no-properties (org-get-heading t t))) (cons \"link\" (substring-no-properties (org-store-link nil nil) 0)) (cons \"content\" (substring-no-properties (org-get-entry) 0))) :from (org-agenda-files) :where '$QUERY))"\
| xargs -I % -0 python -c "print(%)" \
| jq -r '.[] | (.link + "\t" + .header + "\t" + (.content|@json))' \
| fzf -d"\t" --with-nth=2 --preview 'cat <(echo {+2}) <(printf {+3} | sed -e "s/^\"//g" -e "s/\"$//g")' \
@RomainGehrig
RomainGehrig / fastMappend.hs
Last active April 30, 2019 13:08
Use a technique similar to fast exponentiation for repeatedly `mappend`ing the same monoid
import Data.Monoid
import Data.Function (on)
import System.Environment
-- | Apply repeatedly `mappend` on a monoid
-- | Uses the associativity and the identity element of monoids
fastMappend :: (Monoid a) => a -> Integer -> a
fastMappend x n = iter x n mempty
where iter :: (Monoid a) => a -> Integer -> a -> a
iter _ 0 acc = acc
@RomainGehrig
RomainGehrig / dbus_env.sh
Created February 27, 2018 13:31
Import DBUS variables of the current user
# Source dbus variables to enable dbus-dependant commands, like notify-send
# Integrate this gist in a script where you want to use said commands
# /!\ Security is not guaranteed, be careful when sourcing external files
set -o allexport
source $(readlink -f ~/.dbus/session-bus/*)
set +o allexport