Skip to content

Instantly share code, notes, and snippets.

View lichray's full-sized avatar

Zhihao Yuan lichray

View GitHub Profile
// This is how we run libc++ tests on the GPU without modification.
// We force include this header into each test with `-include`.
__host__ __device__
int fake_main(int, char**);
__global__
void fake_main_kernel(int * ret)
{
*ret = fake_main(0, NULL);
@wengxt
wengxt / introspect.c
Last active April 2, 2017 04:40
introspect.c
/* Copyright (c) 2017-2017 Weng Xuetian
* Copyright (c) 2007-2014 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@janlay
janlay / update-repos.sh
Last active April 16, 2019 13:08
Updates all Git repos in directory, defaults to Vim bundles.
#!/bin/bash
# author: janlay@gmail.com
WORKDING_DIR="${1-$HOME/.vim/bundle}"
GIT_DIR_ROOT="$HOME/Workspace/.gitrepo"
echo "Working on $WORKDING_DIR"
for i in `find "$WORKDING_DIR" -mindepth 1 -maxdepth 1 -type d`; do
REPO_NAME="${i##*/}"
export GIT_WORK_TREE="$WORKDING_DIR/$REPO_NAME"
@imneme
imneme / randutils.hpp
Last active March 4, 2024 12:44
Addresses common issues with C++11 random number generation; makes good seeding easier, and makes using RNGs easy while retaining all the power.
/*
* Random-Number Utilities (randutil)
* Addresses common issues with C++11 random number generation.
* Makes good seeding easier, and makes using RNGs easy while retaining
* all the power.
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Melissa E. O'Neill
*
anonymous
anonymous / gist:7700052
Created November 29, 2013 00:46
Fast C++ Integer To String Conversion
/*
*******************************************************************************
* The C++ Integer To String Conversion Benchmark *
* *
* Version: 2.718-20131130 *
* *
* This benchmark is based on the solutions provided in the following *
* stackoverflow question: *
* *
* http://stackoverflow.com/q/4351371 (Date: 20101204) *
@espeed
espeed / install-hyperdex-on-fedora-19.bash
Last active December 22, 2015 03:08
HOWTO Install HyperDex on Fedora 19 - The HyperDex packages in the HyperDex Fedora repo are for Fedora 17, and they don't work on Fedora 19. Here is what you need to do to build and install HyperDex on Fedora 19...
# How to Install HyperDex 1.0x on Fedora 19
# by James Thornton, http://jamesthornton.com
# First ensure you have these Fedora 19 packages installed
sudo yum install git autoconf automake autoconf-archive \
libtool python-devel pyparsing popt-devel \
cityhash-devel gcc-c++ glog-devel leveldb-devel \
bison gperf flex python-sphinx pandoc help2man
@gintenlabo
gintenlabo / make_overloaded.cc
Created August 28, 2013 08:06
compose overloaded function in C++11
#include <type_traits>
#include <utility>
namespace etude {
template<class... Fs>
struct overloaded_function_impl_;
template<>
struct overloaded_function_impl_<> {
template<class... Args,
@lichray
lichray / make_array.cc
Last active August 29, 2023 16:37
Factory function of std::array
#include <array>
#include <functional>
template <typename... T>
using common_type_t = typename std::common_type<T...>::type;
template <typename T>
using remove_cv_t = typename std::remove_cv<T>::type;
template <bool, typename T, typename... U>
@jboner
jboner / latency.txt
Last active March 28, 2024 03:39
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD