Skip to content

Instantly share code, notes, and snippets.

@matthieuheitz
matthieuheitz / djvu2pdf.sh
Last active June 12, 2023 12:47
djvu2pdf, a conversion script using ocrodjvu and pdfbeads
#!/bin/bash
# Method found here https://askubuntu.com/a/122604/423332
# Dependencies:
# On ubuntu, you can install ocrodjvu and pdfbeads with:
# sudo apt install ocrodjvu
# gem install pdfbeads
# The path and filename given can only contain ascii characters
@matthieuheitz
matthieuheitz / catch_fe_except.cpp
Created March 29, 2017 18:15
Catching Floating point exceptions
// For Linux machines
#include <fenv.h> // or <cfenv> but only for C++11
// Enable all exceptions except for INEXACT
feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT);
// More info at https://linux.die.net/man/3/feenableexcept
// For machines using SSE (Apple, etc.)
#include <xmmintrin.h>
// Disable only INVALID exception
@matthieuheitz
matthieuheitz / create_folder.sh
Created February 20, 2017 16:26
Bash - Avoid overwriting a folder and its content by creating indexed folders
# Avoid overwriting on output folder
if [ ! -d "$OUT_FOLDER_PATH" ]; then # If folder doesn't exist, create it
mkdir $OUT_FOLDER_PATH
else
cpt=0
OUT_FOLDER_PATH_NEW=$OUT_FOLDER_PATH
while [ "$(ls -A $OUT_FOLDER_PATH_NEW 2> /dev/null)" ] ; # while folder exist and is not empty
do
let cpt=cpt+1
echo $cpt
@matthieuheitz
matthieuheitz / jacobian.m
Last active February 2, 2017 18:45
Compute numerical derivatives on Matlab
% Jacobian functor
J = @(x,h,F)(F(repmat(x,size(x'))+diag(h))-F(repmat(x,size(x'))))./h';
% Function to differentiate
T = @(x) x./sum(x);
% Evaluation point
x = [0.9134;0.6324;0.0975;0.2785;0.5469];
% Step in each dimension (has to be small enough compared to x)
h = 1e-5*ones(size(x));
% Compute the Jacobian
@matthieuheitz
matthieuheitz / SpeedTest.cpp
Last active February 5, 2016 17:32
Timer functions to calculate execution time of a C/C++ program. Source: http://stackoverflow.com/questions/876901/calculating-execution-time-in-c
// MACRO
#include <time.h>
#ifndef SYSOUT_F
#define SYSOUT_F(f, ...) _RPT1( 0, f, __VA_ARGS__ ) // For Visual studio
#endif
#ifndef speedtest
#define speedtest(data) for (long blockTime = NULL; (blockTime == NULL ? (blockTime = clock()) != NULL : false); SYSOUT_F(data "%.9fs", (double) (clock() - blockTime) / CLOCKS_PER_SEC))
#endif
@matthieuheitz
matthieuheitz / python_resources.md
Last active August 29, 2015 14:20 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@matthieuheitz
matthieuheitz / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@matthieuheitz
matthieuheitz / QtSignalDebuging.cpp
Last active August 29, 2015 14:20
Custom slots to debug signals, verify if they are fired
#include <QMessageBox>
class myClass:
{
// Insert those slots in your myClass.h
public slots:
void displaySignal(QString);
void displaySignal(int);
void displaySignal(float);
void displaySignal(double);