Skip to content

Instantly share code, notes, and snippets.

@dtoma
dtoma / bf.cpp
Last active December 29, 2016 07:05
bf interpreter
#include <cstdio>
#include <functional>
#include <unordered_map>
#include <vector>
// Notes
// [some brainfuck fluff by daniel b cristofani](http://www.hevanet.com/cristofd/brainfuck/)
// [The Epistle to the Implementors](http://www.hevanet.com/cristofd/brainfuck/epistle.html)
// [The BrainFuck Compiler Collection](https://github.com/Sirflankalot/bfcc)
@dtoma
dtoma / ts.cpp
Created December 29, 2016 08:07
C++ timestamp with nanoseconds and timezone
#include <chrono>
#include <iomanip>
#include <iostream>
int main() {
auto now = std::chrono::high_resolution_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto tm = *std::gmtime(&time);
// auto tm = *std::localtime(&time);
@dtoma
dtoma / .gitconfig
Last active March 28, 2019 07:20
git config
[alias]
ls = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
ll = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat --date=short
graph = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
new = !sh -c 'git log $1@{1}..$1@{0} "$@"'
st = status -s
diff = diff --patience
[user]
email = [email]
name = dtoma
@dtoma
dtoma / Makefile
Last active November 5, 2022 14:46
makefile rules to check style using clang-format
style:
@for src in $(SOURCES) ; do \
echo "Formatting $$src..." ; \
clang-format -i "$(SRC_DIR)/$$src" ; \
clang-tidy -checks='-*,readability-identifier-naming' \
-config="{CheckOptions: [ \
{ key: readability-identifier-naming.NamespaceCase, value: lower_case },\
{ key: readability-identifier-naming.ClassCase, value: CamelCase },\
{ key: readability-identifier-naming.StructCase, value: CamelCase },\
{ key: readability-identifier-naming.FunctionCase, value: camelBack },\
@dtoma
dtoma / fix.cpp
Last active January 3, 2017 08:02
ideas for fix parsing/serializing
// http://ldionne.com/hana-cppnow-2015/
// http://boostorg.github.io/hana/
// note: re-read the CppCon pres on fusion for parsing
// somehow hold the tag and value type in the field's type?
template <int Tag, typename T>
struct Field { T value; }
template <int Tag, typename T>
constexpr auto get_tag(field<Tag, T>&&) { return Tag; }
@dtoma
dtoma / asiaconf.md
Last active January 30, 2017 08:54
Conferences in Asia 2017
@dtoma
dtoma / bcc1.cpp
Created February 20, 2017 09:15
book: beautiful code, chapter 1
/*
* Character | Meaning
* c | Matches any literal character c
* . | Matches any single character
* ^ | Matches the beginning of the input string
* $ | Matches the end of the input string
* * | Matches zero or more occurrences of the previous character
*/
#include <cstdio>
@dtoma
dtoma / pi.cpp
Created February 21, 2017 03:05
C++ OpenMP Pi
// http://jakascorner.com/blog/2016/05/omp-monte-carlo-pi.html
#include <iostream>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <iomanip>
#include <limits>
#include <chrono>
@dtoma
dtoma / gcc_perf_attributes.md
Last active February 22, 2017 06:58
gcc attributes for perf tuning

error/warning

Code exammple:

#include <string>

std::string __attribute__((warning("getString not inlined/removed"))) getString() {
  return "Foo";
}