Skip to content

Instantly share code, notes, and snippets.

View smortex's full-sized avatar
🌴
Eating 🥥 and ddrinking 🍹…

Romain Tartière smortex

🌴
Eating 🥥 and ddrinking 🍹…
View GitHub Profile
@smortex
smortex / test_user_agent_parser.py
Created September 30, 2023 21:51
syslog-ng python parser to parse User Agent information from webserver logs
from user_agent_parser import UserAgentParser
from syslogng.message import LogMessage
import pytest
@pytest.fixture
def no_config():
return {
}
@smortex
smortex / sender_rewriting_scheme.py
Created September 30, 2023 21:50
syslog-ng python function to unwrap e-mail addresses rewritten with SRS
import re
def unwrap(message, address):
address = address.decode("utf-8")
result = re.search(r"\ASRS0=[^=]+=[^=]+=(?P<domain_name>[^=]+)=(?P<local_part>[^@]+)@", address)
if result == None:
result = re.search(r"\ASRS1=[^=]+=[^=]+==[^=]+=[^=]+=(?P<domain_name>[^=]+)=(?P<local_part>[^@]+)@", address)
if result == None:
@smortex
smortex / day5.pp
Created December 5, 2022 08:00
Advent of Code 2022 - Day 5
plan aoc::day5 (
Boolean $sample = false,
) {
$file = $sample ? {
false => 'aoc/2022/day5.txt',
true => 'aoc/2022/day5.sample.txt',
}
$lines = file($file).split('\n')
$separator = $lines.index |$value| { $value.empty }
@smortex
smortex / day4.pp
Created December 4, 2022 20:11
Advent of Code 2022 - Day 4
plan aoc::day4 (
Boolean $sample = false,
) {
$file = $sample ? {
false => 'aoc/2022/day4.txt',
true => 'aoc/2022/day4.sample.txt',
}
$data = file($file).split('\n').map |$line| {
$line.split(',').map |$part| {
$part.split('-').map |$n| { Integer($n) }
@smortex
smortex / functions_letter2number.pp
Created December 3, 2022 19:14
Advent of Code 2022 - Day 3
function aoc::letter2number(String $n) >> Integer {
$offset = $n ? {
/[a-z]/ => 1,
/[A-Z]/ => 27,
}
'abcdefghijklmnopqrstuvwxyz'.index |$char| { $char == $n } + $offset
}
@smortex
smortex / day2.pp
Created December 2, 2022 17:36
Advent of Code 2022 - Day 2
$data = file('aoc/2022/day2.txt')
$rounds = $data.split('\n').map |$line| { [$line[0], $line[2]] }
$scores1 = $rounds.map |$round| {
$shape_score = $round[1] ? {
'X' => 1,
'Y' => 2,
'Z' => 3,
}
@smortex
smortex / day1.pp
Last active December 1, 2022 22:25
$each_elf_carry_as_string = file('aoc/day1.txt').split('\n\n')
$each_elf_carry_as_array_of_integers = $each_elf_carry_as_string.map |$value| { $value.split('\n').map |$value| { Integer($value) } }
$each_elf_total_carry = $each_elf_carry_as_array_of_integers.map |$carry| { $carry.reduce |$memo, $value| { $memo + $value } }
warning($each_elf_total_carry.max)
warning($each_elf_total_carry.sort[-3, -1].reduce |$memo, $value| { $memo + $value })
@smortex
smortex / pulseaudio-pcm.sh
Created November 12, 2022 00:12
freebsd-devd-pulseaudio
#!/bin/sh
# /usr/local/bin/pulseaudio-pcm
set -x
/usr/bin/logger "$0 $*"
action=$1
case $action in
attach)
pcm=$2 dsp=dsp${2#pcm} uaudio=$3
@smortex
smortex / linux.pp
Created September 7, 2022 19:26
Monitoring with riemann-tools and virtual resorces
# site-modules/profile/manifests/base/linux.pp
class profile::base::linux {
# [...]
if fact('mountpoints').map |$mountpoint, $info| { $info['device'] }.any |$device| { $device =~ '^/dev/md' } {
@concat::fragment { 'riemann-wrapper-md':
target => '/etc/riemann-wrapper.yml',
order => '10',
content => @("CONFIG"),
- name: "md"
@smortex
smortex / riemann-query-each-node.rb
Created August 20, 2022 21:41
Gather the value of a Riemann metric for each node in PupppetDB
#!/opt/puppetlabs/puppet/bin/ruby
# Gather the value of a Riemann metric for each node in PupppetDB
require 'optparse'
require 'puppetdb'
require 'riemann'
usage = "usage: #{$PROGRAM_NAME} [metric]"