Skip to content

Instantly share code, notes, and snippets.

View sighingnow's full-sized avatar
💭
typing...

Tao He sighingnow

💭
typing...
View GitHub Profile
@sighingnow
sighingnow / .bashrc
Created April 26, 2015 12:47
My bashrc config file.
# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return
# Completion options
#
# These completion tuning parameters change the default behavior of bash_completion:
#
# Define to access remotely checked-out files over passwordless ssh for CVS
COMP_CVS_REMOTE=1
#
@sighingnow
sighingnow / .inputrc
Created April 26, 2015 12:48
My inputrc file
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
# base-files version 4.2-3
# ~/.inputrc: readline initialization file.
@sighingnow
sighingnow / a-genode-develop.md
Last active September 29, 2016 15:01
Code snippets for Genode development.
  • heap-alloc.cpp: allocate memory from env's heap.
  • create-thread-deprecated.cpp: create deprecated thread.
  • transfer-mem.cpp: transfer memory between two entrypoint.
@sighingnow
sighingnow / signal-slot.hs
Last active September 30, 2016 12:49
Signal-slot mechanism in Haskell.
-------------------------------------------------------------
-- |
-- Copyright: (c) Tao He 2016
-- License: MIT
-- Maintainer: sighingnow@gmail.com
--
-- Signal-slot mechanism in Haskell.
--
import Control.Monad
@sighingnow
sighingnow / rdstc-demo.c
Created October 1, 2016 04:52
Demo of Read Time-Stamp Counter (rdstc instruction).
/**
* author: Tao He, sighingnow@gmail.com
*/
uint64_t rdtsc() {
uint32_t lo, hi;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return (uint64_t)hi << 32 | lo;
}
@sighingnow
sighingnow / prime_sum.py
Created October 1, 2016 04:56
Summary of all prime numbers less than or equal to n.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from time import time
import math
def prime_sum_impl(n):
r = int(math.sqrt(n))
v = [n//i for i in range(1, r+1)]
v += list(range(v[-1]-1, 0, -1))
@sighingnow
sighingnow / constexpr.cpp
Created October 1, 2016 05:11
Notes on constexpr in C++.
#include <type_traits>
#include <iostream>
#include <string>
// valid in C++14, but not valid in C++11.
// for statement not allowed in constexpr function in C++11.
constexpr size_t addition(size_t n) {
size_t s = 0;
for (size_t i = 0; i <= n; ++i) {
s += i;
@sighingnow
sighingnow / auto-return-type.cxx
Created October 4, 2016 08:37
When two type parameters are different, how to choose a proper return type in C++ ?
#include <iostream>
#include <typeinfo>
template<typename T, typename S>
auto max(T a, S b) -> decltype(a+b) { // note that T and S may be different.
// for numeric type, automatic type convension will be performed when compare two values.
if (a > b) {
return a;
}
else {
@sighingnow
sighingnow / merge-archive
Created November 22, 2016 12:47
Merge two archive files (.a) into a single one.
## place object files (.o) in two different folders to vaoid overlapping.
mkdir libA
cd libA
ar -x ../libA.a
cd ..
mkdir libB
cd libB
ar -x ../libB.a
@sighingnow
sighingnow / win-cpu-number.py
Created November 29, 2016 05:10
Get CPU number on Windows platform.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def get_cpu_number():
''' Return the processors' number, an integer value.
'''
import os
return int(os.environ['NUMBER_OF_PROCESSORS'])