Skip to content

Instantly share code, notes, and snippets.

View mhitza's full-sized avatar

Marius Ghita mhitza

View GitHub Profile
@mhitza
mhitza / attempt.md
Last active September 5, 2023 10:59
Two lines of shell script in 4 hours of custom Ansible module development

In the last couple of days I've typed away at some Ansible automation, and one specific group of tasks I dealt with was the creation of a target symlink and parent directories. I wasn't able to do this in one go, and thus arrived at the following result:

- name: "absolute home {{ config_path }}"
  set_fact:
    absolute_home_config_path: "{{ user_home_dir + '/.' + config_path }}"

- name: "{{ absolute_home_config_path|dirname }} present"
@mhitza
mhitza / strip-js-comments-run.md
Created August 6, 2023 12:16
Script using babel to strip all comments from JavaScript files
chmod +x strip-js-comments.mjs
npm install --save @babel/generator
npm install --save @babel/parser
./strip-js-comments.mjs assets/js/script.js
@mhitza
mhitza / main.hs
Last active December 14, 2022 10:12
Day 14 advent of code broken code
{-# LANGUAGE BlockArguments, Strict, LambdaCase, NoMonomorphismRestriction, MultiWayIf #-}
import Control.Monad.State.Strict
import Data.List
import Data.Char
import Data.Ord hiding (Down)
import Data.Bifunctor
import Data.Function
import Data.Functor.Identity
import Debug.Trace
@mhitza
mhitza / main.hs
Last active December 11, 2022 08:38
Day 11 advent of code 2022
{-# LANGUAGE BlockArguments, BangPatterns, LambdaCase, NoMonomorphismRestriction #-}
import Control.Monad.State.Strict
import Data.List
import Data.Bifunctor
import Data.Maybe
forEach xs st f = snd $ foldM (\st x -> runState (f x) st) st xs
alterF = modify . first
alterS = modify . second
getF = gets fst
@mhitza
mhitza / main.hs
Last active December 8, 2022 13:14
Day 8 advent of code 2022
{-# LANGUAGE BlockArguments, Strict #-}
import Control.Monad.State
import Data.List
import Data.Char
import Data.Bifunctor
takeUntilIncluding p [] = []
takeUntilIncluding p (x:xs)
| p x == True = x : takeUntilIncluding p xs
| otherwise = [x]
@mhitza
mhitza / main.hs
Created December 5, 2022 11:31
Day 5 advent of code 2022
{-# LANGUAGE BlockArguments, Strict #-}
import Control.Monad.State
import Data.List
import Data.Bifunctor (first)
import Data.Char
forEach xs state' f = foldM (\st v -> runState (f v) st) state' xs
@mhitza
mhitza / centos-stream.md
Last active March 4, 2021 03:33
CentOS 8 Stream on your favorite cloud provider

Q2 is closing in for the first release of [Rocky Linux][1], but until that rolls around I think it might be a good time to give CentOS Stream a try.

While I'm probably one of those users who will jump ship once Rocky Linux hits the shelves, so to speak, 2021 might not necessarily be the moment I make the switch. I'm not going to rant about RedHat's current track record; I will say that I somehow managed to trip on a couple of differences between RedHat 8 and CentOS 8. Which should even exist in the first place. Hopefully, the same issues aren't going to resurface with Rocky Linux. With the amount of Ansible roles I depend on daily, I'll wait things out a bit to stabilize first.

@mhitza
mhitza / vim-guile.md
Last active October 24, 2023 07:19
vim + GNU Guile development environment

This document was based on my local [GNU Guile][1]-3.0.5 setup. I'm not sure if it works as is with an older version of GNU Guile.

Because of a [dependency in Fedora][2] I had to compile GNU Guile from source release. As such, in your local setup the paths will differ. This is only relevant when defining the GUILE shell variable, and referencing the tags file in the vimrc.

Note that when building GNU Guile from source be sure that you have the readline-devel (or distro equivalent package) installed. That way the ./configure step will pick that up, and the ice-9 readline module will be usable.

@mhitza
mhitza / vimwiki.md
Last active June 19, 2020 09:20
Using Vimwiki like a standard desktop application

I've started using [Vimwiki][0] recently, mostly for note keeping, and this post is about how I integrated it into my workflow.

The main feature I use from Vimwiki is the Diary. And the way I've used past note taking applications were always in short bursts.

  1. Have an idea
  2. Launch the note-taking application
  3. Type in note
  4. Quit application.
@mhitza
mhitza / workflow.md
Last active April 12, 2022 12:54
Faster Ansible playbook iteration with tags and Vagrant snapshots

In the last few months, I had to write multiple Ansible playbooks, to the point that the slow write/test cycle became a major annoyance. What seemed to work well for me was a mix between Ansible tags and Vagrant snapshots. I would be happy to hear what workflow others employ, that specifically minimizes the time they spend testing.

Setup

Vagrantfile

Vagrant.configure("2") do |config|