Skip to content

Instantly share code, notes, and snippets.

View alifahrri's full-sized avatar
🌊

Fahri Ali Rahman alifahrri

🌊
View GitHub Profile
@alifahrri
alifahrri / logger.hpp
Created August 29, 2018 00:28
i need to log something,
#ifndef LOGGER_HPP
#define LOGGER_HPP
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
class Logger
{
@alifahrri
alifahrri / timer.hpp
Created August 29, 2018 00:29
i need to measure how long my code runs
#ifndef TIMER_HPP
#define TIMER_HPP
#include <chrono>
template
<
typename numeric,
typename ratio = std::milli,
typename clock = std::chrono::high_resolution_clock
@alifahrri
alifahrri / setup.sh
Created September 30, 2018 07:09
Install GTest
sudo apt-get install cmake libgtest-dev
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
# copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib
@alifahrri
alifahrri / cuda_err_check
Created October 7, 2018 18:02
Error check for cuda code
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}

add breakpoint

(gdb) break filename.ext:line

list breakpoint

(gdb) info break

disable breakpoint

(gdb) disable 1 disable breakpoint 1

backtrace function call

(gdb) bt

examining the stack

@alifahrri
alifahrri / rpy-quat.md
Last active October 26, 2018 04:17
rpy <-> quaternion
#include <tf2/LinearMath/Quaternion.h>
#include <tf/transform_datatypes.h>
...
tf2::Quaternion myQuaternion;
myQuaternion.setRPY( 0, 0, 0 );  // Create this quaternion from roll/pitch/yaw (in radians)
ROS_INFO_STREAM(q);  // Print the quaternion components (0,0,0,1)
...
quaternionMsgToTF(quat_msg , quat_tf);
@alifahrri
alifahrri / cycheat.md
Last active October 28, 2018 04:54
cheatsheet for cython

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

all *.pyx files in a folder

@alifahrri
alifahrri / angle-wrap.py
Last active October 31, 2018 02:38
py code for wrapping around an angle
def norm_angle(dw) :
if math.fabs(dw) > math.pi :
return (-2*math.pi + dw) if dw > 0 else (2*math.pi + dw)
else : return dw
@alifahrri
alifahrri / roscpp-cheat.md
Created November 11, 2018 14:38
cheatsheet for roscpp

yaml

XmlRpc::XmlRpcValue my_list;
nh.getParam("my_list", my_list);
ROS_ASSERT(my_list.getType() == XmlRpc::XmlRpcValue::TypeArray);

for (int32_t i = 0; i < my_list.size(); ++i) 
{
  ROS_ASSERT(my_list[i].getType() == XmlRpc::XmlRpcValue::TypeDouble);
 sum += static_cast(my_list[i]);
@alifahrri
alifahrri / gzlog.md
Last active November 20, 2018 09:34
gazebo data logger

playback in gui

gazebo -u -p ~/logs/double_pendulum/2016-01-25T15\:09\:49.677400/gzserver/state.log

from gazebo_ros

rosrun gazebo_ros gazebo --prefix '-u -p 2018-11-20T162127.065690/gzserver/state.log'