Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / sse_add_vec.cpp
Created December 22, 2016 07:56
SSE add 2 arrays
#include <cstdio>
#include <array>
#include <x86intrin.h>
int main() {
__m128 vector_a = { 1, 2, 3, 4 };
__m128 vector_b = { 5, 6, 7, 8 };
vector_a = _mm_add_ps(vector_a, vector_b);
std::array<float, 4> a;
_mm_store_ps(a.data(), vector_a);
@dtoma
dtoma / epoll.cpp
Last active March 9, 2023 16:58
C++ epoll
// https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/
// http://www.kegel.com/poller/
/** Todo
* - [ ] Split i/o and logic
* - [ ] Unit test logic
* - [ ] Logging
* - [ ] Continuous integration
* - [ ] Linux
* - [ ] Windows
@dtoma
dtoma / cpp.md
Last active October 14, 2016 09:46
Notepad
#include <iostream>
#include <string>
#include <ftw.h>
#include <fts.h>

template <typename T>
void walk_dir(std::string const& fpath, T&& function)
{
  char const* filepath[] = { fpath.c_str(), nullptr };
@dtoma
dtoma / sscanf.cpp
Last active September 29, 2016 06:25
safer sscanf
#include <cstdio>
template <typename ... Args>
bool safe_sscanf(char const* s, char const* fmt, Args*... args)
{
constexpr auto len = sizeof...(args);
auto n = sscanf(s, fmt, args...);
if (n != len)
{
printf("sscanf error: captured %d instead of %zu - string was [%s], format was [%s]\n", n, len, s, fmt);
@dtoma
dtoma / fizz_buzz_lang.py
Last active August 31, 2016 06:37
FizzBuzz Lang
"""
Interpreter for a language targeted at solving fizzbuzz
Source: [The fastest fizzbuzz in the west](https://www.promptworks.com/blog/the-fastest-fizzbuzz-in-the-west)
## Imports
"""
from rply import LexerGenerator, ParserGenerator
from rply.token import BaseBox
import sys
@dtoma
dtoma / packet_mmap.md
Created June 10, 2016 10:17
Packet mmap documentation

ABSTRACT

This file documents the mmap() facility available with the PACKET socket interface on 2.4/2.6/3.x kernels. This type of sockets is used for i) capture network traffic with utilities like tcpdump, ii) transmit network traffic, or any other that needs raw access to network interface.

You can find the latest version of this document at: http://wiki.ipxwarzone.com/index.php5?title=Linux_packet_mmap

@dtoma
dtoma / Makefile
Created May 23, 2016 05:33
Makefile Template (executable + tests)
# TODO:
# - build modes: release, debug
CXX := g++
EXECUTABLE := project.exe
EXECUTABLE_TESTS := project_tests.exe
INCLUDE := -I./deps