Skip to content

Instantly share code, notes, and snippets.

View dhollman's full-sized avatar

Daisy S. Hollman dhollman

View GitHub Profile
@dhollman
dhollman / cute_challenge_details.md
Last active November 9, 2021 18:35
Cute C++ Challenge of the Week

Cute C++ Challenge of the Week

So I've had a lot of fun with my "Cute C++ trick of the day" posts and the talk I gave at CppCon as a result. I wanted to inspire others to create cute tricks and "play" with the language the way I've been over the past few years, so I've decided to start occasionally trying to post the "challenge" I've set for myself when creating a particular "Cute C++ trick of the day" a few days before I post my particular solution.

More details below, but in "TL;DR" form, here's how this works:

  • I'll tweet out a challenge that I have an interesting solution in mind for a few days in advance of posting the corresponding Cute C++ trick of the day.
  • I'll schedule my tweet with the solution at the same time I post the challenge, and I won't change it based on other's solutions.
  • I'll post a unique hashtag for the particular challenge (e.g., #CuteCppNamedTuple) and anyone who wants to participate can tag their soluti
@dhollman
dhollman / cute_trick_caveats_20201002.md
Last active October 2, 2020 17:53
Caveats to Cute C++ Trick of the Day for 2020-10-02

Caveats to Cute C++ Trick of the Day for 2020-10-02

TL;DR

Be very careful about using this if you care about performance, and there are aspects of this trick that appear to touch some fragile parts of the compilers, so proceed with caution.

Helpful links

@dhollman
dhollman / 01_continuation_concept.md
Last active August 8, 2018 00:54
Drawing yet another line between P0443 and P1054

Replacing the Execution Function Arguments with a Continuation Concept

Here are some possible continuation concepts to replace the NullaryCallable argument currently given to execution functions in P0443, ordered from smallest to biggest change. All names are up for discussion (including the term "continuation" itself), with the caveat that I think there is general agreement that the call operator shouldn't be used directly.

Continuation Concept A: simplest, but least generic version

Design decisions:

@dhollman
dhollman / executors_algorithms.md
Last active July 20, 2018 13:59
Standard Algorithms with Executors

Standard Algorithms Interaction with Different Executors Proposals

Disclaimers

Herein I'll use some hand-wavy implementation of the widely-suggested policy.on(executor) where, for instance, par.on(ex) returns something that matches a concept called ParallelPolicyOn<Executor>. I'll also be hand-wavy about a bunch of other things (e.g., ignoring the existence of ranges), but if they become a distraction (or if someone thinks something I've ignored is relevant) I'll be happy to change them. I'm also using compact concept notation for brevity.

An exploration of std::sort

inline void
do_threaded(int nthread, const std::function<void(int)>& f){
boost::thread_group compute_threads;
// Loop over number of threads
for(int ithr = 0; ithr < nthread; ++ithr) {
// create each thread that runs f
compute_threads.create_thread([&, ithr](){
// run the work
f(ithr);
});
from itertools import tee
a, b = "abc", "1234"
ai, bi = iter(a), iter(b)
for i in ai:
bi, bnew = tee(bi)
for j in bnew:
print i, j
from functools import wraps
import inspect
def operable_class(*ops):
""" Decorator to make class work with certain 'magic' double-underscored methods
(specified as arguments *without* the proceeding and trailing double-underscores).
This only works with new-style classes, as far as I can tell.
Examples
## {{{ http://code.activestate.com/recipes/577659/ (r1)
# -*- coding: utf-8 -*-
class alias(object):
"""
Alias class that can be used as a decorator for making methods callable
through other names (or "aliases").
Note: This decorator must be used inside an @aliased -decorated class.
For example, if you want to make the method shout() be also callable as
@dhollman
dhollman / regex_tutorial.py
Created June 7, 2012 20:15
Interactive regular expression tutorial (credit: http://code.activestate.com/recipes/496783/)
#!/usr/bin/env python
"""
Finding (and Replacing) Nemo
Instant Regular Expressions
Created by Aristide Grange
"""
import Tkinter as tk
import sre, itertools