Skip to content

Instantly share code, notes, and snippets.

View danielkraic's full-sized avatar

Daniel Kraic danielkraic

View GitHub Profile
@danielkraic
danielkraic / goole-benchmark-test01.cpp
Created September 2, 2016 17:57
google benchmark c++ example
#include <iostream>
#include <sstream>
#include <benchmark/benchmark.h>
using namespace std;
static void BM_bench01(benchmark::State& st) {
while (st.KeepRunning()) {
std::stringstream s;
for (size_t i = 0; i < st.range(0); i++) {
@danielkraic
danielkraic / logger-rsyslog.py
Last active July 12, 2024 08:48
python app with loggin to rsyslog
"""
rsyslog config: /etc/rsyslog.d/my-sample.conf:
$template AppLogFormat, "%TIMESTAMP:::date-pgsql%%TIMESTAMP:27:32:date-rfc3339%(%syslogseverity-text%)%msg%\n"
if $app-name == 'my-sample-app' then -/var/log/my-sample-app/app.log;AppLogFormat
& ~
"""
from __future__ import print_function
# vim
:set number
:syn on
~/.vimrc: https://github.com/danielkraic/dotfiles/blob/master/vimrc
## files
vim file
vim +10 file
#include <iostream>
#include <memory>
#include <mutex>
// ScopedResource: resource with mutex (acquire resource in constructor, release in destructor)
template <class T>
class ScopedResource {
public:
ScopedResource(std::pair<T*, std::mutex&> resource)
: d_resource(resource.first),

bash

filename metacharacters

  • * any string
  • ? any single character
  • [abc..] match one of enclosed characters
  • [!abc..] match any characters not enclosed
  • ~ home dir
  • ~user user home dir
db.data.drop()
db.data.insertOne({"name": "val1"})
db.data.insertOne({"_id": "id100", "name": "val1"})
db.data.insertMany([
{ "name": "val1" },
{ "name": "val2" }
]
)
@danielkraic
danielkraic / frequency.erl
Last active April 10, 2017 05:06
solution to 'Enhancing the frequency server' - week 1 assignment of futurelearn's Concurrent programming Erlang
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([start/0,allocate/0,deallocate/1,stop/0,clear/0]).
@danielkraic
danielkraic / deprecated_route.py
Created June 6, 2017 20:04
flask deprecated_route
# deprecated_route.py
registered_deprecated_routes = set()
register_deprecated_routes = True
def is_deprecated(route):
return route in registered_deprecated_routes
@danielkraic
danielkraic / bits.cpp
Created December 12, 2017 16:23
bits operartions
short val = 12;
// check if bit is set:
if (val & 0b0010) return true;
// ensure bit is 1:
val = val | 0b0010;
// ensure bit is o:
val = val & ~0b0010;
p, .entry-content, .gallery-caption {
font-size: 14px;
}
.entry-content, .entry-summary {
padding: 0 5% 5%;
}
.site {
max-width: 1600px;