Skip to content

Instantly share code, notes, and snippets.

@dodheim
dodheim / challenge_335_easy.cpp
Created May 15, 2018 15:12
C++17 solution for /r/dailyprogrammer challenge #335 [easy]
#include <cstdint>
#include <cstdlib>
#include <type_traits>
#include <utility>
#include <memory>
#include <range/v3/core.hpp>
#include <range/v3/span.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/numeric/accumulate.hpp>
#include <range/v3/utility/functional.hpp>
@dodheim
dodheim / is_constexpr_copyable.cpp
Last active March 29, 2018 14:27
is_constexpr_copyable [C++17] (candidate for https://stackoverflow.com/q/43120539)
#include <type_traits>
template<typename T, bool = std::is_default_constructible_v<T> && !std::is_array_v<T>>
struct constexpr_instance;
template<typename T>
struct constexpr_instance<T, true> {
constexpr T operator ()() const { return {}; }
};
namespace detail {
@dodheim
dodheim / nice_reddit.user.js
Last active November 26, 2017 14:55 — forked from prahladyeri/nice_reddit.user.js
A Firefox user script to mark unread Reddit comments in blue background
// ==UserScript==
// @name Nice Reddit
// @namespace com.prahladyeri.userscripts.nice_reddit
// @creator prahladyeri@yahoo.com
// @description Beautify your Reddit!
// @homepage http://www.prahladyeri.com
// @include http://*.reddit.com/*
// @include https://*.reddit.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version 1.2
@dodheim
dodheim / challenge_317_easy.cpp
Last active October 5, 2017 20:49
C++17 solution for /r/dailyprogrammer challenge #317 [easy]
#include <cstdint>
#include <type_traits>
#include <string_view>
#include <string>
#include <range/v3/core.hpp>
#include <boost/hana/core/is_a.hpp>
#include <boost/hana/functional/compose.hpp>
#include <boost/hana/functional/partial.hpp>
#include <boost/hana/at.hpp>
#include <boost/hana/at_key.hpp>
@dodheim
dodheim / no_mp11_rangemoves.patch
Created August 29, 2017 04:57
Boost 1.65.0 patches (excluding MP11 and Range move algos)
Left base folder: C:\libs\boost_1_65_0_unpatched
Right base folder: C:\libs\boost_1_65_0_dod
--- boost\algorithm\cxx14\equal.hpp 2017-08-19 09:49:39.000000000 -0700
+++ boost\algorithm\cxx14\equal.hpp 2017-08-21 15:24:58.000000000 -0700
@@ -18,12 +18,15 @@
namespace boost { namespace algorithm {
namespace detail {
template <class T1, class T2>
@dodheim
dodheim / with_mp11_rangemoves.patch
Created August 29, 2017 04:44
Boost 1.65.0 patches (including MP11 and Range move algos)
Left base folder: C:\libs\boost_1_65_0_unpatched
Right base folder: C:\libs\boost_1_65_0_dod
--- boost\algorithm\cxx14\equal.hpp 2017-08-19 09:49:39.000000000 -0700
+++ boost\algorithm\cxx14\equal.hpp 2017-08-21 15:24:58.000000000 -0700
@@ -18,12 +18,15 @@
namespace boost { namespace algorithm {
namespace detail {
template <class T1, class T2>
@dodheim
dodheim / fusion_map.cpp
Created August 28, 2017 20:25
Boost.Hana fusion_map demo for /u/Bitter_Peter
#define BOOST_HANA_CONFIG_ENABLE_STRING_UDL 1
#include <type_traits>
#include <utility>
#include <optional>
#include <string_view>
#include <array>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include <boost/hana.hpp>
@dodheim
dodheim / challenge_317_intermediate.rs
Last active July 11, 2020 19:35
Rust solution for /r/dailyprogrammer challenge #317 [intermediate]
#![feature(iter_map_while)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[repr(align(2))]
pub struct Element([u8; 2]);
impl Element {
fn as_str(&self) -> &str {
let s = if self.0[1] == 0 { &self.0[..1] } else { &self.0 };
unsafe { std::str::from_utf8_unchecked(s) }
@dodheim
dodheim / challenge_317_intermediate.cpp
Last active July 4, 2020 18:08
C++17 solution for /r/dailyprogrammer challenge #317 [intermediate]
#include <cstdint>
#include <type_traits>
#include <utility>
#include <optional>
#include <string_view>
#include <array>
#include <vector>
#include <boost/container/flat_map.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/x3/core.hpp>
@dodheim
dodheim / challenge_294_easy.rs
Created July 26, 2017 10:25
Rust solution for /r/dailyprogrammer challenge #294 [easy]
#![feature(ascii_ctype, attr_literals, const_fn, iterator_for_each, repr_align)]
#![cfg_attr(not(debug_assertions), feature(core_intrinsics))]
#![cfg_attr(test, feature(test))]
#[macro_use]
extern crate lazy_static;
extern crate rayon;
extern crate simd;
#[cfg(test)]