Skip to content

Instantly share code, notes, and snippets.

import numpy as np
def investment_value(principal, rate, time, n, dividends, reinvest_dividends, brokerage_fee, investment_fee):
if reinvest_dividends:
# Calculate dividend reinvestment
for t in range(time):
# Calculate interest with compound
principal = principal * (1 + rate / n) ** n
# Calculate and reinvest dividends
@igricart
igricart / git.md
Last active September 15, 2021 09:17
Print git branch in terminal

Paste the following code in your .bashrc

parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
@igricart
igricart / .clang-format.md
Last active April 19, 2021 11:07
Clang Format for C++

Clang Format

File to format code in C++

---
BasedOnStyle:  Google
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
@igricart
igricart / debian_pkg.md
Last active May 8, 2024 16:01
Create a simple debian package

Having a simple debian package out of a Python script

Create a directory to store the debian folder

$ mkdir -p test_folder/DEBIAN

Create a control file inside debian folder

@igricart
igricart / example.md
Created November 19, 2020 14:52
How to check if a command succeeded or not

How to check it ?

$? represents last command sent

#!/bin/bash

touch a/a/.a
if [ $? -eq 0 ]; then
 echo OK
@igricart
igricart / cheatsheet.md
Last active November 19, 2020 09:47
Cheat sheet for deb packages

Simple Cheat Sheet

This gist is menat to help find some information and handle errors with packages using either dpkg or apt

To use it, change <package> for your package name

Getting install tree from package

$ dpkg -c <package>

Create a debian pkg out of CMakeFiles/CMakeLists.txt

The following script is meant to be used to create a debian package out of a CMake project well defined

  GNU nano 2.9.3                                                                                 build_deb_from_cmake.sh                                                                                 Modified  

export DEBMAIL="your@amazing-email.com"
export DEBFULLNAME="Ignacio Ricart"
export DEB_BUILD_OPTIONS=nocheck
@igricart
igricart / condition_variable.md
Last active November 11, 2020 11:35
example of condition_variable usage

Example to show the usage of condition variable

In addition to the good documentation provided by cppreference

I had a doubt that the mutex would be locked in the waiting cycle, but because of the condition_variable::wait() function, it actually allows other threads to access the variable while no notifi_all() method has been called.

#include <iostream>
#include <condition_variable>
@igricart
igricart / PahoMQTTC.md
Last active November 17, 2020 14:07
Install-Create Deb package Paho MQTT C/Cpp

How create a debian package out of Paho MQTT C

$ git clone https://github.com/eclipse/paho.mqtt.c.git
$ cd paho.mqtt.c

# Check version from Paho MQTT Cpp too
$ git checkout v1.3.1
@igricart
igricart / ros-docker.md
Last active November 6, 2020 14:55
Gist to create a debian package out of a ROS package using docker and meant for amd or arm architectures

Create debian packages out of a ROS package (docker)

The dockerfile should be something like

# If amd64 architecture
# FROM osrf/ros:melodic-desktop-full-bionic

# If arm64 architecture
FROM arm64v8/ros:melodic

# uncomment ARG if you need to interact with a remote repository