Skip to content

Instantly share code, notes, and snippets.

View davidalbertonogueira's full-sized avatar
🚀
building stuff

David Nogueira davidalbertonogueira

🚀
building stuff
  • Lisbon
View GitHub Profile
@davidalbertonogueira
davidalbertonogueira / chrono.h
Last active March 24, 2016 11:32
std cpp Chronometer header
/**
* @file chrono.h
* @author David Alberto Nogueira (dan)
* @brief std::chrono wrapper.
*
* USAGE:
* @code{.cpp}
* chronowrap::Chronometer chrono; //Declare a Chronometer
* chrono.GetTime(); //Start timer
* {
@davidalbertonogueira
davidalbertonogueira / MemPool.h
Created January 13, 2016 19:14
C++ Memory Pool data type agnostic
#ifndef MEM_POOL_H_
#define MEM_POOL_H_
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#define USE_CPLUSCPLUS_MEMORY_POOL_FOR_PARTS 1
#define MEMORY_POOL_CHUNK_SIZE 1024
@davidalbertonogueira
davidalbertonogueira / debug_error_grabber.py
Last active August 16, 2016 10:39
Grab python error and start a debug session
import os
import sys
import pdb
import traceback
try:
your code here
except:
type, value, tb = sys.exc_info()
@davidalbertonogueira
davidalbertonogueira / structsingletonforstaticvariablelikeusage.cpp
Last active September 2, 2016 13:48
Define and initialize static variable in header file using a singleton approach
//header file
struct MyStruct {
public:
const std::unordered_map<std::string, uint32_t> str_to_int{
{ "a", 1 },
{ "b", 2 },
//...
{ "z", 26 }
};
@davidalbertonogueira
davidalbertonogueira / hashing.h
Last active November 8, 2016 13:08
Hashing utils
#include <stdint.h>
#include <functional>
template <typename TFirst, typename TSecond>
struct HashablePair : public std::pair<TFirst, TSecond> {
typedef std::pair<TFirst, TSecond> Base;
public:
HashablePair() : Base() {};
HashablePair(const Base& a) : Base(a) {};
@davidalbertonogueira
davidalbertonogueira / library_makefile
Created November 14, 2016 17:25
Generic Program makefile and Library makefile
#!/bin/bash
# Makefile for RandomLibrary
CC = ~/clang-3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang++
DEBUG = -g
AUXLIBS =
AUXINCLUDES =
LOCALDEPSINCLUDES =
INCLUDES = -I$(AUXINCLUDES) -I$(LOCALDEPSINCLUDES)
@davidalbertonogueira
davidalbertonogueira / MicroSecResolutionClock.h
Created March 13, 2017 20:24
std::chrono::system_clock with microseconds duration
// @brief Created on top of std::chrono::system_clock,
// MicroSecResolutionClock offers a clock with microseconds duration.
struct MicroSecResolutionClock : public std::chrono::system_clock {
typedef std::chrono::microseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<MicroSecResolutionClock, duration> time_point;
static const bool is_steady = false;
static const int ticks_per_time_t = period::den;
@davidalbertonogueira
davidalbertonogueira / MUSEembeddingsexploration.ipynb
Last active October 16, 2018 14:08
MUSE cross lingual embeddings
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidalbertonogueira
davidalbertonogueira / docker.ps
Created October 22, 2018 09:45
Docker commands
docker build -t myapp:2.0 .
docker run --name myapp_2.0 -d -p 7777:7000 myapp:2.0
docker run --name myapp_2.0 -it -p 7777:7000 myapp:2.0
## -it is short for --interactive + --tty when you docker run with this command.
## it would take you straight inside of the container,
## where -d is short for --detach which means you just run the container and
## then detach from it so basically you run container in the background.
## edit : so if you run docker container with -itd it would run the-it options and detach you from the container,
## so your container still running in the background even without any default app to run.
docker build -t myapp:2.0 .
docker run --name myapp_2.0 -d -p 7777:7000 myapp:2.0
docker run --name myapp_2.0 -it -p 7777:7000 myapp:2.0
## -it is short for --interactive + --tty when you docker run with this command.
## it would take you straight inside of the container,
## where -d is short for --detach which means you just run the container and
## then detach from it so basically you run container in the background.
## edit : so if you run docker container with -itd it would run the-it options and detach you from the container,
## so your container still running in the background even without any default app to run.