Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kaidokert's full-sized avatar

Kaido Kert kaidokert

View GitHub Profile
@kaidokert
kaidokert / const_str_len.hpp
Last active January 6, 2020 04:53
C++11 const string length, gcc 4.7+ and clang 3.5+
// https://godbolt.org/z/uu4TMP
// API: constexpr size_t const_strlen( "foo" );
// Much more readable version here: https://gist.github.com/kaidokert/dfc08be8e75a3fc650d3daf8e89c3fe9
// but that doesn't work with GCC before version 7
#include <utility> //std::forward
#include <cstddef> //std::size_t
namespace detail {
template<size_t COUNTER, typename T>
@kaidokert
kaidokert / const_str_funcs.hpp
Last active January 4, 2020 08:59
C++11 recursive constexpr static string length and compare
constexpr bool is_str_end(const char *t) {
return !(t) || !(*t);
}
constexpr int recursive_cstr_len(const char * t) {
return is_str_end(t) ?
0 :
1 + recursive_cstr_len(t + 1);
}
@kaidokert
kaidokert / CoverageConfig.cmake
Last active December 26, 2019 21:52
Create coverage build configs with cmake
function(extend_custom_config_flags added_conf original_conf flags)
set(CMAKE_C_FLAGS_${added_conf} "${CMAKE_C_FLAGS_${original_conf}} ${flags}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_${added_conf} "${CMAKE_CXX_FLAGS_${original_conf}} ${flags}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_${added_conf} "${CMAKE_EXE_LINKER_FLAGS_${original_conf}} ${flags}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_${added_conf} "${CMAKE_SHARED_LINKER_FLAGS_${original_conf}} ${flags}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_${added_conf} "${CMAKE_MODULE_LINKER_FLAGS_${original_conf}} ${flags}" CACHE STRING "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_${added_conf} "${CMAKE_STATIC_LINKER_FLAGS_${original_conf}} " CACHE STRING "" FORCE)
endfunction()
if(True)
# install yq.readthedocs.io
find . -iname "*xml" -exec sh -c 'xq . {} | yq -S -y . > `dirname {}`/`basename {} .xml`.yaml' \;
@kaidokert
kaidokert / re_snippet.py
Last active April 29, 2018 19:39
Tracing excessive callers to re.compile in re.py
callers = {}
def _ghetto_compile(pattern, flags=0):
import inspect
try:
frame = '{}'.format(inspect.currentframe().f_back.f_code)
val = callers.setdefault(frame,0)
callers[frame] = val + 1
# print(frame)
if 'rest_framework.py' in frame:
@kaidokert
kaidokert / angular-bootstrap.html
Last active January 1, 2018 22:59
Minimal standalone bootstrap/angular page
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="" style="" xmlns:ng="http://angularjs.org" ng-app="fooApp" ng-strict-di>
@kaidokert
kaidokert / lambda_script.py
Created November 29, 2017 03:15
Simple AWS Lambda script that self-installs dependencies
import json
import logging
import pip
import site
# installed by lambda env
# import six
# import boto3
# from dateutil.easter import *
@kaidokert
kaidokert / celery_slow_query.py
Last active November 24, 2016 17:29
Django hooks to log slow database queries from celery tasks
import logging
from django.db import connection
from django.conf import settings
from celery.signals import task_prerun, task_postrun
from time import time
@task_prerun.connect()
@kaidokert
kaidokert / beartype.py
Created July 22, 2016 04:57 — forked from leycec/beartype.py
`@beartype` Decorator and Unit Test Suite Thereof
#!/usr/bin/env python3
'''
`@beartype` decorator, implementing a rudimentary subset of PEP 484-style type
checking based on Python 3.x function annotations.
See Also
----------
https://stackoverflow.com/a/37961120/2809027
Stackoverflow answer introducing the `@beartype` decorator.
@kaidokert
kaidokert / staticapp.py
Last active July 14, 2016 16:08
Low fuss bottle app to serve static
import os
import sys
import bottle
bottle.debug(True)
static_root = os.path.abspath(os.path.dirname(__file__))
@bottle.route('/')