Skip to content

Instantly share code, notes, and snippets.

View ptomulik's full-sized avatar

Paweł Tomulik ptomulik

  • Warsaw University of Technology
  • Warsaw, Poland
View GitHub Profile
@ptomulik
ptomulik / list-releases.js
Created January 8, 2021 00:00
List release names for github repository
"use strict";
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: 'my-personal-token'
});
octokit.paginate(
<?php
abstract class AbstractProperties extends \ArrayObject implements PropertiesInterface
{
final public function getComparableArray() : array
{
return $this->getComparableArrayRecursive([]);
}
final protected function getComparableArrayRecursive(array $stack)
{
@ptomulik
ptomulik / dload_untar.py
Created October 12, 2015 00:23
Download and untar file
#! /usr/bin/env python
def download_and_untar(url, **kw):
import os
import tarfile
from io import BytesIO
try: from urllib.request import urlopen
except ImportError: from urllib import urlopen
# Options
try: strip_components = kw['strip_components']
@ptomulik
ptomulik / rotate_old_radacct_detail_files_mtime_based.sh
Last active December 16, 2022 11:44
Rotation script for freeradius accounting detail files. Shall be run as a cron script.
#! /bin/sh
########################################################################################
# Compresses old radacct detail files and removes very old compressed radacct files.
########################################################################################
# Author: P. Tomulik
########################################################################################
# Path to the programs used (for environments without $PATH set)
FIND=/usr/bin/find
@ptomulik
ptomulik / string_mainp.cpp
Created August 11, 2015 11:06
String mainpulations
#include <string>
#include <iostream>
#include <algorithm>
namespace detail {
template<class CharT, class Traits, class SAlloc, class VAlloc>
void
string_split_impl(std::basic_string<CharT, Traits, SAlloc> const& str, CharT delim,
std::vector<std::basic_string<CharT, Traits, SAlloc>, VAlloc>& pieces)
@ptomulik
ptomulik / convert_example.cpp
Created August 11, 2015 00:27
converting wide string to narrow and vice-versa
#include <locale>
#include <string>
#include <stdexcept>
std::wstring
widen(std::string const& str, std::codecvt<wchar_t, char, std::mbstate_t> const& cvt)
{
if(str.empty())
return std::wstring();
@ptomulik
ptomulik / wstream_convert.hpp
Created August 8, 2015 21:31
wstream_convert
// clxx/common/wstring_convert.hpp
/** // doc: clxx/common/wstring_convert.hpp {{{
* \file clxx/common/wstring_convert.hpp
* \brief Provides clxx::wstring_convert
*/ // }}}
#ifndef CLXX_COMMON_WSTRING_CONVERT_HPP_INCLUDED
#define CLXX_COMMON_WSTRING_CONVERT_HPP_INCLUDED
#include <string>
@ptomulik
ptomulik / simple_node_clasifier_2_0.py
Last active August 29, 2015 13:56
Simple node clasifier for Puppet written in python.
#! /usr/bin/env python
# Python ENC
# receives fqdn as argument
import yaml
import sys
enc = {
'classes' : { 'base' : {} },
'environment' : 'production',
@ptomulik
ptomulik / to_lambda.rb
Created January 28, 2014 16:12
Convert procs to lambdas
module ToLambda
def to_lambda(block)
if Puppet::Util::Package.versioncmp(RUBY_VERSION,"1.9") >=0
unless block.lambda?
# This code is based on: https://github.com/schneems/proc_to_lambda
# See also https://github.com/schneems/proc_to_lambda/issues/1
if RUBY_ENGINE && RUBY_ENGINE == "jruby"
lambda(&block)
else
Object.new.define_singleton_method(:_, &block).to_proc
@ptomulik
ptomulik / package_settings.rb
Created January 19, 2014 18:23
Add features and properties dynamically to a resource type
# lib/puppet/backport/type/package/package_settings.rb
package = Puppet::Type.type(:package)
unless package.features.include? :package_settings
package.feature :package_settings ...
package.newproperty(:package_settings, :required_features=>:package_settings) do
...
end
end