Skip to content

Instantly share code, notes, and snippets.

texasbruce

  • Toronto, Canada
Block or report user

Report or block texasbruce

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View generic_overload.scala
/* 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
@texasbruce
texasbruce / perf.md
Last active Jan 17, 2019
C++ Performance Tuning Notes
View perf.md

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:

View cpp_flags
-fno-omit-frame-pointer
-std=c++17
-pedantic
@texasbruce
texasbruce / auto_ptr.cpp
Created Jan 10, 2019
Simple Auto Pointer Impl
View auto_ptr.cpp
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>;
@texasbruce
texasbruce / helper.cpp
Last active Jan 4, 2019
C++: is_iterable, map
View helper.cpp
#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>
@texasbruce
texasbruce / boilerplates.cpp
Last active Jan 4, 2019
Boilerplates for C++
View boilerplates.cpp
//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()
{}
View gist:b0d4aab9440c359b3242d77b66502ad0
bcdedit /set hypervisorlaunchtype off
bcdedit /set hypervisorlaunchtype auto
bcdedit
#hypervisorlaunchtype Auto
@texasbruce
texasbruce / Guide
Last active Dec 21, 2018
MSYS2+cmake+MSVS+GTK3+VSCode
View Guide
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
@texasbruce
texasbruce / install.sh
Created Jan 21, 2018 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
View install.sh
######################
## 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/
View reverse_string.pl
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;
You can’t perform that action at this time.