Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / clang38.sh
Created May 20, 2016 08:33
ubuntu 14.04 LTS clang 3.8
curl http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add
echo 'deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main' >> /etc/apt/sources.list
apt-get update
apt-get install clang-3.8 lldb-3.8
@alepez
alepez / detect-process-restart.sh
Created May 19, 2016 08:56
detect process restart
while true; do sleep 1; npid="$( ps | grep Dia[g] | awk '{ print $1 }' )"; if [ "$npid" != "$pid" ]; then echo "$(date) crash detected"; fi;
pid=$npid; done
montage *png -tile 4x4 -geometry 200x150 -background transparent sprites.png
@alepez
alepez / gist:724cc65cdc5f472ea2e5485832baa663
Created April 14, 2016 09:30
images before sprite matrix
convert all images to a fixed width, expanding the trasparent background. useful to create sprites
for i in ../*.png; do convert $i -gravity NorthWest -background transparent -extent 200x150 $( basename $i ); done
@alepez
alepez / recursive-string-map.cpp
Created January 29, 2016 16:40
recursive map of string
class Cfg {
public:
Cfg(std::initializer_list<std::pair<std::string, Cfg>> init) {
for (auto&& it: init) {
children_.insert(it);
}
}
Cfg(std::initializer_list<std::pair<std::string, std::string>> init) {
for (auto&& it: init) {
children_.insert(it);
@alepez
alepez / server
Last active January 26, 2016 16:40 — forked from pierro43/server
/**
* An Mirf example which copies back the data it recives.
*
* Pins:
* Hardware SPI:
* MISO -> 12
* MOSI -> 11
* SCK -> 13
*
* Configurable:
@alepez
alepez / param_pack_to_string_vector.cpp
Created January 26, 2016 08:33
C++ parameter pack of any type to vector of strings
template <typename... Args>
std::vector<std::string> toStringVector(Args... args) {
std::vector<std::string> result;
auto initList = {args...};
using T = typename decltype(initList)::value_type;
std::vector<T> expanded{initList};
result.resize(expanded.size());
std::transform(expanded.begin(), expanded.end(), result.begin(), [](T value) { return std::to_string(value); });
return result;
}
@alepez
alepez / clang-format
Created January 22, 2016 08:11
my clang format
## http://clang.llvm.org/docs/ClangFormatStyleOptions.html
## Version: 3.8
---
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
@alepez
alepez / base64.cpp
Created January 21, 2016 16:14
c++ base64 RAII
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
using RawData = std::vector<uint8_t>;
RawData encode(const RawData& input) {
BIO* b64 = BIO_new(BIO_f_base64());
BIO* bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);
@alepez
alepez / compose.cpp
Created December 17, 2015 13:51
c++11 checker composition
template <typename T>
using Checker = std::function<bool(T)>;
template <typename T>
class Param {
public:
Param(std::string, Checker<T>) {
}
Param(std::string) {