Skip to content

Instantly share code, notes, and snippets.

Romain Gehrig RomainGehrig

View GitHub Profile
@RomainGehrig
RomainGehrig / dbus_env.sh
Created Feb 27, 2018
Import DBUS variables of the current user
View dbus_env.sh
# 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
@RomainGehrig
RomainGehrig / fastMappend.hs
Last active Apr 30, 2019
Use a technique similar to fast exponentiation for repeatedly `mappend`ing the same monoid
View fastMappend.hs
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
You can’t perform that action at this time.