Skip to content

Instantly share code, notes, and snippets.

@comargo
comargo / model_test.py
Created November 15, 2021 19:49
SQLAlchemy question
import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, relationship
Base = declarative_base()
class A(Base):
__tablename__ = 'A'
id = sa.Column(sa.Integer, primary_key=True)
@comargo
comargo / README.md
Last active June 28, 2024 15:52
OutputDebugString with cpp std::ostream

Sven Axelsson 24 Nov 2001

How to create an output stream that writes to the debug terminal.

Background

There are many different schools of how to debug a program (yeah, I know - write it correctly from the start), but whatever tools you prefer it is often very convenient just to use the printf approach. Well, since you are a modern C++ kind of person, you don't really want printf, you want to use an output stream, like cerr.

@comargo
comargo / round_dt.py
Last active August 1, 2017 21:28
Python ceil up or floor down datetime object to given resolution (not exceeding one day, with one second granularity)
from datetime import timedelta
def ceil_dt(dt, res):
# how many secs have passed this day
nsecs = dt.hour*3600 + dt.minute*60 + dt.second + dt.microsecond*1e-6
delta = res.seconds - nsecs % res.seconds
if delta == res.seconds:
delta = 0
return dt + datetime.timedelta(seconds=delta)
def floor_dt(dt, res):
@comargo
comargo / README.md
Last active July 21, 2017 17:22
gbp walkthrough

GBP Walkthrough

Start new package

git clone <repo>
dh_make -p <pkgName>_<version> -c gpl3 -s --createorig
<put gbp.conf to debian/gbp.conf>
@comargo
comargo / string_split_join.hpp
Last active July 18, 2017 14:52
string split and join
#ifndef STRING_SPLIT_JOIN_HPP
#define STRING_SPLIT_JOIN_HPP
#include <vector>
#include <string>
/**************************
* split/wsplit/basic_split<T>:
* Splits input string (argument #1) by separator (argument #2) and returns vector of strings
#include <gtest/gtest.h>
#include <system_error>
#define ASSERT_SYSTEM_ERROR(statement, error_code) \
ASSERT_THROW({\
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
catch(const std::system_error &exception) {\
ASSERT_EQ(error_code, exception.code());\
throw;\
@comargo
comargo / infix_iterator.h
Created July 28, 2016 17:04
Cool iterator class to join the strings
// infix_iterator.h
//
// Lifted from Jerry Coffin's 's prefix_ostream_iterator
#if !defined(INFIX_ITERATOR_H_)
#define INFIX_ITERATOR_H_
#include <ostream>
#include <iterator>
template <class T,
class charT=char,
class traits=std::char_traits<charT> >