Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View westfly's full-sized avatar

Rayan westfly

  • BeiJing,China
View GitHub Profile
@westfly
westfly / product.cpp
Created May 25, 2021 02:40 — forked from Alexhuszagh/product.cpp
Cartesian Product Implementation in C++
// :copyright: (c) 2017 Alex Huszagh.
// :license: MIT.
/**
* Cartesian product algorithm.
*
* Lazily calculates the cartesian product from a container of containers,
* of either linear (array, vector, set, unordered_set) or associative
* (map, unordered_map, multimap, unordered_multimap) containers.
*
* The code can be used as follows:
@westfly
westfly / to_tuple.cpp
Created February 5, 2021 13:50 — forked from talybin/to_tuple.cpp
Struct to tuple conversion (CppCon 2019, Kris Jusiak)
#include <tuple>
#include <type_traits>
template <class T, class... TArgs>
decltype(void(T{std::declval<TArgs>()...}), std::true_type{})
test_is_braces_constructible(int);
template <class, class...>
std::false_type
test_is_braces_constructible(...);
@westfly
westfly / shell_utils
Created September 3, 2020 03:00
utils_inshell.sh
#!/bin/bash
function FileName()
{
if [[ $# -eq 1 ]]; then
local filename=`basename $1`
echo ${filename%%.*}
fi
}
function FileExtension()
{
@westfly
westfly / tmux-cheatsheet.markdown
Created October 31, 2019 01:08 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表 & 简明教程

注意:本文内容适用于 Tmux 2.3 及以上的版本,但是绝大部分的特性低版本也都适用,鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。

Tmux 快捷键 & 速查表 & 简明教程

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

@westfly
westfly / debug_with_lambda.cpp
Created September 29, 2019 05:49
debug宏定义的参数为lambda
#ifdef DEBUG
#define macro(labmda) \
do { \
labmda; \
} while (0)
#define macro_call(labmda) \
macro(labmda())
#else
#define macro(labmda)
#define macro_call(labmda)
@westfly
westfly / urlencode.sh
Last active May 10, 2023 02:27
urlencode for shell
function urlencode() {
local data
if [[ $# != 1 ]]; then
echo "Usage: $0 string-to-urlencode"
return 1
fi
data="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")"
if [[ $? == 0 ]]; then
echo "${data##/?}"
fi
@westfly
westfly / multi_thread_template.sh
Created June 18, 2017 11:53
shell 管道控制多进程
#!/bin/bash
#usage multi_thread_template.sh
fifo="/tmp/$$.fifo" #建立管道$$表示shell分配的进程号
mkfifo $fifo
exec 6<>$fifo #将fifo的fd与6号fd绑定
thread_num=64 #启动的进程个数
count=0;
#预分配资源
while [[ $count -lt $thread_num ]]; do
echo >&6