Skip to content

Instantly share code, notes, and snippets.

View zuoyan's full-sized avatar

Changsheng Jiang zuoyan

View GitHub Profile
@zuoyan
zuoyan / sum.h
Last active November 3, 2016 15:14
Inexact Sum of Floating Point Numbers
// Returns s and e, such that s = T(a + b), and e = (a + b) - s, i.e. s + e = a
// + b exactly.
template <class T>
std::pair<T, T> AddPair(const T& a, const T& b) {
auto s = a + b;
auto b_v = s - a;
auto e = (a - (s - b_v)) + (b - b_v);
// auto a_v = s - b_v;
// auto b_r = b - b_v;
@zuoyan
zuoyan / scholar_alert_parse.py
Created June 8, 2016 01:12
Download all pdf files from google scholar alert emails and push them to google drive, depending on gmail_cli, google_drive_cli, pjobs and csv_sql.
#!/bin/env/python
# coding: utf8
#
# Parse google scholar alerts email, and output a csv file.
import re
import sys
from HTMLParser import HTMLParser
import traceback
import md5
@zuoyan
zuoyan / f256.h
Last active August 29, 2015 14:15
F256, operations of finite field 2^8.
// Author: Changsheng Jiang(jiangzuoyan@gmail.com)
// Public domain.
namespace weizi {
namespace f256 {
inline unsigned char Add(unsigned char a, unsigned char b) { return a ^ b; }
inline unsigned char Sub(unsigned char a, unsigned char b) { return a ^ b; }
@zuoyan
zuoyan / build.cmake
Last active August 29, 2015 14:03
BUILD like functions in CMake
INCLUDE(CMakeParseArguments)
FUNCTION(WEIZI_ABSOLUTE NAME OUT)
IF (${NAME} MATCHES "^/")
SET(${OUT} ${NAME} PARENT_SCOPE)
RETURN()
ENDIF()
IF ("${CMAKE_SOURCE_DIR}/weizi" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
SET(${OUT} "/${NAME}" PARENT_SCOPE)
RETURN()
@zuoyan
zuoyan / rearranged_tuple.cpp
Created December 6, 2012 14:37
rearranged std::tule
#include <atomic>
#include <iostream>
#include <tuple>
#include "tmp.hpp" // see http://github.com/zuoyan/tmp
template <template <class ...> class F, class ...A>
struct tcurry {
template <class ...T>
struct apply {