Skip to content

Instantly share code, notes, and snippets.

View heejune's full-sized avatar

Heejune heejune

View GitHub Profile
@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 / 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 / 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 / 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.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 / 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 / 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 / democore.cpp
Created February 25, 2017 12:40
wrl and cppwinrt combination
winrt::Windows::Foundation::IAsyncOperation<int> GetAsyncOp()
{
using namespace winrt;
using namespace Windows::Foundation;
for (int i = 0; i != 5; ++i)
{
co_await 5000ms;
}
@heejune
heejune / slack_uploader.py
Created February 28, 2017 02:05
how to upload a file with SlackClient library
from slackclient import SlackClient
class SlackBot(object):
'''
SlackBot:
'''
def __init__(self, logger, slackclient):
self.logger = logger or logging.getLogger(__name__)
self.slack_client = slackclient or SlackClient(os.environ.get('SLACK_BOT_TOKEN'))
bool isPrime(unsigned long num)
{
if (num == 2)
return true;
if (num <= 1 || num % 2 == 0) // 0, 1, and all even numbers
return false;
for (unsigned long x = 3; x*x <= num; x += 2) {
if (num % x == 0)