This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.IO.Compression; | |
using System.Text; | |
// read json | |
var file = @"somedata.json"; | |
using var inStream = File.OpenRead(file); | |
// compress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TaskExtensions | |
{ | |
public static object GetResult(this Task task) | |
{ | |
task.Wait(); | |
var taskType = task.GetType(); | |
var resultProperty = taskType.GetProperty("Result"); | |
return resultProperty?.GetValue(task); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
public interface IState | |
{ | |
Task RunAsync(); | |
} | |
public class StateMachine | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace BroadcastEventSample | |
{ | |
public class EventBroadcastTask | |
{ | |
private readonly CancellationTokenSource cancelSource = new CancellationTokenSource(); | |
private readonly TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct foo | |
{ | |
template<typename... Args> | |
void operator[](Args&&...) | |
{ | |
} | |
}; | |
struct bit {}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool isNumeric(const std::string& input) | |
{ | |
return std::all_of(input.begin(), input.end(), ::isdigit); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stopwatch { | |
using clock = std::chrono::high_resolution_clock; | |
bool is_running() const { return stop_time_ == clock::time_point::min(); } | |
clock::time_point end_time() const { return is_running() ? clock::now() : stop_time_; } | |
clock::time_point begin_time_{clock::now()}, stop_time_{clock::time_point::min()}; | |
public: | |
void stop() { if (is_running()) stop_time_ = clock::now(); } | |
clock::duration elapsed() const { return end_time() - begin_time_; } | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::shared_ptr<widget> get_widget(int id) | |
{ | |
static std::map<int, std::weak_ptr<widget>> cache; | |
static std::mutex m; | |
std::lock_guard<std::mutex> hold(m); | |
auto& wp = cache[id]; | |
auto sp = wp.lock(); | |
if (!sp) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<std::string> | |
sorted(std::vector<std::string> names) | |
{ | |
std::sort(names); | |
return names; | |
} | |
// names is an lvalue; a copy is required so we don't modify names | |
std::vector<std::string> sorted_names1 = sorted( names ); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Setup] | |
[Run] | |
; add the Parameters, WorkingDir and StatusMsg as you wish, just keep here | |
; the conditional installation Check | |
Filename: "{tmp}\vcredist_x86.exe"; Check: VCRedistNeedsInstall | |
[Code] | |
#ifdef UNICODE | |
#DEFINE AW "W" |
NewerOlder