Skip to content

Instantly share code, notes, and snippets.

View arnobaer's full-sized avatar

Bernhard Arnold arnobaer

  • Institute of High Energy Physics, OeAW
View GitHub Profile
@arnobaer
arnobaer / all_equal.hxx
Created November 30, 2017 17:38
c++ test if all items in an iteratable container are equal
#include <algorithm>
template<typename T>
bool all_equal(const T& c)
{
return c.empty() or std::equal(++c.begin(), c.end(), c.begin());
}
// Example:
// std::vector<int> v{42, 42, 42};
@arnobaer
arnobaer / base62.h
Last active July 5, 2018 16:00
Base62 encoding in various languages
#ifndef base62_h
#define base62_h
#include <string>
/** Returns base 62 encoded unsigend integral value.
* base62(1234567890) // -> s"1ly7vk"
*/
std::string base62(unsigned long long value)
{
@arnobaer
arnobaer / ap_array.h
Last active July 20, 2018 12:13
Array container for Xilinx Vivado HLS implementing a compatible subset of std::array (requires C++11)
/*
* ap_array - array container for Xilinx Vivado HLS
* Copyright (C) 2018 Bernhard Arnold <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@arnobaer
arnobaer / hex2bytes.h
Last active January 13, 2023 11:33
C++ infinite hex string to bytes (of any junk size)
/*
* hex2bytes - hex string of unlimited length to a continous block of bytes
* Copyright (C) 2018 Bernhard Arnold <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@arnobaer
arnobaer / TextSearch.php
Last active August 16, 2018 16:11
Simple PHP full text search engine
<?php namespace TextSearch;
/* Fallback if multibyte string plugin is not available. */
if (!extension_loaded('mbstring')) {
function mb_strlen(...$args) { return strlen(...$args); }
function mb_strpos(...$args) { return strpos(...$args); }
function mb_stripos(...$args) { return stripos(...$args); }
function mb_substr(...$args) { return substr(...$args); }
}
#include <iostream>
#include <string>
#include <vector>
// sample container
struct jet
{
typedef size_t pt_type;
pt_type pt;
};
@arnobaer
arnobaer / utm-build-wheel-manylinux1.sh
Last active May 2, 2019 11:56
Build utm python wheels with included c++ libraries
#!/bin/bash
#
# Requires manylinux1 docker image
#
# Run 'init' on local host machine, then 'build', 'install' and 'wheel' from docher image.
# Note: wget will not work from manylinux1 docker image due to dreadful outdated OpenSSL!
#
# Docker instructions
#
# $ docker pull quay.io/pypa/manylinux1_x86_64
# Fractional prescales
from collections import OrderedDict
class Prescale:
def __init__(self, prescale, prec=2):
self.prescale = prescale
self.prec = 10**prec
self.count_max = self.prescale * self.prec
self.count = 0
# Fractional prescale patterns
#
# A = base
# B = base-1
#
# .0: 1B,
# .1: 1A, 9B
# .2: 1A, 4B
# .3: 1A, 2B, 1A, 2B, 1A, 3B
# .4: 1A, 1B, 1A, 2B
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--orbits', type=int, default=1)
parser.add_argument('--precision', type=int, default=1)
parser.add_argument('--prescale', type=float, default=2.0)
parser.add_argument('--show-ticks', action='store_true')
args = parser.parse_args()