Skip to content

Instantly share code, notes, and snippets.

use warnings;
use strict;
$_ = 'abcdefghi';
# s/./ substr $_, -$+[0], 1 /eg; # duh, substr and array
# s#.# /(.).{$-[0]}$/; $1 #eg; # duh, array
my $x = 0; s#.# /(.).{$x}$/; $x++; $1 #eg;
@neontorrent
neontorrent / install.sh
Created January 21, 2018 15:09 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
######################
## shadowsocks-libev
######################
# install dependencies
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
# install shadowsocks-libev
cd /etc/yum.repos.d/
@neontorrent
neontorrent / Guide
Last active October 19, 2022 13:34
MSYS2+cmake+MSVS+GTK3+VSCode
MSYS2:
pacman -S base-devel mingw64/mingw-w64-x86_64-cmake mingw-w64-x86_64-gtk3 mingw-w64-x86_64-gtkmm3 mingw-w64-x86_64-pkg-config
#Optional: pacman -S mingw-w64-x86_64-glade
#In .bashrc
export PATH=/mingw64/bin:$PATH
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig
Compiler:
Option 1: Use MSYS2 GCC
pacman -S mingw-w64-x86_64-gcc
bcdedit /set hypervisorlaunchtype off
bcdedit /set hypervisorlaunchtype auto
bcdedit
#hypervisorlaunchtype Auto
@neontorrent
neontorrent / boilerplates.cpp
Last active January 4, 2019 18:52
Boilerplates for C++
//Template Type Check
template<typename T, typename F,
typename = std::enable_if_t<std::is_invocable<F, T>::value> >
void foo()
{}
template<typename T, typename F,
typename = typename std::enable_if<std::is_invocable<F, T>::value>::type >
void foo()
{}
@neontorrent
neontorrent / helper.cpp
Last active January 4, 2019 21:57
C++: is_iterable, map
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <type_traits>
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
@neontorrent
neontorrent / auto_ptr.cpp
Created January 10, 2019 15:50
Simple Auto Pointer Impl
std::unordered_map<void*, size_t> *auto_ref_cnt;
template<typename T>
class AutoPtr {
T * data;
public:
AutoPtr() = delete;
AutoPtr(T* data): data(data) {
if(auto_ref_cnt == nullptr) {
auto_ref_cnt = new std::unordered_map<void*, size_t>;
@neontorrent
neontorrent / cpp_flags
Created January 12, 2019 20:33
GCC flags
-fno-omit-frame-pointer
-std=c++17
-pedantic
@neontorrent
neontorrent / perf.md
Last active January 17, 2019 02:40
C++ Performance Tuning Notes

In order to gen call graph in perf:

-fno-omit-frame-butter

#Generate perf.data for executable perf record -g executable #0.5 is a filter?, caller is inverse the graph callstack perf report -g 'graph,0.5,caller'

Prevent optimizer to remove code:

/* Ambiguous
def compare[T1, T2](a: T1, b: T2)(implicit ev: T1 => T2) = compareImpl[T2](ev(a), b)
def compare[T1, T2](a: T1, b: T2)(implicit ev: T2 => T1) = compareImpl[T1](a, ev(b))
def compareImpl[T](a: T, b: T) = a == b
*/
import scala.reflect.runtime.universe._
import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
import scala.language.implicitConversions