Skip to content

Instantly share code, notes, and snippets.

@yayj
yayj / coroutine2-cpp11.cpp
Last active November 7, 2017 02:21
test cases for ASIO
#include <asio/io_service.hpp>
#include <asio/spawn.hpp>
#include <asio/strand.hpp>
#include <asio/system_executor.hpp>
#include <iostream>
#include <type_traits>
using namespace std;
static asio::io_service io;
@yayj
yayj / ClosableJedis.java
Created September 27, 2016 04:05
Jedis with ARM
public class CloseableJedis implements AutoCloseable {
private final Jedis delegate;
private final JedisPool pool;
private boolean broken = false;
public CloseableJedis(JedisPool pool) {
this.pool = pool;
delegate = pool.getResource();
}
@yayj
yayj / keybase.md
Last active March 28, 2018 07:14
My Keybase claim

Keybase proof

I hereby claim:

  • I am yayj on github.
  • I am yayj (https://keybase.io/yayj) on keybase.
  • I have a public key whose fingerprint is 22A8 2E02 4D95 4CDE 3C10 2BC2 6B0E 96FB 0398 16A3

To claim this, I am signing this object:

@yayj
yayj / FunctionConcept.hpp
Last active September 27, 2016 03:57
Statically checking function signature in C++14
_Pragma("once");
/*
* Usage:
* 1. static_assert(FunctionConcept<ReturnType, Args...>::check<FunctionType>(), "msg");
* 2. static_assert(FunctionConcept<ReturnType, Args...>::check(functionVariable), "msg");
*
* Supported:
* - Implicitly type conversion on arguments or return value(type in signature implicitly
* converted to type in actual function)
@yayj
yayj / asio_gcd_perf.cpp
Last active March 7, 2016 05:29
Comparing io_service::post's performance with GCD's
#include <chrono>
#include <iostream>
#include <thread>
#include <dispatch/dispatch.h>
#include <boost/asio.hpp>
using namespace std::chrono_literals;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
@yayj
yayj / encrypt.java
Created August 9, 2013 08:02
encrypte
String salt = DigestUtils.md5Hex("linkmatic");
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
cipher.init(Cipher.ENCRYPT_MODE,
new SecretKeySpec(salt.getBytes(), "AES"),
new IvParameterSpec(DigestUtils.md5Hex(salt).substring(0, 16).getBytes()));
byte[] bytes = src.getBytes("UTF-8");
return new String(Base64.encodeBase64(cipher.doFinal(bytes)));
@yayj
yayj / post.scala
Created August 9, 2013 04:51
Future.onSuccess and Future.onFailure
future.onFailure {
case e: Exception =>
Logger.warn("SMS: Error: " + e.getMessage)
case _ =>
Logger.warn("SMS: Unknown error")
}
future.onSuccess {
case response: Response =>
response.status match {
@yayj
yayj / client.cpp
Created April 27, 2013 05:48
ASIO ping-pong test modification for io_service per thread.
//
// client.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//