Skip to content

Instantly share code, notes, and snippets.

View rpapallas's full-sized avatar

Rafael Papallas rpapallas

View GitHub Profile
@rpapallas
rpapallas / Factorial.hs
Created October 17, 2016 19:54
Factorial implementation in Haskell
factorial n = product [1..n]
@rpapallas
rpapallas / DatabaseManager.swift
Last active March 7, 2018 23:11
DatabaseManager class for CoreData
// This work is licensed under a Creative Commons
// Attribution-ShareAlike 4.0 International License.
// © 2016 Rafael Papallas and www.computingstories.com
import Foundation
import CoreData
class DatabaseManager {
/// Implements the Singleton Design Pattern
static let instance = DatabaseManager()
@rpapallas
rpapallas / MockDatabaseManager.swift
Created December 23, 2016 14:31
Core Data Mock Class for Unit Testing
// This work is licensed under a Creative Commons
// Attribution-ShareAlike 4.0 International License.
// © 2016 Rafael Papallas and www.computingstories.com
import Foundation
import CoreData
/// Mock version of DatabaseManager for testing purposes.
///
/// This intent of this class it to inherit all functionality from DatabaseManager
@rpapallas
rpapallas / DatabaseManagerTests.swift
Created December 23, 2016 14:32
Minimal Example of Unit Testing Core Data
import XCTest
import CoreData
@testable import DoIt
/// Test the DatabaseManager against a Mock Database Manager.
///
/// Note that testing is done against a mock version of the database, linking
/// to the memory instead of the actual SQLite file.
///
/// - Author:
@rpapallas
rpapallas / cite.tex
Last active October 27, 2017 14:20
Cite numeric with author
\usepackage[numbers]{natbib}
\usepackage{cleveref}
\usepackage{hyperref}
\begin{document}
Some cite \cite{somepaper} and then with author et al \citet{somepaper}.
\bibliographystyle{unsrtnat}
\bibliography{refs}
\end{document}
@rpapallas
rpapallas / get_translation_and_rotation_xml.py
Last active March 5, 2018 13:50
OpenRAVE: Given a transform 2D list of an object it will return back the translation and rotation as separated XML elements to be used in an environment.xml file.
def get_xml(arr):
rotation = "<RotationMat>"
for row in range(0, 3):
for col in range(0, 3):
rotation += str(arr[row, col])
if row != 2 or col != 2: rotation += " "
rotation += "</RotationMat>"
translation = "<Translation>"
for row in range(0, 3):
@rpapallas
rpapallas / force_attribute_definition.py
Last active March 18, 2018 19:48
This will force the definition of a class attribute and will throw an error if not defined in Python.
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@rpapallas
rpapallas / rotation _matrices.txt
Created March 22, 2018 16:16
Rotation matrices by an angle θ about X, Y, Z axis
Rz(θ) =
[ cos θ -sin θ 0 ]
[ sin θ cos θ 0 ]
[ 0 0 1 ]
Ry(θ) =
[ cos θ 0 sin θ ]
[ 0 1 0 ]
[ -sin θ 0 cos θ ]
@rpapallas
rpapallas / save_env_to_file.py
Last active April 24, 2018 09:52
Export OpenRAVE Environment to XML File
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@rpapallas
rpapallas / trajectory_with_deltatime.cpp
Created September 10, 2018 13:02
OMPL to OpenRAVE Trajectory with custom delta times.
// Input:
// path: ompl::control::PathControl
// penv: OpenRAVE::EnvironmentBasePtr
// robot: OpenRAVE::RobotBasePtr
//
// Output: Will create an OpenRAVE trajectory from the OMPL PathControl and will also parse deltatimes.
TrajectoryBasePtr or_traj = RaveCreateTrajectory(penv, "");
auto configuration_specification = robot->GetActiveConfigurationSpecification();
configuration_specification.AddDeltaTimeGroup();