Skip to content

Instantly share code, notes, and snippets.

View cjhanks's full-sized avatar
🔥

zeekoni cjhanks

🔥
View GitHub Profile
@cjhanks
cjhanks / solve2d.py
Created March 8, 2017 04:01
Sympy Solver Example
"""
Example recovering the C_x and C_y equations from OpenCV's rotation matrix
http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=getrotationmatrix2d#getrotationmatrix2d
"""
from sympy.solvers import solve
from sympy import Symbol, Eq, simplify
Alpha = Symbol('α')
@cjhanks
cjhanks / Makefile
Created February 8, 2017 20:57
Generic Makefile
CXX=g++
CPPFLAGS=
CXXFLAGS=-O3 -Wall -Wextra -Werror -flto -std=c++14 -g -DNDEBUG
LDFLAGS=-flto -g
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
SOURCES = \
src/main.cpp \
@cjhanks
cjhanks / matmul.py
Created January 22, 2017 23:54
Matmul
import numpy as np
R = np.array([[0, 1],
[1, 0]])
p = np.array([3, 5])
print(R @ p)
# > [5 3]
@cjhanks
cjhanks / example.hpp
Created October 4, 2016 22:21
Eigen3 OpenMP Declaraction
#pragma omp declare reduction( \
+: \
Matrix6d: \
omp_out= omp_out + omp_in) \
initializer(omp_priv=Matrix6d::Zero())
#pragma omp declare reduction( \
+: \
Vector6d: \
omp_out = omp_out + omp_in) \
initializer(omp_priv=Vector6d::Zero())
@cjhanks
cjhanks / remove.cpp
Last active October 4, 2016 22:22
FailCase
#include <cassert>
#include <iostream>
#include <map>
#include <unordered_map>
template <typename Map>
void
Remove(Map map)
{
@cjhanks
cjhanks / grid-data.js
Last active September 22, 2016 22:46
MakeJavaScriptFaster
const VerticesData = [
new Vertex(-12.9061002731, -0.974995017052, -1.30131995678),
new Vertex(-12.9061002731, -0.974995017052, 1.27499997616),
new Vertex(4.70302009583, -2.4135799408, -1.30131995678),
new Vertex(4.70302009583, -2.4135799408, 2.47499990463),
new Vertex(-14.3407001495, -2.97080993652, -1.30131995678),
new Vertex(-14.3407001495, -2.97080993652, 2.47499990463),
new Vertex(-13.8633003235, 7.62889003754, -1.30131995678),
new Vertex(-13.8633003235, 7.62889003754, 1.57500004768),
new Vertex(-7.00685977936, 13.7915000916, -1.30131995678),
@cjhanks
cjhanks / printit.cpp
Created September 1, 2016 17:28
NonCompliantCpp (I think)
#include <iostream>
template <typename Scalar>
void
print_bits(Scalar s)
{
static_assert(sizeof(Scalar) == 4, "NO no no ");
uint32_t* k = (uint32_t*)&s;
@cjhanks
cjhanks / StrToEnum.hpp
Created August 18, 2016 16:18
String To Enum
#include <iostream>
#include <map>
#include <string>
using std::string;
namespace {
enum class SomeThing {
BLUE,
@cjhanks
cjhanks / douglas_peuker.hpp
Created August 15, 2016 17:57
Generic Iterator Based Douglas Peucker
#ifndef DOUGLASS_PEUKER_H_
#define DOUGLASS_PEUKER_H_
#include <stack>
#include <tuple>
#include <vector>
/// @{
/// @tparam InputIterator Any STL style container
@cjhanks
cjhanks / example.cpp
Last active July 28, 2016 19:34
Overloading OSTREAM
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
std::vector<int> V;
template <typename Container1, typename Container2>
std::ostream&
operator<<(std::ostream& ostr, const std::pair<Container1&, Container2&> data)