Skip to content

Instantly share code, notes, and snippets.

@dtoma
dtoma / conventions.md
Last active April 19, 2017 10:01
Project conventions
@dtoma
dtoma / simple_style.css
Last active January 31, 2017 08:16
simple style
/* Body and header styles inspired by http://bettermotherfuckingwebsite.com/ */
/*
Bookmarklet:
javascript:(function() {
var style = document.getElementsByTagName("style");
var css = "a,a:link,a:visited{color:#265C83}body{margin:40px auto;max-width:60em;line-height:1.6;font-size:18px;color:#222;background:#EEE;padding:0 10px}h1,h2,h3{line-height:1.2}canvas,iframe,img,select,svg,textarea,video{max-width:100%}.overflow-container{overflow-x:scroll}.aspect-ratio{height:0;padding-top:56.25%;position:relative}.aspect-ratio--object{height:100%;position:absolute;top:0;right:0;bottom:0;left:0;width:100%;z-index:100}a{transition:color .4s;text-decoration:none}a:hover{color:#7FDBFF}a:active{transition:color .3s;color:#007BE6}";
if (style[0]) {
style[0].innerHTML = css;
@dtoma
dtoma / review.md
Last active April 5, 2016 06:59
Code Review Checklist

Code Review Checklist

General

  • Does the code work? Does it perform its intended function, the logic is correct etc.
  • Is all the code easily understood?
  • Does it conform to your agreed coding conventions? These will usually cover location of braces, variable and function names, line length, indentations, formatting, and comments.
  • Is there any redundant or duplicate code?
  • Is the code as modular as possible?
  • Can any global variables be replaced?
@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
@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 / 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 / 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 / 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 / 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 / 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);