Skip to content

Instantly share code, notes, and snippets.

@javidcf
javidcf / null_privacy_policy.txt
Created February 28, 2020 17:14
A privacy policy for when no data is stored
We do not (and cannot) store any personal information, nor use any third-party app or service that does so.
# Split a number into parts with a fixed size unit size
def split_number(number, parts, unit, min_units=0):
current = []
num_units = round(number / unit)
for c in _divide_number_rec(num_units, parts, min_units, current):
yield tuple(u * unit for u in c)
def _split_number_rec(num_units, parts, last_units, current):
if parts <= 0:
@javidcf
javidcf / MyServer.py
Created November 5, 2018 18:37
Basic msgpack server for Unreal Engine Python
import unreal_engine as ue
import asyncio
import threading
import queue
import msgpack
try:
import msgpack_numpy as mnp
mnp.patch()
@javidcf
javidcf / freeze_session.py
Last active April 20, 2018 05:13
Freeze an active TensorFlow session
def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
"""
Freezes the state of a session into a prunned computation graph.
Creates a new computation graph where variable nodes are replaced by
constants taking their current value in the session. The new graph will be
prunned so subgraphs that are not neccesary to compute the requested
outputs are removed.
@param session The TensorFlow session to be frozen.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@javidcf
javidcf / pseudoinverse.cpp
Last active July 27, 2022 21:21
Compute the pseudoinverse of a dense matrix with Eigen (C++11)
#include <Eigen/Dense>
template <class MatT>
Eigen::Matrix<typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime>
pseudoinverse(const MatT &mat, typename MatT::Scalar tolerance = typename MatT::Scalar{1e-4}) // choose appropriately
{
typedef typename MatT::Scalar Scalar;
auto svd = mat.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
const auto &singularValues = svd.singularValues();
Eigen::Matrix<Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> singularValuesInv(mat.cols(), mat.rows());
\documentclass{article}
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture}
\definecolor{gtRed}{RGB}{85,0,0}
@javidcf
javidcf / cpbar
Last active August 29, 2015 14:01
cpbar: cp with a progress bar
#!/bin/sh
# cpbar: cp with a progress bar
MAXCOLS=80
SLEEP=.5
if [ "$#" -ne 2 ]; then
echo "Usage: $(basename $0) <SOURCE> <DEST>" >&2
exit 1