Skip to content

Instantly share code, notes, and snippets.

View Liam0205's full-sized avatar
🎯
Focusing

Liam Huang Liam0205

🎯
Focusing
View GitHub Profile
@Liam0205
Liam0205 / cfuture.h
Last active January 16, 2018 09:24
demo for a C style future/promise multitask frame
#pragma once
#ifndef CFUTURE_H_
#define CFUTURE_H_
#include <stdio.h>
#include <pthread.h>
#ifdef DEBUG
#include <random>
@Liam0205
Liam0205 / stability_test_of_std_sort.cc
Last active January 5, 2018 11:53
`std::sort` does not perserve the order of elements within equal values, however the result of it is of no randomness.
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <random>
namespace {
const constexpr size_t kTestLen = 1000000;
std::random_device rd;
std::mt19937 urbg(rd());
\documentclass{beamer}
\usetheme{metropolis}
\usepackage[backend=biber, style=chem-angew, safeinputenc]{biblatex}
% \renewcommand\multicitedelim{\addsemicolon\space}
\begin{filecontents}{\jobname.bib}
@misc{Book1,
author = {Author, A.},
year = {2001},
title = {Alpha},
@Liam0205
Liam0205 / parallel_sum.cc
Last active December 24, 2017 06:04
A demo show for parallem_sum of hyper_sum by using of std::async.
#include <iostream>
#include <future>
template <typename IntT, typename UnaryFunc>
IntT do_hyper_sum(const IntT begin, const IntT end, const UnaryFunc func) {
IntT res = 0;
for (IntT i = begin; i != end; ++i) {
res += func(i);
}
return std::move(res);
@Liam0205
Liam0205 / result.txt
Created December 13, 2017 11:26
transform std::string to lower case or upper case.
$ ./a.out
HELLO WORLD!
hello world!
@Liam0205
Liam0205 / result.txt
Created December 13, 2017 11:11
Set intersection and union, supporting std::unordered_set
$ ./a.out
4 5
1 2 3 4 5 6 7 8
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>
const std::unordered_set<std::string> replace_str_set{",", "."};
bool IsReplaceStr(const std::string& str) {
return (replace_str_set.find(str) != replace_str_set.end());
}
@Liam0205
Liam0205 / resub.py
Created October 18, 2017 05:03
re.sub(http -> https)
import re
pattern = r'(?P<front><img.*?src=\\")(?P<protocol>http://)(?P<url>.*?\\")(?P<back>.*?\/>)'
_replace_protocol = lambda m: \
'%s%s%s%s' % (m.group('front'), 'https://', m.group('url'), m.group('back'))
source = r'<img src=\"http://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D220/sign=ce3bec3b4d36acaf5de091fe4cd88d03/dc54564e9258d109b60a06b0d758ccbf6d814dc2.jpg\" layout=\"1\" style=\"float:right;\" class=\"fadeInLeftBig\" data-type=\"img\" />'
print source
print re.sub(pattern, _replace_protocol, source)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a = &b+c\\
= &c+d\\
&+e+f
\end{align}
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, decorations.text}
\begin{document}
\begin{tikzpicture}
\path decorate [decoration={text along path,
text={some text along a path}}]{ (0,2) .. controls (2,2) and (1,0) .. (3,0) };
\draw (0,2) .. controls (2,2) and (1,0) .. (3,0);
\end{tikzpicture}
\end{document}