Skip to content

Instantly share code, notes, and snippets.

View heejune's full-sized avatar

Heejune heejune

View GitHub Profile
@heejune
heejune / resumable-idea.cpp
Created February 19, 2017 17:06
resumable test #2
// resumable-idea.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
using namespace std::experimental;
struct resumable_thing
{
@heejune
heejune / resumable.cpp
Created February 19, 2017 17:05
resumable test #1
// resumable-idea.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
struct resumable_thing
{
void resume() {}
@heejune
heejune / future.h
Created February 19, 2017 17:04
future_async_methods
template<class _Ty>
bool await_ready(future<_Ty>& _Fut)
{
return (_Fut._Is_ready());
}
template<class _Ty>
void await_suspend(future<_Ty>& _Fut,
experimental::coroutine_handle<> _ResumeCb)
{ // change to .then when future gets .then
@heejune
heejune / stdafx.h
Created February 19, 2017 17:03
resumable_header
// TODO: reference additional headers your program requires here
#include <windows.h>
#include <future>
#include <iostream>
#ifdef _RESUMABLE_FUNCTIONS_SUPPORTED
#include <experimental/resumable>
#endif
@heejune
heejune / future_coroutine.cpp
Created February 19, 2017 17:00
std::future coroutine
#include <future>
std::future<int> compute_value()
{
int result = co_await std::async([]
{
return 30;
});
co_return result;
@heejune
heejune / MainPage.xaml.cpp
Created February 2, 2017 15:13
Demo registers Progress handler from IAsyncOperationWithProgress
void WebCrawlerSample::MainPage::button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
HttpClient^ client = ref new HttpClient();
Uri^ addr = ref new Uri("https://heejune.me");
auto asyncOp = client->GetAsync(addr);
// create and set Progress handler
asyncOp->Progress = ref new AsyncOperationProgressHandler<HttpResponseMessage^, HttpProgress>(
[=](IAsyncOperationWithProgress<HttpResponseMessage^, HttpProgress>^ pretask, HttpProgress progressInfo) {
@heejune
heejune / CMaktLists.txt
Created August 17, 2016 01:45
CMakeLists.txt for clang standalone tool
## http://qiita.com/Chironian/items/8770c8ab833086fb51a9
############################################################
# base
############################################################
cmake_minimum_required(VERSION 2.8.8)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
set(CMAKE_SUPPRESS_REGENERATION TRUE)
@heejune
heejune / countera.py
Created July 19, 2016 16:50
Telegram bot takes a photo using a pi camera and replies back running on Raspberry Pi
import sys
import asyncio
import telepot
from telepot.aio.delegate import per_chat_id, create_open
import picam
"""
$ python3.5 countera.py <token>
@heejune
heejune / invoke_pdfjs_viewer_with_base64.js
Created June 21, 2016 01:01
Open PDFjs as base64 string
// https://github.com/heejune/WinForm-PDFjs/blob/master/WinFormPDFViewer/pdfjs-1.4.20-dist/web/viewer.js
// PDFViewerApplication.open wrapper for base64 param
window.openPdfAsBase64 = function (base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
@heejune
heejune / PDFFile_webbrowser_invoke.cs
Created June 21, 2016 00:58
Convert the PDF file into base64 string and pass it to the webbrowser control
if (locateText.Text.EndsWith("pdf", true, null) == true &&
File.Exists(locateText.Text) == true)
{
var buffer = File.ReadAllBytes(locateText.Text);
// Document.InvokeScript seems not understanding the Blob type
//object[] args = { fileBytes };
//webBrowser1.Document.InvokeScript("PDFViewerApplication.open", args);
// so convert it to base64 and pass it