Skip to content

Instantly share code, notes, and snippets.

[core]
editor = \"C:/Program Files (x86)/GitExtensions/GitExtensions.exe\" fileeditor
[user]
name = tunmiang
email = tunmiang.su@kla-tencor.com
[pull]
rebase = false
[fetch]
prune = false
[rebase]
@sutm
sutm / sync_wait.hpp
Created December 21, 2021 03:01 — forked from ericniebler/sync_wait.hpp
sync_wait function for an awaitable task type
#include <cassert>
#include <mutex>
#include <condition_variable>
#include <variant>
#include <utility>
#include <exception>
#if __has_include(<coroutine>)
#include <coroutine>
namespace coro = std;
@sutm
sutm / gist:ddae30c14ae6a8b750ff603a1ba32687
Created March 28, 2019 00:57
Show Winform dialog in WPF
var inspWindow = new StationUI.MainWindow(glueInsp, camera, lightingController, new LiteOn.ImageNaming(2, "glue_raw_", "housing_"));
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(inspWindow);
inspWindow.ExpertMode = true;
inspWindow.ShowDialog();
#include "stdafx.h"
#include <iostream>
void overloaded(int const &arg) { std::cout << "by lvalue\n"; }
void overloaded(int && arg) { std::cout << "by rvalue\n"; }
template< typename t >
void forwarding(t && arg) {
std::cout << "via std::forward: ";
@sutm
sutm / test.cpp
Last active October 23, 2016 13:45
SFINAE Expression
// CppCon 2016: Ben Deane “A Static Alternative to Virtual Functions, Using Expression SFINAE"
// detect whether a type has a member method
#define DETECT(name, expr) \
template <typename T> \
using name##_t = decltype(expr); \
\
template <typename T, typename = void> \
struct has_##name : public std::false_type {}; \
\
@sutm
sutm / gist:ae50e50004480a2affd8889468e28cc2
Last active September 24, 2016 14:13
Use reference_wrapper to create views of data
// http://cpp.indi.frih.net/blog/2015/04/tippet-use-reference_wrapper-to-create-views-of-data/
// A job struct
struct job
{
size_t id;
chrono::system_clock::time_point time;
int priority;
static auto order_by_time(job const& a, job const& b)
@sutm
sutm / WPF button style (XAML)
Created April 24, 2016 14:13
WPF button style (icon + text with diff font size)
// http://stackoverflow.com/questions/17630968/wpf-c-sharp-button-style
<Window x:Class="ButtonHelp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ButtonHelp"
Name="MyWindow"
Title="MainWindow" Height="350" Width="525"
WindowStartupLocation="CenterScreen"
local:MyDependencyClass.CurrentDuration="Duration: 50m">
@sutm
sutm / function wrapper
Created April 24, 2016 05:41
wrap logger around a function
#include "stdafx.h"
#include <assert.h>
#include <iostream>
using namespace std;
auto logAspect = [](auto f) {
return [=](auto&&... args) {
cout << "start" << endl;
f(std::forward<decltype(args)>(args)...);
@sutm
sutm / bind
Last active February 21, 2016 10:39
c++ bind
#include "stdafx.h"
#include <functional>
#include <iostream>
struct Foo {
Foo(int num) : num_(num) {}
void print_add(int i) const { std::cout << num_ + i << '\n'; }
int num_;
};
@sutm
sutm / mixin.cpp
Last active February 10, 2016 14:38
Mixin via CRTP
// Fundamentals of Type-Dependent Code Reuse in C++ - Mark Isaacson
// url: https://vimeo.com/131194141
// NDC Conferences 2015
#include "stdafx.h"
#include <assert.h>
#include <type_traits>
using namespace std;