Skip to content

Instantly share code, notes, and snippets.

View ppetr's full-sized avatar
🤞
I may be slow to respond.

Petr ppetr

🤞
I may be slow to respond.
View GitHub Profile
@ppetr
ppetr / monero.conf
Created July 31, 2023 15:34
Instrumenting monerod with Telegraf (InfluxDB)
# /etc/telegraf/telegraf.d/monero.conf
[[inputs.exec]]
name_override = '''monerod'''
interval = '''60s'''
commands = ['''curl --silent --data '{"jsonrpc":"2.0","id":"0","method":"get_info"}' http://localhost:18081/json_rpc''']
timeout = '''30s'''
# See https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
#!/usr/bin/env python3
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@ppetr
ppetr / ansible_combine.yaml
Created July 10, 2022 13:46
Ansible dictionary |combine
{''a'': [''a''], ''b'': [''b''], ''d'': [''LEFT'']}|combine(
{''a'': [''a''], ''c'': [''c''], ''d'': [''RIGHT'']})
a:
- a
b:
- b
c:
- c
d:
@ppetr
ppetr / to_shared_ptr.cc
Created November 20, 2021 16:19
Converts a move-constructible type `U` that provides a value of type `T` via `T& operator*() const;` method into `std::shared_ptr<const T>`.
// Converts a move-constructible type `U` that provides a value of type `T` via
// `T& operator*() const;` method into `std::shared_ptr<const T>`.
template <typename U,
typename T = typename std::remove_reference<decltype(
*std::declval<typename std::add_const<U>::type>())>::type>
std::shared_ptr<T> ToSharedPtr(U container) {
static_assert(std::is_move_constructible<U>::value,
"The container type U must be move-constructible");
const U* on_heap = new U(std::move(container));
return std::shared_ptr<T>(&**on_heap, [on_heap](T*) { delete on_heap; });
{-# LANGUAGE TypeFamilies #-}
import Data.Functor
import Data.Functor.Compose
import qualified Data.Foldable as F
import Data.Knot
import qualified Data.Map as M
import qualified Data.Traversable as T
-- * Functor data types
-- ** Person'
primes :: [Integer]
primes = 2 : filter isPrime [3,5..]
isPrime :: Integer -> Bool
isPrime n = all (\p -> n `rem` p /= 0) . takeWhile (\p -> p^2 <= n) $ primes
@ppetr
ppetr / gist:5fe182116ee22445545d
Created August 11, 2015 06:21
Building a recursive lazy pure FIFO
Empty
FIFO [0] Empty 1 [] 0
FIFO [0] Empty 1 [1] 1
FIFO [0] (FIFO [[1,2]] Empty 1 [] 0) 3 [] 0
FIFO [0] (FIFO [[1,2]] Empty 1 [] 0) 3 [3] 1
FIFO [0] (FIFO [[1,2]] Empty 1 [] 0) 3 [4,3] 2
FIFO [0] (FIFO [[1,2]] Empty 1 [] 0) 3 [5,4,3] 3
FIFO [0] (FIFO [[1,2]] Empty 1 [[3,4,5,6]] 1) 7 [] 0
FIFO [0] (FIFO [[1,2]] Empty 1 [[3,4,5,6]] 1) 7 [7] 1
FIFO [0] (FIFO [[1,2]] Empty 1 [[3,4,5,6]] 1) 7 [8,7] 2
@ppetr
ppetr / gist:f64c95613ecc481f80a1
Created March 27, 2015 12:39
Sub/supersonic propeller sound and shock wave diagrams
module Propeller where
import qualified Data.Foldable as F
import Diagrams.Prelude
import Diagrams.Backend.SVG
import Diagrams.Backend.SVG.CmdLine
type Diag = Diagram SVG R2
wave :: Double -> Double -> Diag
import Control.Arrow
import Control.Applicative
import Control.Category
import Prelude hiding ((.), id)
-- * Arrow from an applicative
newtype AppArrow f a b = AppArrow (f (a -> b))
instance (Applicative f) => Category (AppArrow f) where
@ppetr
ppetr / gist:6251714
Created August 16, 2013 17:15
Ideas for conduit-extras.
-- | Just like 'awaitForever', but adds state that is passed between
-- invocations of conduits.
awaitFold :: (Monad m) => (r -> i -> ConduitM i o m r) -> r -> Conduit i m o
awaitFold f = loop
where
loop r = await >>= maybe (return ()) (f r >=> mseq loop)
{-# INLINE awaitFold #-}
-- | Just like 'awaitFold', but allows premature termination of a
-- conduit by returning @mzero@.